MCPcopy
hub / github.com/expr-lang/expr / TestOptimize_in_array

Function TestOptimize_in_array

optimizer/optimizer_test.go:94–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestOptimize_in_array(t *testing.T) {
95 config := conf.New(map[string]int{"v": 0})
96
97 tree, err := parser.Parse(`v in [1,2,3]`)
98 require.NoError(t, err)
99
100 _, err = checker.Check(tree, config)
101 require.NoError(t, err)
102
103 err = optimizer.Optimize(&tree.Node, nil)
104 require.NoError(t, err)
105
106 expected := &ast.BinaryNode{
107 Operator: "in",
108 Left: &ast.IdentifierNode{Value: "v"},
109 Right: &ast.ConstantNode{Value: map[int]struct{}{1: {}, 2: {}, 3: {}}},
110 }
111
112 assert.Equal(t, ast.Dump(expected), ast.Dump(tree.Node))
113}
114
115func TestOptimize_in_range(t *testing.T) {
116 tree, err := parser.Parse(`age in 18..31`)

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
ParseFunction · 0.92
NoErrorFunction · 0.92
CheckFunction · 0.92
OptimizeFunction · 0.92
EqualFunction · 0.92
DumpFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…