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

Function TestNavigableCallExprGlobal

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

Source from the content-addressed store, hash-verified

410}
411
412func TestNavigableCallExprGlobal(t *testing.T) {
413 checked := mustTypeCheck(t, `size('hello')`)
414 expr := ast.NavigateAST(checked)
415 if expr.Kind() != ast.CallKind {
416 t.Errorf("Kind() got %v, wanted CallKind", expr.Kind())
417 }
418 call := expr.AsCall()
419 if call.FunctionName() != "size" {
420 t.Errorf("FunctionName() got %s, wanted size", call.FunctionName())
421 }
422 if call.IsMemberFunction() {
423 t.Fatal("IsMemberFunction() returned true, wanted false")
424 }
425 if len(call.Args()) != 1 {
426 t.Errorf("Args() got %v, wanted 1", call.Args())
427 }
428 arg := call.Args()[0]
429 if arg.Kind() != ast.LiteralKind {
430 t.Errorf("Kind() got %v, wanted literal", arg.Kind())
431 }
432 if arg.AsLiteral().Equal(types.String("hello")) != types.True {
433 t.Errorf("AsLiteral() got %v, wanted 'hello'", arg.AsLiteral())
434 }
435 if p, found := arg.(ast.NavigableExpr).Parent(); !found || p != expr {
436 t.Errorf("Parent() got %v, wanted %v", p, expr)
437 }
438 sizeFn := ast.MatchDescendants(expr, ast.FunctionMatcher("size"))
439 if len(sizeFn) != 1 {
440 t.Errorf("ast.MatchDescendants() size function returned %v, wanted 1", sizeFn)
441 }
442 constantValues := ast.MatchDescendants(expr, ast.ConstantValueMatcher())
443 if len(constantValues) != 1 {
444 t.Fatalf("ast.MatchDescendants() constant values returned %v, wanted 1 value", constantValues)
445 }
446 if constantValues[0].AsLiteral().Equal(types.String("hello")) != types.True {
447 t.Errorf("constantValues[0] got %v, wanted 'hello'", constantValues[0])
448 }
449}
450
451func TestNavigableListExpr(t *testing.T) {
452 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