(t *testing.T)
| 177 | } |
| 178 | |
| 179 | func TestAddLetFn(t *testing.T) { |
| 180 | eval, err := NewEvaluator() |
| 181 | if err != nil { |
| 182 | t.Fatalf("NewEvaluator() failed with: %v", err) |
| 183 | } |
| 184 | |
| 185 | err = eval.AddLetFn("fn", []letFunctionParam{ |
| 186 | {identifier: "x", typeHint: mustParseType(t, "int")}, |
| 187 | {identifier: "y", typeHint: mustParseType(t, "int")}}, |
| 188 | mustParseType(t, "int"), |
| 189 | "x * x - y * y") |
| 190 | if err != nil { |
| 191 | t.Fatalf("AddLetFn{fn(x: int, y: int): int -> x * x - y * y} = (err) %v", err) |
| 192 | } |
| 193 | |
| 194 | eval.AddLetVar("testcases", "[[1, 2], [2, 3], [3, 4], [10, 20]]", mustParseType(t, "list<list<int>>")) |
| 195 | |
| 196 | result, _, err := eval.Evaluate("testcases.all(e, fn(e[0], e[1]) == (e[0] - e[1]) * (e[0] + e[1]))") |
| 197 | |
| 198 | if err != nil { |
| 199 | t.Errorf("eval.Evaluate() got error %v wanted nil", err) |
| 200 | } else if !result.Value().(bool) { |
| 201 | t.Errorf("eval.Evaluate() got %v wanted true", result.Value()) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | func TestAddLetFnComposed(t *testing.T) { |
| 206 | eval, err := NewEvaluator() |
nothing calls this directly
no test coverage detected