(t *testing.T)
| 410 | } |
| 411 | |
| 412 | func 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 | |
| 451 | func TestNavigableListExpr(t *testing.T) { |
| 452 | checked := mustTypeCheck(t, `[[1], [2]]`) |
nothing calls this directly
no test coverage detected