(t *testing.T)
| 294 | } |
| 295 | |
| 296 | func 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 | |
| 335 | func TestNavigableCallExprGlobal(t *testing.T) { |
| 336 | checked := mustTypeCheck(t, `size('hello')`) |
nothing calls this directly
no test coverage detected