(t *testing.T)
| 267 | } |
| 268 | |
| 269 | func TestNavigableExpr(t *testing.T) { |
| 270 | checkedAST := mustTypeCheck(t, `'a' == 'b'`) |
| 271 | navAST := ast.NavigateAST(checkedAST) |
| 272 | literals := ast.MatchDescendants(navAST, func(expr ast.NavigableExpr) bool { |
| 273 | return expr.Kind() == ast.LiteralKind && |
| 274 | expr.AsLiteral().Equal(types.String("a")) == types.True |
| 275 | }) |
| 276 | if len(literals) != 1 { |
| 277 | t.Fatalf("MatchDescendents('a') got %d results, wanted 1", len(literals)) |
| 278 | } |
| 279 | litA := literals[0] |
| 280 | if litA.Depth() != 1 { |
| 281 | t.Fatalf("litA.Depth() got %d, wanted 1", litA.Depth()) |
| 282 | } |
| 283 | parent, found := litA.Parent() |
| 284 | if !found { |
| 285 | t.Fatal("litA.Parent() returned nil") |
| 286 | } |
| 287 | if parent.Kind() != ast.CallKind && parent.AsCall().FunctionName() != "==" { |
| 288 | t.Fatalf("litA.Parent() got %v, watned '==' function call", parent) |
| 289 | } |
| 290 | litAPrime := ast.NavigateExpr(checkedAST, litA) |
| 291 | if litAPrime.Depth() != litA.Depth() { |
| 292 | t.Errorf("litAPrime.Depth() != litA.Depth(), got %d, wanted %d", litAPrime.Depth(), litA.Depth()) |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | func TestNavigableCallExprMember(t *testing.T) { |
| 297 | checked := mustTypeCheck(t, `'hello'.size()`) |
nothing calls this directly
no test coverage detected