@@ -6,49 +6,74 @@ import (
66)
77
88func TestTextCases (t * testing.T ) {
9- t .Parallel ()
10-
119 tt := []struct {
1210 in string
1311 camel string
1412 snake string
1513 }{
16- {in : "Add updated_at to users table" , camel : "addUpdatedAtToUsersTable" , snake : "add_updated_at_to_users_table" },
17- {in : "$()&^%(_--crazy__--input$)" , camel : "crazyInput" , snake : "crazy_input" },
18- {in : "Hey, this TEXT will have to obey some rules!!" , camel : "heyThisTextWillHaveToObeySomeRules" , snake : "hey_this_text_will_have_to_obey_some_rules" },
19- {in : "_$$_This is some text, OK?!" , camel : "thisIsSomeTextOk" , snake : "this_is_some_text_ok" },
20- {in : "_" , camel : "" , snake : "" },
21- {in : "$(((*&^%$#@!)))#$%^&*" , camel : "" , snake : "" },
2214 {in : "" , camel : "" , snake : "" },
15+ {in : "_" , camel : "" , snake : "" },
2316 {in : "a" , camel : "a" , snake : "a" },
2417 {in : "a___" , camel : "a" , snake : "a" },
18+ {in : "___a" , camel : "a" , snake : "a" },
19+ {in : "a_b" , camel : "aB" , snake : "a_b" },
2520 {in : "a___b" , camel : "aB" , snake : "a_b" },
2621 {in : "ax___by" , camel : "axBy" , snake : "ax_by" },
22+ {in : "someText" , camel : "someText" , snake : "some_text" },
23+ {in : "someTEXT" , camel : "someText" , snake : "some_text" },
24+ {in : "NeXT" , camel : "neXt" , snake : "ne_xt" },
25+ {in : "Add updated_at to users table" , camel : "addUpdatedAtToUsersTable" , snake : "add_updated_at_to_users_table" },
26+ {in : "Hey, this TEXT will have to obey some rules!!" , camel : "heyThisTextWillHaveToObeySomeRules" , snake : "hey_this_text_will_have_to_obey_some_rules" },
2727 {in : "Háčky, čárky. Příliš žluťoučký kůň úpěl ďábelské ódy." , camel : "háčkyČárkyPřílišŽluťoučkýKůňÚpělĎábelskéÓdy" , snake : "háčky_čárky_příliš_žluťoučký_kůň_úpěl_ďábelské_ódy" },
2828 {in : "here comes O'Brian" , camel : "hereComesOBrian" , snake : "here_comes_o_brian" },
29+ {in : "thisIsCamelCase" , camel : "thisIsCamelCase" , snake : "this_is_camel_case" },
30+ {in : "this_is_snake_case" , camel : "thisIsSnakeCase" , snake : "this_is_snake_case" },
31+ {in : "__snake_case__" , camel : "snakeCase" , snake : "snake_case" },
32+ {in : "fromCamelCaseToCamelCase" , camel : "fromCamelCaseToCamelCase" , snake : "from_camel_case_to_camel_case" },
33+ {in : "$()&^%(_--crazy__--input$)" , camel : "crazyInput" , snake : "crazy_input" },
34+ {in : "_$$_This is some text, OK?!" , camel : "thisIsSomeTextOk" , snake : "this_is_some_text_ok" },
35+ {in : "$(((*&^%$#@!)))#$%^&*" , camel : "" , snake : "" },
2936 }
3037
3138 for _ , test := range tt {
3239 // camelCase
3340 if got := CamelCase (test .in ); got != test .camel {
34- t .Errorf ("unexpected camelCase for input(%q), got %q, want %q" , test .in , got , test .camel )
41+ t .Errorf ("unexpected camelCase for %q: got %q, want %q" , test .in , got , test .camel )
3542 }
3643
3744 // PascalCase
3845 testPascal := strings .Title (test .camel )
3946 if got := PascalCase (test .in ); got != testPascal {
40- t .Errorf ("unexpected PascalCase for input(%q), got %q, want %q" , test .in , got , testPascal )
47+ t .Errorf ("unexpected PascalCase for %q: got %q, want %q" , test .in , got , testPascal )
4148 }
4249
4350 // snake_case
4451 if got := SnakeCase (test .in ); got != test .snake {
45- t .Errorf ("unexpected snake_case for input(%q), got %q, want %q" , test .in , got , test .snake )
52+ t .Errorf ("unexpected snake_case for %q: got %q, want %q" , test .in , got , test .snake )
4653 }
4754
4855 // kebab-case
4956 testKebab := strings .ReplaceAll (test .snake , "_" , "-" )
5057 if got := KebabCase (test .in ); got != testKebab {
51- t .Errorf ("unexpected kebab-case for input(%q), got %q, want %q" , test .in , got , testKebab )
58+ t .Errorf ("unexpected kebab-case for %q: got %q, want %q" , test .in , got , testKebab )
59+ }
60+ }
61+ }
62+
63+ func TestMarkLetterCaseChanges (t * testing.T ) {
64+ tt := []struct {
65+ in string
66+ out string
67+ }{
68+ {in : "detectUpperLowerChanges" , out : "detect_Upper_Lower_Changes" },
69+ {in : "detectUPPERchange" , out : "detect_UPPER_change" },
70+ {in : "detect_UPPER_change" , out : "detect_UPPER_change" },
71+ {in : "Some camelCase and PascalCase text, OK?" , out : "Some camel_Case and Pascal_Case text, OK?" },
72+ }
73+
74+ for _ , test := range tt {
75+ if got := markLetterCaseChanges (test .in ); got != test .out {
76+ t .Errorf ("unexpected markLowerUpperChanges for %q: got %q, want %q" , test .in , got , test .out )
5277 }
5378 }
5479}
0 commit comments