diff --git a/Makefile b/Makefile index 598f250b9b..7c87d0dff8 100644 --- a/Makefile +++ b/Makefile @@ -140,6 +140,7 @@ regenerate: make -C test/issue620 regenerate make -C test/protobuffer regenerate make -C test/issue630 regenerate + make -C test/issue635 regenerate make gofmt diff --git a/plugin/gostring/gostring.go b/plugin/gostring/gostring.go index bc89a7b871..af533a8741 100644 --- a/plugin/gostring/gostring.go +++ b/plugin/gostring/gostring.go @@ -103,6 +103,7 @@ import ( "strings" "github.com/gogo/protobuf/gogoproto" + "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" "github.com/gogo/protobuf/protoc-gen-gogo/generator" ) @@ -260,8 +261,8 @@ func (p *gostring) Generate(file *generator.FileDescriptor) { } if field.IsEnum() { if nullable && !repeated && !proto3 { - goTyp, _ := p.GoType(message, field) - p.P(`s = append(s, "`, fieldname, `: " + valueToGoString`, p.localName, `(this.`, fieldname, `,"`, generator.GoTypeToName(goTyp), `"`, `) + ",\n")`) + typ := enumTypeName(field) + p.P(`s = append(s, "`, fieldname, `: " + valueToGoString`, p.localName, `(this.`, fieldname, `,"`, typ, `"`, `) + ",\n")`) } else { p.P(`s = append(s, "`, fieldname, `: " + `, fmtPkg.Use(), `.Sprintf("%#v", this.`, fieldname, `) + ",\n")`) } @@ -381,6 +382,25 @@ func (p *gostring) Generate(file *generator.FileDescriptor) { } } +func enumTypeName(field *descriptor.FieldDescriptorProto) string { + tn := []byte(field.GetTypeName()) + if len(tn) > 1 && tn[0] == '.' { + tn = tn[1:] + } + first := true + for i, v := range tn { + if v != '.' { + continue + } + if first { + first = false + continue + } + tn[i] = '_' + } + return string(tn) +} + func init() { generator.RegisterPlugin(NewGoString()) } diff --git a/protoc-gen-gogo/descriptor/descriptor_gostring.gen.go b/protoc-gen-gogo/descriptor/descriptor_gostring.gen.go index 165b2110df..905bf9439d 100644 --- a/protoc-gen-gogo/descriptor/descriptor_gostring.gen.go +++ b/protoc-gen-gogo/descriptor/descriptor_gostring.gen.go @@ -192,10 +192,10 @@ func (this *FieldDescriptorProto) GoString() string { s = append(s, "Number: "+valueToGoStringDescriptor(this.Number, "int32")+",\n") } if this.Label != nil { - s = append(s, "Label: "+valueToGoStringDescriptor(this.Label, "FieldDescriptorProto_Label")+",\n") + s = append(s, "Label: "+valueToGoStringDescriptor(this.Label, "google.protobuf_FieldDescriptorProto_Label")+",\n") } if this.Type != nil { - s = append(s, "Type: "+valueToGoStringDescriptor(this.Type, "FieldDescriptorProto_Type")+",\n") + s = append(s, "Type: "+valueToGoStringDescriptor(this.Type, "google.protobuf_FieldDescriptorProto_Type")+",\n") } if this.TypeName != nil { s = append(s, "TypeName: "+valueToGoStringDescriptor(this.TypeName, "string")+",\n") @@ -378,7 +378,7 @@ func (this *FileOptions) GoString() string { s = append(s, "JavaStringCheckUtf8: "+valueToGoStringDescriptor(this.JavaStringCheckUtf8, "bool")+",\n") } if this.OptimizeFor != nil { - s = append(s, "OptimizeFor: "+valueToGoStringDescriptor(this.OptimizeFor, "FileOptions_OptimizeMode")+",\n") + s = append(s, "OptimizeFor: "+valueToGoStringDescriptor(this.OptimizeFor, "google.protobuf_FileOptions_OptimizeMode")+",\n") } if this.GoPackage != nil { s = append(s, "GoPackage: "+valueToGoStringDescriptor(this.GoPackage, "string")+",\n") @@ -467,13 +467,13 @@ func (this *FieldOptions) GoString() string { s := make([]string, 0, 11) s = append(s, "&descriptor.FieldOptions{") if this.Ctype != nil { - s = append(s, "Ctype: "+valueToGoStringDescriptor(this.Ctype, "FieldOptions_CType")+",\n") + s = append(s, "Ctype: "+valueToGoStringDescriptor(this.Ctype, "google.protobuf_FieldOptions_CType")+",\n") } if this.Packed != nil { s = append(s, "Packed: "+valueToGoStringDescriptor(this.Packed, "bool")+",\n") } if this.Jstype != nil { - s = append(s, "Jstype: "+valueToGoStringDescriptor(this.Jstype, "FieldOptions_JSType")+",\n") + s = append(s, "Jstype: "+valueToGoStringDescriptor(this.Jstype, "google.protobuf_FieldOptions_JSType")+",\n") } if this.Lazy != nil { s = append(s, "Lazy: "+valueToGoStringDescriptor(this.Lazy, "bool")+",\n") @@ -580,7 +580,7 @@ func (this *MethodOptions) GoString() string { s = append(s, "Deprecated: "+valueToGoStringDescriptor(this.Deprecated, "bool")+",\n") } if this.IdempotencyLevel != nil { - s = append(s, "IdempotencyLevel: "+valueToGoStringDescriptor(this.IdempotencyLevel, "MethodOptions_IdempotencyLevel")+",\n") + s = append(s, "IdempotencyLevel: "+valueToGoStringDescriptor(this.IdempotencyLevel, "google.protobuf_MethodOptions_IdempotencyLevel")+",\n") } if this.UninterpretedOption != nil { s = append(s, "UninterpretedOption: "+fmt.Sprintf("%#v", this.UninterpretedOption)+",\n") diff --git a/test/combos/both/thetest.pb.go b/test/combos/both/thetest.pb.go index b1f0e7e1da..d187ca3066 100644 --- a/test/combos/both/thetest.pb.go +++ b/test/combos/both/thetest.pb.go @@ -21317,13 +21317,13 @@ func (this *NinOptEnum) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.NinOptEnum{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "TheTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.TheTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -21380,13 +21380,13 @@ func (this *NinOptEnumDefault) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.NinOptEnumDefault{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "TheTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.TheTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -21401,13 +21401,13 @@ func (this *AnotherNinOptEnum) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.AnotherNinOptEnum{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "AnotherTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.AnotherTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -21422,13 +21422,13 @@ func (this *AnotherNinOptEnumDefault) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.AnotherNinOptEnumDefault{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "AnotherTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.AnotherTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -21499,7 +21499,7 @@ func (this *NestedDefinition) GoString() string { s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "int64")+",\n") } if this.EnumField != nil { - s = append(s, "EnumField: "+valueToGoStringThetest(this.EnumField, "NestedDefinition_NestedEnum")+",\n") + s = append(s, "EnumField: "+valueToGoStringThetest(this.EnumField, "test.NestedDefinition_NestedEnum")+",\n") } if this.NNM != nil { s = append(s, "NNM: "+fmt.Sprintf("%#v", this.NNM)+",\n") @@ -21556,7 +21556,7 @@ func (this *NestedScope) GoString() string { s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") } if this.B != nil { - s = append(s, "B: "+valueToGoStringThetest(this.B, "NestedDefinition_NestedEnum")+",\n") + s = append(s, "B: "+valueToGoStringThetest(this.B, "test.NestedDefinition_NestedEnum")+",\n") } if this.C != nil { s = append(s, "C: "+fmt.Sprintf("%#v", this.C)+",\n") @@ -21872,7 +21872,7 @@ func (this *CustomNameEnum) GoString() string { s := make([]string, 0, 6) s = append(s, "&test.CustomNameEnum{") if this.FieldA != nil { - s = append(s, "FieldA: "+valueToGoStringThetest(this.FieldA, "TheTestEnum")+",\n") + s = append(s, "FieldA: "+valueToGoStringThetest(this.FieldA, "test.TheTestEnum")+",\n") } if this.FieldB != nil { s = append(s, "FieldB: "+fmt.Sprintf("%#v", this.FieldB)+",\n") diff --git a/test/combos/marshaler/thetest.pb.go b/test/combos/marshaler/thetest.pb.go index a5340326c7..9a43c65cc1 100644 --- a/test/combos/marshaler/thetest.pb.go +++ b/test/combos/marshaler/thetest.pb.go @@ -21316,13 +21316,13 @@ func (this *NinOptEnum) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.NinOptEnum{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "TheTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.TheTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -21379,13 +21379,13 @@ func (this *NinOptEnumDefault) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.NinOptEnumDefault{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "TheTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.TheTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -21400,13 +21400,13 @@ func (this *AnotherNinOptEnum) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.AnotherNinOptEnum{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "AnotherTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.AnotherTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -21421,13 +21421,13 @@ func (this *AnotherNinOptEnumDefault) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.AnotherNinOptEnumDefault{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "AnotherTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.AnotherTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -21498,7 +21498,7 @@ func (this *NestedDefinition) GoString() string { s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "int64")+",\n") } if this.EnumField != nil { - s = append(s, "EnumField: "+valueToGoStringThetest(this.EnumField, "NestedDefinition_NestedEnum")+",\n") + s = append(s, "EnumField: "+valueToGoStringThetest(this.EnumField, "test.NestedDefinition_NestedEnum")+",\n") } if this.NNM != nil { s = append(s, "NNM: "+fmt.Sprintf("%#v", this.NNM)+",\n") @@ -21555,7 +21555,7 @@ func (this *NestedScope) GoString() string { s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") } if this.B != nil { - s = append(s, "B: "+valueToGoStringThetest(this.B, "NestedDefinition_NestedEnum")+",\n") + s = append(s, "B: "+valueToGoStringThetest(this.B, "test.NestedDefinition_NestedEnum")+",\n") } if this.C != nil { s = append(s, "C: "+fmt.Sprintf("%#v", this.C)+",\n") @@ -21871,7 +21871,7 @@ func (this *CustomNameEnum) GoString() string { s := make([]string, 0, 6) s = append(s, "&test.CustomNameEnum{") if this.FieldA != nil { - s = append(s, "FieldA: "+valueToGoStringThetest(this.FieldA, "TheTestEnum")+",\n") + s = append(s, "FieldA: "+valueToGoStringThetest(this.FieldA, "test.TheTestEnum")+",\n") } if this.FieldB != nil { s = append(s, "FieldB: "+fmt.Sprintf("%#v", this.FieldB)+",\n") diff --git a/test/combos/unmarshaler/thetest.pb.go b/test/combos/unmarshaler/thetest.pb.go index 22b1625a98..395268aeb1 100644 --- a/test/combos/unmarshaler/thetest.pb.go +++ b/test/combos/unmarshaler/thetest.pb.go @@ -20705,13 +20705,13 @@ func (this *NinOptEnum) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.NinOptEnum{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "TheTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.TheTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -20768,13 +20768,13 @@ func (this *NinOptEnumDefault) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.NinOptEnumDefault{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "TheTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.TheTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -20789,13 +20789,13 @@ func (this *AnotherNinOptEnum) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.AnotherNinOptEnum{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "AnotherTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.AnotherTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -20810,13 +20810,13 @@ func (this *AnotherNinOptEnumDefault) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.AnotherNinOptEnumDefault{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "AnotherTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.AnotherTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -20887,7 +20887,7 @@ func (this *NestedDefinition) GoString() string { s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "int64")+",\n") } if this.EnumField != nil { - s = append(s, "EnumField: "+valueToGoStringThetest(this.EnumField, "NestedDefinition_NestedEnum")+",\n") + s = append(s, "EnumField: "+valueToGoStringThetest(this.EnumField, "test.NestedDefinition_NestedEnum")+",\n") } if this.NNM != nil { s = append(s, "NNM: "+fmt.Sprintf("%#v", this.NNM)+",\n") @@ -20944,7 +20944,7 @@ func (this *NestedScope) GoString() string { s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") } if this.B != nil { - s = append(s, "B: "+valueToGoStringThetest(this.B, "NestedDefinition_NestedEnum")+",\n") + s = append(s, "B: "+valueToGoStringThetest(this.B, "test.NestedDefinition_NestedEnum")+",\n") } if this.C != nil { s = append(s, "C: "+fmt.Sprintf("%#v", this.C)+",\n") @@ -21260,7 +21260,7 @@ func (this *CustomNameEnum) GoString() string { s := make([]string, 0, 6) s = append(s, "&test.CustomNameEnum{") if this.FieldA != nil { - s = append(s, "FieldA: "+valueToGoStringThetest(this.FieldA, "TheTestEnum")+",\n") + s = append(s, "FieldA: "+valueToGoStringThetest(this.FieldA, "test.TheTestEnum")+",\n") } if this.FieldB != nil { s = append(s, "FieldB: "+fmt.Sprintf("%#v", this.FieldB)+",\n") diff --git a/test/issue635/Makefile b/test/issue635/Makefile new file mode 100644 index 0000000000..9f915aea7f --- /dev/null +++ b/test/issue635/Makefile @@ -0,0 +1,30 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/gogo/protobuf +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + (protoc --proto_path=../../protobuf/:../../../../../:. --gogo_out=. issue635.proto) diff --git a/test/issue635/issue635.pb.go b/test/issue635/issue635.pb.go new file mode 100644 index 0000000000..da50c28d1b --- /dev/null +++ b/test/issue635/issue635.pb.go @@ -0,0 +1,1064 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue635.proto + +package issue635 + +import ( + bytes "bytes" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + test "github.com/gogo/protobuf/test" + math "math" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type TheEnum int32 + +const ( + TheEnum_TheEnum0 TheEnum = 0 +) + +var TheEnum_name = map[int32]string{ + 0: "TheEnum0", +} + +var TheEnum_value = map[string]int32{ + "TheEnum0": 0, +} + +func (x TheEnum) Enum() *TheEnum { + p := new(TheEnum) + *p = x + return p +} + +func (x TheEnum) String() string { + return proto.EnumName(TheEnum_name, int32(x)) +} + +func (x *TheEnum) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(TheEnum_value, data, "TheEnum") + if err != nil { + return err + } + *x = TheEnum(value) + return nil +} + +func (TheEnum) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{0} +} + +type NestedDefinition_NestedEnum int32 + +const ( + NestedDefinition_TYPE_NESTED NestedDefinition_NestedEnum = 1 +) + +var NestedDefinition_NestedEnum_name = map[int32]string{ + 1: "TYPE_NESTED", +} + +var NestedDefinition_NestedEnum_value = map[string]int32{ + "TYPE_NESTED": 1, +} + +func (x NestedDefinition_NestedEnum) Enum() *NestedDefinition_NestedEnum { + p := new(NestedDefinition_NestedEnum) + *p = x + return p +} + +func (x NestedDefinition_NestedEnum) String() string { + return proto.EnumName(NestedDefinition_NestedEnum_name, int32(x)) +} + +func (x *NestedDefinition_NestedEnum) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(NestedDefinition_NestedEnum_value, data, "NestedDefinition_NestedEnum") + if err != nil { + return err + } + *x = NestedDefinition_NestedEnum(value) + return nil +} + +func (NestedDefinition_NestedEnum) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{5, 0} +} + +type EnumNullable struct { + TheEnum *TheEnum `protobuf:"varint,1,opt,name=TheEnum,enum=issue635.TheEnum" json:"TheEnum,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EnumNullable) Reset() { *m = EnumNullable{} } +func (m *EnumNullable) String() string { return proto.CompactTextString(m) } +func (*EnumNullable) ProtoMessage() {} +func (*EnumNullable) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{0} +} +func (m *EnumNullable) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EnumNullable.Unmarshal(m, b) +} +func (m *EnumNullable) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EnumNullable.Marshal(b, m, deterministic) +} +func (m *EnumNullable) XXX_Merge(src proto.Message) { + xxx_messageInfo_EnumNullable.Merge(m, src) +} +func (m *EnumNullable) XXX_Size() int { + return xxx_messageInfo_EnumNullable.Size(m) +} +func (m *EnumNullable) XXX_DiscardUnknown() { + xxx_messageInfo_EnumNullable.DiscardUnknown(m) +} + +var xxx_messageInfo_EnumNullable proto.InternalMessageInfo + +func (m *EnumNullable) GetTheEnum() TheEnum { + if m != nil && m.TheEnum != nil { + return *m.TheEnum + } + return TheEnum_TheEnum0 +} + +type EnumNonNullable struct { + TheEnum TheEnum `protobuf:"varint,1,opt,name=TheEnum,enum=issue635.TheEnum" json:"TheEnum"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EnumNonNullable) Reset() { *m = EnumNonNullable{} } +func (m *EnumNonNullable) String() string { return proto.CompactTextString(m) } +func (*EnumNonNullable) ProtoMessage() {} +func (*EnumNonNullable) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{1} +} +func (m *EnumNonNullable) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EnumNonNullable.Unmarshal(m, b) +} +func (m *EnumNonNullable) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EnumNonNullable.Marshal(b, m, deterministic) +} +func (m *EnumNonNullable) XXX_Merge(src proto.Message) { + xxx_messageInfo_EnumNonNullable.Merge(m, src) +} +func (m *EnumNonNullable) XXX_Size() int { + return xxx_messageInfo_EnumNonNullable.Size(m) +} +func (m *EnumNonNullable) XXX_DiscardUnknown() { + xxx_messageInfo_EnumNonNullable.DiscardUnknown(m) +} + +var xxx_messageInfo_EnumNonNullable proto.InternalMessageInfo + +func (m *EnumNonNullable) GetTheEnum() TheEnum { + if m != nil { + return m.TheEnum + } + return TheEnum_TheEnum0 +} + +type EnumNullableRepeated struct { + TheEnum []TheEnum `protobuf:"varint,1,rep,name=TheEnum,enum=issue635.TheEnum" json:"TheEnum,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EnumNullableRepeated) Reset() { *m = EnumNullableRepeated{} } +func (m *EnumNullableRepeated) String() string { return proto.CompactTextString(m) } +func (*EnumNullableRepeated) ProtoMessage() {} +func (*EnumNullableRepeated) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{2} +} +func (m *EnumNullableRepeated) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EnumNullableRepeated.Unmarshal(m, b) +} +func (m *EnumNullableRepeated) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EnumNullableRepeated.Marshal(b, m, deterministic) +} +func (m *EnumNullableRepeated) XXX_Merge(src proto.Message) { + xxx_messageInfo_EnumNullableRepeated.Merge(m, src) +} +func (m *EnumNullableRepeated) XXX_Size() int { + return xxx_messageInfo_EnumNullableRepeated.Size(m) +} +func (m *EnumNullableRepeated) XXX_DiscardUnknown() { + xxx_messageInfo_EnumNullableRepeated.DiscardUnknown(m) +} + +var xxx_messageInfo_EnumNullableRepeated proto.InternalMessageInfo + +func (m *EnumNullableRepeated) GetTheEnum() []TheEnum { + if m != nil { + return m.TheEnum + } + return nil +} + +type EnumNullableDifferentPackage struct { + TheEnum *test.TheTestEnum `protobuf:"varint,1,opt,name=TheEnum,enum=test.TheTestEnum" json:"TheEnum,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EnumNullableDifferentPackage) Reset() { *m = EnumNullableDifferentPackage{} } +func (m *EnumNullableDifferentPackage) String() string { return proto.CompactTextString(m) } +func (*EnumNullableDifferentPackage) ProtoMessage() {} +func (*EnumNullableDifferentPackage) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{3} +} +func (m *EnumNullableDifferentPackage) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EnumNullableDifferentPackage.Unmarshal(m, b) +} +func (m *EnumNullableDifferentPackage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EnumNullableDifferentPackage.Marshal(b, m, deterministic) +} +func (m *EnumNullableDifferentPackage) XXX_Merge(src proto.Message) { + xxx_messageInfo_EnumNullableDifferentPackage.Merge(m, src) +} +func (m *EnumNullableDifferentPackage) XXX_Size() int { + return xxx_messageInfo_EnumNullableDifferentPackage.Size(m) +} +func (m *EnumNullableDifferentPackage) XXX_DiscardUnknown() { + xxx_messageInfo_EnumNullableDifferentPackage.DiscardUnknown(m) +} + +var xxx_messageInfo_EnumNullableDifferentPackage proto.InternalMessageInfo + +func (m *EnumNullableDifferentPackage) GetTheEnum() test.TheTestEnum { + if m != nil && m.TheEnum != nil { + return *m.TheEnum + } + return test.A +} + +type EnumNullableNested struct { + NestedEnum *NestedDefinition_NestedEnum `protobuf:"varint,1,opt,name=NestedEnum,enum=issue635.NestedDefinition_NestedEnum" json:"NestedEnum,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EnumNullableNested) Reset() { *m = EnumNullableNested{} } +func (m *EnumNullableNested) String() string { return proto.CompactTextString(m) } +func (*EnumNullableNested) ProtoMessage() {} +func (*EnumNullableNested) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{4} +} +func (m *EnumNullableNested) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EnumNullableNested.Unmarshal(m, b) +} +func (m *EnumNullableNested) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EnumNullableNested.Marshal(b, m, deterministic) +} +func (m *EnumNullableNested) XXX_Merge(src proto.Message) { + xxx_messageInfo_EnumNullableNested.Merge(m, src) +} +func (m *EnumNullableNested) XXX_Size() int { + return xxx_messageInfo_EnumNullableNested.Size(m) +} +func (m *EnumNullableNested) XXX_DiscardUnknown() { + xxx_messageInfo_EnumNullableNested.DiscardUnknown(m) +} + +var xxx_messageInfo_EnumNullableNested proto.InternalMessageInfo + +func (m *EnumNullableNested) GetNestedEnum() NestedDefinition_NestedEnum { + if m != nil && m.NestedEnum != nil { + return *m.NestedEnum + } + return NestedDefinition_TYPE_NESTED +} + +type NestedDefinition struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *NestedDefinition) Reset() { *m = NestedDefinition{} } +func (m *NestedDefinition) String() string { return proto.CompactTextString(m) } +func (*NestedDefinition) ProtoMessage() {} +func (*NestedDefinition) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{5} +} +func (m *NestedDefinition) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NestedDefinition.Unmarshal(m, b) +} +func (m *NestedDefinition) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NestedDefinition.Marshal(b, m, deterministic) +} +func (m *NestedDefinition) XXX_Merge(src proto.Message) { + xxx_messageInfo_NestedDefinition.Merge(m, src) +} +func (m *NestedDefinition) XXX_Size() int { + return xxx_messageInfo_NestedDefinition.Size(m) +} +func (m *NestedDefinition) XXX_DiscardUnknown() { + xxx_messageInfo_NestedDefinition.DiscardUnknown(m) +} + +var xxx_messageInfo_NestedDefinition proto.InternalMessageInfo + +type StringNullable struct { + TheString *string `protobuf:"bytes,1,opt,name=TheString" json:"TheString,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StringNullable) Reset() { *m = StringNullable{} } +func (m *StringNullable) String() string { return proto.CompactTextString(m) } +func (*StringNullable) ProtoMessage() {} +func (*StringNullable) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{6} +} +func (m *StringNullable) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StringNullable.Unmarshal(m, b) +} +func (m *StringNullable) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StringNullable.Marshal(b, m, deterministic) +} +func (m *StringNullable) XXX_Merge(src proto.Message) { + xxx_messageInfo_StringNullable.Merge(m, src) +} +func (m *StringNullable) XXX_Size() int { + return xxx_messageInfo_StringNullable.Size(m) +} +func (m *StringNullable) XXX_DiscardUnknown() { + xxx_messageInfo_StringNullable.DiscardUnknown(m) +} + +var xxx_messageInfo_StringNullable proto.InternalMessageInfo + +func (m *StringNullable) GetTheString() string { + if m != nil && m.TheString != nil { + return *m.TheString + } + return "" +} + +type StringNonNullable struct { + TheString string `protobuf:"bytes,1,opt,name=TheString" json:"TheString"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StringNonNullable) Reset() { *m = StringNonNullable{} } +func (m *StringNonNullable) String() string { return proto.CompactTextString(m) } +func (*StringNonNullable) ProtoMessage() {} +func (*StringNonNullable) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{7} +} +func (m *StringNonNullable) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StringNonNullable.Unmarshal(m, b) +} +func (m *StringNonNullable) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StringNonNullable.Marshal(b, m, deterministic) +} +func (m *StringNonNullable) XXX_Merge(src proto.Message) { + xxx_messageInfo_StringNonNullable.Merge(m, src) +} +func (m *StringNonNullable) XXX_Size() int { + return xxx_messageInfo_StringNonNullable.Size(m) +} +func (m *StringNonNullable) XXX_DiscardUnknown() { + xxx_messageInfo_StringNonNullable.DiscardUnknown(m) +} + +var xxx_messageInfo_StringNonNullable proto.InternalMessageInfo + +func (m *StringNonNullable) GetTheString() string { + if m != nil { + return m.TheString + } + return "" +} + +type StringNullableRepeated struct { + TheString []string `protobuf:"bytes,1,rep,name=TheString" json:"TheString,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StringNullableRepeated) Reset() { *m = StringNullableRepeated{} } +func (m *StringNullableRepeated) String() string { return proto.CompactTextString(m) } +func (*StringNullableRepeated) ProtoMessage() {} +func (*StringNullableRepeated) Descriptor() ([]byte, []int) { + return fileDescriptor_2a294f080984fc41, []int{8} +} +func (m *StringNullableRepeated) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StringNullableRepeated.Unmarshal(m, b) +} +func (m *StringNullableRepeated) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StringNullableRepeated.Marshal(b, m, deterministic) +} +func (m *StringNullableRepeated) XXX_Merge(src proto.Message) { + xxx_messageInfo_StringNullableRepeated.Merge(m, src) +} +func (m *StringNullableRepeated) XXX_Size() int { + return xxx_messageInfo_StringNullableRepeated.Size(m) +} +func (m *StringNullableRepeated) XXX_DiscardUnknown() { + xxx_messageInfo_StringNullableRepeated.DiscardUnknown(m) +} + +var xxx_messageInfo_StringNullableRepeated proto.InternalMessageInfo + +func (m *StringNullableRepeated) GetTheString() []string { + if m != nil { + return m.TheString + } + return nil +} + +func init() { + proto.RegisterEnum("issue635.TheEnum", TheEnum_name, TheEnum_value) + proto.RegisterEnum("issue635.NestedDefinition_NestedEnum", NestedDefinition_NestedEnum_name, NestedDefinition_NestedEnum_value) + proto.RegisterType((*EnumNullable)(nil), "issue635.EnumNullable") + proto.RegisterType((*EnumNonNullable)(nil), "issue635.EnumNonNullable") + proto.RegisterType((*EnumNullableRepeated)(nil), "issue635.EnumNullableRepeated") + proto.RegisterType((*EnumNullableDifferentPackage)(nil), "issue635.EnumNullableDifferentPackage") + proto.RegisterType((*EnumNullableNested)(nil), "issue635.EnumNullableNested") + proto.RegisterType((*NestedDefinition)(nil), "issue635.NestedDefinition") + proto.RegisterType((*StringNullable)(nil), "issue635.StringNullable") + proto.RegisterType((*StringNonNullable)(nil), "issue635.StringNonNullable") + proto.RegisterType((*StringNullableRepeated)(nil), "issue635.StringNullableRepeated") +} + +func init() { proto.RegisterFile("issue635.proto", fileDescriptor_2a294f080984fc41) } + +var fileDescriptor_2a294f080984fc41 = []byte{ + // 359 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcb, 0x2c, 0x2e, 0x2e, + 0x4d, 0x35, 0x33, 0x36, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x80, 0xf1, 0xa5, 0x74, + 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xd3, 0xf3, 0xd3, 0xf3, 0xf5, + 0xc1, 0x0a, 0x92, 0x4a, 0xd3, 0xc0, 0x3c, 0x30, 0x07, 0xcc, 0x82, 0x68, 0x94, 0xd2, 0xc6, 0xa9, + 0xbc, 0x24, 0xb5, 0xb8, 0x44, 0xbf, 0x24, 0x23, 0x15, 0x44, 0x43, 0x14, 0x2b, 0x39, 0x72, 0xf1, + 0xb8, 0xe6, 0x95, 0xe6, 0xfa, 0x95, 0xe6, 0xe4, 0x24, 0x26, 0xe5, 0xa4, 0x0a, 0x19, 0x72, 0xb1, + 0x87, 0x64, 0xa4, 0x82, 0x84, 0x24, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0x04, 0xf5, 0xe0, 0xee, + 0x82, 0x4a, 0x38, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x18, 0x04, 0x53, 0xa7, 0xe4, 0xc2, 0xc5, 0x0f, + 0x36, 0x22, 0x3f, 0x8f, 0x64, 0x53, 0x18, 0x10, 0xa6, 0x78, 0x72, 0x89, 0x20, 0x3b, 0x24, 0x28, + 0xb5, 0x20, 0x35, 0xb1, 0x24, 0x35, 0x05, 0xd5, 0x28, 0x66, 0xa2, 0x1c, 0x14, 0xc8, 0x25, 0x83, + 0x6c, 0x94, 0x4b, 0x66, 0x5a, 0x5a, 0x6a, 0x51, 0x6a, 0x5e, 0x49, 0x40, 0x62, 0x72, 0x76, 0x62, + 0x3a, 0x56, 0xd7, 0x81, 0x43, 0x24, 0x24, 0x23, 0x35, 0x24, 0xb5, 0xb8, 0x04, 0x9b, 0x91, 0x89, + 0x5c, 0x42, 0xc8, 0x46, 0xfa, 0xa5, 0x16, 0x83, 0xdc, 0xe6, 0xcd, 0xc5, 0x05, 0x61, 0x21, 0x99, + 0xa5, 0x8a, 0x70, 0x1e, 0x44, 0xce, 0x25, 0x35, 0x2d, 0x33, 0x2f, 0xb3, 0x24, 0x33, 0x3f, 0x4f, + 0x0f, 0xa1, 0x18, 0x6a, 0x3e, 0x92, 0x76, 0x25, 0x43, 0x2e, 0x01, 0x74, 0x0d, 0x4a, 0xb2, 0xc8, + 0x16, 0x08, 0xf1, 0x73, 0x71, 0x87, 0x44, 0x06, 0xb8, 0xc6, 0xfb, 0xb9, 0x06, 0x87, 0xb8, 0xba, + 0x08, 0x30, 0x2a, 0x99, 0x70, 0xf1, 0x05, 0x97, 0x14, 0x65, 0xe6, 0xa5, 0xc3, 0x03, 0x5e, 0x89, + 0x8b, 0x33, 0x24, 0x23, 0x15, 0x22, 0x08, 0x76, 0x10, 0x27, 0xd4, 0x26, 0x84, 0xb0, 0x92, 0x39, + 0x97, 0x20, 0x54, 0x17, 0x52, 0x8c, 0xe1, 0xd0, 0xc8, 0x80, 0xac, 0xd1, 0x86, 0x4b, 0x0c, 0xd5, + 0x3a, 0x78, 0x24, 0xa1, 0xe9, 0x66, 0xc6, 0x62, 0xad, 0x96, 0x38, 0x3c, 0xd4, 0x85, 0x78, 0xb8, + 0x38, 0xa0, 0x4c, 0x03, 0x01, 0x06, 0x27, 0x81, 0x0f, 0x0f, 0xe5, 0x18, 0x7f, 0x3c, 0x94, 0x63, + 0x5c, 0xf1, 0x48, 0x8e, 0x71, 0xc7, 0x23, 0x39, 0x46, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x99, + 0xdb, 0x01, 0x64, 0x0b, 0x03, 0x00, 0x00, +} + +func (this *EnumNullable) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*EnumNullable) + if !ok { + that2, ok := that.(EnumNullable) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.TheEnum != nil && that1.TheEnum != nil { + if *this.TheEnum != *that1.TheEnum { + return false + } + } else if this.TheEnum != nil { + return false + } else if that1.TheEnum != nil { + return false + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *EnumNonNullable) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*EnumNonNullable) + if !ok { + that2, ok := that.(EnumNonNullable) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.TheEnum != that1.TheEnum { + return false + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *EnumNullableRepeated) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*EnumNullableRepeated) + if !ok { + that2, ok := that.(EnumNullableRepeated) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.TheEnum) != len(that1.TheEnum) { + return false + } + for i := range this.TheEnum { + if this.TheEnum[i] != that1.TheEnum[i] { + return false + } + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *EnumNullableDifferentPackage) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*EnumNullableDifferentPackage) + if !ok { + that2, ok := that.(EnumNullableDifferentPackage) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.TheEnum != nil && that1.TheEnum != nil { + if *this.TheEnum != *that1.TheEnum { + return false + } + } else if this.TheEnum != nil { + return false + } else if that1.TheEnum != nil { + return false + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *EnumNullableNested) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*EnumNullableNested) + if !ok { + that2, ok := that.(EnumNullableNested) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.NestedEnum != nil && that1.NestedEnum != nil { + if *this.NestedEnum != *that1.NestedEnum { + return false + } + } else if this.NestedEnum != nil { + return false + } else if that1.NestedEnum != nil { + return false + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *NestedDefinition) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*NestedDefinition) + if !ok { + that2, ok := that.(NestedDefinition) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *StringNullable) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*StringNullable) + if !ok { + that2, ok := that.(StringNullable) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.TheString != nil && that1.TheString != nil { + if *this.TheString != *that1.TheString { + return false + } + } else if this.TheString != nil { + return false + } else if that1.TheString != nil { + return false + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *StringNonNullable) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*StringNonNullable) + if !ok { + that2, ok := that.(StringNonNullable) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.TheString != that1.TheString { + return false + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *StringNullableRepeated) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*StringNullableRepeated) + if !ok { + that2, ok := that.(StringNullableRepeated) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.TheString) != len(that1.TheString) { + return false + } + for i := range this.TheString { + if this.TheString[i] != that1.TheString[i] { + return false + } + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (this *EnumNullable) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue635.EnumNullable{") + if this.TheEnum != nil { + s = append(s, "TheEnum: "+valueToGoStringIssue635(this.TheEnum, "issue635.TheEnum")+",\n") + } + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *EnumNonNullable) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue635.EnumNonNullable{") + s = append(s, "TheEnum: "+fmt.Sprintf("%#v", this.TheEnum)+",\n") + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *EnumNullableRepeated) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue635.EnumNullableRepeated{") + if this.TheEnum != nil { + s = append(s, "TheEnum: "+fmt.Sprintf("%#v", this.TheEnum)+",\n") + } + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *EnumNullableDifferentPackage) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue635.EnumNullableDifferentPackage{") + if this.TheEnum != nil { + s = append(s, "TheEnum: "+valueToGoStringIssue635(this.TheEnum, "test.TheTestEnum")+",\n") + } + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *EnumNullableNested) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue635.EnumNullableNested{") + if this.NestedEnum != nil { + s = append(s, "NestedEnum: "+valueToGoStringIssue635(this.NestedEnum, "issue635.NestedDefinition_NestedEnum")+",\n") + } + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *NestedDefinition) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 4) + s = append(s, "&issue635.NestedDefinition{") + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *StringNullable) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue635.StringNullable{") + if this.TheString != nil { + s = append(s, "TheString: "+valueToGoStringIssue635(this.TheString, "string")+",\n") + } + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *StringNonNullable) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue635.StringNonNullable{") + s = append(s, "TheString: "+fmt.Sprintf("%#v", this.TheString)+",\n") + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *StringNullableRepeated) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&issue635.StringNullableRepeated{") + if this.TheString != nil { + s = append(s, "TheString: "+fmt.Sprintf("%#v", this.TheString)+",\n") + } + if this.XXX_unrecognized != nil { + s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringIssue635(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func NewPopulatedEnumNullable(r randyIssue635, easy bool) *EnumNullable { + this := &EnumNullable{} + if r.Intn(5) != 0 { + v1 := TheEnum([]int32{0}[r.Intn(1)]) + this.TheEnum = &v1 + } + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 2) + } + return this +} + +func NewPopulatedEnumNonNullable(r randyIssue635, easy bool) *EnumNonNullable { + this := &EnumNonNullable{} + this.TheEnum = TheEnum([]int32{0}[r.Intn(1)]) + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 2) + } + return this +} + +func NewPopulatedEnumNullableRepeated(r randyIssue635, easy bool) *EnumNullableRepeated { + this := &EnumNullableRepeated{} + if r.Intn(5) != 0 { + v2 := r.Intn(10) + this.TheEnum = make([]TheEnum, v2) + for i := 0; i < v2; i++ { + this.TheEnum[i] = TheEnum([]int32{0}[r.Intn(1)]) + } + } + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 2) + } + return this +} + +func NewPopulatedEnumNullableDifferentPackage(r randyIssue635, easy bool) *EnumNullableDifferentPackage { + this := &EnumNullableDifferentPackage{} + if r.Intn(5) != 0 { + v3 := test.TheTestEnum([]int32{0, 1, 2}[r.Intn(3)]) + this.TheEnum = &v3 + } + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 2) + } + return this +} + +func NewPopulatedEnumNullableNested(r randyIssue635, easy bool) *EnumNullableNested { + this := &EnumNullableNested{} + if r.Intn(5) != 0 { + v4 := NestedDefinition_NestedEnum([]int32{1}[r.Intn(1)]) + this.NestedEnum = &v4 + } + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 2) + } + return this +} + +func NewPopulatedNestedDefinition(r randyIssue635, easy bool) *NestedDefinition { + this := &NestedDefinition{} + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 1) + } + return this +} + +func NewPopulatedStringNullable(r randyIssue635, easy bool) *StringNullable { + this := &StringNullable{} + if r.Intn(5) != 0 { + v5 := string(randStringIssue635(r)) + this.TheString = &v5 + } + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 2) + } + return this +} + +func NewPopulatedStringNonNullable(r randyIssue635, easy bool) *StringNonNullable { + this := &StringNonNullable{} + this.TheString = string(randStringIssue635(r)) + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 2) + } + return this +} + +func NewPopulatedStringNullableRepeated(r randyIssue635, easy bool) *StringNullableRepeated { + this := &StringNullableRepeated{} + if r.Intn(5) != 0 { + v6 := r.Intn(10) + this.TheString = make([]string, v6) + for i := 0; i < v6; i++ { + this.TheString[i] = string(randStringIssue635(r)) + } + } + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedIssue635(r, 2) + } + return this +} + +type randyIssue635 interface { + Float32() float32 + Float64() float64 + Int63() int64 + Int31() int32 + Uint32() uint32 + Intn(n int) int +} + +func randUTF8RuneIssue635(r randyIssue635) rune { + ru := r.Intn(62) + if ru < 10 { + return rune(ru + 48) + } else if ru < 36 { + return rune(ru + 55) + } + return rune(ru + 61) +} +func randStringIssue635(r randyIssue635) string { + v7 := r.Intn(100) + tmps := make([]rune, v7) + for i := 0; i < v7; i++ { + tmps[i] = randUTF8RuneIssue635(r) + } + return string(tmps) +} +func randUnrecognizedIssue635(r randyIssue635, maxFieldNumber int) (dAtA []byte) { + l := r.Intn(5) + for i := 0; i < l; i++ { + wire := r.Intn(4) + if wire == 3 { + wire = 5 + } + fieldNumber := maxFieldNumber + r.Intn(100) + dAtA = randFieldIssue635(dAtA, r, fieldNumber, wire) + } + return dAtA +} +func randFieldIssue635(dAtA []byte, r randyIssue635, fieldNumber int, wire int) []byte { + key := uint32(fieldNumber)<<3 | uint32(wire) + switch wire { + case 0: + dAtA = encodeVarintPopulateIssue635(dAtA, uint64(key)) + v8 := r.Int63() + if r.Intn(2) == 0 { + v8 *= -1 + } + dAtA = encodeVarintPopulateIssue635(dAtA, uint64(v8)) + case 1: + dAtA = encodeVarintPopulateIssue635(dAtA, uint64(key)) + dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) + case 2: + dAtA = encodeVarintPopulateIssue635(dAtA, uint64(key)) + ll := r.Intn(100) + dAtA = encodeVarintPopulateIssue635(dAtA, uint64(ll)) + for j := 0; j < ll; j++ { + dAtA = append(dAtA, byte(r.Intn(256))) + } + default: + dAtA = encodeVarintPopulateIssue635(dAtA, uint64(key)) + dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) + } + return dAtA +} +func encodeVarintPopulateIssue635(dAtA []byte, v uint64) []byte { + for v >= 1<<7 { + dAtA = append(dAtA, uint8(uint64(v)&0x7f|0x80)) + v >>= 7 + } + dAtA = append(dAtA, uint8(v)) + return dAtA +} diff --git a/test/issue635/issue635.proto b/test/issue635/issue635.proto new file mode 100644 index 0000000000..83d0a20811 --- /dev/null +++ b/test/issue635/issue635.proto @@ -0,0 +1,81 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto2"; + +package issue635; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/gogo/protobuf/test/thetest.proto"; + +option (gogoproto.gostring_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.testgen_all) = true; + +message EnumNullable { + optional TheEnum TheEnum = 1 [(gogoproto.nullable) = true]; +} + +message EnumNonNullable { + optional TheEnum TheEnum = 1 [(gogoproto.nullable) = false]; +} + +message EnumNullableRepeated { + repeated TheEnum TheEnum = 1 [(gogoproto.nullable) = true]; +} + +message EnumNullableDifferentPackage { + optional test.TheTestEnum TheEnum = 1 [(gogoproto.nullable) = true]; +} + +message EnumNullableNested { + optional NestedDefinition.NestedEnum NestedEnum = 1 [(gogoproto.nullable) = true]; +} + +message NestedDefinition { + enum NestedEnum { + TYPE_NESTED = 1; + } +} + +enum TheEnum { + TheEnum0 = 0; +} + +message StringNullable { + optional string TheString = 1 [(gogoproto.nullable) = true]; +} + +message StringNonNullable { + optional string TheString = 1 [(gogoproto.nullable) = false]; +} + +message StringNullableRepeated { + repeated string TheString = 1 [(gogoproto.nullable) = true]; +} \ No newline at end of file diff --git a/test/issue635/issue635_test.go b/test/issue635/issue635_test.go new file mode 100644 index 0000000000..b2c33e6826 --- /dev/null +++ b/test/issue635/issue635_test.go @@ -0,0 +1,103 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2015, The GoGo Authors. All rights reserved. +// http://github.com/gogo/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package issue635_test + +import ( + fmt "fmt" + "testing" + + "github.com/gogo/protobuf/test" + "github.com/gogo/protobuf/test/issue635" +) + +func TestEnumNullableGoString(t *testing.T) { + theEnum := issue635.TheEnum_TheEnum0 + enumNullable := &issue635.EnumNullable{TheEnum: &theEnum} + expected := `&issue635.EnumNullable{TheEnum: func(v issue635.TheEnum) *issue635.TheEnum { return &v } ( 0 ), +}` + testGostring(t, enumNullable, expected) +} + +func TestEnumNonNullableGoString(t *testing.T) { + enumNonNullable := &issue635.EnumNonNullable{TheEnum: issue635.TheEnum_TheEnum0} + expected := `&issue635.EnumNonNullable{TheEnum: 0, +}` + testGostring(t, enumNonNullable, expected) +} + +func TestEnumNullableRepeatedGoString(t *testing.T) { + enumNullableRepeated := &issue635.EnumNullableRepeated{TheEnum: []issue635.TheEnum{issue635.TheEnum_TheEnum0, issue635.TheEnum_TheEnum0}} + expected := `&issue635.EnumNullableRepeated{TheEnum: []issue635.TheEnum{0, 0}, +}` + testGostring(t, enumNullableRepeated, expected) +} + +func TestEnumNullableDifferentPackageGoString(t *testing.T) { + theEnum := test.A + enumNullableDifferentPackage := &issue635.EnumNullableDifferentPackage{TheEnum: &theEnum} + expected := `&issue635.EnumNullableDifferentPackage{TheEnum: func(v test.TheTestEnum) *test.TheTestEnum { return &v } ( 0 ), +}` + testGostring(t, enumNullableDifferentPackage, expected) +} + +func TestEnumNullableNestedGoString(t *testing.T) { + nestedEnum := issue635.NestedDefinition_TYPE_NESTED + enumNullableNested := &issue635.EnumNullableNested{NestedEnum: &nestedEnum} + expected := `&issue635.EnumNullableNested{NestedEnum: func(v issue635.NestedDefinition_NestedEnum) *issue635.NestedDefinition_NestedEnum { return &v } ( 1 ), +}` + testGostring(t, enumNullableNested, expected) +} + +func TestStringNullableGoString(t *testing.T) { + theString := "theString" + stringNullable := &issue635.StringNullable{TheString: &theString} + expected := `&issue635.StringNullable{TheString: func(v string) *string { return &v } ( "theString" ), +}` + testGostring(t, stringNullable, expected) +} +func TestStringNonNullableGoString(t *testing.T) { + stringNonNullable := &issue635.StringNonNullable{TheString: "theString"} + expected := `&issue635.StringNonNullable{TheString: "theString", +}` + testGostring(t, stringNonNullable, expected) +} + +func TestStringNullableRepeatedGoString(t *testing.T) { + stringNullableRepeated := &issue635.StringNullableRepeated{TheString: []string{"theFirstString", "theSecondString"}} + expected := `&issue635.StringNullableRepeated{TheString: []string{"theFirstString", "theSecondString"}, +}` + testGostring(t, stringNullableRepeated, expected) +} + +func testGostring(t *testing.T, gs fmt.GoStringer, expected string) { + actual := gs.GoString() + if expected != actual { + t.Fatalf("expected:\n%s\ngot:\n%s\n", expected, actual) + } +} diff --git a/test/issue635/issue635pb_test.go b/test/issue635/issue635pb_test.go new file mode 100644 index 0000000000..9a168a08fb --- /dev/null +++ b/test/issue635/issue635pb_test.go @@ -0,0 +1,836 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: issue635.proto + +package issue635 + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" + github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" + proto "github.com/gogo/protobuf/proto" + _ "github.com/gogo/protobuf/test" + go_parser "go/parser" + math "math" + math_rand "math/rand" + testing "testing" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +func TestEnumNullableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNullable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestEnumNonNullableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNonNullable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNonNullable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestEnumNullableRepeatedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableRepeated(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNullableRepeated{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestEnumNullableDifferentPackageProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableDifferentPackage(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNullableDifferentPackage{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestEnumNullableNestedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableNested(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNullableNested{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestNestedDefinitionProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestStringNullableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNullable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StringNullable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestStringNonNullableProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNonNullable(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StringNonNullable{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestStringNullableRepeatedProto(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNullableRepeated(popr, false) + dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StringNullableRepeated{} + if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + littlefuzz := make([]byte, len(dAtA)) + copy(littlefuzz, dAtA) + for i := range dAtA { + dAtA[i] = byte(popr.Intn(256)) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } + if len(littlefuzz) > 0 { + fuzzamount := 100 + for i := 0; i < fuzzamount; i++ { + littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) + littlefuzz = append(littlefuzz, byte(popr.Intn(256))) + } + // shouldn't panic + _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) + } +} + +func TestEnumNullableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNullable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestEnumNonNullableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNonNullable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNonNullable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestEnumNullableRepeatedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableRepeated(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNullableRepeated{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestEnumNullableDifferentPackageJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableDifferentPackage(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNullableDifferentPackage{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestEnumNullableNestedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableNested(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &EnumNullableNested{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestNestedDefinitionJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &NestedDefinition{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStringNullableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNullable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StringNullable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStringNonNullableJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNonNullable(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StringNonNullable{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestStringNullableRepeatedJSON(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNullableRepeated(popr, true) + marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} + jsondata, err := marshaler.MarshalToString(p) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + msg := &StringNullableRepeated{} + err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) + if err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) + } +} +func TestEnumNullableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &EnumNullable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNullableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &EnumNullable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNonNullableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNonNullable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &EnumNonNullable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNonNullableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNonNullable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &EnumNonNullable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNullableRepeatedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableRepeated(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &EnumNullableRepeated{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNullableRepeatedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableRepeated(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &EnumNullableRepeated{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNullableDifferentPackageProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableDifferentPackage(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &EnumNullableDifferentPackage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNullableDifferentPackageProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableDifferentPackage(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &EnumNullableDifferentPackage{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNullableNestedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &EnumNullableNested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNullableNestedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedEnumNullableNested(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &EnumNullableNested{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestNestedDefinitionProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedNestedDefinition(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &NestedDefinition{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStringNullableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNullable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &StringNullable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStringNullableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNullable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &StringNullable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStringNonNullableProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNonNullable(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &StringNonNullable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStringNonNullableProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNonNullable(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &StringNonNullable{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStringNullableRepeatedProtoText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNullableRepeated(popr, true) + dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) + msg := &StringNullableRepeated{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestStringNullableRepeatedProtoCompactText(t *testing.T) { + seed := time.Now().UnixNano() + popr := math_rand.New(math_rand.NewSource(seed)) + p := NewPopulatedStringNullableRepeated(popr, true) + dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) + msg := &StringNullableRepeated{} + if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { + t.Fatalf("seed = %d, err = %v", seed, err) + } + if !p.Equal(msg) { + t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) + } +} + +func TestEnumNullableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedEnumNullable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestEnumNonNullableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedEnumNonNullable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestEnumNullableRepeatedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedEnumNullableRepeated(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestEnumNullableDifferentPackageGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedEnumNullableDifferentPackage(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestEnumNullableNestedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedEnumNullableNested(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestNestedDefinitionGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedNestedDefinition(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestStringNullableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStringNullable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestStringNonNullableGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStringNonNullable(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} +func TestStringNullableRepeatedGoString(t *testing.T) { + popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) + p := NewPopulatedStringNullableRepeated(popr, false) + s1 := p.GoString() + s2 := fmt.Sprintf("%#v", p) + if s1 != s2 { + t.Fatalf("GoString want %v got %v", s1, s2) + } + _, err := go_parser.ParseExpr(s1) + if err != nil { + t.Fatal(err) + } +} + +//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/test/thetest.pb.go b/test/thetest.pb.go index 67187fa5ad..141feeb693 100644 --- a/test/thetest.pb.go +++ b/test/thetest.pb.go @@ -20702,13 +20702,13 @@ func (this *NinOptEnum) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.NinOptEnum{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "TheTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.TheTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -20765,13 +20765,13 @@ func (this *NinOptEnumDefault) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.NinOptEnumDefault{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "TheTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.TheTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -20786,13 +20786,13 @@ func (this *AnotherNinOptEnum) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.AnotherNinOptEnum{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "AnotherTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.AnotherTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -20807,13 +20807,13 @@ func (this *AnotherNinOptEnumDefault) GoString() string { s := make([]string, 0, 7) s = append(s, "&test.AnotherNinOptEnumDefault{") if this.Field1 != nil { - s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "AnotherTestEnum")+",\n") + s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "test.AnotherTestEnum")+",\n") } if this.Field2 != nil { - s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "YetAnotherTestEnum")+",\n") + s = append(s, "Field2: "+valueToGoStringThetest(this.Field2, "test.YetAnotherTestEnum")+",\n") } if this.Field3 != nil { - s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "YetYetAnotherTestEnum")+",\n") + s = append(s, "Field3: "+valueToGoStringThetest(this.Field3, "test.YetYetAnotherTestEnum")+",\n") } if this.XXX_unrecognized != nil { s = append(s, "XXX_unrecognized:"+fmt.Sprintf("%#v", this.XXX_unrecognized)+",\n") @@ -20884,7 +20884,7 @@ func (this *NestedDefinition) GoString() string { s = append(s, "Field1: "+valueToGoStringThetest(this.Field1, "int64")+",\n") } if this.EnumField != nil { - s = append(s, "EnumField: "+valueToGoStringThetest(this.EnumField, "NestedDefinition_NestedEnum")+",\n") + s = append(s, "EnumField: "+valueToGoStringThetest(this.EnumField, "test.NestedDefinition_NestedEnum")+",\n") } if this.NNM != nil { s = append(s, "NNM: "+fmt.Sprintf("%#v", this.NNM)+",\n") @@ -20941,7 +20941,7 @@ func (this *NestedScope) GoString() string { s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n") } if this.B != nil { - s = append(s, "B: "+valueToGoStringThetest(this.B, "NestedDefinition_NestedEnum")+",\n") + s = append(s, "B: "+valueToGoStringThetest(this.B, "test.NestedDefinition_NestedEnum")+",\n") } if this.C != nil { s = append(s, "C: "+fmt.Sprintf("%#v", this.C)+",\n") @@ -21257,7 +21257,7 @@ func (this *CustomNameEnum) GoString() string { s := make([]string, 0, 6) s = append(s, "&test.CustomNameEnum{") if this.FieldA != nil { - s = append(s, "FieldA: "+valueToGoStringThetest(this.FieldA, "TheTestEnum")+",\n") + s = append(s, "FieldA: "+valueToGoStringThetest(this.FieldA, "test.TheTestEnum")+",\n") } if this.FieldB != nil { s = append(s, "FieldB: "+fmt.Sprintf("%#v", this.FieldB)+",\n")