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

Function TestNavigableCallExprGlobal

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

Source from the content-addressed store, hash-verified

333}
334
335func TestNavigableCallExprGlobal(t *testing.T) {
336 checked := mustTypeCheck(t, `size('hello')`)
337 expr := ast.NavigateAST(checked)
338 if expr.Kind() != ast.CallKind {
339 t.Errorf("Kind() got %v, wanted CallKind", expr.Kind())
340 }
341 call := expr.AsCall()
342 if call.FunctionName() != "size" {
343 t.Errorf("FunctionName() got %s, wanted size", call.FunctionName())
344 }
345 if call.IsMemberFunction() {
346 t.Fatal("IsMemberFunction() returned true, wanted false")
347 }
348 if len(call.Args()) != 1 {
349 t.Errorf("Args() got %v, wanted 1", call.Args())
350 }
351 arg := call.Args()[0]
352 if arg.Kind() != ast.LiteralKind {
353 t.Errorf("Kind() got %v, wanted literal", arg.Kind())
354 }
355 if arg.AsLiteral().Equal(types.String("hello")) != types.True {
356 t.Errorf("AsLiteral() got %v, wanted 'hello'", arg.AsLiteral())
357 }
358 if p, found := arg.(ast.NavigableExpr).Parent(); !found || p != expr {
359 t.Errorf("Parent() got %v, wanted %v", p, expr)
360 }
361 sizeFn := ast.MatchDescendants(expr, ast.FunctionMatcher("size"))
362 if len(sizeFn) != 1 {
363 t.Errorf("ast.MatchDescendants() size function returned %v, wanted 1", sizeFn)
364 }
365 constantValues := ast.MatchDescendants(expr, ast.ConstantValueMatcher())
366 if len(constantValues) != 1 {
367 t.Fatalf("ast.MatchDescendants() constant values returned %v, wanted 1 value", constantValues)
368 }
369 if constantValues[0].AsLiteral().Equal(types.String("hello")) != types.True {
370 t.Errorf("constantValues[0] got %v, wanted 'hello'", constantValues[0])
371 }
372}
373
374func TestNavigableListExpr(t *testing.T) {
375 checked := mustTypeCheck(t, `[[1], [2]]`)

Callers

nothing calls this directly

Calls 14

NavigateASTFunction · 0.92
StringTypeAlias · 0.92
MatchDescendantsFunction · 0.92
FunctionMatcherFunction · 0.92
ConstantValueMatcherFunction · 0.92
mustTypeCheckFunction · 0.85
KindMethod · 0.65
AsCallMethod · 0.65
FunctionNameMethod · 0.65
IsMemberFunctionMethod · 0.65
ArgsMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected