|
| 1 | +package main |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestLowercaseFirst(t *testing.T) { |
| 6 | + var tests = map[string]struct { |
| 7 | + input string |
| 8 | + expected string |
| 9 | + }{ |
| 10 | + "empty string": { |
| 11 | + input: "", |
| 12 | + expected: "", |
| 13 | + }, |
| 14 | + "first lower case": { |
| 15 | + input: "helloWorld", |
| 16 | + expected: "helloWorld", |
| 17 | + }, |
| 18 | + "first upper case": { |
| 19 | + input: "HelloWorld", |
| 20 | + expected: "helloWorld", |
| 21 | + }, |
| 22 | + } |
| 23 | + |
| 24 | + for testName, test := range tests { |
| 25 | + t.Run(testName, func(t *testing.T) { |
| 26 | + actual := lowercaseFirst(test.input) |
| 27 | + if actual != test.expected { |
| 28 | + t.Errorf( |
| 29 | + "unexpected output\nexpected: [%v]\nactual: [%v]", |
| 30 | + test.expected, |
| 31 | + actual, |
| 32 | + ) |
| 33 | + } |
| 34 | + }) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func TestUppercaseFirst(t *testing.T) { |
| 39 | + var tests = map[string]struct { |
| 40 | + input string |
| 41 | + expected string |
| 42 | + }{ |
| 43 | + "empty string": { |
| 44 | + input: "", |
| 45 | + expected: "", |
| 46 | + }, |
| 47 | + "first upper case": { |
| 48 | + input: "HelloWorld", |
| 49 | + expected: "HelloWorld", |
| 50 | + }, |
| 51 | + "first lower case": { |
| 52 | + input: "helloWorld", |
| 53 | + expected: "HelloWorld", |
| 54 | + }, |
| 55 | + } |
| 56 | + |
| 57 | + for testName, test := range tests { |
| 58 | + t.Run(testName, func(t *testing.T) { |
| 59 | + actual := uppercaseFirst(test.input) |
| 60 | + if actual != test.expected { |
| 61 | + t.Errorf( |
| 62 | + "unexpected output\nexpected: [%v]\nactual: [%v]", |
| 63 | + test.expected, |
| 64 | + actual, |
| 65 | + ) |
| 66 | + } |
| 67 | + }) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +func TestCamelCase(t *testing.T) { |
| 72 | + var tests = map[string]struct { |
| 73 | + input string |
| 74 | + expected string |
| 75 | + }{ |
| 76 | + "empty string": { |
| 77 | + input: "", |
| 78 | + expected: "", |
| 79 | + }, |
| 80 | + "no underscores": { |
| 81 | + input: "HelloWorld", |
| 82 | + expected: "helloWorld", |
| 83 | + }, |
| 84 | + "with underscores": { |
| 85 | + input: "hello_world", |
| 86 | + expected: "helloWorld", |
| 87 | + }, |
| 88 | + "one underscore first": { |
| 89 | + input: "_beacon_callback", |
| 90 | + expected: "beaconCallback", |
| 91 | + }, |
| 92 | + "multiple underscores first": { |
| 93 | + input: "__beacon_callback", |
| 94 | + expected: "beaconCallback", |
| 95 | + }, |
| 96 | + } |
| 97 | + |
| 98 | + for testName, test := range tests { |
| 99 | + t.Run(testName, func(t *testing.T) { |
| 100 | + actual := camelCase(test.input) |
| 101 | + if actual != test.expected { |
| 102 | + t.Errorf( |
| 103 | + "unexpected output\nexpected: [%v]\nactual: [%v]", |
| 104 | + test.expected, |
| 105 | + actual, |
| 106 | + ) |
| 107 | + } |
| 108 | + }) |
| 109 | + } |
| 110 | +} |
0 commit comments