Skip to content

[generate] If base type of enum is string, String() should return the original value #2

@neglect-yp

Description

@neglect-yp
// enumizer:target
type Color string

const (
    Red   Color = "red"
    Green Color = "green"
    Blue  Color = "blue"
)

If base type of enum is string like Color, String() should be as follows:

func String(c Color) string {
    switch c {
        case Red, Green, Blue:
            return string(c)
        default:
            return "unknown Color"
    }
}

If the value and String() result are different, users will be confused.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions