(t *testing.T)
| 479 | } |
| 480 | |
| 481 | func TestNavigableMapExpr(t *testing.T) { |
| 482 | checked := mustTypeCheck(t, `{'hello': 1}`) |
| 483 | expr := ast.NavigateAST(checked) |
| 484 | if expr.Kind() != ast.MapKind { |
| 485 | t.Errorf("Kind() got %v, wanted MapKind", expr.Kind()) |
| 486 | } |
| 487 | m := expr.AsMap() |
| 488 | if m.Size() != 1 { |
| 489 | t.Errorf("Size() got %d, wanted 1", m.Size()) |
| 490 | } |
| 491 | if len(m.Entries()) != 1 { |
| 492 | t.Errorf("Entries() returned %v, wanted 1", m.Entries()) |
| 493 | } |
| 494 | e := m.Entries()[0] |
| 495 | entry := e.AsMapEntry() |
| 496 | if entry.IsOptional() { |
| 497 | t.Error("IsOptional() returned true, wanted false") |
| 498 | } |
| 499 | if entry.Key().AsLiteral().Equal(types.String("hello")) != types.True { |
| 500 | t.Errorf("Key() returned %v, wanted 'hello'", entry.Key().AsLiteral()) |
| 501 | } |
| 502 | if entry.Value().AsLiteral().Equal(types.Int(1)) != types.True { |
| 503 | t.Errorf("Value() returned %v, wanted 1", entry.Value().AsLiteral()) |
| 504 | } |
| 505 | descendants := ast.MatchDescendants(expr, ast.AllMatcher()) |
| 506 | if len(descendants) != 3 { |
| 507 | t.Errorf("ast.MatchDescendants() returned %v, wanted 3", descendants) |
| 508 | } |
| 509 | literals := ast.MatchSubset(descendants, ast.KindMatcher(ast.LiteralKind)) |
| 510 | if len(literals) != 2 { |
| 511 | t.Errorf("ast.MatchSubset() literals returned %v, wanted 2", literals) |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | func TestNavigableStructExpr(t *testing.T) { |
| 516 | checked := mustTypeCheck(t, `google.expr.proto3.test.TestAllTypes{single_int32: 1}`) |
nothing calls this directly
no test coverage detected