(t *testing.T)
| 333 | } |
| 334 | |
| 335 | func TestNavigableCallExprGlobal(t *testing.T) { |
| 336 | checked := mustTypeCheck(t, `size('hello')`) |
| 337 | expr := ast.NavigateAST(checked) |
| 338 | if expr.Kind() != ast.CallKind { |
| 339 | t.Errorf("Kind() got %v, wanted CallKind", expr.Kind()) |
| 340 | } |
| 341 | call := expr.AsCall() |
| 342 | if call.FunctionName() != "size" { |
| 343 | t.Errorf("FunctionName() got %s, wanted size", call.FunctionName()) |
| 344 | } |
| 345 | if call.IsMemberFunction() { |
| 346 | t.Fatal("IsMemberFunction() returned true, wanted false") |
| 347 | } |
| 348 | if len(call.Args()) != 1 { |
| 349 | t.Errorf("Args() got %v, wanted 1", call.Args()) |
| 350 | } |
| 351 | arg := call.Args()[0] |
| 352 | if arg.Kind() != ast.LiteralKind { |
| 353 | t.Errorf("Kind() got %v, wanted literal", arg.Kind()) |
| 354 | } |
| 355 | if arg.AsLiteral().Equal(types.String("hello")) != types.True { |
| 356 | t.Errorf("AsLiteral() got %v, wanted 'hello'", arg.AsLiteral()) |
| 357 | } |
| 358 | if p, found := arg.(ast.NavigableExpr).Parent(); !found || p != expr { |
| 359 | t.Errorf("Parent() got %v, wanted %v", p, expr) |
| 360 | } |
| 361 | sizeFn := ast.MatchDescendants(expr, ast.FunctionMatcher("size")) |
| 362 | if len(sizeFn) != 1 { |
| 363 | t.Errorf("ast.MatchDescendants() size function returned %v, wanted 1", sizeFn) |
| 364 | } |
| 365 | constantValues := ast.MatchDescendants(expr, ast.ConstantValueMatcher()) |
| 366 | if len(constantValues) != 1 { |
| 367 | t.Fatalf("ast.MatchDescendants() constant values returned %v, wanted 1 value", constantValues) |
| 368 | } |
| 369 | if constantValues[0].AsLiteral().Equal(types.String("hello")) != types.True { |
| 370 | t.Errorf("constantValues[0] got %v, wanted 'hello'", constantValues[0]) |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | func TestNavigableListExpr(t *testing.T) { |
| 375 | checked := mustTypeCheck(t, `[[1], [2]]`) |
nothing calls this directly
no test coverage detected