-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstring_case_test.go
88 lines (85 loc) · 2.44 KB
/
string_case_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package microerror
import (
"testing"
)
func Test_toStringCase(t *testing.T) {
testCases := []struct {
Name string
InputString string
ExpectedString string
}{
{
Name: "case 0: camel case to string case with lower start",
InputString: "fooBar",
ExpectedString: "foo bar",
},
{
Name: "case 1: camel case to string case with lower start and longer input",
InputString: "fooBarBazupKick",
ExpectedString: "foo bar bazup kick",
},
{
Name: "case 2: camel case to string case with upper start",
InputString: "FooBar",
ExpectedString: "foo bar",
},
{
Name: "case 3: camel case to string case with upper start and longer input",
InputString: "FooBarBazupKick",
ExpectedString: "foo bar bazup kick",
},
{
Name: "case 4: real private error kind",
InputString: "authenticationError",
ExpectedString: "authentication error",
},
{
Name: "case 5: real public error kind",
InputString: "AuthenticationError",
ExpectedString: "authentication error",
},
{
Name: "case 6: camel case with abbreviation at the start",
InputString: "APINotAvailableError",
ExpectedString: "api not available error",
},
{
Name: "case 7: camel case with abbreviation in the middle",
InputString: "invalidHTTPStatusError",
ExpectedString: "invalid http status error",
},
{
Name: "case 8: camel case with abbreviation at the end",
InputString: "fooBarBAZ",
ExpectedString: "foo bar baz",
},
{
Name: "case 9: with version numbers at the start",
InputString: "v2RouteNotReachable",
ExpectedString: "v2 route not reachable",
},
{
Name: "case 10: with version numbers in the middle",
InputString: "oldV2RouteNotReachable",
ExpectedString: "old v2 route not reachable",
},
{
Name: "case 11: with version numbers in the middle",
InputString: "oldV2RouteNotReachable",
ExpectedString: "old v2 route not reachable",
},
{
Name: "case 12: with version numbers at the end does not work",
InputString: "statusCode200",
ExpectedString: "status code200",
},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
output := toStringCase(tc.InputString)
if output != tc.ExpectedString {
t.Fatalf("expected %#v got %#v", tc.ExpectedString, output)
}
})
}
}