1
+ /*
2
+ edition = "2023";
3
+
4
+ option features.amazing_feature = A;
5
+ option (mo_single_msg).nested.value = "x";
6
+ service MyService {
7
+ option features.amazing_feature = E;
8
+ message MyRequest {};
9
+ message MyResponse {};
10
+ rpc MyMethod (MyRequest) returns (MyResponse) {
11
+ option features.amazing_feature = L;
12
+ };
13
+ }
14
+
15
+ message Message {
16
+ option features.amazing_feature = B;
17
+
18
+ string string_val = 1;
19
+ string string_repeated = 2 [features.amazing_feature = F];
20
+
21
+ uint64 uint64_val = 3;
22
+ uint64 uint64_repeated = 4;
23
+
24
+ bytes bytes_val = 5;
25
+ bytes bytes_repeated = 6;
26
+
27
+ SomeEnum enum_val = 7;
28
+ SomeEnum enum_repeated = 8;
29
+
30
+ extensions 10 to 100;
31
+ extend Message {
32
+ int32 bar = 10 [features.amazing_feature = I];
33
+ }
34
+
35
+ message Nested {
36
+ option features.amazing_feature = H;
37
+ int64 count = 9;
38
+ }
39
+
40
+ enum SomeEnumInMessage {
41
+ option features.amazing_feature = G;
42
+ ONE = 11;
43
+ TWO = 12;
44
+ }
45
+
46
+ oneof SomeOneOf {
47
+ option features.amazing_feature = J;
48
+ int32 a = 13;
49
+ string b = 14;
50
+ }
51
+
52
+ map<string,int64> int64_map = 15;
53
+ }
54
+
55
+ extend Message {
56
+ int32 bar = 16 [features.amazing_feature = D];
57
+ }
58
+
59
+ enum SomeEnum {
60
+ option features.amazing_feature = C;
61
+ ONE = 1 [features.amazing_feature = K];
62
+ TWO = 2;
63
+ }
64
+ */
1
65
var tape = require ( "tape" ) ;
2
66
3
67
var protobuf = require ( ".." ) ;
@@ -29,6 +93,106 @@ message Message {
29
93
}
30
94
}
31
95
`
96
+
97
+ var test1 = `edition = "2023";
98
+
99
+ option features.amazing_feature = A;`
100
+ var test2 = `edition = "2023";
101
+ option features.amazing_feature = A;
102
+
103
+ message Message {
104
+ option features.amazing_feature = B;
105
+ }`
106
+ var test3 = `edition = "2023";
107
+ option features.amazing_feature = A;
108
+ enum SomeEnum {
109
+ option features.amazing_feature = C;
110
+ ONE = 1;
111
+ TWO = 2;
112
+ }`
113
+
114
+ var test4 = `edition = "2023";
115
+ option features.amazing_feature = A;
116
+
117
+ message Message {
118
+ option features.amazing_feature = B;
119
+ }
120
+
121
+ extend Message {
122
+ int32 bar = 16 [features.amazing_feature = D];
123
+ }
124
+ `
125
+ var test5 = `edition = "2023";
126
+ option features.amazing_feature = A;
127
+ service MyService {
128
+ option features.amazing_feature = E;
129
+ message MyRequest {};
130
+ message MyResponse {};
131
+ }
132
+ `
133
+ var test6 = `edition = "2023";
134
+ option features.amazing_feature = A;
135
+ message Message {
136
+ string string_val = 1;
137
+ string string_repeated = 2 [features.amazing_feature = F];
138
+ }`
139
+
140
+ var test7 = `edition = "2023";
141
+ option features.amazing_feature = A;
142
+ message Message {
143
+ enum SomeEnumInMessage {
144
+ option features.amazing_feature = G;
145
+ ONE = 11;
146
+ TWO = 12;
147
+ }
148
+ }`
149
+
150
+ var test8 = `edition = "2023";
151
+ option features.amazing_feature = A;
152
+ message Message {
153
+ message Nested {
154
+ option features.amazing_feature = H;
155
+ int64 count = 9;
156
+ }
157
+ }`
158
+
159
+ var test9 = `edition = "2023";
160
+ option features.amazing_feature = A;
161
+ message Message {
162
+ extend Message {
163
+ int32 bar = 10 [features.amazing_feature = I];
164
+ }
165
+ }`
166
+
167
+ var test10 = `edition = "2023";
168
+ option features.amazing_feature = A;
169
+ message Message {
170
+ oneof SomeOneOf {
171
+ option features.amazing_feature = J;
172
+ int32 a = 13;
173
+ string b = 14;
174
+ }
175
+ }`
176
+
177
+ var test11 = `edition = "2023";
178
+ option features.amazing_feature = A;
179
+ enum SomeEnum {
180
+ option features.amazing_feature = C;
181
+ ONE = 1 [features.amazing_feature = K];
182
+ TWO = 2;
183
+ }`
184
+
185
+ var test12 = `edition = "2023";
186
+ option features.amazing_feature = A;
187
+ service MyService {
188
+ option features.amazing_feature = E;
189
+ message MyRequest {};
190
+ message MyResponse {};
191
+ rpc MyMethod (MyRequest) returns (MyResponse) {
192
+ option features.amazing_feature = L;
193
+ };
194
+ }
195
+ `
32
196
tape . test ( "feautre resolution defaults" , function ( test ) {
33
197
var rootEditions = protobuf . parse ( protoEditions2023 ) . root ;
34
198
rootEditions . resolveAll ( ) ;
@@ -70,24 +234,30 @@ tape.test("feature resolution inheritance", function(test) {
70
234
} )
71
235
// Tests precedence for different levels of feature resolution
72
236
tape . test ( "feature resolution editions precedence" , function ( test ) {
237
+ var root1 = protobuf . parse ( test1 ) . root . resolveAll ( )
238
+ var root2 = protobuf . parse ( test2 ) . root . resolveAll ( ) ;
239
+ var root3 = protobuf . parse ( test3 ) . root . resolveAll ( ) ;
240
+ var root4 = protobuf . parse ( test4 ) . root . resolveAll ( ) ;
241
+ var root5 = protobuf . parse ( test5 ) . root . resolveAll ( ) ;
242
+ var root6 = protobuf . parse ( test6 ) . root . resolveAll ( ) ;
243
+ var root7 = protobuf . parse ( test7 ) . root . resolveAll ( ) ;
244
+ var root8 = protobuf . parse ( test8 ) . root . resolveAll ( ) ;
245
+ var root9 = protobuf . parse ( test9 ) . root . resolveAll ( ) ;
246
+ var root10 = protobuf . parse ( test10 ) . root . resolveAll ( ) ;
247
+ var root11 = protobuf . parse ( test11 ) . root . resolveAll ( ) ;
248
+ var root12 = protobuf . parse ( test12 ) . root . resolveAll ( ) ;
249
+ test . same ( root1 . _features . amazing_feature , 'A' ) ;
250
+ test . same ( root2 . lookup ( "Message" ) . _features . amazing_feature , 'B' )
251
+ test . same ( root3 . lookupEnum ( "SomeEnum" ) . _features . amazing_feature , 'C' )
252
+ test . same ( root4 . lookup ( "Message" ) . fields [ ".bar" ] . declaringField . _features . amazing_feature , 'D' )
253
+ test . same ( root5 . lookupService ( "MyService" ) . _features . amazing_feature , 'E' ) ;
254
+ test . same ( root6 . lookup ( "Message" ) . fields . stringRepeated . _features . amazing_feature , 'F' )
255
+ test . same ( root7 . lookup ( "Message" ) . lookupEnum ( "SomeEnumInMessage" ) . _features . amazing_feature , 'G' )
256
+ test . same ( root8 . lookup ( "Message" ) . lookup ( "Nested" ) . _features . amazing_feature , 'H' )
257
+ test . same ( root9 . lookup ( "Message" ) . lookup ( ".Message.bar" ) . _features . amazing_feature , 'I' )
258
+ test . same ( root10 . lookup ( "Message" ) . lookup ( "SomeOneOf" ) . _features . amazing_feature , 'J' )
259
+ test . same ( root11 . lookupEnum ( "SomeEnum" ) . _valuesFeatures [ "ONE" ] . amazing_feature , 'K' )
260
+ test . same ( root12 . lookupService ( "MyService" ) . lookup ( "MyMethod" ) . _features . amazing_feature , 'L' )
73
261
74
- protobuf . load ( "tests/data/feature-resolution.proto" , function ( err , root ) {
75
- if ( err )
76
- return test . fail ( err . message ) ;
77
- root . resolveAll ( ) ;
78
- test . same ( root . _features . amazing_feature , 'A' ) ;
79
- test . same ( root . lookup ( "Message" ) . _features . amazing_feature , 'B' )
80
- test . same ( root . lookupEnum ( "SomeEnum" ) . _features . amazing_feature , 'C' )
81
- test . same ( root . lookup ( "Message" ) . fields [ ".bar" ] . declaringField . _features . amazing_feature , 'D' )
82
- test . same ( root . lookupService ( "MyService" ) . _features . amazing_feature , 'E' ) ;
83
- test . same ( root . lookup ( "Message" ) . fields . stringRepeated . _features . amazing_feature , 'F' )
84
- test . same ( root . lookup ( "Message" ) . lookupEnum ( "SomeEnumInMessage" ) . _features . amazing_feature , 'G' )
85
- test . same ( root . lookup ( "Message" ) . lookup ( "Nested" ) . _features . amazing_feature , 'H' )
86
- test . same ( root . lookup ( "Message" ) . lookup ( ".Message.bar" ) . _features . amazing_feature , 'I' )
87
- test . same ( root . lookup ( "Message" ) . lookup ( "SomeOneOf" ) . _features . amazing_feature , 'J' )
88
- test . same ( root . lookupEnum ( "SomeEnum" ) . _valuesFeatures [ "ONE" ] . amazing_feature , 'K' )
89
- test . same ( root . lookupService ( "MyService" ) . lookup ( "MyMethod" ) . _features . amazing_feature , 'L' )
90
-
91
- test . end ( ) ;
92
- } )
262
+ test . end ( ) ;
93
263
} )
0 commit comments