| 87 | } |
| 88 | |
| 89 | func 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 |
| 117 | func BenchmarkCountGtZero(b *testing.B) { |