MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestSetsMembershipRewriter

Function TestSetsMembershipRewriter

ext/sets_test.go:303–469  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

301}
302
303func 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),

Callers

nothing calls this directly

Calls 12

OptimizeMethod · 0.95
VariableFunction · 0.92
ContainerFunction · 0.92
TypesFunction · 0.92
NewStaticOptimizerFunction · 0.92
AstToStringFunction · 0.92
testSetsEnvFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
CompileMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected