diff --git a/enumer.go b/enumer.go index 591e37d..95c0000 100644 --- a/enumer.go +++ b/enumer.go @@ -65,10 +65,12 @@ func (g *Generator) buildJSONMethods(runs [][]Value, typeName string, runsThresh // Arguments to format are: // [1]: type name const textMethods = ` +// MarshalText implements the encoding.TextMarshaler interface for %[1]s func (i %[1]s) MarshalText() ([]byte, error) { return []byte(i.String()), nil } +// MarshalText implements the encoding.TextUnmarshaler interface for %[1]s func (i *%[1]s) UnmarshalText(text []byte) error { var err error *i, err = %[1]sString(string(text)) @@ -83,12 +85,12 @@ func (g *Generator) buildTextMethods(runs [][]Value, typeName string, runsThresh // Arguments to format are: // [1]: type name const yamlMethods = ` -// MarshalYAML implements a YAML Marshaler interface for %[1]s +// MarshalYAML implements a YAML Marshaler for %[1]s func (i %[1]s) MarshalYAML() (interface{}, error) { return i.String(), nil } -// UnmarshalYAML implements a YAML Unmarshaler interface for %[1]s +// UnmarshalYAML implements a YAML Unmarshaler for %[1]s func (i *%[1]s) UnmarshalYAML(unmarshal func(interface{}) error) error { var s string if err := unmarshal(&s); err != nil { diff --git a/golden_test.go b/golden_test.go index 849323f..23eaf64 100644 --- a/golden_test.go +++ b/golden_test.go @@ -531,10 +531,12 @@ func PrimeString(s string) (Prime, error) { return 0, fmt.Errorf("%s does not belong to Prime values", s) } +// MarshalText implements the encoding.TextMarshaler interface for Prime func (i Prime) MarshalText() ([]byte, error) { return []byte(i.String()), nil } +// MarshalText implements the encoding.TextUnmarshaler interface for Prime func (i *Prime) UnmarshalText(text []byte) error { var err error *i, err = PrimeString(string(text)) @@ -612,12 +614,12 @@ func PrimeString(s string) (Prime, error) { return 0, fmt.Errorf("%s does not belong to Prime values", s) } -// MarshalYAML implements a YAML Marshaler interface for Prime +// MarshalYAML implements a YAML Marshaler for Prime func (i Prime) MarshalYAML() (interface{}, error) { return i.String(), nil } -// UnmarshalYAML implements a YAML Unmarshaler interface for Prime +// UnmarshalYAML implements a YAML Unmarshaler for Prime func (i *Prime) UnmarshalYAML(unmarshal func(interface{}) error) error { var s string if err := unmarshal(&s); err != nil {