(t *testing.T)
| 301 | } |
| 302 | |
| 303 | func TestSetsMembershipRewriter(t *testing.T) { |
| 304 | tests := []struct { |
| 305 | expr string |
| 306 | optimized string |
| 307 | opts []cel.EnvOption |
| 308 | in map[string]any |
| 309 | out ref.Val |
| 310 | }{ |
| 311 | { |
| 312 | expr: `a in [1, 2, 3, 4]`, |
| 313 | optimized: `a in {1: true, 2: true, 3: true, 4: true}`, |
| 314 | opts: []cel.EnvOption{ |
| 315 | cel.Variable("a", cel.IntType), |
| 316 | }, |
| 317 | in: map[string]any{ |
| 318 | "a": 3, |
| 319 | }, |
| 320 | out: types.True, |
| 321 | }, |
| 322 | { |
| 323 | expr: `a in ['1', '2', '3', 4]`, |
| 324 | optimized: `a in {"1": true, "2": true, "3": true, 4: true}`, |
| 325 | opts: []cel.EnvOption{ |
| 326 | cel.Variable("a", cel.IntType), |
| 327 | }, |
| 328 | in: map[string]any{ |
| 329 | "a": 3, |
| 330 | }, |
| 331 | out: types.False, |
| 332 | }, |
| 333 | { |
| 334 | expr: `a in [1u, '2', '3', 4]`, |
| 335 | optimized: `a in {1u: true, "2": true, "3": true, 4: true}`, |
| 336 | opts: []cel.EnvOption{ |
| 337 | cel.Variable("a", cel.IntType), |
| 338 | }, |
| 339 | in: map[string]any{ |
| 340 | "a": 4, |
| 341 | }, |
| 342 | out: types.True, |
| 343 | }, |
| 344 | { |
| 345 | expr: `a in [1u, 2.0, '3', 4]`, |
| 346 | optimized: `a in [1u, 2.0, "3", 4]`, |
| 347 | opts: []cel.EnvOption{ |
| 348 | cel.Variable("a", cel.IntType), |
| 349 | }, |
| 350 | in: map[string]any{ |
| 351 | "a": 4, |
| 352 | }, |
| 353 | out: types.True, |
| 354 | }, |
| 355 | { |
| 356 | expr: `a in [b, 32]`, |
| 357 | optimized: `a in [b, 32]`, |
| 358 | opts: []cel.EnvOption{ |
| 359 | cel.Variable("a", cel.IntType), |
| 360 | cel.Variable("b", cel.IntType), |
nothing calls this directly
no test coverage detected