| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package envcar |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
var normalizeCases = []struct { |
| 13 |
in, want string |
| 14 |
}{ |
| 15 |
{"", ""}, |
| 16 |
{"ABC", "ABC"}, |
| 17 |
{"abc", "ABC"}, |
| 18 |
{"01239", "_01239"}, |
| 19 |
{"0abc", "_0ABC"}, |
| 20 |
{"9", "_9"}, |
| 21 |
{"a_b_c", "A_B_C"}, |
| 22 |
{"hello-world", "HELLO_WORLD"}, |
| 23 |
{"foo.bar", "FOO_BAR"}, |
| 24 |
{"Content-Type", "CONTENT_TYPE"}, |
| 25 |
{"traceparent", "TRACEPARENT"}, |
| 26 |
{"key with spaces", "KEY_WITH_SPACES"}, |
| 27 |
{"MiXeD_123!", "MIXED_123_"}, |
| 28 |
{"🧳", "_"}, |
| 29 |
{"Mój Bagaż", "M_J_BAGA_"}, |
| 30 |
} |
| 31 |
|
| 32 |
func TestNormalize(t *testing.T) { |
| 33 |
for _, tc := range normalizeCases { |
| 34 |
t.Run(tc.in, func(t *testing.T) { |
| 35 |
assert.Equal(t, tc.want, normalize(tc.in)) |
| 36 |
}) |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
func BenchmarkNormalize(b *testing.B) { |
| 41 |
for _, tc := range normalizeCases { |
| 42 |
b.Run(tc.in, func(b *testing.B) { |
| 43 |
b.ReportAllocs() |
| 44 |
for b.Loop() { |
| 45 |
normalize(tc.in) |
| 46 |
} |
| 47 |
}) |
| 48 |
} |
| 49 |
} |