source: code/trunk/service_test.go@ 573

Last change on this file since 573 was 566, checked in by hubert, 4 years ago

Hand-made word splitter for BouncerServ

Remove the (direct) dependency on shlex (go-scfg still depends on it).

Co-authored-by: Simon Ser <contact@…>

File size: 1.3 KB
RevLine 
[566]1package soju
2
3import (
4 "testing"
5)
6
7func assertSplit(t *testing.T, input string, expected []string) {
8 actual, err := splitWords(input)
9 if err != nil {
10 t.Errorf("%q: %v", input, err)
11 return
12 }
13 if len(actual) != len(expected) {
14 t.Errorf("%q: expected %d words, got %d\nexpected: %v\ngot: %v", input, len(expected), len(actual), expected, actual)
15 return
16 }
17 for i := 0; i < len(actual); i++ {
18 if actual[i] != expected[i] {
19 t.Errorf("%q: expected word #%d to be %q, got %q\nexpected: %v\ngot: %v", input, i, expected[i], actual[i], expected, actual)
20 }
21 }
22}
23
24func TestSplit(t *testing.T) {
25 assertSplit(t, " ch 'up' #soju 'relay'-det\"ache\"d message ", []string{
26 "ch",
27 "up",
28 "#soju",
29 "relay-detached",
30 "message",
31 })
32 assertSplit(t, "net update \\\"free\\\"node -pass 'political \"stance\" desu!' -realname '' -nick lee", []string{
33 "net",
34 "update",
35 "\"free\"node",
36 "-pass",
37 "political \"stance\" desu!",
38 "-realname",
39 "",
40 "-nick",
41 "lee",
42 })
43 assertSplit(t, "Omedeto,\\ Yui! ''", []string{
44 "Omedeto, Yui!",
45 "",
46 })
47
48 if _, err := splitWords("end of 'file"); err == nil {
49 t.Errorf("expected error on unterminated single quote")
50 }
51 if _, err := splitWords("end of backquote \\"); err == nil {
52 t.Errorf("expected error on unterminated backquote sequence")
53 }
54}
Note: See TracBrowser for help on using the repository browser.