-
Notifications
You must be signed in to change notification settings - Fork 20
/
service_test.go
54 lines (50 loc) · 1.28 KB
/
service_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
package soju
import (
"testing"
)
func assertSplit(t *testing.T, input string, expected []string) {
actual, err := splitWords(input)
if err != nil {
t.Errorf("%q: %v", input, err)
return
}
if len(actual) != len(expected) {
t.Errorf("%q: expected %d words, got %d\nexpected: %v\ngot: %v", input, len(expected), len(actual), expected, actual)
return
}
for i := 0; i < len(actual); i++ {
if actual[i] != expected[i] {
t.Errorf("%q: expected word #%d to be %q, got %q\nexpected: %v\ngot: %v", input, i, expected[i], actual[i], expected, actual)
}
}
}
func TestSplit(t *testing.T) {
assertSplit(t, " ch 'up' #soju 'relay'-det\"ache\"d message ", []string{
"ch",
"up",
"#soju",
"relay-detached",
"message",
})
assertSplit(t, "net update \\\"free\\\"node -pass 'political \"stance\" desu!' -realname '' -nick lee", []string{
"net",
"update",
"\"free\"node",
"-pass",
"political \"stance\" desu!",
"-realname",
"",
"-nick",
"lee",
})
assertSplit(t, "Omedeto,\\ Yui! ''", []string{
"Omedeto, Yui!",
"",
})
if _, err := splitWords("end of 'file"); err == nil {
t.Errorf("expected error on unterminated single quote")
}
if _, err := splitWords("end of backquote \\"); err == nil {
t.Errorf("expected error on unterminated backquote sequence")
}
}