@@ -289,14 +289,15 @@ func TestEnumAnnotations(t *testing.T) {
289
289
}
290
290
annotateModel (model , codec , "" )
291
291
292
- if diff := cmp .Diff (& enumAnnotation {
293
- Name : "TestEnum" ,
294
- ModuleName : "test_enum" ,
295
- QualifiedName : "crate::model::TestEnum" ,
296
- RelativeName : "TestEnum" ,
297
- DocLines : []string {"/// The enum is documented." },
298
- DefaultValueName : "VALUE" ,
299
- }, enum .Codec ); diff != "" {
292
+ want := & enumAnnotation {
293
+ Name : "TestEnum" ,
294
+ ModuleName : "test_enum" ,
295
+ QualifiedName : "crate::model::TestEnum" ,
296
+ RelativeName : "TestEnum" ,
297
+ DocLines : []string {"/// The enum is documented." },
298
+ UniqueNames : []* api.EnumValue {v0 , v1 , v2 },
299
+ }
300
+ if diff := cmp .Diff (want , enum .Codec , cmpopts .IgnoreFields (api.EnumValue {}, "Codec" , "Parent" )); diff != "" {
300
301
t .Errorf ("mismatch in enum annotations (-want, +got)\n :%s" , diff )
301
302
}
302
303
@@ -315,7 +316,6 @@ func TestEnumAnnotations(t *testing.T) {
315
316
}, v1 .Codec ); diff != "" {
316
317
t .Errorf ("mismatch in enum annotations (-want, +got)\n :%s" , diff )
317
318
}
318
-
319
319
if diff := cmp .Diff (& enumValueAnnotation {
320
320
Name : "VALUE" ,
321
321
EnumType : "TestEnum" ,
@@ -325,6 +325,57 @@ func TestEnumAnnotations(t *testing.T) {
325
325
}
326
326
}
327
327
328
+ func TestDuplicateEnumValueAnnotations (t * testing.T ) {
329
+ // Verify we can handle values that are not in SCREAMING_SNAKE_CASE style.
330
+ v0 := & api.EnumValue {
331
+ Name : "full" ,
332
+ ID : ".test.v1.TestEnum.full" ,
333
+ Number : 1 ,
334
+ }
335
+ v1 := & api.EnumValue {
336
+ Name : "FULL" ,
337
+ ID : ".test.v1.TestEnum.FULL" ,
338
+ Number : 1 ,
339
+ }
340
+ v2 := & api.EnumValue {
341
+ Name : "partial" ,
342
+ ID : ".test.v1.TestEnum.partial" ,
343
+ Number : 2 ,
344
+ }
345
+ // This does not happen in practice, but we want to verify the code can
346
+ // handle it if it ever does.
347
+ v3 := & api.EnumValue {
348
+ Name : "PARTIAL" ,
349
+ ID : ".test.v1.TestEnum.PARTIAL" ,
350
+ Number : 3 ,
351
+ }
352
+ enum := & api.Enum {
353
+ Name : "TestEnum" ,
354
+ ID : ".test.v1.TestEnum" ,
355
+ Values : []* api.EnumValue {v0 , v1 , v2 , v3 },
356
+ }
357
+
358
+ model := api .NewTestAPI (
359
+ []* api.Message {}, []* api.Enum {enum }, []* api.Service {})
360
+ codec , err := newCodec (true , map [string ]string {})
361
+ if err != nil {
362
+ t .Fatal (err )
363
+ }
364
+ annotateModel (model , codec , "" )
365
+
366
+ want := & enumAnnotation {
367
+ Name : "TestEnum" ,
368
+ ModuleName : "test_enum" ,
369
+ QualifiedName : "crate::model::TestEnum" ,
370
+ RelativeName : "TestEnum" ,
371
+ UniqueNames : []* api.EnumValue {v0 , v2 },
372
+ }
373
+
374
+ if diff := cmp .Diff (want , enum .Codec , cmpopts .IgnoreFields (api.EnumValue {}, "Codec" , "Parent" )); diff != "" {
375
+ t .Errorf ("mismatch in enum annotations (-want, +got)\n :%s" , diff )
376
+ }
377
+ }
378
+
328
379
func TestJsonNameAnnotations (t * testing.T ) {
329
380
parent := & api.Field {
330
381
Name : "parent" ,
0 commit comments