From d0032defe6d350ad7c4933dd3d01aa9ac269b9ee Mon Sep 17 00:00:00 2001 From: Alex Bice Date: Sun, 23 Jan 2022 09:36:20 -0700 Subject: [PATCH 1/3] Add puncuation to comments --- example/animal_enum.go | 2 +- example/color_enum.go | 6 +- example/commented_enum.go | 12 ++-- example/custom_prefix_enum.go | 2 +- example/example_enum.go | 12 ++-- example/globs/letter_enum.go | 2 +- example/globs/number_enum.go | 2 +- example/sql_enum.go | 6 +- example/sql_int_enum.go | 2 +- example/sql_str_enum.go | 2 +- example/user_template_enum.go | 2 +- .../generator-TestCustomPrefixExampleFile | 66 +++++++++---------- .../.snapshots/generator-TestExampleFile | 66 +++++++++---------- .../generator-TestNoPrefixExampleFile | 66 +++++++++---------- ...or-TestNoPrefixExampleFileWithSnakeToCamel | 66 +++++++++---------- generator/enum.tmpl | 6 +- 16 files changed, 160 insertions(+), 160 deletions(-) diff --git a/example/animal_enum.go b/example/animal_enum.go index f6c15a95..47d05e4a 100644 --- a/example/animal_enum.go +++ b/example/animal_enum.go @@ -49,7 +49,7 @@ var _AnimalValue = map[string]Animal{ _AnimalName[16:21]: AnimalFishSharp, } -// ParseAnimal attempts to convert a string to a Animal +// ParseAnimal attempts to convert a string to a Animal. func ParseAnimal(name string) (Animal, error) { if x, ok := _AnimalValue[name]; ok { return x, nil diff --git a/example/color_enum.go b/example/color_enum.go index 96321e57..7899fbe1 100644 --- a/example/color_enum.go +++ b/example/color_enum.go @@ -86,7 +86,7 @@ var _ColorValue = map[string]Color{ strings.ToLower(_ColorName[64:79]): ColorRedOrangeBlue, } -// ParseColor attempts to convert a string to a Color +// ParseColor attempts to convert a string to a Color. func ParseColor(name string) (Color, error) { if x, ok := _ColorValue[name]; ok { return x, nil @@ -98,12 +98,12 @@ func (x Color) Ptr() *Color { return &x } -// MarshalText implements the text marshaller method +// MarshalText implements the text marshaller method. func (x Color) MarshalText() ([]byte, error) { return []byte(x.String()), nil } -// UnmarshalText implements the text unmarshaller method +// UnmarshalText implements the text unmarshaller method. func (x *Color) UnmarshalText(text []byte) error { name := string(text) tmp, err := ParseColor(name) diff --git a/example/commented_enum.go b/example/commented_enum.go index 5d3e0380..5c3b6b52 100644 --- a/example/commented_enum.go +++ b/example/commented_enum.go @@ -47,7 +47,7 @@ var _CommentedValue = map[string]Commented{ strings.ToLower(_CommentedName[12:18]): CommentedValue3, } -// ParseCommented attempts to convert a string to a Commented +// ParseCommented attempts to convert a string to a Commented. func ParseCommented(name string) (Commented, error) { if x, ok := _CommentedValue[name]; ok { return x, nil @@ -55,12 +55,12 @@ func ParseCommented(name string) (Commented, error) { return Commented(0), fmt.Errorf("%s is not a valid Commented", name) } -// MarshalText implements the text marshaller method +// MarshalText implements the text marshaller method. func (x Commented) MarshalText() ([]byte, error) { return []byte(x.String()), nil } -// UnmarshalText implements the text unmarshaller method +// UnmarshalText implements the text unmarshaller method. func (x *Commented) UnmarshalText(text []byte) error { name := string(text) tmp, err := ParseCommented(name) @@ -110,7 +110,7 @@ var _ComplexCommentedValue = map[string]ComplexCommented{ strings.ToLower(_ComplexCommentedName[12:18]): ComplexCommentedValue3, } -// ParseComplexCommented attempts to convert a string to a ComplexCommented +// ParseComplexCommented attempts to convert a string to a ComplexCommented. func ParseComplexCommented(name string) (ComplexCommented, error) { if x, ok := _ComplexCommentedValue[name]; ok { return x, nil @@ -118,12 +118,12 @@ func ParseComplexCommented(name string) (ComplexCommented, error) { return ComplexCommented(0), fmt.Errorf("%s is not a valid ComplexCommented", name) } -// MarshalText implements the text marshaller method +// MarshalText implements the text marshaller method. func (x ComplexCommented) MarshalText() ([]byte, error) { return []byte(x.String()), nil } -// UnmarshalText implements the text unmarshaller method +// UnmarshalText implements the text unmarshaller method. func (x *ComplexCommented) UnmarshalText(text []byte) error { name := string(text) tmp, err := ParseComplexCommented(name) diff --git a/example/custom_prefix_enum.go b/example/custom_prefix_enum.go index 081dd843..3e580a94 100644 --- a/example/custom_prefix_enum.go +++ b/example/custom_prefix_enum.go @@ -41,7 +41,7 @@ var _ProductValue = map[string]Product{ _ProductName[13:17]: AcmeIncProductGlue, } -// ParseProduct attempts to convert a string to a Product +// ParseProduct attempts to convert a string to a Product. func ParseProduct(name string) (Product, error) { if x, ok := _ProductValue[name]; ok { return x, nil diff --git a/example/example_enum.go b/example/example_enum.go index d9ae2ea8..0f3305bc 100644 --- a/example/example_enum.go +++ b/example/example_enum.go @@ -126,7 +126,7 @@ var _MakeValue = map[string]Make{ strings.ToLower(_MakeName[59:69]): MakeVolkswagon, } -// ParseMake attempts to convert a string to a Make +// ParseMake attempts to convert a string to a Make. func ParseMake(name string) (Make, error) { if x, ok := _MakeValue[name]; ok { return x, nil @@ -138,12 +138,12 @@ func ParseMake(name string) (Make, error) { return Make(0), fmt.Errorf("%s is not a valid Make, try [%s]", name, strings.Join(_MakeNames, ", ")) } -// MarshalText implements the text marshaller method +// MarshalText implements the text marshaller method. func (x Make) MarshalText() ([]byte, error) { return []byte(x.String()), nil } -// UnmarshalText implements the text unmarshaller method +// UnmarshalText implements the text unmarshaller method. func (x *Make) UnmarshalText(text []byte) error { name := string(text) tmp, err := ParseMake(name) @@ -236,7 +236,7 @@ var _NoZerosValue = map[string]NoZeros{ strings.ToLower(_NoZerosName[19:23]): NoZerosPpps, } -// ParseNoZeros attempts to convert a string to a NoZeros +// ParseNoZeros attempts to convert a string to a NoZeros. func ParseNoZeros(name string) (NoZeros, error) { if x, ok := _NoZerosValue[name]; ok { return x, nil @@ -248,12 +248,12 @@ func ParseNoZeros(name string) (NoZeros, error) { return NoZeros(0), fmt.Errorf("%s is not a valid NoZeros, try [%s]", name, strings.Join(_NoZerosNames, ", ")) } -// MarshalText implements the text marshaller method +// MarshalText implements the text marshaller method. func (x NoZeros) MarshalText() ([]byte, error) { return []byte(x.String()), nil } -// UnmarshalText implements the text unmarshaller method +// UnmarshalText implements the text unmarshaller method. func (x *NoZeros) UnmarshalText(text []byte) error { name := string(text) tmp, err := ParseNoZeros(name) diff --git a/example/globs/letter_enum.go b/example/globs/letter_enum.go index be1d4fd9..126593ad 100644 --- a/example/globs/letter_enum.go +++ b/example/globs/letter_enum.go @@ -133,7 +133,7 @@ var _LetterValue = map[string]Letter{ _LetterName[25:26]: LetterZ, } -// ParseLetter attempts to convert a string to a Letter +// ParseLetter attempts to convert a string to a Letter. func ParseLetter(name string) (Letter, error) { if x, ok := _LetterValue[name]; ok { return x, nil diff --git a/example/globs/number_enum.go b/example/globs/number_enum.go index 46982e1c..7a7183af 100644 --- a/example/globs/number_enum.go +++ b/example/globs/number_enum.go @@ -69,7 +69,7 @@ var _NumberValue = map[string]Number{ _NumberName[9:10]: Number9, } -// ParseNumber attempts to convert a string to a Number +// ParseNumber attempts to convert a string to a Number. func ParseNumber(name string) (Number, error) { if x, ok := _NumberValue[name]; ok { return x, nil diff --git a/example/sql_enum.go b/example/sql_enum.go index 2ecd2277..9f373649 100644 --- a/example/sql_enum.go +++ b/example/sql_enum.go @@ -49,7 +49,7 @@ var _ProjectStatusValue = map[string]ProjectStatus{ _ProjectStatusName[22:30]: ProjectStatusRejected, } -// ParseProjectStatus attempts to convert a string to a ProjectStatus +// ParseProjectStatus attempts to convert a string to a ProjectStatus. func ParseProjectStatus(name string) (ProjectStatus, error) { if x, ok := _ProjectStatusValue[name]; ok { return x, nil @@ -61,12 +61,12 @@ func (x ProjectStatus) Ptr() *ProjectStatus { return &x } -// MarshalText implements the text marshaller method +// MarshalText implements the text marshaller method. func (x ProjectStatus) MarshalText() ([]byte, error) { return []byte(x.String()), nil } -// UnmarshalText implements the text unmarshaller method +// UnmarshalText implements the text unmarshaller method. func (x *ProjectStatus) UnmarshalText(text []byte) error { name := string(text) tmp, err := ParseProjectStatus(name) diff --git a/example/sql_int_enum.go b/example/sql_int_enum.go index 04d68c87..4d404e24 100644 --- a/example/sql_int_enum.go +++ b/example/sql_int_enum.go @@ -52,7 +52,7 @@ var _ImageTypeValue = map[string]ImageType{ _ImageTypeName[14:17]: ImageTypeGif, } -// ParseImageType attempts to convert a string to a ImageType +// ParseImageType attempts to convert a string to a ImageType. func ParseImageType(name string) (ImageType, error) { if x, ok := _ImageTypeValue[name]; ok { return x, nil diff --git a/example/sql_str_enum.go b/example/sql_str_enum.go index 1c73e048..2184cc07 100644 --- a/example/sql_str_enum.go +++ b/example/sql_str_enum.go @@ -47,7 +47,7 @@ var _JobStateValue = map[string]JobState{ _JobStateName[26:32]: JobStateFailed, } -// ParseJobState attempts to convert a string to a JobState +// ParseJobState attempts to convert a string to a JobState. func ParseJobState(name string) (JobState, error) { if x, ok := _JobStateValue[name]; ok { return x, nil diff --git a/example/user_template_enum.go b/example/user_template_enum.go index 4783884b..e90c1524 100644 --- a/example/user_template_enum.go +++ b/example/user_template_enum.go @@ -41,7 +41,7 @@ var _OceanColorValue = map[string]OceanColor{ _OceanColorName[12:17]: OceanColorGreen, } -// ParseOceanColor attempts to convert a string to a OceanColor +// ParseOceanColor attempts to convert a string to a OceanColor. func ParseOceanColor(name string) (OceanColor, error) { if x, ok := _OceanColorValue[name]; ok { return x, nil diff --git a/generator/.snapshots/generator-TestCustomPrefixExampleFile b/generator/.snapshots/generator-TestCustomPrefixExampleFile index 92be2a10..ffa6185d 100644 --- a/generator/.snapshots/generator-TestCustomPrefixExampleFile +++ b/generator/.snapshots/generator-TestCustomPrefixExampleFile @@ -51,7 +51,7 @@ (string) (len=56) "\tstrings.ToLower(_AnimalName[6:10]): Custom_prefix_Fish,", (string) (len=1) "}", (string) "", - (string) (len=55) "// ParseAnimal attempts to convert a string to a Animal", + (string) (len=56) "// ParseAnimal attempts to convert a string to a Animal.", (string) (len=47) "func ParseAnimal(name string) (Animal, error) {", (string) (len=37) "\tif x, ok := _AnimalValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -63,12 +63,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=47) "func (x Animal) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=51) "func (x *Animal) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=30) "\ttmp, err := ParseAnimal(name)", @@ -313,7 +313,7 @@ (string) (len=73) "\tstrings.ToLower(_CasesName[22:43]): Custom_prefix_AnotherLowerCaseStart,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseCases attempts to convert a string to a Cases", + (string) (len=54) "// ParseCases attempts to convert a string to a Cases.", (string) (len=45) "func ParseCases(name string) (Cases, error) {", (string) (len=36) "\tif x, ok := _CasesValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -325,12 +325,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Cases) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Cases) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseCases(name)", @@ -595,7 +595,7 @@ (string) (len=58) "\tstrings.ToLower(_ColorName[26:32]): Custom_prefix_Yellow,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseColor attempts to convert a string to a Color", + (string) (len=54) "// ParseColor attempts to convert a string to a Color.", (string) (len=45) "func ParseColor(name string) (Color, error) {", (string) (len=36) "\tif x, ok := _ColorValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -607,12 +607,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Color) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Color) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseColor(name)", @@ -878,7 +878,7 @@ (string) (len=69) "\tstrings.ToLower(_ColorWithCommentName[26:32]): Custom_prefix_Yellow,", (string) (len=1) "}", (string) "", - (string) (len=75) "// ParseColorWithComment attempts to convert a string to a ColorWithComment", + (string) (len=76) "// ParseColorWithComment attempts to convert a string to a ColorWithComment.", (string) (len=67) "func ParseColorWithComment(name string) (ColorWithComment, error) {", (string) (len=47) "\tif x, ok := _ColorWithCommentValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -890,12 +890,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=57) "func (x ColorWithComment) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=61) "func (x *ColorWithComment) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=40) "\ttmp, err := ParseColorWithComment(name)", @@ -1161,7 +1161,7 @@ (string) (len=70) "\tstrings.ToLower(_ColorWithComment2Name[26:32]): Custom_prefix_Yellow,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment2 attempts to convert a string to a ColorWithComment2", + (string) (len=78) "// ParseColorWithComment2 attempts to convert a string to a ColorWithComment2.", (string) (len=69) "func ParseColorWithComment2(name string) (ColorWithComment2, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment2Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -1173,12 +1173,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment2) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment2) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment2(name)", @@ -1460,7 +1460,7 @@ (string) (len=77) "\tstrings.ToLower(_ColorWithComment3Name[52:67]): Custom_prefix_RedOrangeBlue,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment3 attempts to convert a string to a ColorWithComment3", + (string) (len=78) "// ParseColorWithComment3 attempts to convert a string to a ColorWithComment3.", (string) (len=69) "func ParseColorWithComment3(name string) (ColorWithComment3, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment3Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -1472,12 +1472,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment3) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment3) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment3(name)", @@ -1759,7 +1759,7 @@ (string) (len=73) "\tstrings.ToLower(_ColorWithComment4Name[42:52]): Custom_prefix_RedOrange,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment4 attempts to convert a string to a ColorWithComment4", + (string) (len=78) "// ParseColorWithComment4 attempts to convert a string to a ColorWithComment4.", (string) (len=69) "func ParseColorWithComment4(name string) (ColorWithComment4, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment4Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -1771,12 +1771,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment4) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment4) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment4(name)", @@ -2025,7 +2025,7 @@ (string) (len=56) "\tstrings.ToLower(_ModelName[11:15]): Custom_prefix_Ford,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseModel attempts to convert a string to a Model", + (string) (len=54) "// ParseModel attempts to convert a string to a Model.", (string) (len=45) "func ParseModel(name string) (Model, error) {", (string) (len=36) "\tif x, ok := _ModelValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -2037,12 +2037,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Model) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Model) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseModel(name)", @@ -2307,7 +2307,7 @@ (string) (len=69) "\tstrings.ToLower(_SanitizingName[72:86]): Custom_prefix_EndingHyphen,", (string) (len=1) "}", (string) "", - (string) (len=63) "// ParseSanitizing attempts to convert a string to a Sanitizing", + (string) (len=64) "// ParseSanitizing attempts to convert a string to a Sanitizing.", (string) (len=55) "func ParseSanitizing(name string) (Sanitizing, error) {", (string) (len=41) "\tif x, ok := _SanitizingValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -2319,12 +2319,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=51) "func (x Sanitizing) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=55) "func (x *Sanitizing) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=34) "\ttmp, err := ParseSanitizing(name)", @@ -2569,7 +2569,7 @@ (string) (len=56) "\tstrings.ToLower(_SodaName[9:15]): Custom_prefix_MtnDew,", (string) (len=1) "}", (string) "", - (string) (len=51) "// ParseSoda attempts to convert a string to a Soda", + (string) (len=52) "// ParseSoda attempts to convert a string to a Soda.", (string) (len=43) "func ParseSoda(name string) (Soda, error) {", (string) (len=35) "\tif x, ok := _SodaValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -2581,12 +2581,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=45) "func (x Soda) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=49) "func (x *Soda) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=28) "\ttmp, err := ParseSoda(name)", @@ -2826,7 +2826,7 @@ (string) (len=66) "\tstrings.ToLower(_StartNotZeroName[12:19]): Custom_prefix_NextNum,", (string) (len=1) "}", (string) "", - (string) (len=67) "// ParseStartNotZero attempts to convert a string to a StartNotZero", + (string) (len=68) "// ParseStartNotZero attempts to convert a string to a StartNotZero.", (string) (len=59) "func ParseStartNotZero(name string) (StartNotZero, error) {", (string) (len=43) "\tif x, ok := _StartNotZeroValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -2838,12 +2838,12 @@ (string) (len=10) "\treturn &x", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=53) "func (x StartNotZero) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=57) "func (x *StartNotZero) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=36) "\ttmp, err := ParseStartNotZero(name)", diff --git a/generator/.snapshots/generator-TestExampleFile b/generator/.snapshots/generator-TestExampleFile index f3d738ee..4a3028da 100644 --- a/generator/.snapshots/generator-TestExampleFile +++ b/generator/.snapshots/generator-TestExampleFile @@ -62,7 +62,7 @@ (string) (len=48) "\tstrings.ToLower(_AnimalName[6:10]): AnimalFish,", (string) (len=1) "}", (string) "", - (string) (len=55) "// ParseAnimal attempts to convert a string to a Animal", + (string) (len=56) "// ParseAnimal attempts to convert a string to a Animal.", (string) (len=47) "func ParseAnimal(name string) (Animal, error) {", (string) (len=37) "\tif x, ok := _AnimalValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -74,12 +74,12 @@ (string) (len=107) "\treturn Animal(0), fmt.Errorf(\"%s is not a valid Animal, try [%s]\", name, strings.Join(_AnimalNames, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=47) "func (x Animal) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=51) "func (x *Animal) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=30) "\ttmp, err := ParseAnimal(name)", @@ -210,7 +210,7 @@ (string) (len=64) "\tstrings.ToLower(_CasesName[22:43]): CasesAnotherLowerCaseStart,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseCases attempts to convert a string to a Cases", + (string) (len=54) "// ParseCases attempts to convert a string to a Cases.", (string) (len=45) "func ParseCases(name string) (Cases, error) {", (string) (len=36) "\tif x, ok := _CasesValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -222,12 +222,12 @@ (string) (len=104) "\treturn Cases(0), fmt.Errorf(\"%s is not a valid Cases, try [%s]\", name, strings.Join(_CasesNames, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Cases) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Cases) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseCases(name)", @@ -382,7 +382,7 @@ (string) (len=49) "\tstrings.ToLower(_ColorName[26:32]): ColorYellow,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseColor attempts to convert a string to a Color", + (string) (len=54) "// ParseColor attempts to convert a string to a Color.", (string) (len=45) "func ParseColor(name string) (Color, error) {", (string) (len=36) "\tif x, ok := _ColorValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -394,12 +394,12 @@ (string) (len=104) "\treturn Color(0), fmt.Errorf(\"%s is not a valid Color, try [%s]\", name, strings.Join(_ColorNames, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Color) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Color) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseColor(name)", @@ -555,7 +555,7 @@ (string) (len=71) "\tstrings.ToLower(_ColorWithCommentName[26:32]): ColorWithCommentYellow,", (string) (len=1) "}", (string) "", - (string) (len=75) "// ParseColorWithComment attempts to convert a string to a ColorWithComment", + (string) (len=76) "// ParseColorWithComment attempts to convert a string to a ColorWithComment.", (string) (len=67) "func ParseColorWithComment(name string) (ColorWithComment, error) {", (string) (len=47) "\tif x, ok := _ColorWithCommentValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -567,12 +567,12 @@ (string) (len=137) "\treturn ColorWithComment(0), fmt.Errorf(\"%s is not a valid ColorWithComment, try [%s]\", name, strings.Join(_ColorWithCommentNames, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=57) "func (x ColorWithComment) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=61) "func (x *ColorWithComment) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=40) "\ttmp, err := ParseColorWithComment(name)", @@ -728,7 +728,7 @@ (string) (len=73) "\tstrings.ToLower(_ColorWithComment2Name[26:32]): ColorWithComment2Yellow,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment2 attempts to convert a string to a ColorWithComment2", + (string) (len=78) "// ParseColorWithComment2 attempts to convert a string to a ColorWithComment2.", (string) (len=69) "func ParseColorWithComment2(name string) (ColorWithComment2, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment2Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -740,12 +740,12 @@ (string) (len=140) "\treturn ColorWithComment2(0), fmt.Errorf(\"%s is not a valid ColorWithComment2, try [%s]\", name, strings.Join(_ColorWithComment2Names, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment2) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment2) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment2(name)", @@ -920,7 +920,7 @@ (string) (len=80) "\tstrings.ToLower(_ColorWithComment3Name[52:67]): ColorWithComment3RedOrangeBlue,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment3 attempts to convert a string to a ColorWithComment3", + (string) (len=78) "// ParseColorWithComment3 attempts to convert a string to a ColorWithComment3.", (string) (len=69) "func ParseColorWithComment3(name string) (ColorWithComment3, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment3Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -932,12 +932,12 @@ (string) (len=140) "\treturn ColorWithComment3(0), fmt.Errorf(\"%s is not a valid ColorWithComment3, try [%s]\", name, strings.Join(_ColorWithComment3Names, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment3) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment3) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment3(name)", @@ -1111,7 +1111,7 @@ (string) (len=76) "\tstrings.ToLower(_ColorWithComment4Name[42:52]): ColorWithComment4RedOrange,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment4 attempts to convert a string to a ColorWithComment4", + (string) (len=78) "// ParseColorWithComment4 attempts to convert a string to a ColorWithComment4.", (string) (len=69) "func ParseColorWithComment4(name string) (ColorWithComment4, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment4Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -1123,12 +1123,12 @@ (string) (len=140) "\treturn ColorWithComment4(0), fmt.Errorf(\"%s is not a valid ColorWithComment4, try [%s]\", name, strings.Join(_ColorWithComment4Names, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment4) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment4) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment4(name)", @@ -1263,7 +1263,7 @@ (string) (len=47) "\tstrings.ToLower(_ModelName[11:15]): ModelFord,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseModel attempts to convert a string to a Model", + (string) (len=54) "// ParseModel attempts to convert a string to a Model.", (string) (len=45) "func ParseModel(name string) (Model, error) {", (string) (len=36) "\tif x, ok := _ModelValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -1275,12 +1275,12 @@ (string) (len=104) "\treturn Model(0), fmt.Errorf(\"%s is not a valid Model, try [%s]\", name, strings.Join(_ModelNames, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Model) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Model) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseModel(name)", @@ -1435,7 +1435,7 @@ (string) (len=65) "\tstrings.ToLower(_SanitizingName[72:86]): SanitizingEndingHyphen,", (string) (len=1) "}", (string) "", - (string) (len=63) "// ParseSanitizing attempts to convert a string to a Sanitizing", + (string) (len=64) "// ParseSanitizing attempts to convert a string to a Sanitizing.", (string) (len=55) "func ParseSanitizing(name string) (Sanitizing, error) {", (string) (len=41) "\tif x, ok := _SanitizingValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -1447,12 +1447,12 @@ (string) (len=119) "\treturn Sanitizing(0), fmt.Errorf(\"%s is not a valid Sanitizing, try [%s]\", name, strings.Join(_SanitizingNames, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=51) "func (x Sanitizing) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=55) "func (x *Sanitizing) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=34) "\ttmp, err := ParseSanitizing(name)", @@ -1583,7 +1583,7 @@ (string) (len=46) "\tstrings.ToLower(_SodaName[9:15]): SodaMtnDew,", (string) (len=1) "}", (string) "", - (string) (len=51) "// ParseSoda attempts to convert a string to a Soda", + (string) (len=52) "// ParseSoda attempts to convert a string to a Soda.", (string) (len=43) "func ParseSoda(name string) (Soda, error) {", (string) (len=35) "\tif x, ok := _SodaValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -1595,12 +1595,12 @@ (string) (len=101) "\treturn Soda(0), fmt.Errorf(\"%s is not a valid Soda, try [%s]\", name, strings.Join(_SodaNames, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=45) "func (x Soda) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=49) "func (x *Soda) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=28) "\ttmp, err := ParseSoda(name)", @@ -1725,7 +1725,7 @@ (string) (len=64) "\tstrings.ToLower(_StartNotZeroName[12:19]): StartNotZeroNextNum,", (string) (len=1) "}", (string) "", - (string) (len=67) "// ParseStartNotZero attempts to convert a string to a StartNotZero", + (string) (len=68) "// ParseStartNotZero attempts to convert a string to a StartNotZero.", (string) (len=59) "func ParseStartNotZero(name string) (StartNotZero, error) {", (string) (len=43) "\tif x, ok := _StartNotZeroValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -1737,12 +1737,12 @@ (string) (len=125) "\treturn StartNotZero(0), fmt.Errorf(\"%s is not a valid StartNotZero, try [%s]\", name, strings.Join(_StartNotZeroNames, \", \"))", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=53) "func (x StartNotZero) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=57) "func (x *StartNotZero) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=36) "\ttmp, err := ParseStartNotZero(name)", diff --git a/generator/.snapshots/generator-TestNoPrefixExampleFile b/generator/.snapshots/generator-TestNoPrefixExampleFile index 7edbe7fc..03038784 100644 --- a/generator/.snapshots/generator-TestNoPrefixExampleFile +++ b/generator/.snapshots/generator-TestNoPrefixExampleFile @@ -46,7 +46,7 @@ (string) (len=42) "\tstrings.ToLower(_AnimalName[6:10]): Fish,", (string) (len=1) "}", (string) "", - (string) (len=55) "// ParseAnimal attempts to convert a string to a Animal", + (string) (len=56) "// ParseAnimal attempts to convert a string to a Animal.", (string) (len=47) "func ParseAnimal(name string) (Animal, error) {", (string) (len=37) "\tif x, ok := _AnimalValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -54,12 +54,12 @@ (string) (len=63) "\treturn Animal(0), fmt.Errorf(\"%s is not a valid Animal\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=47) "func (x Animal) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=51) "func (x *Animal) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=30) "\ttmp, err := ParseAnimal(name)", @@ -121,7 +121,7 @@ (string) (len=59) "\tstrings.ToLower(_CasesName[22:43]): AnotherLowerCaseStart,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseCases attempts to convert a string to a Cases", + (string) (len=54) "// ParseCases attempts to convert a string to a Cases.", (string) (len=45) "func ParseCases(name string) (Cases, error) {", (string) (len=36) "\tif x, ok := _CasesValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -129,12 +129,12 @@ (string) (len=61) "\treturn Cases(0), fmt.Errorf(\"%s is not a valid Cases\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Cases) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Cases) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseCases(name)", @@ -216,7 +216,7 @@ (string) (len=44) "\tstrings.ToLower(_ColorName[26:32]): Yellow,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseColor attempts to convert a string to a Color", + (string) (len=54) "// ParseColor attempts to convert a string to a Color.", (string) (len=45) "func ParseColor(name string) (Color, error) {", (string) (len=36) "\tif x, ok := _ColorValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -224,12 +224,12 @@ (string) (len=61) "\treturn Color(0), fmt.Errorf(\"%s is not a valid Color\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Color) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Color) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseColor(name)", @@ -312,7 +312,7 @@ (string) (len=55) "\tstrings.ToLower(_ColorWithCommentName[26:32]): Yellow,", (string) (len=1) "}", (string) "", - (string) (len=75) "// ParseColorWithComment attempts to convert a string to a ColorWithComment", + (string) (len=76) "// ParseColorWithComment attempts to convert a string to a ColorWithComment.", (string) (len=67) "func ParseColorWithComment(name string) (ColorWithComment, error) {", (string) (len=47) "\tif x, ok := _ColorWithCommentValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -320,12 +320,12 @@ (string) (len=83) "\treturn ColorWithComment(0), fmt.Errorf(\"%s is not a valid ColorWithComment\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=57) "func (x ColorWithComment) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=61) "func (x *ColorWithComment) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=40) "\ttmp, err := ParseColorWithComment(name)", @@ -408,7 +408,7 @@ (string) (len=56) "\tstrings.ToLower(_ColorWithComment2Name[26:32]): Yellow,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment2 attempts to convert a string to a ColorWithComment2", + (string) (len=78) "// ParseColorWithComment2 attempts to convert a string to a ColorWithComment2.", (string) (len=69) "func ParseColorWithComment2(name string) (ColorWithComment2, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment2Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -416,12 +416,12 @@ (string) (len=85) "\treturn ColorWithComment2(0), fmt.Errorf(\"%s is not a valid ColorWithComment2\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment2) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment2) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment2(name)", @@ -520,7 +520,7 @@ (string) (len=63) "\tstrings.ToLower(_ColorWithComment3Name[52:67]): RedOrangeBlue,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment3 attempts to convert a string to a ColorWithComment3", + (string) (len=78) "// ParseColorWithComment3 attempts to convert a string to a ColorWithComment3.", (string) (len=69) "func ParseColorWithComment3(name string) (ColorWithComment3, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment3Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -528,12 +528,12 @@ (string) (len=85) "\treturn ColorWithComment3(0), fmt.Errorf(\"%s is not a valid ColorWithComment3\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment3) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment3) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment3(name)", @@ -632,7 +632,7 @@ (string) (len=59) "\tstrings.ToLower(_ColorWithComment4Name[42:52]): RedOrange,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment4 attempts to convert a string to a ColorWithComment4", + (string) (len=78) "// ParseColorWithComment4 attempts to convert a string to a ColorWithComment4.", (string) (len=69) "func ParseColorWithComment4(name string) (ColorWithComment4, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment4Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -640,12 +640,12 @@ (string) (len=85) "\treturn ColorWithComment4(0), fmt.Errorf(\"%s is not a valid ColorWithComment4\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment4) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment4) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment4(name)", @@ -711,7 +711,7 @@ (string) (len=42) "\tstrings.ToLower(_ModelName[11:15]): Ford,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseModel attempts to convert a string to a Model", + (string) (len=54) "// ParseModel attempts to convert a string to a Model.", (string) (len=45) "func ParseModel(name string) (Model, error) {", (string) (len=36) "\tif x, ok := _ModelValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -719,12 +719,12 @@ (string) (len=61) "\treturn Model(0), fmt.Errorf(\"%s is not a valid Model\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Model) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Model) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseModel(name)", @@ -806,7 +806,7 @@ (string) (len=55) "\tstrings.ToLower(_SanitizingName[72:86]): EndingHyphen,", (string) (len=1) "}", (string) "", - (string) (len=63) "// ParseSanitizing attempts to convert a string to a Sanitizing", + (string) (len=64) "// ParseSanitizing attempts to convert a string to a Sanitizing.", (string) (len=55) "func ParseSanitizing(name string) (Sanitizing, error) {", (string) (len=41) "\tif x, ok := _SanitizingValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -814,12 +814,12 @@ (string) (len=71) "\treturn Sanitizing(0), fmt.Errorf(\"%s is not a valid Sanitizing\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=51) "func (x Sanitizing) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=55) "func (x *Sanitizing) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=34) "\ttmp, err := ParseSanitizing(name)", @@ -881,7 +881,7 @@ (string) (len=42) "\tstrings.ToLower(_SodaName[9:15]): MtnDew,", (string) (len=1) "}", (string) "", - (string) (len=51) "// ParseSoda attempts to convert a string to a Soda", + (string) (len=52) "// ParseSoda attempts to convert a string to a Soda.", (string) (len=43) "func ParseSoda(name string) (Soda, error) {", (string) (len=35) "\tif x, ok := _SodaValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -889,12 +889,12 @@ (string) (len=59) "\treturn Soda(0), fmt.Errorf(\"%s is not a valid Soda\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=45) "func (x Soda) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=49) "func (x *Soda) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=28) "\ttmp, err := ParseSoda(name)", @@ -951,7 +951,7 @@ (string) (len=52) "\tstrings.ToLower(_StartNotZeroName[12:19]): NextNum,", (string) (len=1) "}", (string) "", - (string) (len=67) "// ParseStartNotZero attempts to convert a string to a StartNotZero", + (string) (len=68) "// ParseStartNotZero attempts to convert a string to a StartNotZero.", (string) (len=59) "func ParseStartNotZero(name string) (StartNotZero, error) {", (string) (len=43) "\tif x, ok := _StartNotZeroValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -959,12 +959,12 @@ (string) (len=75) "\treturn StartNotZero(0), fmt.Errorf(\"%s is not a valid StartNotZero\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=53) "func (x StartNotZero) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=57) "func (x *StartNotZero) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=36) "\ttmp, err := ParseStartNotZero(name)", diff --git a/generator/.snapshots/generator-TestNoPrefixExampleFileWithSnakeToCamel b/generator/.snapshots/generator-TestNoPrefixExampleFileWithSnakeToCamel index aa507325..6497e6ba 100644 --- a/generator/.snapshots/generator-TestNoPrefixExampleFileWithSnakeToCamel +++ b/generator/.snapshots/generator-TestNoPrefixExampleFileWithSnakeToCamel @@ -46,7 +46,7 @@ (string) (len=42) "\tstrings.ToLower(_AnimalName[6:10]): Fish,", (string) (len=1) "}", (string) "", - (string) (len=55) "// ParseAnimal attempts to convert a string to a Animal", + (string) (len=56) "// ParseAnimal attempts to convert a string to a Animal.", (string) (len=47) "func ParseAnimal(name string) (Animal, error) {", (string) (len=37) "\tif x, ok := _AnimalValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -54,12 +54,12 @@ (string) (len=63) "\treturn Animal(0), fmt.Errorf(\"%s is not a valid Animal\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=47) "func (x Animal) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=51) "func (x *Animal) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=30) "\ttmp, err := ParseAnimal(name)", @@ -121,7 +121,7 @@ (string) (len=59) "\tstrings.ToLower(_CasesName[22:43]): AnotherLowerCaseStart,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseCases attempts to convert a string to a Cases", + (string) (len=54) "// ParseCases attempts to convert a string to a Cases.", (string) (len=45) "func ParseCases(name string) (Cases, error) {", (string) (len=36) "\tif x, ok := _CasesValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -129,12 +129,12 @@ (string) (len=61) "\treturn Cases(0), fmt.Errorf(\"%s is not a valid Cases\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Cases) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Cases) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseCases(name)", @@ -216,7 +216,7 @@ (string) (len=44) "\tstrings.ToLower(_ColorName[26:32]): Yellow,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseColor attempts to convert a string to a Color", + (string) (len=54) "// ParseColor attempts to convert a string to a Color.", (string) (len=45) "func ParseColor(name string) (Color, error) {", (string) (len=36) "\tif x, ok := _ColorValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -224,12 +224,12 @@ (string) (len=61) "\treturn Color(0), fmt.Errorf(\"%s is not a valid Color\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Color) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Color) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseColor(name)", @@ -312,7 +312,7 @@ (string) (len=55) "\tstrings.ToLower(_ColorWithCommentName[26:32]): Yellow,", (string) (len=1) "}", (string) "", - (string) (len=75) "// ParseColorWithComment attempts to convert a string to a ColorWithComment", + (string) (len=76) "// ParseColorWithComment attempts to convert a string to a ColorWithComment.", (string) (len=67) "func ParseColorWithComment(name string) (ColorWithComment, error) {", (string) (len=47) "\tif x, ok := _ColorWithCommentValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -320,12 +320,12 @@ (string) (len=83) "\treturn ColorWithComment(0), fmt.Errorf(\"%s is not a valid ColorWithComment\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=57) "func (x ColorWithComment) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=61) "func (x *ColorWithComment) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=40) "\ttmp, err := ParseColorWithComment(name)", @@ -408,7 +408,7 @@ (string) (len=56) "\tstrings.ToLower(_ColorWithComment2Name[26:32]): Yellow,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment2 attempts to convert a string to a ColorWithComment2", + (string) (len=78) "// ParseColorWithComment2 attempts to convert a string to a ColorWithComment2.", (string) (len=69) "func ParseColorWithComment2(name string) (ColorWithComment2, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment2Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -416,12 +416,12 @@ (string) (len=85) "\treturn ColorWithComment2(0), fmt.Errorf(\"%s is not a valid ColorWithComment2\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment2) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment2) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment2(name)", @@ -520,7 +520,7 @@ (string) (len=63) "\tstrings.ToLower(_ColorWithComment3Name[52:67]): RedOrangeBlue,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment3 attempts to convert a string to a ColorWithComment3", + (string) (len=78) "// ParseColorWithComment3 attempts to convert a string to a ColorWithComment3.", (string) (len=69) "func ParseColorWithComment3(name string) (ColorWithComment3, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment3Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -528,12 +528,12 @@ (string) (len=85) "\treturn ColorWithComment3(0), fmt.Errorf(\"%s is not a valid ColorWithComment3\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment3) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment3) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment3(name)", @@ -632,7 +632,7 @@ (string) (len=59) "\tstrings.ToLower(_ColorWithComment4Name[42:52]): RedOrange,", (string) (len=1) "}", (string) "", - (string) (len=77) "// ParseColorWithComment4 attempts to convert a string to a ColorWithComment4", + (string) (len=78) "// ParseColorWithComment4 attempts to convert a string to a ColorWithComment4.", (string) (len=69) "func ParseColorWithComment4(name string) (ColorWithComment4, error) {", (string) (len=48) "\tif x, ok := _ColorWithComment4Value[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -640,12 +640,12 @@ (string) (len=85) "\treturn ColorWithComment4(0), fmt.Errorf(\"%s is not a valid ColorWithComment4\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=58) "func (x ColorWithComment4) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=62) "func (x *ColorWithComment4) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=41) "\ttmp, err := ParseColorWithComment4(name)", @@ -711,7 +711,7 @@ (string) (len=42) "\tstrings.ToLower(_ModelName[11:15]): Ford,", (string) (len=1) "}", (string) "", - (string) (len=53) "// ParseModel attempts to convert a string to a Model", + (string) (len=54) "// ParseModel attempts to convert a string to a Model.", (string) (len=45) "func ParseModel(name string) (Model, error) {", (string) (len=36) "\tif x, ok := _ModelValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -719,12 +719,12 @@ (string) (len=61) "\treturn Model(0), fmt.Errorf(\"%s is not a valid Model\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=46) "func (x Model) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=50) "func (x *Model) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=29) "\ttmp, err := ParseModel(name)", @@ -806,7 +806,7 @@ (string) (len=55) "\tstrings.ToLower(_SanitizingName[72:86]): EndingHyphen,", (string) (len=1) "}", (string) "", - (string) (len=63) "// ParseSanitizing attempts to convert a string to a Sanitizing", + (string) (len=64) "// ParseSanitizing attempts to convert a string to a Sanitizing.", (string) (len=55) "func ParseSanitizing(name string) (Sanitizing, error) {", (string) (len=41) "\tif x, ok := _SanitizingValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -814,12 +814,12 @@ (string) (len=71) "\treturn Sanitizing(0), fmt.Errorf(\"%s is not a valid Sanitizing\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=51) "func (x Sanitizing) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=55) "func (x *Sanitizing) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=34) "\ttmp, err := ParseSanitizing(name)", @@ -881,7 +881,7 @@ (string) (len=42) "\tstrings.ToLower(_SodaName[9:15]): MtnDew,", (string) (len=1) "}", (string) "", - (string) (len=51) "// ParseSoda attempts to convert a string to a Soda", + (string) (len=52) "// ParseSoda attempts to convert a string to a Soda.", (string) (len=43) "func ParseSoda(name string) (Soda, error) {", (string) (len=35) "\tif x, ok := _SodaValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -889,12 +889,12 @@ (string) (len=59) "\treturn Soda(0), fmt.Errorf(\"%s is not a valid Soda\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=45) "func (x Soda) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=49) "func (x *Soda) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=28) "\ttmp, err := ParseSoda(name)", @@ -951,7 +951,7 @@ (string) (len=52) "\tstrings.ToLower(_StartNotZeroName[12:19]): NextNum,", (string) (len=1) "}", (string) "", - (string) (len=67) "// ParseStartNotZero attempts to convert a string to a StartNotZero", + (string) (len=68) "// ParseStartNotZero attempts to convert a string to a StartNotZero.", (string) (len=59) "func ParseStartNotZero(name string) (StartNotZero, error) {", (string) (len=43) "\tif x, ok := _StartNotZeroValue[name]; ok {", (string) (len=15) "\t\treturn x, nil", @@ -959,12 +959,12 @@ (string) (len=75) "\treturn StartNotZero(0), fmt.Errorf(\"%s is not a valid StartNotZero\", name)", (string) (len=1) "}", (string) "", - (string) (len=52) "// MarshalText implements the text marshaller method", + (string) (len=53) "// MarshalText implements the text marshaller method.", (string) (len=53) "func (x StartNotZero) MarshalText() ([]byte, error) {", (string) (len=31) "\treturn []byte(x.String()), nil", (string) (len=1) "}", (string) "", - (string) (len=56) "// UnmarshalText implements the text unmarshaller method", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", (string) (len=57) "func (x *StartNotZero) UnmarshalText(text []byte) error {", (string) (len=21) "\tname := string(text)", (string) (len=36) "\ttmp, err := ParseStartNotZero(name)", diff --git a/generator/enum.tmpl b/generator/enum.tmpl index 0d512836..65fbf76e 100644 --- a/generator/enum.tmpl +++ b/generator/enum.tmpl @@ -40,7 +40,7 @@ func (x {{.enum.Name}}) String() string { var _{{.enum.Name}}Value = {{ unmapify .enum .lowercase }} -// Parse{{.enum.Name}} attempts to convert a string to a {{.enum.Name}} +// Parse{{.enum.Name}} attempts to convert a string to a {{.enum.Name}}. func Parse{{.enum.Name}}(name string) ({{.enum.Name}}, error) { if x, ok := _{{.enum.Name}}Value[name]; ok { return x, nil @@ -63,12 +63,12 @@ func (x {{.enum.Name}}) Ptr() *{{.enum.Name}} { {{end}} {{ if .marshal }} -// MarshalText implements the text marshaller method +// MarshalText implements the text marshaller method. func (x {{.enum.Name}}) MarshalText() ([]byte, error) { return []byte(x.String()), nil } -// UnmarshalText implements the text unmarshaller method +// UnmarshalText implements the text unmarshaller method. func (x *{{.enum.Name}}) UnmarshalText(text []byte) error { name := string(text) tmp, err := Parse{{.enum.Name}}(name) From 135899dee3950d16b86153d55aac8228f7fdc520 Mon Sep 17 00:00:00 2001 From: Alex Bice Date: Sun, 23 Jan 2022 10:30:39 -0700 Subject: [PATCH 2/3] ForceLower and MustParse --- Makefile | 4 ++-- README.md | 42 +++++++++++++++++++++++++++++++++ example/color.go | 2 +- example/color_enum.go | 9 ++++++++ example/color_test.go | 6 +++++ example/force_lower.go | 9 ++++++++ example/force_lower_enum.go | 46 +++++++++++++++++++++++++++++++++++++ example/force_lower_test.go | 34 +++++++++++++++++++++++++++ generator/enum.tmpl | 13 ++++++++++- generator/generator.go | 16 +++++++++++++ generator/template_funcs.go | 9 ++++++-- main.go | 18 +++++++++++++++ 12 files changed, 202 insertions(+), 6 deletions(-) create mode 100644 example/force_lower.go create mode 100644 example/force_lower_enum.go create mode 100644 example/force_lower_test.go diff --git a/Makefile b/Makefile index 230ad113..dce793ca 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ else .SILENT: endif -GO ?= GO111MODULE=on go +GO ?= CGO_ENABLED=0 GO111MODULE=on go COVERAGEDIR= coverage SERVICE=local @@ -51,7 +51,7 @@ fmt: gofmt -l -w -s $$(find . -type f -name '*.go' -not -path "./vendor/*") test: gen-test generate - $(GO) test -v -race -coverprofile=coverage.out ./... + $(GO) test -v -coverprofile=coverage.out ./... cover: gen-test test $(GO) tool cover -html=coverage.out -o coverage.html diff --git a/README.md b/README.md index 8e3b3b9b..d5a15bf0 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,48 @@ An enum generator for go ## How it works +go-enum will take a commented type declaration like this: + +```go +// ENUM(jpeg, jpg, png, tiff, gif) +type ImageType int +``` + +and generate a file with the iota definition along various optional niceties that you may need: + +```go +const ( + // ImageTypeJpeg is a ImageType of type Jpeg. + ImageTypeJpeg ImageType = iota + // ImageTypeJpg is a ImageType of type Jpg. + ImageTypeJpg + // ImageTypePng is a ImageType of type Png. + ImageTypePng + // ImageTypeTiff is a ImageType of type Tiff. + ImageTypeTiff + // ImageTypeGif is a ImageType of type Gif. + ImageTypeGif +) + +// String implements the Stringer interface. +func (x ImageType) String() string + +// ParseImageType attempts to convert a string to a ImageType. +func ParseImageType(name string) (ImageType, error) + +// MarshalText implements the text marshaller method. +func (x ImageType) MarshalText() ([]byte, error) + +// UnmarshalText implements the text unmarshaller method. +func (x *ImageType) UnmarshalText(text []byte) error +``` + +**Fear not the fact that the `MarshalText` and `UnmarshalText` are generated rather than JSON methods... they will still be utilized by the default JSON encoding methods.** + +If you find that the options given are not adequate for your use case, there is an option to add a custom template (`-t` flag) to the processing engine so that your custom code can be created! + +## Goal + The goal of go-enum is to create an easy to use enum generator that will take a decorated type declaration like `type EnumName int` and create the associated constant values and funcs that will make life a little easier for adding new values. It's not perfect, but I think it's useful. diff --git a/example/color.go b/example/color.go index b0a32b1b..b3a4b738 100644 --- a/example/color.go +++ b/example/color.go @@ -1,4 +1,4 @@ -//go:generate ../bin/go-enum -f=$GOFILE --marshal --lower --ptr +//go:generate ../bin/go-enum -f=$GOFILE --marshal --lower --ptr --mustparse package example diff --git a/example/color_enum.go b/example/color_enum.go index 7899fbe1..0d3e091b 100644 --- a/example/color_enum.go +++ b/example/color_enum.go @@ -94,6 +94,15 @@ func ParseColor(name string) (Color, error) { return Color(0), fmt.Errorf("%s is not a valid Color", name) } +// MustParseColor converts a string to a Color, and panics if is not valid. +func MustParseColor(name string) Color { + val, err := ParseColor(name) + if err != nil { + panic(err) + } + return val +} + func (x Color) Ptr() *Color { return &x } diff --git a/example/color_test.go b/example/color_test.go index bb2ef35e..3c813c75 100644 --- a/example/color_test.go +++ b/example/color_test.go @@ -23,6 +23,12 @@ func TestColorString(t *testing.T) { assert.Equal(t, &x, Color(109).Ptr()) } +func TestColorMustParse(t *testing.T) { + x := `avocadogreen` + + assert.PanicsWithError(t, x+" is not a valid Color", func() { MustParseColor(x) }) +} + func TestColorUnmarshal(t *testing.T) { tests := []struct { name string diff --git a/example/force_lower.go b/example/force_lower.go new file mode 100644 index 00000000..44e895e6 --- /dev/null +++ b/example/force_lower.go @@ -0,0 +1,9 @@ +//go:generate ../bin/go-enum -f=$GOFILE --forcelower + +package example + +// ENUM( +// DataSwap, +// BootNode, +// ) +type ForceLowerType int diff --git a/example/force_lower_enum.go b/example/force_lower_enum.go new file mode 100644 index 00000000..e8853d46 --- /dev/null +++ b/example/force_lower_enum.go @@ -0,0 +1,46 @@ +// Code generated by go-enum DO NOT EDIT. +// Version: example +// Revision: example +// Build Date: example +// Built By: example + +package example + +import ( + "fmt" +) + +const ( + // ForceLowerTypeDataSwap is a ForceLowerType of type DataSwap. + ForceLowerTypeDataSwap ForceLowerType = iota + // ForceLowerTypeBootNode is a ForceLowerType of type BootNode. + ForceLowerTypeBootNode +) + +const _ForceLowerTypeName = "dataswapbootnode" + +var _ForceLowerTypeMap = map[ForceLowerType]string{ + ForceLowerTypeDataSwap: _ForceLowerTypeName[0:8], + ForceLowerTypeBootNode: _ForceLowerTypeName[8:16], +} + +// String implements the Stringer interface. +func (x ForceLowerType) String() string { + if str, ok := _ForceLowerTypeMap[x]; ok { + return str + } + return fmt.Sprintf("ForceLowerType(%d)", x) +} + +var _ForceLowerTypeValue = map[string]ForceLowerType{ + _ForceLowerTypeName[0:8]: ForceLowerTypeDataSwap, + _ForceLowerTypeName[8:16]: ForceLowerTypeBootNode, +} + +// ParseForceLowerType attempts to convert a string to a ForceLowerType. +func ParseForceLowerType(name string) (ForceLowerType, error) { + if x, ok := _ForceLowerTypeValue[name]; ok { + return x, nil + } + return ForceLowerType(0), fmt.Errorf("%s is not a valid ForceLowerType", name) +} diff --git a/example/force_lower_test.go b/example/force_lower_test.go new file mode 100644 index 00000000..6ec9460a --- /dev/null +++ b/example/force_lower_test.go @@ -0,0 +1,34 @@ +package example + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestForceLowerString(t *testing.T) { + + tests := map[string]struct { + input string + output ForceLowerType + }{ + "dataswap": { + input: `dataswap`, + output: ForceLowerTypeDataSwap, + }, + "bootnode": { + input: `bootnode`, + output: ForceLowerTypeBootNode, + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + output, err := ParseForceLowerType(tc.input) + assert.NoError(t, err) + assert.Equal(t, tc.output, output) + + assert.Equal(t, tc.input, output.String()) + }) + } +} diff --git a/generator/enum.tmpl b/generator/enum.tmpl index 65fbf76e..4ac6c304 100644 --- a/generator/enum.tmpl +++ b/generator/enum.tmpl @@ -56,6 +56,17 @@ func Parse{{.enum.Name}}(name string) ({{.enum.Name}}, error) { {{- end}} } +{{ if .mustparse }} +// MustParse{{.enum.Name}} converts a string to a {{.enum.Name}}, and panics if is not valid. +func MustParse{{.enum.Name}}(name string) {{.enum.Name}} { + val, err := Parse{{.enum.Name}}(name) + if err != nil { + panic(err) + } + return val +} +{{end}} + {{ if .ptr }} func (x {{.enum.Name}}) Ptr() *{{.enum.Name}} { return &x @@ -315,7 +326,7 @@ func (n *Null{{.enum.Name}}Str) UnmarshalJSON(b []byte) error { {{- define "stringer"}} -const _{{.enum.Name}}Name = "{{ stringify .enum }}" +const _{{.enum.Name}}Name = "{{ stringify .enum .forcelower }}" {{ if .names }}var _{{.enum.Name}}Names = {{namify .enum}} diff --git a/generator/generator.go b/generator/generator.go index 2887d0ae..b8329a67 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -49,6 +49,8 @@ type Generator struct { sqlNullInt bool sqlNullStr bool ptr bool + mustParse bool + forceLower bool } // Enum holds data for a discovered enum in the parsed source @@ -172,6 +174,18 @@ func (g *Generator) WithSQLNullStr() *Generator { return g } +// WithMustParse is used to add a method `MustParse` that will panic on failure. +func (g *Generator) WithMustParse() *Generator { + g.mustParse = true + return g +} + +// WithForceLower is used to force enums names to lower case while keeping variable names the same. +func (g *Generator) WithForceLower() *Generator { + g.forceLower = true + return g +} + // ParseAliases is used to add aliases to replace during name sanitization. func ParseAliases(aliases []string) error { aliasMap := map[string]string{} @@ -266,6 +280,8 @@ func (g *Generator) Generate(f *ast.File) ([]byte, error) { "ptr": g.ptr, "sqlnullint": g.sqlNullInt, "sqlnullstr": g.sqlNullStr, + "mustparse": g.mustParse, + "forcelower": g.forceLower, } err = g.t.ExecuteTemplate(vBuff, "enum", data) diff --git a/generator/template_funcs.go b/generator/template_funcs.go index a8291081..359c5b45 100644 --- a/generator/template_funcs.go +++ b/generator/template_funcs.go @@ -2,13 +2,18 @@ package generator import ( "fmt" + "strings" ) // Stringify returns a string that is all of the enum value names concatenated without a separator -func Stringify(e Enum) (ret string, err error) { +func Stringify(e Enum, forceLower bool) (ret string, err error) { for _, val := range e.Values { if val.Name != skipHolder { - ret = ret + val.RawName + next := val.RawName + if forceLower { + next = strings.ToLower(next) + } + ret = ret + next } } return diff --git a/main.go b/main.go index 5507186f..83126897 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,8 @@ type rootT struct { Ptr bool TemplateFileNames cli.StringSlice Aliases cli.StringSlice + MustParse bool + ForceLower bool } func main() { @@ -131,6 +133,16 @@ func main() { Usage: "Adds or replaces aliases for a non alphanumeric value that needs to be accounted for. [Format should be \"key:value,key2:value2\", or specify multiple entries, or both!]", Destination: &argv.Aliases, }, + &cli.BoolFlag{ + Name: "mustparse", + Usage: "Adds a Must version of the Parse that will panic on failure.", + Destination: &argv.MustParse, + }, + &cli.BoolFlag{ + Name: "forcelower", + Usage: "Forces a camel cased comment to generate lowercased names.", + Destination: &argv.ForceLower, + }, }, Action: func(ctx *cli.Context) error { if err := generator.ParseAliases(argv.Aliases.Value()); err != nil { @@ -180,6 +192,12 @@ func main() { if argv.SQLNullStr { g.WithSQLNullStr() } + if argv.MustParse { + g.WithMustParse() + } + if argv.ForceLower { + g.WithForceLower() + } if templates := []string(argv.TemplateFileNames.Value()); len(templates) > 0 { for _, t := range templates { if fn, err := globFilenames(t); err != nil { From 5e3f0374f68eada473dbd4e1aad6b2c4b94c0caa Mon Sep 17 00:00:00 2001 From: Alex Bice Date: Sun, 23 Jan 2022 10:37:29 -0700 Subject: [PATCH 3/3] Revert makefile changes --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dce793ca..230ad113 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ else .SILENT: endif -GO ?= CGO_ENABLED=0 GO111MODULE=on go +GO ?= GO111MODULE=on go COVERAGEDIR= coverage SERVICE=local @@ -51,7 +51,7 @@ fmt: gofmt -l -w -s $$(find . -type f -name '*.go' -not -path "./vendor/*") test: gen-test generate - $(GO) test -v -coverprofile=coverage.out ./... + $(GO) test -v -race -coverprofile=coverage.out ./... cover: gen-test test $(GO) tool cover -html=coverage.out -o coverage.html