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

Function TestNavigableExpr

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

Source from the content-addressed store, hash-verified

267}
268
269func TestNavigableExpr(t *testing.T) {
270 checkedAST := mustTypeCheck(t, `'a' == 'b'`)
271 navAST := ast.NavigateAST(checkedAST)
272 literals := ast.MatchDescendants(navAST, func(expr ast.NavigableExpr) bool {
273 return expr.Kind() == ast.LiteralKind &&
274 expr.AsLiteral().Equal(types.String("a")) == types.True
275 })
276 if len(literals) != 1 {
277 t.Fatalf("MatchDescendents('a') got %d results, wanted 1", len(literals))
278 }
279 litA := literals[0]
280 if litA.Depth() != 1 {
281 t.Fatalf("litA.Depth() got %d, wanted 1", litA.Depth())
282 }
283 parent, found := litA.Parent()
284 if !found {
285 t.Fatal("litA.Parent() returned nil")
286 }
287 if parent.Kind() != ast.CallKind && parent.AsCall().FunctionName() != "==" {
288 t.Fatalf("litA.Parent() got %v, watned '==' function call", parent)
289 }
290 litAPrime := ast.NavigateExpr(checkedAST, litA)
291 if litAPrime.Depth() != litA.Depth() {
292 t.Errorf("litAPrime.Depth() != litA.Depth(), got %d, wanted %d", litAPrime.Depth(), litA.Depth())
293 }
294}
295
296func TestNavigableCallExprMember(t *testing.T) {
297 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