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

Function TestNavigableComprehensionExpr

common/ast/navigable_test.go:552–590  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

550}
551
552func TestNavigableComprehensionExpr(t *testing.T) {
553 checked := mustTypeCheck(t, `[true].exists(i, i)`)
554 expr := ast.NavigateAST(checked)
555 if expr.Kind() != ast.ComprehensionKind {
556 t.Errorf("Kind() got %v, wanted ComprehensionKind", expr.Kind())
557 }
558 comp := expr.AsComprehension()
559 iterRange := comp.IterRange()
560 if len(ast.MatchSubset([]ast.NavigableExpr{iterRange.(ast.NavigableExpr)}, ast.ConstantValueMatcher())) != 1 {
561 t.Errorf("IterRange() returned a non-constant list")
562 }
563 if comp.IterVar() != "i" {
564 t.Errorf("IterVar() got %s, wanted 'i'", comp.IterVar())
565 }
566 if comp.HasIterVar2() {
567 t.Error("HasIterVar2() returned true, wanted false")
568 }
569 if comp.IterVar2() != "" {
570 t.Errorf("IterVar2() returned %s, wanted empty string", comp.IterVar2())
571 }
572 if comp.AccuVar() != "@result" {
573 t.Errorf("AccuVar() got %s, wanted '@result'", comp.AccuVar())
574 }
575 if comp.AccuInit().AsLiteral() != types.False {
576 t.Errorf("AccuInit() returned %v, wanted false", comp.AccuInit().AsLiteral())
577 }
578 if comp.Result().Kind() != ast.IdentKind {
579 t.Errorf("Result() returned %v, wanted ident", comp.Result())
580 }
581 if comp.LoopCondition().Kind() != ast.CallKind {
582 t.Errorf("LoopCondition() returned %v, wanted call", comp.LoopCondition())
583 }
584 if comp.LoopStep().Kind() != ast.CallKind {
585 t.Errorf("LoopStep() returned %v, wanted call", comp.LoopStep())
586 }
587 if comp.Result().AsIdent() != "@result" {
588 t.Errorf("AsIdent() returned %v, wanted @result", comp.Result().AsIdent())
589 }
590}
591
592func TestNavigableSelectExpr(t *testing.T) {
593 checked := mustTypeCheck(t, `msg.single_int32`)

Callers

nothing calls this directly

Calls 15

NavigateASTFunction · 0.92
MatchSubsetFunction · 0.92
ConstantValueMatcherFunction · 0.92
mustTypeCheckFunction · 0.85
KindMethod · 0.65
AsComprehensionMethod · 0.65
IterRangeMethod · 0.65
IterVarMethod · 0.65
HasIterVar2Method · 0.65
IterVar2Method · 0.65
AccuVarMethod · 0.65
AsLiteralMethod · 0.65

Tested by

no test coverage detected