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

Function TestNavigableCallExprMember

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

Source from the content-addressed store, hash-verified

294}
295
296func TestNavigableCallExprMember(t *testing.T) {
297 checked := mustTypeCheck(t, `'hello'.size()`)
298 expr := ast.NavigateAST(checked)
299 if expr.Kind() != ast.CallKind {
300 t.Errorf("Kind() got %v, wanted CallKind", expr.Kind())
301 }
302 call := expr.AsCall()
303 if call.FunctionName() != "size" {
304 t.Errorf("FunctionName() got %s, wanted size", call.FunctionName())
305 }
306 if call.Target() == nil {
307 t.Fatalf("Target() got nil, wanted non-nil")
308 }
309 if len(call.Args()) != 0 {
310 t.Errorf("Args() got %v, wanted 0", call.Args())
311 }
312 target := call.Target()
313 if target.Kind() != ast.LiteralKind {
314 t.Errorf("Kind() got %v, wanted literal", target.Kind())
315 }
316 if target.AsLiteral().Equal(types.String("hello")) != types.True {
317 t.Errorf("AsLiteral() got %v, wanted 'hello'", target.AsLiteral())
318 }
319 if p, found := target.(ast.NavigableExpr).Parent(); !found || p != expr {
320 t.Errorf("Parent() got %v, wanted %v", p, expr)
321 }
322 sizeFn := ast.MatchDescendants(expr, ast.FunctionMatcher("size"))
323 if len(sizeFn) != 1 {
324 t.Errorf("ast.MatchDescendants() size function returned %v, wanted 1", sizeFn)
325 }
326 constantValues := ast.MatchDescendants(expr, ast.ConstantValueMatcher())
327 if len(constantValues) != 1 {
328 t.Fatalf("ast.MatchDescendants() constant values returned %v, wanted 1 value", constantValues)
329 }
330 if constantValues[0].AsLiteral().Equal(types.String("hello")) != types.True {
331 t.Errorf("constantValues[0] got %v, wanted 'hello'", constantValues[0])
332 }
333}
334
335func TestNavigableCallExprGlobal(t *testing.T) {
336 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