-
Notifications
You must be signed in to change notification settings - Fork 8
/
symbol_test.go
67 lines (60 loc) · 2.28 KB
/
symbol_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
package thriftlint
import (
"strings"
"github.com/alecthomas/go-thrift/parser"
"github.com/stretchr/testify/require"
"testing"
)
func TestSplitSymbol(t *testing.T) {
actual := SplitSymbol("someSnakeCaseAPI")
require.Equal(t, []string{"some", "Snake", "Case", "API"}, actual)
actual = SplitSymbol("someSnakeCase")
require.Equal(t, []string{"some", "Snake", "Case"}, actual)
actual = SplitSymbol("SomeCamelCase")
require.Equal(t, []string{"Some", "Camel", "Case"}, actual)
actual = SplitSymbol("SomeCamelCaseAPI")
require.Equal(t, []string{"Some", "Camel", "Case", "API"}, actual)
actual = SplitSymbol("some_underscore_case")
require.Equal(t, []string{"some", "underscore", "case"}, actual)
actual = SplitSymbol("SOME_UNDERSCORE_CASE")
require.Equal(t, []string{"SOME", "UNDERSCORE", "CASE"}, actual)
actual = SplitSymbol("ListingDBService")
require.Equal(t, []string{"Listing", "DB", "Service"}, actual)
actual = SplitSymbol("some1")
require.Equal(t, []string{"some1"}, actual)
actual = SplitSymbol("_id")
require.Equal(t, []string{"", "id"}, actual)
actual = SplitSymbol("listingIdSHAs")
require.Equal(t, []string{"listing", "Id", "SHA", "s"}, actual)
actual = SplitSymbol("listingIdSHAsToAdd")
require.Equal(t, []string{"listing", "Id", "SHA", "s", "To", "Add"}, actual)
actual = SplitSymbol("APIv3ProtocolTestService")
require.Equal(t, []string{"API", "v3", "Protocol", "Test", "Service"}, actual)
}
func TestUpperCamelCase(t *testing.T) {
actual := UpperCamelCase("listingIdSHAs")
require.Equal(t, "ListingIDSHAs", actual)
actual = UpperCamelCase("listingIdSHAsToAdd")
require.Equal(t, "ListingIDSHAsToAdd", actual)
}
func TestLowerCamelCase(t *testing.T) {
actual := LowerCamelCase("listingIdSHAs")
require.Equal(t, "listingIDSHAs", actual)
actual = LowerCamelCase("listingIdSHAsToAdd")
require.Equal(t, "listingIDSHAsToAdd", actual)
}
func TestComment(t *testing.T) {
enum := &parser.Enum{
Comment: strings.Repeat("hello ", 30),
}
actual := Comment(enum)
expected := []string{
"hello hello hello hello hello hello hello hello hello hello hello hello hello",
"hello hello hello hello hello hello hello hello hello hello hello hello hello",
"hello hello hello hello",
}
require.Equal(t, expected, actual)
enum = &parser.Enum{}
actual = Comment(enum)
require.Nil(t, actual)
}