Repository navigation
Expand file tree
/
Copy pathstring_test.go
More file actions
334 lines (310 loc) · 7.67 KB
/
Copy pathstring_test.go
File metadata and controls
334 lines (310 loc) · 7.67 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
package is
import "testing"
// TestDigit tests the Digit function.
func TestDigit(t *testing.T) {
testCases := []struct {
input string
want bool
}{
{"0", true},
{"1234", true},
{"Ⅳ", false},
{"1234abc", false},
{"", false},
{"1.23", false},
{"1,23", false},
{"0000", true},
{" 1234", false},
{"1234 ", false},
{"0b10001", false},
{"0o21", false},
{"0x11", false},
{"0", true},
{"⅕", false},
{"一", false},
}
for _, tc := range testCases {
got := Digit(tc.input)
if got != tc.want {
t.Errorf("Digit(%q) = %v; want %v", tc.input, got, tc.want)
}
}
}
// TestNumeric tests the Numeric function.
func TestNumeric(t *testing.T) {
testCases := []struct {
input string
want bool
}{
{"0", true},
{"1234", true},
{"+1234", true},
{"-1234", true},
{"1234abc", false},
{"", false},
{"1.23", true},
{"1,23", true},
{"0000", true},
{" 1234", false},
{"1234 ", false},
{"1234,,00", false},
{"0b10001", false},
{"0o21", false},
{"0x11", false},
// BUG-02: letter-based and ideographic "numerals" are NOT decimal
// digits and must be rejected (otherwise ordinary words pass).
{"Ⅳ", false}, // Roman numeral (category Nl)
{"三・十四", false}, // CJK numerals (category Lo)
{"⅕", false}, // vulgar fraction (category No)
{"一", false}, // CJK numeral
{"שלום", false}, // Hebrew word ("peace") — letters, not digits
{"ΑΒΓ", false}, // Greek letters
{"ԱԲԳ", false}, // Armenian letters
// True decimal digits of non-ASCII scripts (category Nd) pass.
{"٣", true}, // Arabic-Indic three
{"٣٫١٤", true}, // Arabic-Indic with Arabic decimal separator
{"۴۲", true}, // Persian digits
{"१२३", true}, // Devanagari digits
// BUG-03: a separator or sign with no digit is not a number.
{".", false},
{",", false},
{"-", false},
{"+", false},
{"+.", false},
{"-,", false},
}
for _, tc := range testCases {
got := Numeric(tc.input)
if got != tc.want {
t.Errorf("Numeric(%q) = %v; want %v", tc.input, got, tc.want)
}
}
}
// TestDecimal tests the Decimal function.
func TestDecimal(t *testing.T) {
testCases := []struct {
input string
want bool
}{
{"0", true},
{"1234", true},
{"Ⅳ", false},
{"1234abc", false},
{"", false},
{"1.23", false},
{"1,23", false},
{"0000", true},
{" 1234", false},
{"1234 ", false},
{"0b10001", false},
{"0o21", false},
{"0x11", false},
{"0", true},
{"⅕", false},
{"一", false},
}
for _, tc := range testCases {
got := Decimal(tc.input)
if got != tc.want {
t.Errorf("Decimal(%q) = %v; want %v", tc.input, got, tc.want)
}
}
}
// TestFloat tests the Float function.
func TestFloat(t *testing.T) {
testCases := []struct {
input string
want bool
}{
{"0", true},
{"123", true},
{"123.456", true},
{"+123.456", true},
{"-123.456", true},
{"123.", true},
{".456", true},
{"0.0", true},
{"-.456", true},
{"+.456", true},
{"123.456.789", false},
{"abc", false},
{"123a", false},
{"", false},
{".", false},
{"123,456", false},
{"123.456e7", false}, // exponential notation not supported
{"-0", true},
{"-0.0", true},
{"--123.456", false},
{"123..456", false},
{"12.34.56", false},
{" 123.456", false},
{"123.456 ", false},
{"123.456.789.0", false},
{"+", false},
{"-", false},
}
for _, tc := range testCases {
got := Float(tc.input)
if got != tc.want {
t.Errorf("Float(%q) = %v; want %v", tc.input, got, tc.want)
}
}
}
// TestAlpha tests the Alpha function.
func TestAlpha(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{"Київ", true},
{"abc", true},
{"abc1", false},
{"abc!", false},
{"abcΔ", true},
{"", false},
{"123", false},
{"!@#$%^&*", false},
}
for _, test := range tests {
result := Alpha(test.input)
if result != test.expected {
t.Errorf("Input: %s, Expected: %t, Got: %t",
test.input, test.expected, result)
}
}
}
// TestAlnum tests the Alnum function.
func TestAlnum(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{"Дніпро1", true},
{"abc123", true},
{"abc", true},
{"123", true},
{"abc!", false},
{"abcΔ", true},
{"", false},
{"!@#$%^&*", false},
}
for _, test := range tests {
result := Alnum(test.input)
if result != test.expected {
t.Errorf("Input: %s, Expected: %t, Got: %t",
test.input, test.expected, result)
}
}
}
// TestLower tests the Lower function.
func TestLower(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{"abc", true}, // contains lowercase letters only
{"Abc", false}, // contains an uppercase letter
{"abc123", false}, // contains a number
{"abc!", false}, // contains a special character
{"", false}, // empty string
{"ABC", false}, // contains uppercase letters only
{"abcABC", false}, // contains both lowercase and uppercase letters
{"abc ", false}, // contains whitespace
{"abc\txyz", false}, // contains whitespace
{"\nabc", false}, // contains whitespace
}
for _, test := range tests {
result := Lower(test.input)
if result != test.expected {
t.Errorf("Input: %s, Expected: %t, Got: %t",
test.input, test.expected, result)
}
}
}
// TestUpper tests the Upper function.
func TestUpper(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{"ABC", true}, // contains uppercase letters only
{"AbC", false}, // contains a lowercase letter
{"ABC123", false}, // contains a number
{"ABC!", false}, // contains a special character
{"", false}, // empty string
{"abc", false}, // contains lowercase letters only
{"ABCabc", false}, // contains both uppercase and lowercase letters
{"ABC ", false}, // contains whitespace
{"ABC\txyz", false}, // contains whitespace
{"\nABC", false}, // contains whitespace
}
for _, test := range tests {
result := Upper(test.input)
if result != test.expected {
t.Errorf("Input: %s, Expected: %t, Got: %t",
test.input, test.expected, result)
}
}
}
// TestTitle tests the Title function.
func TestTitle(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{"Hello World", true},
{"Hello world", false},
{"HELLO WORLD", false},
{"hELLO wORLD", false},
{"", false},
{"Hello World!", true},
{"Hello123 World", true},
{"Hello-World", true},
{"Hello_World", true},
{"Hello, World", true},
{"Hello World", true},
{"Hello\nWorld", true},
{"Hello.World", true},
{"Hello:World", true},
{"Hello;World", true},
{"Hello?World", true},
{"Hello!World", true},
{"Hello( )World", true},
{"Hello( )World", true},
{"Hello[ ]World", true},
{"Hello< >World", true},
}
for _, test := range tests {
result := Title(test.input)
if result != test.expected {
t.Errorf("Input: %s, Expected: %t, Got: %t",
test.input, test.expected, result)
}
}
}
// TestSpace tests the Space function.
func TestSpace(t *testing.T) {
tests := []struct {
input string
expected bool
}{
{" \t\n", true}, // whitespace characters
{"Hello", false}, // non-whitespace characters
{" ", true}, // single space
{"\n\t ", true}, // whitespace characters with newline and tab
{"", false}, // empty string
{" ", true}, // multiple spaces
{"\t\t\t", true}, // multiple tabs
{"\n\n\n", true}, // multiple newlines
{"\t \n", true}, // combination of whitespace characters
{"\tHello\n", false}, // non-whitespace character in the middle
}
for _, test := range tests {
result := Space(test.input)
if result != test.expected {
t.Errorf("Input: %s, Expected: %t, Got: %t",
test.input, test.expected, result)
}
}
}