-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathircfmt_test.go
233 lines (216 loc) · 6.48 KB
/
ircfmt_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
226
227
228
229
230
231
232
233
package ircfmt
import (
"reflect"
"testing"
)
type testcase struct {
escaped string
unescaped string
}
var tests = []testcase{
{"te$bst", "te\x02st"},
{"te$c[green]st", "te\x033st"},
{"te$c[red,green]st", "te\x034,3st"},
{"te$c[green]4st", "te\x03034st"},
{"te$c[red,green]9st", "te\x034,039st"},
{" ▀█▄▀▪.▀ ▀ ▀ ▀ ·▀▀▀▀ ▀█▄▀ ▀▀ █▪ ▀█▄▀▪", " ▀█▄▀▪.▀ ▀ ▀ ▀ ·▀▀▀▀ ▀█▄▀ ▀▀ █▪ ▀█▄▀▪"},
{"test $$c", "test $c"},
{"test $c[]", "test \x03"},
{"test $$", "test $"},
}
var escapetests = []testcase{
{"te$c[]st", "te\x03st"},
{"test$c[]", "test\x03"},
}
var unescapetests = []testcase{
{"te$xt", "text"},
{"te$st", "te\x1et"},
{"test$c", "test\x03"},
{"te$c[red velvet", "te\x03[red velvet"},
{"te$c[[red velvet", "te\x03[[red velvet"},
{"test$c[light blue,black]asdf", "test\x0312,1asdf"},
{"test$c[light blue, black]asdf", "test\x0312,1asdf"},
{"test$c[light gray]asdf", "test\x0315asdf"},
{"te$c[4,3]st", "te\x034,3st"},
{"te$c[4]1st", "te\x03041st"},
{"te$c[4,3]9st", "te\x034,039st"},
{"te$c[04,03]9st", "te\x0304,039st"},
{"te$c[asdf !23a fd4*#]st", "te\x03st"},
{"te$c[asdf , !2,3a fd4*#]st", "te\x03st"},
{"Client opered up $c[grey][$r%s$c[grey], $r%s$c[grey]]", "Client opered up \x0314[\x0f%s\x0314, \x0f%s\x0314]"},
{"Client opered up $c[grey][$r%s$c[gray], $r%s$c[grey]]", "Client opered up \x0314[\x0f%s\x0314, \x0f%s\x0314]"},
}
var stripTests = []testcase{
{"te\x02st", "test"},
{"te\x033st", "test"},
{"te\x034,3st", "test"},
{"te\x03034st", "te4st"},
{"te\x034,039st", "te9st"},
{" ▀█▄▀▪.▀ ▀ ▀ ▀ ·▀▀▀▀ ▀█▄▀ ▀▀ █▪ ▀█▄▀▪", " ▀█▄▀▪.▀ ▀ ▀ ▀ ·▀▀▀▀ ▀█▄▀ ▀▀ █▪ ▀█▄▀▪"},
{"test\x02case", "testcase"},
{"", ""},
{"test string", "test string"},
{"test \x03", "test "},
{"test \x031x", "test x"},
{"test \x031,11x", "test x"},
{"test \x0311,0x", "test x"},
{"test \x039,99", "test "},
{"test \x0301string", "test string"},
{"test\x031,2 string", "test string"},
{"test\x0301,02 string", "test string"},
{"test\x03, string", "test, string"},
{"test\x03,12 string", "test,12 string"},
{"\x02\x031,2\x11\x16\x1d\x1e\x0f\x1f", ""},
{"\x03", ""},
{"\x03,", ","},
{"\x031,2", ""},
{"\x0315,1234", "34"},
{"\x03151234", "1234"},
{"\x03\x03\x03\x03\x03\x03\x03", ""},
{"\x03\x03\x03\x03\x03\x03\x03\x03", ""},
{"\x03,\x031\x0312\x0334,\x0356,\x0378,90\x031234", ",,,34"},
{"\x0312,12\x03121212\x0311,333\x03,3\x038\x0399\x0355\x03test", "12123,3test"},
}
type splitTestCase struct {
input string
output []FormattedSubstring
}
var splitTestCases = []splitTestCase{
{"", nil},
{"a", []FormattedSubstring{
{Content: "a"},
}},
{"\x02", nil},
{"\x02\x03", nil},
{"\x0311", nil},
{"\x0311,13", nil},
{"\x02a", []FormattedSubstring{
{Content: "a", Bold: true},
}},
{"\x02ab", []FormattedSubstring{
{Content: "ab", Bold: true},
}},
{"c\x02ab", []FormattedSubstring{
{Content: "c"},
{Content: "ab", Bold: true},
}},
{"\x02a\x02", []FormattedSubstring{
{Content: "a", Bold: true},
}},
{"\x02a\x02b", []FormattedSubstring{
{Content: "a", Bold: true},
{Content: "b", Bold: false},
}},
{"\x02\x1fa", []FormattedSubstring{
{Content: "a", Bold: true, Underline: true},
}},
{"\x1e\x1fa\x1fb", []FormattedSubstring{
{Content: "a", Strikethrough: true, Underline: true},
{Content: "b", Strikethrough: true, Underline: false},
}},
{"\x02\x031,0a\x0f", []FormattedSubstring{
{Content: "a", Bold: true, ForegroundColor: ColorCode{true, 1}, BackgroundColor: ColorCode{true, 0}},
}},
{"\x02\x0301,0a\x0f", []FormattedSubstring{
{Content: "a", Bold: true, ForegroundColor: ColorCode{true, 1}, BackgroundColor: ColorCode{true, 0}},
}},
{"\x02\x031,00a\x0f", []FormattedSubstring{
{Content: "a", Bold: true, ForegroundColor: ColorCode{true, 1}, BackgroundColor: ColorCode{true, 0}},
}},
{"\x02\x0301,00a\x0f", []FormattedSubstring{
{Content: "a", Bold: true, ForegroundColor: ColorCode{true, 1}, BackgroundColor: ColorCode{true, 0}},
}},
{"\x02\x031,0a\x0fb", []FormattedSubstring{
{Content: "a", Bold: true, ForegroundColor: ColorCode{true, 1}, BackgroundColor: ColorCode{true, 0}},
{Content: "b"},
}},
{"\x02\x031,0a\x02b", []FormattedSubstring{
{Content: "a", Bold: true, ForegroundColor: ColorCode{true, 1}, BackgroundColor: ColorCode{true, 0}},
{Content: "b", Bold: false, ForegroundColor: ColorCode{true, 1}, BackgroundColor: ColorCode{true, 0}},
}},
{"\x031,", []FormattedSubstring{
{Content: ",", ForegroundColor: ColorCode{true, 1}},
}},
{"\x0311,", []FormattedSubstring{
{Content: ",", ForegroundColor: ColorCode{true, 11}},
}},
{"\x0311,13ab", []FormattedSubstring{
{Content: "ab", ForegroundColor: ColorCode{true, 11}, BackgroundColor: ColorCode{true, 13}},
}},
{"\x0399,04the quick \t brown fox", []FormattedSubstring{
{Content: "the quick \t brown fox", BackgroundColor: ColorCode{true, 4}},
}},
}
func TestSplit(t *testing.T) {
for i, testCase := range splitTestCases {
actual := Split(testCase.input)
if !reflect.DeepEqual(actual, testCase.output) {
t.Errorf("Test case %d failed: expected %#v, got %#v", i, testCase.output, actual)
}
}
}
func TestEscape(t *testing.T) {
for _, pair := range tests {
val := Escape(pair.unescaped)
if val != pair.escaped {
t.Error(
"For", pair.unescaped,
"expected", pair.escaped,
"got", val,
)
}
}
for _, pair := range escapetests {
val := Escape(pair.unescaped)
if val != pair.escaped {
t.Error(
"For", pair.unescaped,
"expected", pair.escaped,
"got", val,
)
}
}
}
func TestChain(t *testing.T) {
for _, pair := range tests {
escaped := Escape(pair.unescaped)
unescaped := Unescape(escaped)
if unescaped != pair.unescaped {
t.Errorf("for %q expected %q got %q", pair.unescaped, pair.unescaped, unescaped)
}
}
}
func TestUnescape(t *testing.T) {
for _, pair := range tests {
val := Unescape(pair.escaped)
if val != pair.unescaped {
t.Error(
"For", pair.escaped,
"expected", pair.unescaped,
"got", val,
)
}
}
for _, pair := range unescapetests {
val := Unescape(pair.escaped)
if val != pair.unescaped {
t.Error(
"For", pair.escaped,
"expected", pair.unescaped,
"got", val,
)
}
}
}
func TestStrip(t *testing.T) {
for _, pair := range stripTests {
val := Strip(pair.escaped)
if val != pair.unescaped {
t.Error(
"For", pair.escaped,
"expected", pair.unescaped,
"got", val,
)
}
}
}