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

Function TestOptimize_in_range

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

Source from the content-addressed store, hash-verified

113}
114
115func TestOptimize_in_range(t *testing.T) {
116 tree, err := parser.Parse(`age in 18..31`)
117 require.NoError(t, err)
118
119 config := conf.New(map[string]int{"age": 30})
120 _, err = checker.Check(tree, config)
121
122 err = optimizer.Optimize(&tree.Node, nil)
123 require.NoError(t, err)
124
125 left := &ast.IdentifierNode{
126 Value: "age",
127 }
128 expected := &ast.BinaryNode{
129 Operator: "and",
130 Left: &ast.BinaryNode{
131 Operator: ">=",
132 Left: left,
133 Right: &ast.IntegerNode{
134 Value: 18,
135 },
136 },
137 Right: &ast.BinaryNode{
138 Operator: "<=",
139 Left: left,
140 Right: &ast.IntegerNode{
141 Value: 31,
142 },
143 },
144 }
145
146 assert.Equal(t, ast.Dump(expected), ast.Dump(tree.Node))
147}
148
149func TestOptimize_in_range_with_floats(t *testing.T) {
150 out, err := expr.Eval(`f in 1..3`, map[string]any{"f": 1.5})

Callers

nothing calls this directly

Calls 7

ParseFunction · 0.92
NoErrorFunction · 0.92
NewFunction · 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…