diff --git a/snake.go b/snake.go index e3a481f..8e8867b 100644 --- a/snake.go +++ b/snake.go @@ -94,7 +94,11 @@ func ToScreamingDelimited(s string, delimiter uint8, ignore uint8, screaming boo } } else if v == ' ' || v == '_' || v == '-' { // replace spaces/underscores with delimiters - n += string(delimiter) + if uint8(v) == ignore { + n += string(v) + } else { + n += string(delimiter) + } } else { n = n + string(v) } diff --git a/snake_test.go b/snake_test.go index 90dd98a..92f1249 100644 --- a/snake_test.go +++ b/snake_test.go @@ -179,3 +179,19 @@ func TestToScreamingDelimited(t *testing.T) { } } } + +func TestToScreamingDelimitedWithIgnore(t *testing.T) { + cases := [][]string{ + {"AnyKind of_string", "ANY.KIND OF.STRING", ".", " "}, + } + for _, i := range cases { + in := i[0] + out := i[1] + delimiter := uint8(i[2][0]) + ignore := uint8(i[3][0]) + result := ToScreamingDelimited(in, delimiter, ignore, true) + if result != out { + t.Error("'" + result + "' != '" + out + "'") + } + } +}