forked from Masterminds/goutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordutils_test.go
225 lines (166 loc) · 4.92 KB
/
wordutils_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
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
package goutils
import (
"fmt"
"testing"
)
// ****************************** TESTS ********************************************
func TestWrapNormalWord(t *testing.T) {
in := "Bob Manuel Bob Manuel"
out := "Bob Manuel\nBob Manuel"
wrapLength := 10
if x := Wrap(in, wrapLength); x != out {
t.Errorf("Wrap(%v) = %v, want %v", in, x, out)
}
}
func TestWrapCustomLongWordFalse(t *testing.T) {
in := "BobManuelBob Bob"
out := "BobManuelBob<br\\>Bob"
wrapLength := 10
newLineStr := "<br\\>"
wrapLongWords := false
if x := WrapCustom(in, wrapLength, newLineStr, wrapLongWords); x != out {
t.Errorf("Wrap(%v) = %v, want %v", in, x, out)
}
}
func TestWrapCustomLongWordTrue(t *testing.T) {
in := "BobManuelBob Bob"
out := "BobManuelB<br\\>ob Bob"
wrapLength := 10
newLineStr := "<br\\>"
wrapLongWords := true
if x := WrapCustom(in, wrapLength, newLineStr, wrapLongWords); x != out {
t.Errorf("WrapCustom(%v) = %v, want %v", in, x, out)
}
}
func TestCapitalize(t *testing.T) {
// Test 1: Checks if function works with 1 parameter, and default whitespace delimiter
in := "test is going.well.thank.you.for inquiring"
out := "Test Is Going.well.thank.you.for Inquiring"
if x := Capitalize(in); x != out {
t.Errorf("Capitalize(%v) = %v, want %v", in, x, out)
}
// Test 2: Checks if function works with both parameters, with param 2 containing whitespace and '.'
out = "Test Is Going.Well.Thank.You.For Inquiring"
delimiters := []rune{' ', '.'}
if x := Capitalize(in, delimiters...); x != out {
t.Errorf("Capitalize(%v) = %v, want %v", in, x, out)
}
}
func TestCapitalizeFully(t *testing.T) {
// Test 1
in := "tEsT iS goiNG.wELL.tHaNk.yOU.for inqUIrING"
out := "Test Is Going.well.thank.you.for Inquiring"
if x := CapitalizeFully(in); x != out {
t.Errorf("CapitalizeFully(%v) = %v, want %v", in, x, out)
}
// Test 2
out = "Test Is Going.Well.Thank.You.For Inquiring"
delimiters := []rune{' ', '.'}
if x := CapitalizeFully(in, delimiters...); x != out {
t.Errorf("CapitalizeFully(%v) = %v, want %v", in, x, out)
}
}
func TestUncapitalize(t *testing.T) {
// Test 1: Checks if function works with 1 parameter, and default whitespace delimiter
in := "This Is A.Test"
out := "this is a.Test"
if x := Uncapitalize(in); x != out {
t.Errorf("Uncapitalize(%v) = %v, want %v", in, x, out)
}
// Test 2: Checks if function works with both parameters, with param 2 containing whitespace and '.'
out = "this is a.test"
delimiters := []rune{' ', '.'}
if x := Uncapitalize(in, delimiters...); x != out {
t.Errorf("Uncapitalize(%v) = %v, want %v", in, x, out)
}
}
func TestSwapCase(t *testing.T) {
in := "This Is A.Test"
out := "tHIS iS a.tEST"
if x := SwapCase(in); x != out {
t.Errorf("SwapCase(%v) = %v, want %v", in, x, out)
}
}
func TestInitials(t *testing.T) {
// Test 1
in := "John Doe.Ray"
out := "JD"
if x := Initials(in); x != out {
t.Errorf("Initials(%v) = %v, want %v", in, x, out)
}
// Test 2
out = "JDR"
delimiters := []rune{' ', '.'}
if x := Initials(in, delimiters...); x != out {
t.Errorf("Initials(%v) = %v, want %v", in, x, out)
}
}
// ****************************** EXAMPLES ********************************************
func ExampleWrap() {
in := "Bob Manuel Bob Manuel"
wrapLength := 10
fmt.Println(Wrap(in, wrapLength))
// Output:
// Bob Manuel
// Bob Manuel
}
func ExampleWrapCustom_1() {
in := "BobManuelBob Bob"
wrapLength := 10
newLineStr := "<br\\>"
wrapLongWords := false
fmt.Println(WrapCustom(in, wrapLength, newLineStr, wrapLongWords))
// Output:
// BobManuelBob<br\>Bob
}
func ExampleWrapCustom_2() {
in := "BobManuelBob Bob"
wrapLength := 10
newLineStr := "<br\\>"
wrapLongWords := true
fmt.Println(WrapCustom(in, wrapLength, newLineStr, wrapLongWords))
// Output:
// BobManuelB<br\>ob Bob
}
func ExampleCapitalize() {
in := "test is going.well.thank.you.for inquiring" // Compare input to CapitalizeFully example
delimiters := []rune{' ', '.'}
fmt.Println(Capitalize(in))
fmt.Println(Capitalize(in, delimiters...))
// Output:
// Test Is Going.well.thank.you.for Inquiring
// Test Is Going.Well.Thank.You.For Inquiring
}
func ExampleCapitalizeFully() {
in := "tEsT iS goiNG.wELL.tHaNk.yOU.for inqUIrING" // Notice scattered capitalization
delimiters := []rune{' ', '.'}
fmt.Println(CapitalizeFully(in))
fmt.Println(CapitalizeFully(in, delimiters...))
// Output:
// Test Is Going.well.thank.you.for Inquiring
// Test Is Going.Well.Thank.You.For Inquiring
}
func ExampleUncapitalize() {
in := "This Is A.Test"
delimiters := []rune{' ', '.'}
fmt.Println(Uncapitalize(in))
fmt.Println(Uncapitalize(in, delimiters...))
// Output:
// this is a.Test
// this is a.test
}
func ExampleSwapCase() {
in := "This Is A.Test"
fmt.Println(SwapCase(in))
// Output:
// tHIS iS a.tEST
}
func ExampleInitials() {
in := "John Doe.Ray"
delimiters := []rune{' ', '.'}
fmt.Println(Initials(in))
fmt.Println(Initials(in, delimiters...))
// Output:
// JD
// JDR
}