1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-08-15 20:02:56 +02:00

Remove redundant base imports from integration tests and refactor usage of UseCase to TestCase for improved clarity and consistency.

This commit is contained in:
Tim Voronov
2025-07-02 13:30:01 -04:00
parent b95d39a552
commit 2f25e4e4be
35 changed files with 22 additions and 71 deletions

View File

@@ -6,7 +6,7 @@ import (
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
) )
type UseCase struct { type TestCase struct {
Expression string Expression string
Expected any Expected any
PreAssertion Assertion PreAssertion Assertion
@@ -16,8 +16,8 @@ type UseCase struct {
RawOutput bool RawOutput bool
} }
func NewCase(expression string, expected any, assertion Assertion, desc ...string) UseCase { func NewCase(expression string, expected any, assertion Assertion, desc ...string) TestCase {
return UseCase{ return TestCase{
Expression: expression, Expression: expression,
Expected: expected, Expected: expected,
Assertions: []Assertion{assertion}, Assertions: []Assertion{assertion},
@@ -25,7 +25,7 @@ func NewCase(expression string, expected any, assertion Assertion, desc ...strin
} }
} }
func Skip(uc UseCase) UseCase { func Skip(uc TestCase) TestCase {
uc.Skip = true uc.Skip = true
return uc return uc
} }

View File

@@ -2,8 +2,6 @@ package benchmarks_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func BenchmarkForSort(b *testing.B) { func BenchmarkForSort(b *testing.B) {

View File

@@ -6,8 +6,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func BenchmarkFunctionCall(b *testing.B) { func BenchmarkFunctionCall(b *testing.B) {

View File

@@ -6,7 +6,7 @@ import (
) )
type BC = []vm.Instruction type BC = []vm.Instruction
type UseCase = base.UseCase type UseCase = base.TestCase
var I = vm.NewInstruction var I = vm.NewInstruction
var C = vm.NewConstant var C = vm.NewConstant

View File

@@ -3,14 +3,15 @@ package vm_test
import ( import (
"context" "context"
"github.com/MontFerret/ferret/test/integration/base"
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func ForWhileHelpers() runtime.Functions { func ForWhileHelpers() runtime.Functions {
return runtime.NewFunctionsFromMap(map[string]runtime.Function{ return runtime.NewFunctionsFromMap(map[string]runtime.Function{
"UNTIL": StateFn[int](func(ctx context.Context, args ...runtime.Value) (runtime.Value, error) { "UNTIL": base.StateFn[int](func(ctx context.Context, args ...runtime.Value) (runtime.Value, error) {
state := GetFnState[int](ctx) state := base.GetFnState[int](ctx)
untilCounter := state.Get() untilCounter := state.Get()
if untilCounter < int(runtime.ToIntSafe(ctx, args[0])) { if untilCounter < int(runtime.ToIntSafe(ctx, args[0])) {
@@ -24,8 +25,8 @@ func ForWhileHelpers() runtime.Functions {
}, func(ctx context.Context) int { }, func(ctx context.Context) int {
return 0 return 0
}), }),
"COUNTER": StateFn[int](func(ctx context.Context, args ...runtime.Value) (runtime.Value, error) { "COUNTER": base.StateFn[int](func(ctx context.Context, args ...runtime.Value) (runtime.Value, error) {
state := GetFnState[int](ctx) state := base.GetFnState[int](ctx)
counter := state.Get() counter := state.Get()
counter++ counter++

View File

@@ -5,11 +5,12 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/MontFerret/ferret/test/integration/base"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/compiler"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func Case(expression string, expected any, desc ...string) UseCase { func Case(expression string, expected any, desc ...string) UseCase {
@@ -45,7 +46,7 @@ func SkipCaseRuntimeErrorAs(expression string, expected error, desc ...string) U
} }
func CaseCompilationError(expression string, desc ...string) UseCase { func CaseCompilationError(expression string, desc ...string) UseCase {
return NewCase(expression, nil, ShouldBeCompilationError, desc...) return NewCase(expression, nil, base.ShouldBeCompilationError, desc...)
} }
func SkipCaseCompilationError(expression string, desc ...string) UseCase { func SkipCaseCompilationError(expression string, desc ...string) UseCase {
@@ -73,7 +74,7 @@ func SkipCaseArray(expression string, expected []any, desc ...string) UseCase {
} }
func CaseItems(expression string, expected ...any) UseCase { func CaseItems(expression string, expected ...any) UseCase {
return NewCase(expression, expected, ShouldHaveSameItems) return NewCase(expression, expected, base.ShouldHaveSameItems)
} }
func CaseFn(expression string, assertion func(actual any, expected ...any) string) UseCase { func CaseFn(expression string, assertion func(actual any, expected ...any) string) UseCase {
@@ -118,7 +119,7 @@ func RunUseCasesWith(t *testing.T, c *compiler.Compiler, useCases []UseCase, opt
Convey(useCase.Expression, t, func() { Convey(useCase.Expression, t, func() {
prog, err := c.Compile(useCase.Expression) prog, err := c.Compile(useCase.Expression)
if !ArePtrsEqual(useCase.PreAssertion, ShouldBeCompilationError) { if !base.ArePtrsEqual(useCase.PreAssertion, base.ShouldBeCompilationError) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
} else { } else {
So(err, ShouldBeError) So(err, ShouldBeError)
@@ -132,10 +133,10 @@ func RunUseCasesWith(t *testing.T, c *compiler.Compiler, useCases []UseCase, opt
options = append(options, opts...) options = append(options, opts...)
expected := useCase.Expected expected := useCase.Expected
actual, err := Exec(prog, useCase.RawOutput, options...) actual, err := base.Exec(prog, useCase.RawOutput, options...)
for _, assertion := range useCase.Assertions { for _, assertion := range useCase.Assertions {
if ArePtrsEqual(assertion, ShouldBeError) { if base.ArePtrsEqual(assertion, ShouldBeError) {
So(err, ShouldBeError) So(err, ShouldBeError)
if expected != nil { if expected != nil {
@@ -149,13 +150,13 @@ func RunUseCasesWith(t *testing.T, c *compiler.Compiler, useCases []UseCase, opt
So(err, ShouldBeNil) So(err, ShouldBeNil)
if ArePtrsEqual(assertion, ShouldEqualJSON) { if base.ArePtrsEqual(assertion, ShouldEqualJSON) {
expectedJ, err := j.Marshal(expected) expectedJ, err := j.Marshal(expected)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(actual, ShouldEqualJSON, string(expectedJ)) So(actual, ShouldEqualJSON, string(expectedJ))
} else if ArePtrsEqual(assertion, ShouldHaveSameItems) { } else if base.ArePtrsEqual(assertion, base.ShouldHaveSameItems) {
So(actual, ShouldHaveSameItems, expected) So(actual, base.ShouldHaveSameItems, expected)
} else if ArePtrsEqual(assertion, ShouldBeNil) { } else if base.ArePtrsEqual(assertion, ShouldBeNil) {
So(actual, ShouldBeNil) So(actual, ShouldBeNil)
} else { } else {
So(actual, assertion, expected) So(actual, assertion, expected)

View File

@@ -3,8 +3,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
) )

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestCollectAggregate(t *testing.T) { func TestCollectAggregate(t *testing.T) {

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestForCollect(t *testing.T) { func TestForCollect(t *testing.T) {

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestForDistinct(t *testing.T) { func TestForDistinct(t *testing.T) {

View File

@@ -6,7 +6,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestForFilter(t *testing.T) { func TestForFilter(t *testing.T) {

View File

@@ -6,7 +6,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestForLimit(t *testing.T) { func TestForLimit(t *testing.T) {

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestForNested(t *testing.T) { func TestForNested(t *testing.T) {

View File

@@ -6,7 +6,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestForSort(t *testing.T) { func TestForSort(t *testing.T) {

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestForTernaryExpression(t *testing.T) { func TestForTernaryExpression(t *testing.T) {

View File

@@ -4,8 +4,6 @@ import (
"context" "context"
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
) )

View File

@@ -4,7 +4,6 @@ import (
"testing" "testing"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestForWhileFilter(t *testing.T) { func TestForWhileFilter(t *testing.T) {

View File

@@ -3,8 +3,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
) )

View File

@@ -3,8 +3,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
) )

View File

@@ -6,8 +6,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestFunctionCall(t *testing.T) { func TestFunctionCall(t *testing.T) {

View File

@@ -12,7 +12,6 @@ import (
"github.com/MontFerret/ferret/pkg/parser" "github.com/MontFerret/ferret/pkg/parser"
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
) )

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestArrayAllOperator(t *testing.T) { func TestArrayAllOperator(t *testing.T) {

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestEqualityOperators(t *testing.T) { func TestEqualityOperators(t *testing.T) {

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestInOperator(t *testing.T) { func TestInOperator(t *testing.T) {

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestLikeOperator(t *testing.T) { func TestLikeOperator(t *testing.T) {

View File

@@ -7,7 +7,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestLogicalOperators(t *testing.T) { func TestLogicalOperators(t *testing.T) {

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestMathOperators(t *testing.T) { func TestMathOperators(t *testing.T) {

View File

@@ -5,8 +5,6 @@ import (
"fmt" "fmt"
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
"github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/compiler"
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"

View File

@@ -6,7 +6,6 @@ import (
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/compiler"
. "github.com/MontFerret/ferret/test/integration/base"
"testing" "testing"
) )

View File

@@ -5,7 +5,6 @@ import (
"github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/compiler"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
gocontext "context" gocontext "context"

View File

@@ -5,7 +5,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestParam(t *testing.T) { func TestParam(t *testing.T) {

View File

@@ -5,7 +5,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestRange(t *testing.T) { func TestRange(t *testing.T) {

View File

@@ -3,8 +3,6 @@ package vm_test
import ( import (
"fmt" "fmt"
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestString(t *testing.T) { func TestString(t *testing.T) {

View File

@@ -7,7 +7,6 @@ import (
"github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/compiler"
"github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/vm" "github.com/MontFerret/ferret/pkg/vm"
. "github.com/MontFerret/ferret/test/integration/base"
gocontext "context" gocontext "context"

View File

@@ -2,8 +2,6 @@ package vm_test
import ( import (
"testing" "testing"
. "github.com/MontFerret/ferret/test/integration/base"
) )
func TestWaitforEvent(t *testing.T) { func TestWaitforEvent(t *testing.T) {