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

Function TestOptimize_constant_folding

optimizer/fold_test.go:14–27  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestOptimize_constant_folding(t *testing.T) {
15 tree, err := parser.Parse(`[1,2,3][5*5-25]`)
16 require.NoError(t, err)
17
18 err = optimizer.Optimize(&tree.Node, nil)
19 require.NoError(t, err)
20
21 expected := &ast.MemberNode{
22 Node: &ast.ConstantNode{Value: []any{1, 2, 3}},
23 Property: &ast.IntegerNode{Value: 0},
24 }
25
26 assert.Equal(t, ast.Dump(expected), ast.Dump(tree.Node))
27}
28
29func TestOptimize_constant_folding_with_floats(t *testing.T) {
30 tree, err := parser.Parse(`1 + 2.0 * ((1.0 * 2) / 2) - 0`)

Callers

nothing calls this directly

Calls 5

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