(t *testing.T)
| 6273 | } |
| 6274 | |
| 6275 | func TestLateBoundFunctionVariableNamespace(t *testing.T) { |
| 6276 | // Late bindings are supplied in a namespace which is separate from variables, so the same |
| 6277 | // qualified name may refer to both a variable and a late-bound function. |
| 6278 | env, err := NewEnv( |
| 6279 | Variable("inc", IntType), |
| 6280 | Function("inc", Overload("inc_int", []*Type{IntType}, IntType, LateFunctionBinding())), |
| 6281 | ) |
| 6282 | if err != nil { |
| 6283 | t.Fatalf("NewEnv() failed: %v", err) |
| 6284 | } |
| 6285 | ast, iss := env.Compile("inc(inc)") |
| 6286 | if iss.Err() != nil { |
| 6287 | t.Fatalf("Compile() failed: %v", iss.Err()) |
| 6288 | } |
| 6289 | prg, err := env.Program(ast) |
| 6290 | if err != nil { |
| 6291 | t.Fatalf("Program() failed: %v", err) |
| 6292 | } |
| 6293 | act, err := FunctionVars(map[string]any{"inc": 41}, map[string]LateBoundFunction{ |
| 6294 | "inc": func(overloadID string, args ...ref.Val) ref.Val { |
| 6295 | return types.Int(args[0].(types.Int) + 1) |
| 6296 | }, |
| 6297 | }) |
| 6298 | if err != nil { |
| 6299 | t.Fatalf("FunctionVars() failed: %v", err) |
| 6300 | } |
| 6301 | out, _, err := prg.Eval(act) |
| 6302 | if err != nil { |
| 6303 | t.Fatalf("Eval() failed: %v", err) |
| 6304 | } |
| 6305 | if out.Equal(types.Int(42)) != types.True { |
| 6306 | t.Errorf("Eval() got %v, wanted 42", out) |
| 6307 | } |
| 6308 | } |
| 6309 | |
| 6310 | func TestLateBoundFunctionCost(t *testing.T) { |
| 6311 | env, err := NewEnv( |
nothing calls this directly
no test coverage detected