(t *testing.T)
| 402 | } |
| 403 | |
| 404 | func TestNavigableMapExpr(t *testing.T) { |
| 405 | checked := mustTypeCheck(t, `{'hello': 1}`) |
| 406 | expr := ast.NavigateAST(checked) |
| 407 | if expr.Kind() != ast.MapKind { |
| 408 | t.Errorf("Kind() got %v, wanted MapKind", expr.Kind()) |
| 409 | } |
| 410 | m := expr.AsMap() |
| 411 | if m.Size() != 1 { |
| 412 | t.Errorf("Size() got %d, wanted 1", m.Size()) |
| 413 | } |
| 414 | if len(m.Entries()) != 1 { |
| 415 | t.Errorf("Entries() returned %v, wanted 1", m.Entries()) |
| 416 | } |
| 417 | e := m.Entries()[0] |
| 418 | entry := e.AsMapEntry() |
| 419 | if entry.IsOptional() { |
| 420 | t.Error("IsOptional() returned true, wanted false") |
| 421 | } |
| 422 | if entry.Key().AsLiteral().Equal(types.String("hello")) != types.True { |
| 423 | t.Errorf("Key() returned %v, wanted 'hello'", entry.Key().AsLiteral()) |
| 424 | } |
| 425 | if entry.Value().AsLiteral().Equal(types.Int(1)) != types.True { |
| 426 | t.Errorf("Value() returned %v, wanted 1", entry.Value().AsLiteral()) |
| 427 | } |
| 428 | descendants := ast.MatchDescendants(expr, ast.AllMatcher()) |
| 429 | if len(descendants) != 3 { |
| 430 | t.Errorf("ast.MatchDescendants() returned %v, wanted 3", descendants) |
| 431 | } |
| 432 | literals := ast.MatchSubset(descendants, ast.KindMatcher(ast.LiteralKind)) |
| 433 | if len(literals) != 2 { |
| 434 | t.Errorf("ast.MatchSubset() literals returned %v, wanted 2", literals) |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | func TestNavigableStructExpr(t *testing.T) { |
| 439 | checked := mustTypeCheck(t, `google.expr.proto3.test.TestAllTypes{single_int32: 1}`) |
nothing calls this directly
no test coverage detected