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

Function TestNavigableComprehensionExpr

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

Source from the content-addressed store, hash-verified

473}
474
475func TestNavigableComprehensionExpr(t *testing.T) {
476 checked := mustTypeCheck(t, `[true].exists(i, i)`)
477 expr := ast.NavigateAST(checked)
478 if expr.Kind() != ast.ComprehensionKind {
479 t.Errorf("Kind() got %v, wanted ComprehensionKind", expr.Kind())
480 }
481 comp := expr.AsComprehension()
482 iterRange := comp.IterRange()
483 if len(ast.MatchSubset([]ast.NavigableExpr{iterRange.(ast.NavigableExpr)}, ast.ConstantValueMatcher())) != 1 {
484 t.Errorf("IterRange() returned a non-constant list")
485 }
486 if comp.IterVar() != "i" {
487 t.Errorf("IterVar() got %s, wanted 'i'", comp.IterVar())
488 }
489 if comp.HasIterVar2() {
490 t.Error("HasIterVar2() returned true, wanted false")
491 }
492 if comp.IterVar2() != "" {
493 t.Errorf("IterVar2() returned %s, wanted empty string", comp.IterVar2())
494 }
495 if comp.AccuVar() != "@result" {
496 t.Errorf("AccuVar() got %s, wanted '@result'", comp.AccuVar())
497 }
498 if comp.AccuInit().AsLiteral() != types.False {
499 t.Errorf("AccuInit() returned %v, wanted false", comp.AccuInit().AsLiteral())
500 }
501 if comp.Result().Kind() != ast.IdentKind {
502 t.Errorf("Result() returned %v, wanted ident", comp.Result())
503 }
504 if comp.LoopCondition().Kind() != ast.CallKind {
505 t.Errorf("LoopCondition() returned %v, wanted call", comp.LoopCondition())
506 }
507 if comp.LoopStep().Kind() != ast.CallKind {
508 t.Errorf("LoopStep() returned %v, wanted call", comp.LoopStep())
509 }
510 if comp.Result().AsIdent() != "@result" {
511 t.Errorf("AsIdent() returned %v, wanted @result", comp.Result().AsIdent())
512 }
513}
514
515func TestNavigableSelectExpr(t *testing.T) {
516 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