(t *testing.T)
| 85 | } |
| 86 | |
| 87 | func TestASTJsonNames(t *testing.T) { |
| 88 | tests := []string{ |
| 89 | `google.expr.proto3.test.TestAllTypes{}`, |
| 90 | `google.expr.proto3.test.TestAllTypes{repeatedInt32: [1, 2]}`, |
| 91 | `google.expr.proto3.test.TestAllTypes{singleInt32: 2}.singleInt32 == 2`, |
| 92 | } |
| 93 | |
| 94 | for _, tst := range tests { |
| 95 | checked := mustTypeCheck(t, tst, checker.JSONFieldNames(true), types.JSONFieldNames(true)) |
| 96 | copyChecked := ast.Copy(checked) |
| 97 | if !reflect.DeepEqual(copyChecked.Expr(), checked.Expr()) { |
| 98 | t.Errorf("Copy() got expr %v, wanted %v", copyChecked.Expr(), checked.Expr()) |
| 99 | } |
| 100 | if !reflect.DeepEqual(copyChecked.SourceInfo(), checked.SourceInfo()) { |
| 101 | t.Errorf("Copy() got source info %v, wanted %v", copyChecked.SourceInfo(), checked.SourceInfo()) |
| 102 | } |
| 103 | copyParsed := ast.Copy(ast.NewAST(checked.Expr(), checked.SourceInfo())) |
| 104 | if !reflect.DeepEqual(copyParsed.Expr(), checked.Expr()) { |
| 105 | t.Errorf("Copy() got expr %v, wanted %v", copyParsed.Expr(), checked.Expr()) |
| 106 | } |
| 107 | if !reflect.DeepEqual(copyParsed.SourceInfo(), checked.SourceInfo()) { |
| 108 | t.Errorf("Copy() got source info %v, wanted %v", copyParsed.SourceInfo(), checked.SourceInfo()) |
| 109 | } |
| 110 | checkedPB, err := ast.ToProto(checked) |
| 111 | if err != nil { |
| 112 | t.Errorf("ast.ToProto() failed: %v", err) |
| 113 | } |
| 114 | copyCheckedPB, err := ast.ToProto(copyChecked) |
| 115 | if err != nil { |
| 116 | t.Errorf("ast.ToProto() failed: %v", err) |
| 117 | } |
| 118 | if !proto.Equal(checkedPB, copyCheckedPB) { |
| 119 | t.Errorf("Copy() produced different proto results, got %v, wanted %v", |
| 120 | prototext.Format(checkedPB), prototext.Format(copyCheckedPB)) |
| 121 | } |
| 122 | checkedRoundtrip, err := ast.ToAST(checkedPB) |
| 123 | if err != nil { |
| 124 | t.Errorf("ast.ToAST() failed: %v", err) |
| 125 | } |
| 126 | same := reflect.DeepEqual(checked.Expr(), checkedRoundtrip.Expr()) && |
| 127 | reflect.DeepEqual(checked.ReferenceMap(), checkedRoundtrip.ReferenceMap()) && |
| 128 | reflect.DeepEqual(checked.TypeMap(), checkedRoundtrip.TypeMap()) && |
| 129 | reflect.DeepEqual(checked.SourceInfo().MacroCalls(), checkedRoundtrip.SourceInfo().MacroCalls()) |
| 130 | if !same { |
| 131 | t.Errorf("Roundtrip got %v, wanted %v", checkedRoundtrip, checked) |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | func TestASTNilSafety(t *testing.T) { |
| 137 | ex, err := ast.ProtoToExpr(nil) |
nothing calls this directly
no test coverage detected