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
3 changes: 2 additions & 1 deletion casing/casing.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ func Join(parts []string, sep string, transform ...TransformFunc) string {
parts[i] = t(parts[i])

if parts[i] == "" {
// Transformer completely removed this part.
// Removing the part shifts the rest down, so stop transforming this index.
parts = append(parts[:i], parts[i+1:]...)
i--
break
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions casing/casing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ func TestRemovePart(t *testing.T) {
}))
}

func TestRemovePartWithMultipleTransforms(t *testing.T) {
drop := func(part string) string {
if part == "and" {
return ""
}

return part
}

// Camel always appends strings.Title, so a removing transform in first
// position leaves two transforms for the shifted index.
assert.Equal(t, "OneTwo", casing.Camel("and-one-two", drop))

suffix := func(part string) string { return part + "x" }
assert.Equal(t, "onex_twox", casing.Join([]string{"one", "and", "two"}, "_", drop, suffix))
}

func TestRightAlign(t *testing.T) {
assert.Equal(t, "stream_1080p", casing.Snake("Stream1080P"))

Expand Down
Loading