import() function added
This commit is contained in:
+15
-8
@@ -130,11 +130,16 @@ func TestParser(t *testing.T) {
|
||||
/* 109 */ {`double=func(x){2*x}; double(3)`, int64(6), nil},
|
||||
/* 110 */ {`double=func(x){2*x}; a=5; double(3+a) + 1`, int64(17), nil},
|
||||
/* 111 */ {`double=func(x){2*x}; a=5; two=func() {2}; (double(3+a) + 1) * two()`, int64(34), nil},
|
||||
/* 112 */ {`import("./test-funcs.expr"); (double(3+a) + 1) * two()`, int64(34), nil},
|
||||
/* 113 */ {`import("test-funcs.expr"); (double(3+a) + 1) * two()`, int64(34), nil},
|
||||
}
|
||||
check_env_expr_path := 113
|
||||
|
||||
succeeded := 0
|
||||
failed := 0
|
||||
|
||||
// inputs1 := []inputType{
|
||||
// {`import("./test-funcs.expr"); (double(3+a) + 1) * two()`, int64(34), nil},
|
||||
// {`add(1,2,3)`, int64(6), nil},
|
||||
// {`a=5; a`, int64(5), nil},
|
||||
// {`a=5; b=2; add(a, b*3)`, int64(11), nil},
|
||||
@@ -150,6 +155,7 @@ func TestParser(t *testing.T) {
|
||||
ctx.SetValue("var1", int64(123))
|
||||
ctx.SetValue("var2", "abc")
|
||||
importMathFuncs(ctx)
|
||||
importImportFunc(ctx)
|
||||
parser := NewParser(ctx)
|
||||
|
||||
logTest(t, i+1, input.source, input.wantResult, input.wantErr)
|
||||
@@ -178,6 +184,9 @@ func TestParser(t *testing.T) {
|
||||
succeeded++
|
||||
} else {
|
||||
failed++
|
||||
if i+1 == check_env_expr_path {
|
||||
t.Logf(`NOTICE: Test nr %d requires EXPR_PATH environment variable with value "."`, check_env_expr_path)
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Log(fmt.Sprintf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed))
|
||||
@@ -190,13 +199,6 @@ func TestListParser(t *testing.T) {
|
||||
wantErr error
|
||||
}
|
||||
|
||||
// ctx := newTestContext()
|
||||
ctx := NewSimpleFuncStore()
|
||||
ctx.SetValue("var1", int64(123))
|
||||
ctx.SetValue("var2", "abc")
|
||||
// ctx.addFunc("add", addFunc)
|
||||
importMathFuncs(ctx)
|
||||
|
||||
// inputs1 := []inputType{
|
||||
// {`add(1,2,3)`, int64(6), nil},
|
||||
// }
|
||||
@@ -220,12 +222,17 @@ func TestListParser(t *testing.T) {
|
||||
succeeded := 0
|
||||
failed := 0
|
||||
|
||||
parser := NewParser(ctx)
|
||||
for i, input := range inputs {
|
||||
var expr *ast
|
||||
var gotResult any
|
||||
var gotErr error
|
||||
|
||||
ctx := NewSimpleFuncStore()
|
||||
ctx.SetValue("var1", int64(123))
|
||||
ctx.SetValue("var2", "abc")
|
||||
importMathFuncs(ctx)
|
||||
parser := NewParser(ctx)
|
||||
|
||||
logTest(t, i+1, input.source, input.wantResult, input.wantErr)
|
||||
|
||||
r := strings.NewReader(input.source)
|
||||
|
||||
Reference in New Issue
Block a user