1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package text
16
17 import "testing"
18
19 func TestAsSnakeCase(t *testing.T) {
20 tests := []struct {
21 input string
22 expected string
23 }{
24 {
25 input: "lowerCamelCaseInput",
26 expected: "lower_camel_case_input",
27 },
28 {
29 input: "UpperCamelCaseInput",
30 expected: "upper_camel_case_input",
31 },
32 {
33 input: "snake_case_input",
34 expected: "snake_case_input",
35 },
36 }
37 for _, tc := range tests {
38 t.Run(tc.input, func(t *testing.T) {
39 output := AsSnakeCase(tc.input)
40 if tc.expected != output {
41 t.Errorf("expected: %v, actual: %v", tc.expected, output)
42 }
43 })
44 }
45 }
46
47 func TestSnakeCaseToLowerCase(t *testing.T) {
48 tests := []struct {
49 input string
50 expected string
51 }{
52 {
53 input: "snake_case_input",
54 expected: "snakecaseinput",
55 },
56 {
57 input: "input",
58 expected: "input",
59 },
60 }
61 for _, tc := range tests {
62 t.Run(tc.input, func(t *testing.T) {
63 output := SnakeCaseToLowerCase(tc.input)
64 if tc.expected != output {
65 t.Errorf("error parsing snake case to lower case: got %v, want %v", output, tc.expected)
66 }
67 })
68 }
69 }
70
71 func TestIsPascalCase(t *testing.T) {
72 tests := []struct {
73 input string
74 expected bool
75 }{
76 {
77 input: "PrivateCA",
78 expected: true,
79 },
80 {
81 input: "CAPool",
82 expected: true,
83 },
84 {
85 input: "IAM",
86 expected: true,
87 },
88 {
89 input: "Bigtable",
90 expected: true,
91 },
92 {
93 input: "bigquery",
94 expected: false,
95 },
96 {
97 input: "MD5",
98 expected: false,
99 },
100 }
101 for _, tc := range tests {
102 t.Run(tc.input, func(t *testing.T) {
103 output := IsPascalCase(tc.input)
104 if tc.expected != output {
105 t.Errorf("error checking if the input is pascal case: got %v, want %v", output, tc.expected)
106 }
107 })
108 }
109 }
110
111 func TestRemoveSpecialCharacters(t *testing.T) {
112 tests := []struct {
113 input string
114 expected string
115 }{
116 {
117 input: "Config Connector 123",
118 expected: "Config Connector 123",
119 },
120 {
121 input: "project_id",
122 expected: "projectid",
123 },
124 {
125 input: "${uniqueId}",
126 expected: "uniqueId",
127 },
128 }
129 for _, tc := range tests {
130 t.Run(tc.input, func(t *testing.T) {
131 output := RemoveSpecialCharacters(tc.input)
132 if tc.expected != output {
133 t.Errorf("error checking if the input is pascal case: got %v, want %v", output, tc.expected)
134 }
135 })
136 }
137 }
138
View as plain text