|
| 1 | +package generator |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestToPascal(t *testing.T) { |
| 8 | + tests := []struct { |
| 9 | + name string |
| 10 | + input string |
| 11 | + expected string |
| 12 | + }{ |
| 13 | + { |
| 14 | + name: "empty string", |
| 15 | + input: "", |
| 16 | + expected: "", |
| 17 | + }, |
| 18 | + { |
| 19 | + name: "single lowercase word", |
| 20 | + input: "hello", |
| 21 | + expected: "Hello", |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "snake_case with two words", |
| 25 | + input: "hello_world", |
| 26 | + expected: "HelloWorld", |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "snake_case with multiple words", |
| 30 | + input: "hello_world_golang", |
| 31 | + expected: "HelloWorldGolang", |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "leading underscore", |
| 35 | + input: "_hello", |
| 36 | + expected: "Hello", |
| 37 | + }, |
| 38 | + { |
| 39 | + name: "trailing underscore", |
| 40 | + input: "hello_", |
| 41 | + expected: "Hello", |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "multiple leading underscores", |
| 45 | + input: "__hello", |
| 46 | + expected: "Hello", |
| 47 | + }, |
| 48 | + { |
| 49 | + name: "multiple trailing underscores", |
| 50 | + input: "hello__", |
| 51 | + expected: "Hello", |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "middle double underscore", |
| 55 | + input: "hello__world", |
| 56 | + expected: "HelloWorld", |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "multiple underscores", |
| 60 | + input: "hello___world___golang", |
| 61 | + expected: "HelloWorldGolang", |
| 62 | + }, |
| 63 | + { |
| 64 | + name: "all uppercase snake_case", |
| 65 | + input: "HELLO_WORLD", |
| 66 | + expected: "HELLOWORLD", |
| 67 | + }, |
| 68 | + { |
| 69 | + name: "mixed case snake_case", |
| 70 | + input: "Hello_World", |
| 71 | + expected: "HelloWorld", |
| 72 | + }, |
| 73 | + { |
| 74 | + name: "with numbers", |
| 75 | + input: "http_200_status", |
| 76 | + expected: "Http200Status", |
| 77 | + }, |
| 78 | + { |
| 79 | + name: "first character uppercase", |
| 80 | + input: "Http_client", |
| 81 | + expected: "HttpClient", |
| 82 | + }, |
| 83 | + { |
| 84 | + name: "only underscores", |
| 85 | + input: "___", |
| 86 | + expected: "", |
| 87 | + }, |
| 88 | + { |
| 89 | + name: "single character words", |
| 90 | + input: "a_b_c", |
| 91 | + expected: "ABC", |
| 92 | + }, |
| 93 | + { |
| 94 | + name: "non-ascii characters", |
| 95 | + input: "héllo_wörld", |
| 96 | + expected: "HélloWörld", |
| 97 | + }, |
| 98 | + } |
| 99 | + |
| 100 | + for _, tt := range tests { |
| 101 | + t.Run(tt.name, func(t *testing.T) { |
| 102 | + actual := ToPascal(tt.input) |
| 103 | + if actual != tt.expected { |
| 104 | + t.Errorf("ToPascal(%q) = %q, expected %q", tt.input, actual, tt.expected) |
| 105 | + } |
| 106 | + }) |
| 107 | + } |
| 108 | +} |
0 commit comments