(t *testing.T)
| 344 | } |
| 345 | |
| 346 | func TestNavigableExpr(t *testing.T) { |
| 347 | checkedAST := mustTypeCheck(t, `'a' == 'b'`) |
| 348 | navAST := ast.NavigateAST(checkedAST) |
| 349 | literals := ast.MatchDescendants(navAST, func(expr ast.NavigableExpr) bool { |
| 350 | return expr.Kind() == ast.LiteralKind && |
| 351 | expr.AsLiteral().Equal(types.String("a")) == types.True |
| 352 | }) |
| 353 | if len(literals) != 1 { |
| 354 | t.Fatalf("MatchDescendents('a') got %d results, wanted 1", len(literals)) |
| 355 | } |
| 356 | litA := literals[0] |
| 357 | if litA.Depth() != 1 { |
| 358 | t.Fatalf("litA.Depth() got %d, wanted 1", litA.Depth()) |
| 359 | } |
| 360 | parent, found := litA.Parent() |
| 361 | if !found { |
| 362 | t.Fatal("litA.Parent() returned nil") |
| 363 | } |
| 364 | if parent.Kind() != ast.CallKind && parent.AsCall().FunctionName() != "==" { |
| 365 | t.Fatalf("litA.Parent() got %v, watned '==' function call", parent) |
| 366 | } |
| 367 | litAPrime := ast.NavigateExpr(checkedAST, litA) |
| 368 | if litAPrime.Depth() != litA.Depth() { |
| 369 | t.Errorf("litAPrime.Depth() != litA.Depth(), got %d, wanted %d", litAPrime.Depth(), litA.Depth()) |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | func TestNavigableCallExprMember(t *testing.T) { |
| 374 | checked := mustTypeCheck(t, `'hello'.size()`) |
nothing calls this directly
no test coverage detected