(t *testing.T)
| 513 | } |
| 514 | |
| 515 | func TestNavigableStructExpr(t *testing.T) { |
| 516 | checked := mustTypeCheck(t, `google.expr.proto3.test.TestAllTypes{single_int32: 1}`) |
| 517 | expr := ast.NavigateAST(checked) |
| 518 | if expr.Kind() != ast.StructKind { |
| 519 | t.Errorf("Kind() got %v, wanted StructKind", expr.Kind()) |
| 520 | } |
| 521 | s := expr.AsStruct() |
| 522 | if s.TypeName() != "google.expr.proto3.test.TestAllTypes" { |
| 523 | t.Errorf("TypeName() got %s, wanted TestAllTypes", s.TypeName()) |
| 524 | } |
| 525 | if len(s.Fields()) != 1 { |
| 526 | t.Errorf("Fields() returned %v, wanted 1", s.Fields()) |
| 527 | } |
| 528 | f := s.Fields()[0] |
| 529 | field := f.AsStructField() |
| 530 | if field.IsOptional() { |
| 531 | t.Error("IsOptional() returned true, wanted false") |
| 532 | } |
| 533 | if field.Name() != "single_int32" { |
| 534 | t.Errorf("Name() returned %s, wanted 'single_int32'", field.Name()) |
| 535 | } |
| 536 | if field.Value().AsLiteral().Equal(types.Int(1)) != types.True { |
| 537 | t.Errorf("Value() returned %v, wanted 1", field.Value().AsLiteral()) |
| 538 | } |
| 539 | descendants := ast.MatchDescendants(expr, ast.AllMatcher()) |
| 540 | if len(descendants) != 2 { |
| 541 | t.Errorf("ast.MatchDescendants() returned %v, wanted 2", descendants) |
| 542 | } |
| 543 | literals := ast.MatchSubset(descendants, ast.KindMatcher(ast.LiteralKind)) |
| 544 | if len(literals) != 1 { |
| 545 | t.Errorf("ast.MatchSubset() literals returned %v, wanted 1", literals) |
| 546 | } |
| 547 | if literals[0].AsLiteral().Equal(types.Int(1)) != types.True { |
| 548 | t.Errorf("Value().AsLiteral() got %v, wanted 1", literals[0].AsLiteral()) |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | func TestNavigableComprehensionExpr(t *testing.T) { |
| 553 | checked := mustTypeCheck(t, `[true].exists(i, i)`) |
nothing calls this directly
no test coverage detected