@@ -89,3 +89,101 @@ tape.test("reflected enums", function(test) {
89
89
90
90
test . end ( ) ;
91
91
} ) ;
92
+
93
+ tape . test ( "feature resolution legacy proto3" , function ( test ) {
94
+ var json = {
95
+ values : {
96
+ a : 0 , b : 1
97
+ }
98
+ } ;
99
+ var messageJson = {
100
+ fields : { } ,
101
+ nested : { Enum : { values : {
102
+ a : 0 , b :1
103
+ } } }
104
+ } ;
105
+ var root = new protobuf . Root ( ) ;
106
+ var Enum = protobuf . Enum . fromJSON ( "Enum" , json ) ;
107
+ var Message = protobuf . Type . fromJSON ( "Message" , messageJson )
108
+ var Nested = Message . nested . Enum ;
109
+ root . add ( Enum ) . add ( Message ) . resolveAll ( ) ;
110
+
111
+ test . same ( Enum . toJSON ( ) , json , "JSON should roundtrip" ) ;
112
+ test . same ( Message . toJSON ( ) , messageJson , "container JSON should roundtrip" ) ;
113
+ test . same ( Nested . toJSON ( ) , messageJson . nested . Enum , "nested JSON should roundtrip" ) ;
114
+
115
+ test . equal ( Enum . _edition , "proto3" , "should infer proto3 syntax" ) ;
116
+ test . equal ( Enum . _features . enum_type , "OPEN" , "should be open by default" ) ;
117
+
118
+ test . equal ( Nested . _edition , null , "should not set edition" ) ;
119
+ test . equal ( Nested . _features . enum_type , "OPEN" , "should be open by default" ) ;
120
+
121
+ test . end ( ) ;
122
+ } ) ;
123
+
124
+ tape . test ( "feature resolution proto2" , function ( test ) {
125
+ var json = {
126
+ edition : "proto2" ,
127
+ values : {
128
+ a : 0 , b : 1
129
+ }
130
+ } ;
131
+ var messageJson = {
132
+ edition : "proto2" ,
133
+ fields : { } ,
134
+ nested : { Enum : { values : {
135
+ a : 0 , b : 1
136
+ } } }
137
+ } ;
138
+ var root = new protobuf . Root ( ) ;
139
+ var Enum = protobuf . Enum . fromJSON ( "Enum" , json ) ;
140
+ var Message = protobuf . Type . fromJSON ( "Message" , messageJson )
141
+ var Nested = Message . nested . Enum ;
142
+ root . add ( Enum ) . add ( Message ) . resolveAll ( ) ;
143
+
144
+ test . same ( Enum . toJSON ( ) , json , "JSON should roundtrip" ) ;
145
+ test . same ( Message . toJSON ( ) , messageJson , "container JSON should roundtrip" ) ;
146
+ test . same ( Nested . toJSON ( ) , messageJson . nested . Enum , "nested JSON should roundtrip" ) ;
147
+
148
+ test . equal ( Enum . _edition , "proto2" , "should set edition" ) ;
149
+ test . equal ( Enum . _features . enum_type , "CLOSED" , "should be closed by default" ) ;
150
+
151
+ test . equal ( Nested . _edition , null , "should not set edition" ) ;
152
+ test . equal ( Nested . _features . enum_type , "CLOSED" , "should be closed by default" ) ;
153
+
154
+ test . end ( ) ;
155
+ } ) ;
156
+
157
+ tape . test ( "feature resolution legacy proto3" , function ( test ) {
158
+ var json = {
159
+ edition : "2023" ,
160
+ values : {
161
+ a : 0 , b : 1
162
+ }
163
+ } ;
164
+ var messageJson = {
165
+ edition : "2023" ,
166
+ options : { features : { enum_type : "CLOSED" } } ,
167
+ fields : { } ,
168
+ nested : { Enum : { values : {
169
+ a : 0 , b : 1
170
+ } } }
171
+ } ;
172
+ var root = new protobuf . Root ( ) ;
173
+ var Enum = protobuf . Enum . fromJSON ( "Enum" , json ) ;
174
+ var Message = protobuf . Type . fromJSON ( "Message" , messageJson )
175
+ var Nested = Message . nested . Enum ;
176
+ root . add ( Enum ) . add ( Message ) . resolveAll ( ) ;
177
+
178
+ test . same ( Enum . toJSON ( ) , json , "JSON should roundtrip" ) ;
179
+ test . same ( Message . toJSON ( ) , messageJson , "container JSON should roundtrip" ) ;
180
+ test . same ( Nested . toJSON ( ) , messageJson . nested . Enum , "nested JSON should roundtrip" ) ;
181
+
182
+ test . equal ( Enum . _edition , "2023" , "should set edition" ) ;
183
+ test . equal ( Enum . _features . enum_type , "OPEN" , "should be open by default" ) ;
184
+
185
+ test . equal ( Nested . _edition , null , "should not set edition" ) ;
186
+ test . equal ( Nested . _features . enum_type , "CLOSED" , "should inherit override" ) ;
187
+
188
+ test . end ( ) ;
189
+ } ) ;
0 commit comments