-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
97 lines (87 loc) · 3.41 KB
/
helpers_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
89
90
91
92
93
94
95
96
97
package fsm
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestToCamelCase(t *testing.T) {
tests := []struct {
str string
want string
firstUpper bool
}{
{str: "some_str", want: "SomeStr", firstUpper: true},
{str: "", want: "", firstUpper: true},
{str: "F", want: "F", firstUpper: true},
{str: "foo", want: "Foo", firstUpper: true},
{str: "FooBar", want: "FooBar", firstUpper: true},
{str: "fooBarBaz", want: "FooBarBaz", firstUpper: true},
{str: "fooBar_baz", want: "FooBarBaz", firstUpper: true},
{str: " foo_bar\n", want: "FooBar", firstUpper: true},
{str: " foo-bar\t", want: "FooBar", firstUpper: true},
{str: " foo bar\r", want: "FooBar", firstUpper: true},
{str: "HTTP_status_code", want: "HttpStatusCode", firstUpper: true},
{str: "foo_bar_v2", want: "FooBarV2", firstUpper: true},
{str: "some_str", want: "someStr", firstUpper: false},
{str: "", want: "", firstUpper: false},
{str: "F", want: "f", firstUpper: false},
{str: "foo", want: "foo", firstUpper: false},
{str: "FooBar", want: "fooBar", firstUpper: false},
{str: "fooBarBaz", want: "fooBarBaz", firstUpper: false},
{str: "fooBar_baz", want: "fooBarBaz", firstUpper: false},
{str: " foo_bar\n", want: "fooBar", firstUpper: false},
{str: " foo-bar\t", want: "fooBar", firstUpper: false},
{str: " foo bar\r", want: "fooBar", firstUpper: false},
{str: "HTTP_status_code", want: "httpStatusCode", firstUpper: false},
{str: "foo_bar_v2", want: "fooBarV2", firstUpper: false},
}
for _, tt := range tests {
t.Run(tt.str, func(t *testing.T) {
got := ToCamelCase(tt.str, tt.firstUpper)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("ToCamelCase() mismatch (-want +got):\n%s", diff)
}
})
}
}
func TestToSnackCase(t *testing.T) {
tests := []struct {
str string
want string
upper bool
}{
{str: "SomeStr", want: "SOME_STR", upper: true},
{str: "", want: "", upper: true},
{str: "F", want: "F", upper: true},
{str: "foo", want: "FOO", upper: true},
{str: "FooBar", want: "FOO_BAR", upper: true},
{str: "fooBarBaz", want: "FOO_BAR_BAZ", upper: true},
{str: "fooBar_baz", want: "FOO_BAR_BAZ", upper: true},
{str: " foo_bar\n", want: "FOO_BAR", upper: true},
{str: " foo-bar\t", want: "FOO_BAR", upper: true},
{str: " foo bar\r", want: "FOO_BAR", upper: true},
{str: "HTTP_status_code", want: "HTTP_STATUS_CODE", upper: true},
{str: "foo_bar_v2_baz", want: "FOO_BAR_V2_BAZ", upper: true},
{str: "fooBarV2Baz", want: "FOO_BAR_V2_BAZ", upper: true},
{str: "some_str", want: "some_str", upper: false},
{str: "", want: "", upper: false},
{str: "F", want: "f", upper: false},
{str: "foo", want: "foo", upper: false},
{str: "FooBar", want: "foo_bar", upper: false},
{str: "fooBarBaz", want: "foo_bar_baz", upper: false},
{str: "fooBar_baz", want: "foo_bar_baz", upper: false},
{str: " foo_bar\n", want: "foo_bar", upper: false},
{str: " foo-bar\t", want: "foo_bar", upper: false},
{str: " foo bar\r", want: "foo_bar", upper: false},
{str: "HTTP_status_code", want: "http_status_code", upper: false},
{str: "foo_bar_v2_baz", want: "foo_bar_v2_baz", upper: false},
{str: "fooBarV2Baz", want: "foo_bar_v2_baz", upper: false},
}
for _, tt := range tests {
t.Run(tt.str, func(t *testing.T) {
got := ToSnackCase(tt.str, tt.upper)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("ToSnackCase() mismatch (-want +got):\n%s", diff)
}
})
}
}