(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func TestInliningOptimizerPresenceTests(t *testing.T) { |
| 117 | type varExpr struct { |
| 118 | name string |
| 119 | alias string |
| 120 | t *cel.Type |
| 121 | expr string |
| 122 | } |
| 123 | tests := []struct { |
| 124 | name string |
| 125 | expr string |
| 126 | vars []varExpr |
| 127 | inlined string |
| 128 | }{ |
| 129 | { |
| 130 | name: "presence with bool literal", |
| 131 | expr: `has(msg.single_any.processing_purpose)`, |
| 132 | vars: []varExpr{ |
| 133 | { |
| 134 | name: "msg.single_any.processing_purpose", |
| 135 | t: cel.BoolType, |
| 136 | expr: "true", |
| 137 | }, |
| 138 | }, |
| 139 | inlined: `true != false`, |
| 140 | }, |
| 141 | { |
| 142 | name: "presence with bytes literal", |
| 143 | expr: `has(msg.single_any.processing_purpose)`, |
| 144 | vars: []varExpr{ |
| 145 | { |
| 146 | name: "msg.single_any.processing_purpose", |
| 147 | t: cel.BytesType, |
| 148 | expr: "b'abc'", |
| 149 | }, |
| 150 | }, |
| 151 | inlined: `b"\141\142\143".size() != 0`, |
| 152 | }, |
| 153 | { |
| 154 | name: "presence with double literal", |
| 155 | expr: `has(msg.single_any.processing_purpose)`, |
| 156 | vars: []varExpr{ |
| 157 | { |
| 158 | name: "msg.single_any.processing_purpose", |
| 159 | t: cel.DoubleType, |
| 160 | expr: "42.0", |
| 161 | }, |
| 162 | }, |
| 163 | inlined: `42.0 != 0.0`, |
| 164 | }, |
| 165 | { |
| 166 | name: "presence with duration literal", |
| 167 | expr: `has(msg.single_any.processing_purpose)`, |
| 168 | vars: []varExpr{ |
| 169 | { |
| 170 | name: "msg.single_any.processing_purpose", |
| 171 | t: cel.DurationType, |
| 172 | expr: "duration('1s')", |
| 173 | }, |
nothing calls this directly
no test coverage detected