completed list-type to array-type conversion and fixed common test module

This commit is contained in:
2026-07-13 10:42:17 +02:00
parent 77f36642b4
commit 072fd9af39
39 changed files with 160 additions and 318 deletions
+35 -6
View File
@@ -6,6 +6,8 @@ package expr
import (
"errors"
"path"
"runtime"
"strings"
"testing"
@@ -19,9 +21,27 @@ type inputType struct {
wantErr any
}
func getSourceName(startFrame int) (sourcename string) {
for i := startFrame; i < 10; i++ {
_, sourcepath, _, ok := runtime.Caller(i)
if !ok {
break
}
sourcename = path.Base(sourcepath)
if sourcename != "t_common_test.go" {
break
}
}
return
}
func RunCtxTestSuiteSpec(t *testing.T, ctx kern.ExprContext, section string, inputs []inputType, spec ...int) {
succeeded := 0
failed := 0
sourcename := getSourceName(2)
t.Logf("Test suite %s from file %s", section, sourcename)
for _, count := range spec {
index := count - 1
if index >= 0 && index < len(inputs) {
@@ -49,6 +69,10 @@ func RunCtxTestSuite(t *testing.T, ctx kern.ExprContext, section string, inputs
succeeded := 0
failed := 0
sourcename := getSourceName(2)
t.Logf("Test suite %s from file %s", section, sourcename)
for i, input := range inputs {
// fmt.Printf("%3d: %s\n", i+1, input.source)
@@ -61,7 +85,7 @@ func RunCtxTestSuite(t *testing.T, ctx kern.ExprContext, section string, inputs
}
t.Logf("%s -- test count: %d, succeeded: %d, failed: %d", section, len(inputs), succeeded, failed)
}
func runTestSuite(t *testing.T, section string, inputs []inputType) {
func RunTestSuite(t *testing.T, section string, inputs []inputType) {
RunCtxTestSuite(t, nil, section, inputs)
}
@@ -98,16 +122,21 @@ func doTest(t *testing.T, ctx kern.ExprContext, section string, input *inputType
gotResult, gotErr = ast.Eval(ctx)
}
if gotErr == nil && wantErr != nil {
eq := kern.Equal(gotResult, input.wantResult)
if gotErr == nil {
if wantErr == nil {
eq := kern.Equal(gotResult, input.wantResult)
if !eq /*gotResult != input.wantResult*/ {
t.Errorf(">>>%s/%d: `%s` -> result = %v [%s], want = %v [%s]", section, count, input.source, gotResult, kern.TypeName(gotResult), input.wantResult, kern.TypeName(input.wantResult))
if !eq /*gotResult != input.wantResult*/ {
t.Errorf(">>>%s/%d: `%s` -> result = %v [%s], want = %v [%s]", section, count, input.source, gotResult, kern.TypeName(gotResult), input.wantResult, kern.TypeName(input.wantResult))
good = false
}
} else {
t.Errorf(">>>%s/%d: `%s` -> got-err = <nil>, expected-err = %v [%s]", section, count, input.source, input.wantResult, kern.TypeName(input.wantResult))
good = false
}
}
if gotErr != wantErr {
if good && gotErr != wantErr {
if wantErr == nil || gotErr == nil || (gotErr.Error() != wantErr.Error()) {
t.Errorf(">>>%s/%d: %s -> got-err = <%v>, expected-err = <%v>", section, count, input.source, gotErr, wantErr)
good = false