Skip to content

Commit

Permalink
Adding more tests (#12)
Browse files Browse the repository at this point in the history
* Adding more tests
  • Loading branch information
liyanchang authored Jan 14, 2023
1 parent 879920e commit 38713c7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 5 deletions.
11 changes: 6 additions & 5 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ func convertWithGoInitialisms(input string, delimiter rune, wordCase WordCase) s
for i := start; i < end; i++ {
word.WriteRune(toUpper(runes[i]))
}
if golintInitialisms[word.String()] {
w := word.String()
if golintInitialisms[w] {
if !firstWord || wordCase != CamelCase {
b.WriteString(word.String())
b.WriteString(w)
firstWord = false
return
}
Expand Down Expand Up @@ -232,10 +233,10 @@ func convert(input string, fn SplitFn, delimiter rune, wordCase WordCase,
for i := start; i < end; i++ {
word.WriteRune(toUpper(runes[i]))
}
key := word.String()
if initialisms[key] {
w := word.String()
if initialisms[w] {
if !firstWord || wordCase != CamelCase {
b.WriteString(key)
b.WriteString(w)
firstWord = false
return
}
Expand Down
93 changes: 93 additions & 0 deletions strcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,99 @@ func TestAll(t *testing.T) {
title: "Bad Utf8 ���",
goTitle: "Bad UTF8 ���",
},
// Need to consider if this is worth a breaking change - currently
// because the split is 'ID3', this does not match the initialism of
// ID and thus renders as 'id3'
// {
// input: "ID3",
// snake: "id3",
// goSnake: "ID3", // Currently id3
// SNAKE: "ID3",
// kebab: "id3",
// goKebab: "ID3", // Currently id3
// KEBAB: "ID3",
// pascal: "Id3",
// goPascal: "ID3", // Currently Id3
// camel: "id3",
// goCamel: "id3", // Currently id3
// title: "Id3",
// goTitle: "ID3", // Currently Id3
// },
{
input: "IDENT3",
snake: "ident3",
goSnake: "ident3",
SNAKE: "IDENT3",
kebab: "ident3",
goKebab: "ident3",
KEBAB: "IDENT3",
pascal: "Ident3",
goPascal: "Ident3",
camel: "ident3",
goCamel: "ident3",
title: "Ident3",
goTitle: "Ident3",
},
{
input: "LogRouterS3BucketName",
snake: "log_router_s3_bucket_name",
goSnake: "log_router_s3_bucket_name",
SNAKE: "LOG_ROUTER_S3_BUCKET_NAME",
kebab: "log-router-s3-bucket-name",
goKebab: "log-router-s3-bucket-name",
KEBAB: "LOG-ROUTER-S3-BUCKET-NAME",
pascal: "LogRouterS3BucketName",
goPascal: "LogRouterS3BucketName",
camel: "logRouterS3BucketName",
goCamel: "logRouterS3BucketName",
title: "Log Router S3 Bucket Name",
goTitle: "Log Router S3 Bucket Name",
},
{
input: "PINEAPPLE",
snake: "pineapple",
goSnake: "pineapple",
SNAKE: "PINEAPPLE",
kebab: "pineapple",
goKebab: "pineapple",
KEBAB: "PINEAPPLE",
pascal: "Pineapple",
goPascal: "Pineapple",
camel: "pineapple",
goCamel: "pineapple",
title: "Pineapple",
goTitle: "Pineapple",
},
{
input: "Int8Value",
snake: "int8_value",
goSnake: "int8_value",
SNAKE: "INT8_VALUE",
kebab: "int8-value",
goKebab: "int8-value",
KEBAB: "INT8-VALUE",
pascal: "Int8Value",
goPascal: "Int8Value",
camel: "int8Value",
goCamel: "int8Value",
title: "Int8 Value",
goTitle: "Int8 Value",
},
{
input: "first.last",
snake: "first_last",
goSnake: "first_last",
SNAKE: "FIRST_LAST",
kebab: "first-last",
goKebab: "first-last",
KEBAB: "FIRST-LAST",
pascal: "FirstLast",
goPascal: "FirstLast",
camel: "firstLast",
goCamel: "firstLast",
title: "First Last",
goTitle: "First Last",
},
} {
t.Run(test.input, func(t *testing.T) {
output := data{
Expand Down

0 comments on commit 38713c7

Please sign in to comment.