MCPcopy Create free account
hub / github.com/expr-lang/expr / TestOptimize_predicate_combination_nested

Function TestOptimize_predicate_combination_nested

optimizer/optimizer_test.go:413–460  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

411}
412
413func TestOptimize_predicate_combination_nested(t *testing.T) {
414 tree, err := parser.Parse(`all(users, {all(.Friends, {.Age == 18 })}) && all(users, {all(.Friends, {.Name != "Bob" })})`)
415 require.NoError(t, err)
416
417 err = optimizer.Optimize(&tree.Node, nil)
418 require.NoError(t, err)
419
420 expected := &ast.BuiltinNode{
421 Name: "all",
422 Arguments: []ast.Node{
423 &ast.IdentifierNode{Value: "users"},
424 &ast.PredicateNode{
425 Node: &ast.BuiltinNode{
426 Name: "all",
427 Arguments: []ast.Node{
428 &ast.MemberNode{
429 Node: &ast.PointerNode{},
430 Property: &ast.StringNode{Value: "Friends"},
431 },
432 &ast.PredicateNode{
433 Node: &ast.BinaryNode{
434 Operator: "&&",
435 Left: &ast.BinaryNode{
436 Operator: "==",
437 Left: &ast.MemberNode{
438 Node: &ast.PointerNode{},
439 Property: &ast.StringNode{Value: "Age"},
440 },
441 Right: &ast.IntegerNode{Value: 18},
442 },
443 Right: &ast.BinaryNode{
444 Operator: "!=",
445 Left: &ast.MemberNode{
446 Node: &ast.PointerNode{},
447 Property: &ast.StringNode{Value: "Name"},
448 },
449 Right: &ast.StringNode{Value: "Bob"},
450 },
451 },
452 },
453 },
454 },
455 },
456 },
457 }
458
459 assert.Equal(t, ast.Dump(expected), ast.Dump(tree.Node))
460}

Callers

nothing calls this directly

Calls 5

ParseFunction · 0.92
NoErrorFunction · 0.92
OptimizeFunction · 0.92
EqualFunction · 0.92
DumpFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…