(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func TestEval(t *testing.T) { |
| 99 | env, err := NewEnv( |
| 100 | Variable("input", ListType(IntType)), |
| 101 | CostEstimatorOptions( |
| 102 | checker.OverloadCostEstimate(overloads.TimestampToYear, estimateTimestampToYear), |
| 103 | ), |
| 104 | ) |
| 105 | if err != nil { |
| 106 | t.Fatalf("NewEnv() failed: %v", err) |
| 107 | } |
| 108 | tests := []struct { |
| 109 | expr string |
| 110 | in any |
| 111 | }{ |
| 112 | { |
| 113 | expr: `input.size() != 0`, |
| 114 | in: map[string]any{"input": []int{1, 2, 3}}, |
| 115 | }, |
| 116 | } |
| 117 | for i, tst := range tests { |
| 118 | tc := tst |
| 119 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 120 | ast, iss := env.Compile(tc.expr) |
| 121 | if iss.Err() != nil { |
| 122 | t.Fatalf("env.Compile(%s) failed: %v", tc.expr, iss.Err()) |
| 123 | } |
| 124 | ctx := context.Background() |
| 125 | prgOpts := []ProgramOption{ |
| 126 | CostTracking(testRuntimeCostEstimator{}), |
| 127 | CostTrackerOptions( |
| 128 | interpreter.OverloadCostTracker(overloads.TimestampToYear, trackTimestampToYear), |
| 129 | ), |
| 130 | EvalOptions(OptOptimize, OptTrackCost), |
| 131 | InterruptCheckFrequency(100), |
| 132 | } |
| 133 | prg, err := env.Program(ast, prgOpts...) |
| 134 | if err != nil { |
| 135 | t.Fatalf("env.Program() failed: %v", err) |
| 136 | } |
| 137 | for k := 0; k < 100; k++ { |
| 138 | t.Run(fmt.Sprintf("[%d]", k), func(t *testing.T) { |
| 139 | t.Parallel() |
| 140 | prg.Eval(tc.in) |
| 141 | evalCtx, cancel := context.WithTimeout(ctx, time.Minute) |
| 142 | defer cancel() |
| 143 | _, _, err := prg.ContextEval(evalCtx, tc.in) |
| 144 | if err != nil { |
| 145 | t.Fatalf("prg.ContextEval() failed: %v", err) |
| 146 | } |
| 147 | }) |
| 148 | } |
| 149 | }) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | func TestAbbrevsCompiled(t *testing.T) { |
| 154 | // Test whether abbreviations successfully resolve at type-check time (compile time). |
nothing calls this directly
no test coverage detected