(t *testing.T)
| 371 | } |
| 372 | |
| 373 | func 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 | |
| 412 | func TestNavigableCallExprGlobal(t *testing.T) { |
| 413 | checked := mustTypeCheck(t, `size('hello')`) |
nothing calls this directly
no test coverage detected