-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapitalize_test.go
More file actions
124 lines (117 loc) · 2.51 KB
/
capitalize_test.go
File metadata and controls
124 lines (117 loc) · 2.51 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
package fmt
import "testing"
func TestCapitalize(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "Simple Conv",
input: "hello world",
expected: "Hello World",
},
{
name: "Already capitalized",
input: "Hello World",
expected: "Hello World",
},
{
name: "Mixed case",
input: "hELLo wORLd",
expected: "Hello World",
},
{
name: "Extra spaces",
input: " hello world ",
expected: " Hello World ",
},
{
name: "With numbers",
input: "hello 123 world",
expected: "Hello 123 World",
},
{
name: "With special characters",
input: "héllö wörld",
expected: "Héllö Wörld",
},
{
name: "Empty string",
input: "",
expected: "",
},
{
name: "Single word",
input: "hello",
expected: "Hello",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out := Convert(tt.input).Capitalize().String()
if out != tt.expected {
t.Errorf("Capitalize() = %q, want %q", out, tt.expected)
}
})
}
}
func TestCapitalizeChaining(t *testing.T) {
tests := []struct {
name string
input string
expected string
chain func(*Conv) *Conv
}{
{
name: "With Tilde",
input: "hólá múndo",
expected: "Hola Mundo",
chain: func(Conv *Conv) *Conv {
return Conv.Tilde().Capitalize()
},
},
{
name: "After ToLower",
input: "HELLO WORLD",
expected: "Hello World",
chain: func(Conv *Conv) *Conv {
return Conv.ToLower().Capitalize()
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out := tt.chain(Convert(tt.input)).String()
if out != tt.expected {
t.Errorf("%s = %q, want %q", tt.name, out, tt.expected)
}
})
}
}
func TestHasUpperPrefix(t *testing.T) {
tests := []struct {
name string
input string
expected bool
}{
{"Empty string", "", false},
{"ASCII uppercase", "Hello", true},
{"ASCII lowercase", "hello", false},
{"Accented uppercase Á", "Ángel", true},
{"Accented uppercase É", "Éxito", true},
{"Accented lowercase á", "ángel", false},
{"Number first", "123abc", false},
{"Space first", " Hello", false},
{"Single uppercase", "A", true},
{"Single lowercase", "a", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := HasUpperPrefix(tt.input)
if got != tt.expected {
t.Errorf("HasUpperPrefix(%q) = %v, want %v", tt.input, got, tt.expected)
}
})
}
}