Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions example/noparse_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generator/enum.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func (x {{.enum.Name}}) IsValid() bool {
return ok
}

{{- if .generateParse }}
var _{{.enum.Name}}Value = {{ unmapify .enum .lowercase }}

{{- if .generateParse }}
// {{.parseName}}{{.enum.Name}} attempts to convert a string to a {{.enum.Name}}.
func {{.parseName}}{{.enum.Name}}(name string) ({{.enum.Name}}, error) {
if x, ok := _{{.enum.Name}}Value[name]; ok {
Expand Down
4 changes: 4 additions & 0 deletions generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ type Number int
// Should not contain Parse method
assert.NotContains(t, outputStr, "func ParseNumber")
assert.NotContains(t, outputStr, "func parseNumber")
assert.NotContains(t, outputStr, "var _NumberValue")

// Should still contain other methods
assert.Contains(t, outputStr, "func (x Number) String()")
Expand All @@ -744,6 +745,8 @@ type Greek string
// Should not contain Parse method
assert.NotContains(t, outputStr, "func ParseGreek")
assert.NotContains(t, outputStr, "func parseGreek")
// String enum IsValid still needs its lookup map.
assert.Contains(t, outputStr, "var _GreekValue")

// Should still contain other methods
assert.Contains(t, outputStr, "func (x Greek) String()")
Expand Down Expand Up @@ -772,6 +775,7 @@ type Number int

// Should contain unexported parse method
assert.Contains(t, outputStr, "func parseNumber(")
assert.Contains(t, outputStr, "var _NumberValue")

// Should contain marshal methods that use the unexported parse
assert.Contains(t, outputStr, "func (x *Number) UnmarshalText(")
Expand Down