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

Function TestNavigableCallExprMember

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

Source from the content-addressed store, hash-verified

371}
372
373func TestNavigableCallExprMember(t *testing.T) {
374 checked := mustTypeCheck(t, `'hello'.size()`)
375 expr := ast.NavigateAST(checked)
376 if expr.Kind() != ast.CallKind {
377 t.Errorf("Kind() got %v, wanted CallKind", expr.Kind())
378 }
379 call := expr.AsCall()
380 if call.FunctionName() != "size" {
381 t.Errorf("FunctionName() got %s, wanted size", call.FunctionName())
382 }
383 if call.Target() == nil {
384 t.Fatalf("Target() got nil, wanted non-nil")
385 }
386 if len(call.Args()) != 0 {
387 t.Errorf("Args() got %v, wanted 0", call.Args())
388 }
389 target := call.Target()
390 if target.Kind() != ast.LiteralKind {
391 t.Errorf("Kind() got %v, wanted literal", target.Kind())
392 }
393 if target.AsLiteral().Equal(types.String("hello")) != types.True {
394 t.Errorf("AsLiteral() got %v, wanted 'hello'", target.AsLiteral())
395 }
396 if p, found := target.(ast.NavigableExpr).Parent(); !found || p != expr {
397 t.Errorf("Parent() got %v, wanted %v", p, expr)
398 }
399 sizeFn := ast.MatchDescendants(expr, ast.FunctionMatcher("size"))
400 if len(sizeFn) != 1 {
401 t.Errorf("ast.MatchDescendants() size function returned %v, wanted 1", sizeFn)
402 }
403 constantValues := ast.MatchDescendants(expr, ast.ConstantValueMatcher())
404 if len(constantValues) != 1 {
405 t.Fatalf("ast.MatchDescendants() constant values returned %v, wanted 1 value", constantValues)
406 }
407 if constantValues[0].AsLiteral().Equal(types.String("hello")) != types.True {
408 t.Errorf("constantValues[0] got %v, wanted 'hello'", constantValues[0])
409 }
410}
411
412func TestNavigableCallExprGlobal(t *testing.T) {
413 checked := mustTypeCheck(t, `size('hello')`)

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
TargetMethod · 0.65
ArgsMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected