mirror of
https://github.com/MontFerret/ferret.git
synced 2025-08-13 19:52:52 +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:
@@ -6,7 +6,7 @@ import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
type UseCase struct {
|
||||
type TestCase struct {
|
||||
Expression string
|
||||
Expected any
|
||||
PreAssertion Assertion
|
||||
@@ -16,8 +16,8 @@ type UseCase struct {
|
||||
RawOutput bool
|
||||
}
|
||||
|
||||
func NewCase(expression string, expected any, assertion Assertion, desc ...string) UseCase {
|
||||
return UseCase{
|
||||
func NewCase(expression string, expected any, assertion Assertion, desc ...string) TestCase {
|
||||
return TestCase{
|
||||
Expression: expression,
|
||||
Expected: expected,
|
||||
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
|
||||
return uc
|
||||
}
|
@@ -2,8 +2,6 @@ package benchmarks_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func BenchmarkForSort(b *testing.B) {
|
||||
|
@@ -6,8 +6,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func BenchmarkFunctionCall(b *testing.B) {
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type BC = []vm.Instruction
|
||||
type UseCase = base.UseCase
|
||||
type UseCase = base.TestCase
|
||||
|
||||
var I = vm.NewInstruction
|
||||
var C = vm.NewConstant
|
||||
|
@@ -3,14 +3,15 @@ package vm_test
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func ForWhileHelpers() runtime.Functions {
|
||||
return runtime.NewFunctionsFromMap(map[string]runtime.Function{
|
||||
"UNTIL": StateFn[int](func(ctx context.Context, args ...runtime.Value) (runtime.Value, error) {
|
||||
state := GetFnState[int](ctx)
|
||||
"UNTIL": base.StateFn[int](func(ctx context.Context, args ...runtime.Value) (runtime.Value, error) {
|
||||
state := base.GetFnState[int](ctx)
|
||||
untilCounter := state.Get()
|
||||
|
||||
if untilCounter < int(runtime.ToIntSafe(ctx, args[0])) {
|
||||
@@ -24,8 +25,8 @@ func ForWhileHelpers() runtime.Functions {
|
||||
}, func(ctx context.Context) int {
|
||||
return 0
|
||||
}),
|
||||
"COUNTER": StateFn[int](func(ctx context.Context, args ...runtime.Value) (runtime.Value, error) {
|
||||
state := GetFnState[int](ctx)
|
||||
"COUNTER": base.StateFn[int](func(ctx context.Context, args ...runtime.Value) (runtime.Value, error) {
|
||||
state := base.GetFnState[int](ctx)
|
||||
counter := state.Get()
|
||||
counter++
|
||||
|
||||
|
@@ -5,11 +5,12 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/compiler"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
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 {
|
||||
return NewCase(expression, nil, ShouldBeCompilationError, desc...)
|
||||
return NewCase(expression, nil, base.ShouldBeCompilationError, desc...)
|
||||
}
|
||||
|
||||
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 {
|
||||
return NewCase(expression, expected, ShouldHaveSameItems)
|
||||
return NewCase(expression, expected, base.ShouldHaveSameItems)
|
||||
}
|
||||
|
||||
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() {
|
||||
prog, err := c.Compile(useCase.Expression)
|
||||
|
||||
if !ArePtrsEqual(useCase.PreAssertion, ShouldBeCompilationError) {
|
||||
if !base.ArePtrsEqual(useCase.PreAssertion, base.ShouldBeCompilationError) {
|
||||
So(err, ShouldBeNil)
|
||||
} else {
|
||||
So(err, ShouldBeError)
|
||||
@@ -132,10 +133,10 @@ func RunUseCasesWith(t *testing.T, c *compiler.Compiler, useCases []UseCase, opt
|
||||
options = append(options, opts...)
|
||||
|
||||
expected := useCase.Expected
|
||||
actual, err := Exec(prog, useCase.RawOutput, options...)
|
||||
actual, err := base.Exec(prog, useCase.RawOutput, options...)
|
||||
|
||||
for _, assertion := range useCase.Assertions {
|
||||
if ArePtrsEqual(assertion, ShouldBeError) {
|
||||
if base.ArePtrsEqual(assertion, ShouldBeError) {
|
||||
So(err, ShouldBeError)
|
||||
|
||||
if expected != nil {
|
||||
@@ -149,13 +150,13 @@ func RunUseCasesWith(t *testing.T, c *compiler.Compiler, useCases []UseCase, opt
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
if ArePtrsEqual(assertion, ShouldEqualJSON) {
|
||||
if base.ArePtrsEqual(assertion, ShouldEqualJSON) {
|
||||
expectedJ, err := j.Marshal(expected)
|
||||
So(err, ShouldBeNil)
|
||||
So(actual, ShouldEqualJSON, string(expectedJ))
|
||||
} else if ArePtrsEqual(assertion, ShouldHaveSameItems) {
|
||||
So(actual, ShouldHaveSameItems, expected)
|
||||
} else if ArePtrsEqual(assertion, ShouldBeNil) {
|
||||
} else if base.ArePtrsEqual(assertion, base.ShouldHaveSameItems) {
|
||||
So(actual, base.ShouldHaveSameItems, expected)
|
||||
} else if base.ArePtrsEqual(assertion, ShouldBeNil) {
|
||||
So(actual, ShouldBeNil)
|
||||
} else {
|
||||
So(actual, assertion, expected)
|
||||
|
@@ -3,8 +3,6 @@ package vm_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
)
|
||||
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestCollectAggregate(t *testing.T) {
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestForCollect(t *testing.T) {
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestForDistinct(t *testing.T) {
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestForFilter(t *testing.T) {
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestForLimit(t *testing.T) {
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestForNested(t *testing.T) {
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestForSort(t *testing.T) {
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestForTernaryExpression(t *testing.T) {
|
||||
|
@@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
)
|
||||
|
@@ -4,7 +4,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestForWhileFilter(t *testing.T) {
|
||||
|
@@ -3,8 +3,6 @@ package vm_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
)
|
||||
|
||||
|
@@ -3,8 +3,6 @@ package vm_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
)
|
||||
|
||||
|
@@ -6,8 +6,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestFunctionCall(t *testing.T) {
|
||||
|
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/parser"
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestArrayAllOperator(t *testing.T) {
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestEqualityOperators(t *testing.T) {
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestInOperator(t *testing.T) {
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestLikeOperator(t *testing.T) {
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestLogicalOperators(t *testing.T) {
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestMathOperators(t *testing.T) {
|
||||
|
@@ -5,8 +5,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/compiler"
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/compiler"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/compiler"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
gocontext "context"
|
||||
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestParam(t *testing.T) {
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestRange(t *testing.T) {
|
||||
|
@@ -3,8 +3,6 @@ package vm_test
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/compiler"
|
||||
"github.com/MontFerret/ferret/pkg/runtime"
|
||||
"github.com/MontFerret/ferret/pkg/vm"
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
|
||||
gocontext "context"
|
||||
|
||||
|
@@ -2,8 +2,6 @@ package vm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/MontFerret/ferret/test/integration/base"
|
||||
)
|
||||
|
||||
func TestWaitforEvent(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user