(t *testing.T)
| 5702 | } |
| 5703 | |
| 5704 | func TestCostSizingStrategy(t *testing.T) { |
| 5705 | env, err := NewEnv( |
| 5706 | CostSizingStrategy(cost.AggregateSizingStrategy()), |
| 5707 | Variable("str", StringType), |
| 5708 | ) |
| 5709 | if err != nil { |
| 5710 | t.Fatalf("NewEnv failed: %v", err) |
| 5711 | } |
| 5712 | ast, iss := env.Compile(`str.startsWith("prefix")`) |
| 5713 | if iss.Err() != nil { |
| 5714 | t.Fatalf("Compile failed: %v", iss.Err()) |
| 5715 | } |
| 5716 | prg, err := env.Program(ast, CostTracking(nil)) |
| 5717 | if err != nil { |
| 5718 | t.Fatalf("Program failed: %v", err) |
| 5719 | } |
| 5720 | evalDetails := &EvalDetails{} |
| 5721 | res, valDetails, err := prg.Eval(map[string]any{ |
| 5722 | "str": "prefix_hello_world", |
| 5723 | }) |
| 5724 | if err != nil { |
| 5725 | t.Fatalf("Eval failed: %v", err) |
| 5726 | } |
| 5727 | if res != types.True { |
| 5728 | t.Errorf("got %v, want true", res) |
| 5729 | } |
| 5730 | evalDetails = valDetails |
| 5731 | actualCost := *evalDetails.ActualCost() |
| 5732 | if actualCost == 0 { |
| 5733 | t.Errorf("expected non-zero actual cost, got %d", actualCost) |
| 5734 | } |
| 5735 | } |
| 5736 | |
| 5737 | func TestCostModel(t *testing.T) { |
| 5738 | model1 := cost.MemberOverload(overloads.StartsWithString, |
nothing calls this directly
no test coverage detected