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

Function TestNavigableExpr

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

Source from the content-addressed store, hash-verified

344}
345
346func TestNavigableExpr(t *testing.T) {
347 checkedAST := mustTypeCheck(t, `'a' == 'b'`)
348 navAST := ast.NavigateAST(checkedAST)
349 literals := ast.MatchDescendants(navAST, func(expr ast.NavigableExpr) bool {
350 return expr.Kind() == ast.LiteralKind &&
351 expr.AsLiteral().Equal(types.String("a")) == types.True
352 })
353 if len(literals) != 1 {
354 t.Fatalf("MatchDescendents('a') got %d results, wanted 1", len(literals))
355 }
356 litA := literals[0]
357 if litA.Depth() != 1 {
358 t.Fatalf("litA.Depth() got %d, wanted 1", litA.Depth())
359 }
360 parent, found := litA.Parent()
361 if !found {
362 t.Fatal("litA.Parent() returned nil")
363 }
364 if parent.Kind() != ast.CallKind && parent.AsCall().FunctionName() != "==" {
365 t.Fatalf("litA.Parent() got %v, watned '==' function call", parent)
366 }
367 litAPrime := ast.NavigateExpr(checkedAST, litA)
368 if litAPrime.Depth() != litA.Depth() {
369 t.Errorf("litAPrime.Depth() != litA.Depth(), got %d, wanted %d", litAPrime.Depth(), litA.Depth())
370 }
371}
372
373func TestNavigableCallExprMember(t *testing.T) {
374 checked := mustTypeCheck(t, `'hello'.size()`)

Callers

nothing calls this directly

Calls 12

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
StringTypeAlias · 0.92
NavigateExprFunction · 0.92
mustTypeCheckFunction · 0.85
KindMethod · 0.65
EqualMethod · 0.65
AsLiteralMethod · 0.65
DepthMethod · 0.65
ParentMethod · 0.65
FunctionNameMethod · 0.65
AsCallMethod · 0.65

Tested by

no test coverage detected