(t *testing.T)
| 302 | } |
| 303 | |
| 304 | func TestNavigableASTNilSafety(t *testing.T) { |
| 305 | tests := []struct { |
| 306 | name string |
| 307 | e ast.NavigableExpr |
| 308 | }{ |
| 309 | { |
| 310 | name: "nil expr", |
| 311 | e: ast.NavigateAST(ast.NewAST(nil, nil)), |
| 312 | }, |
| 313 | } |
| 314 | for _, tst := range tests { |
| 315 | tc := tst |
| 316 | t.Run(tc.name, func(t *testing.T) { |
| 317 | e := tc.e |
| 318 | if e.ID() != 0 { |
| 319 | t.Errorf("ID() got %d, wanted 0", e.ID()) |
| 320 | } |
| 321 | if e.Kind() != ast.UnspecifiedExprKind { |
| 322 | t.Errorf("Kind() got %v, wanted unspecified kind", e.Kind()) |
| 323 | } |
| 324 | if e.Type() != types.DynType { |
| 325 | t.Errorf("Type() got %v, wanted types.DynType", e.Type()) |
| 326 | } |
| 327 | if p, found := e.Parent(); found { |
| 328 | t.Errorf("Parent() got %v, wanted not found", p) |
| 329 | } |
| 330 | if len(e.Children()) != 0 { |
| 331 | t.Errorf("Children() got %v, wanted none", e.Children()) |
| 332 | } |
| 333 | if e.AsLiteral() != nil { |
| 334 | t.Errorf("AsLiteral() got %v, wanted nil", e.AsLiteral()) |
| 335 | } |
| 336 | if e.AsCall() == nil { |
| 337 | t.Errorf("AsCall() got nil, wanted non-nil for safe traversal") |
| 338 | } |
| 339 | if e.AsComprehension() == nil { |
| 340 | t.Errorf("AsComprehension() got nil, wanted non-nil for safe traversal") |
| 341 | } |
| 342 | }) |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | func TestNavigableExpr(t *testing.T) { |
| 347 | checkedAST := mustTypeCheck(t, `'a' == 'b'`) |
nothing calls this directly
no test coverage detected