-
Notifications
You must be signed in to change notification settings - Fork 9
/
snake_test.go
56 lines (49 loc) · 1.71 KB
/
snake_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
// Copyright (c) 2017, A. Stoewer <[email protected]>
// All rights reserved.
package strcase
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSnakeCase(t *testing.T) {
data := map[string]string{
"": "",
"F": "f",
"Foo": "foo",
"FooB": "foo_b",
"FooID": "foo_id",
" FooBar\t": "foo_bar",
"HTTPStatusCode": "http_status_code",
"ParseURL.DoParse": "parse_url.do_parse",
"Convert Space": "convert_space",
"Convert-dash": "convert_dash",
"Skip___MultipleUnderscores": "skip_multiple_underscores",
"Skip MultipleSpaces": "skip_multiple_spaces",
"Skip---MultipleDashes": "skip_multiple_dashes",
}
for camel, snake := range data {
converted := SnakeCase(camel)
assert.Equal(t, snake, converted)
}
}
func TestUpperSnakeCase(t *testing.T) {
data := map[string]string{
"": "",
"F": "F",
"Foo": "FOO",
"FooB": "FOO_B",
"FooID": "FOO_ID",
" FooBar\t": "FOO_BAR",
"HTTPStatusCode": "HTTP_STATUS_CODE",
"ParseURL.DoParse": "PARSE_URL.DO_PARSE",
"Convert Space": "CONVERT_SPACE",
"Convert-dash": "CONVERT_DASH",
"Skip___MultipleUnderscores": "SKIP_MULTIPLE_UNDERSCORES",
"Skip MultipleSpaces": "SKIP_MULTIPLE_SPACES",
"Skip---MultipleDashes": "SKIP_MULTIPLE_DASHES",
}
for camel, snake := range data {
converted := UpperSnakeCase(camel)
assert.Equal(t, snake, converted)
}
}