Skip to content
Merged
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ Given a constant named `MyTypeValue`:
| `snake-upper` | `MY_TYPE_VALUE` |
| `kebab` | `my-type-value` |
| `kebab-upper` | `MY-TYPE-VALUE` |
| `dot` | `my.type.value` |
| `dot-upper` | `MY.TYPE.VALUE` |
| `whitespace` | `my type value` |
| `lower` | `mytypevalue` |
| `upper` | `MYTYPEVALUE` |
Expand All @@ -145,8 +147,8 @@ Given a constant named `MyTypeValue`:
| `first-upper` | `M` |
| `first-lower` | `m` |

Word splitting only works from CamelCase. `snake_upper`, `kebab_upper`, `first_upper`, and
`first_lower` are accepted as aliases of the hyphenated names.
Word splitting only works from CamelCase. `snake_upper`, `kebab_upper`, `dot_upper`, `first_upper`,
and `first_lower` are accepted as aliases of the hyphenated names.

### Line comments

Expand Down
6 changes: 6 additions & 0 deletions endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func TestEndToEnd(t *testing.T) {
case "transform_kebab_upper.go":
typeName = "KebabUpperCaseValue"
transformNameMethod = "kebab-upper"
case "transform_dot.go":
typeName = "DotCaseValue"
transformNameMethod = "dot"
case "transform_dot_upper.go":
typeName = "DotUpperCaseValue"
transformNameMethod = "dot-upper"
case "transform_upper.go":
typeName = "UpperCaseValue"
transformNameMethod = "upper"
Expand Down
8 changes: 8 additions & 0 deletions stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ func (g *Generator) transformValueNames(values []Value, transformMethod string)
fn = func(s string) string {
return strings.ToUpper(name.Delimit(s, '-'))
}
case "dot":
fn = func(s string) string {
return strings.ToLower(name.Delimit(s, '.'))
}
case "dot_upper", "dot-upper":
fn = func(s string) string {
return strings.ToUpper(name.Delimit(s, '.'))
}
case "upper":
fn = func(s string) string {
return strings.ToUpper(s)
Expand Down
25 changes: 25 additions & 0 deletions testdata/transform_dot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import "fmt"

type DotCaseValue int

const (
DotCaseValueOne DotCaseValue = iota
DotCaseValueTwo
DotCaseValueThree
)

func main() {
ck(DotCaseValueOne, "dot.case.value.one")
ck(DotCaseValueTwo, "dot.case.value.two")
ck(DotCaseValueThree, "dot.case.value.three")
ck(-127, "DotCaseValue(-127)")
ck(127, "DotCaseValue(127)")
}

func ck(value DotCaseValue, str string) {
if fmt.Sprint(value) != str {
panic("transform_dot.go: " + str)
}
}
25 changes: 25 additions & 0 deletions testdata/transform_dot_upper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import "fmt"

type DotUpperCaseValue int

const (
DotUpperCaseValueOne DotUpperCaseValue = iota
DotUpperCaseValueTwo
DotUpperCaseValueThree
)

func main() {
ck(DotUpperCaseValueOne, "DOT.UPPER.CASE.VALUE.ONE")
ck(DotUpperCaseValueTwo, "DOT.UPPER.CASE.VALUE.TWO")
ck(DotUpperCaseValueThree, "DOT.UPPER.CASE.VALUE.THREE")
ck(-127, "DotUpperCaseValue(-127)")
ck(127, "DotUpperCaseValue(127)")
}

func ck(value DotUpperCaseValue, str string) {
if fmt.Sprint(value) != str {
panic("transform_dot_upper.go: " + str)
}
}
Loading