Add test for ToScreamingDelimitedWithIgnore

This commit is contained in:
Ian Coleman 2019-11-13 10:24:17 +11:00
parent e7b55ac809
commit cb1a286566
2 changed files with 21 additions and 1 deletions

View File

@ -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)
}

View File

@ -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 + "'")
}
}
}