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

Function TestOptimize_const_expr

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

Source from the content-addressed store, hash-verified

153}
154
155func TestOptimize_const_expr(t *testing.T) {
156 tree, err := parser.Parse(`toUpper("hello")`)
157 require.NoError(t, err)
158
159 env := map[string]any{
160 "toUpper": strings.ToUpper,
161 }
162
163 config := conf.New(env)
164 config.ConstExpr("toUpper")
165
166 err = optimizer.Optimize(&tree.Node, config)
167 require.NoError(t, err)
168
169 expected := &ast.ConstantNode{
170 Value: "HELLO",
171 }
172
173 assert.Equal(t, ast.Dump(expected), ast.Dump(tree.Node))
174}
175
176func TestOptimize_filter_len(t *testing.T) {
177 tree, err := parser.Parse(`len(filter(users, .Name == "Bob"))`)

Callers

nothing calls this directly

Calls 7

ParseFunction · 0.92
NoErrorFunction · 0.92
NewFunction · 0.92
OptimizeFunction · 0.92
EqualFunction · 0.92
DumpFunction · 0.92
ConstExprMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…