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

Function TestOptimize_count_no_optimization

optimizer/count_any_test.go:89–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestOptimize_count_no_optimization(t *testing.T) {
90 // These should NOT be optimized
91 tests := []string{
92 `count(items, .active) > 1`, // not > 0
93 `count(items, .active) >= 2`, // not >= 1
94 `count(items, .active) == 0`, // not optimized (none has overhead)
95 `count(items, .active) == 1`, // not == 0
96 `count(items, .active) < 1`, // not optimized (none has overhead)
97 `count(items, .active) <= 0`, // not optimized (none has overhead)
98 `count(items, .active) != 0`, // different operator
99 }
100
101 for _, code := range tests {
102 t.Run(code, func(t *testing.T) {
103 tree, err := parser.Parse(code)
104 require.NoError(t, err)
105
106 err = optimizer.Optimize(&tree.Node, nil)
107 require.NoError(t, err)
108
109 // Should still be a BinaryNode (not optimized to any)
110 _, ok := tree.Node.(*BinaryNode)
111 assert.True(t, ok, "expected BinaryNode, got %T", tree.Node)
112 })
113 }
114}
115
116// Benchmarks for count > 0 → any
117func BenchmarkCountGtZero(b *testing.B) {

Callers

nothing calls this directly

Calls 5

ParseFunction · 0.92
NoErrorFunction · 0.92
OptimizeFunction · 0.92
TrueFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…