-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
executable file
·138 lines (125 loc) · 2.61 KB
/
message_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
package ircbot
import (
"testing"
)
var parseLineTestTable = []struct {
input string
expect *IrcMsg
}{
{
":weber.freenode.net NOTICE * :*** Looking up your hostname... ",
&IrcMsg{
Prefix: "weber.freenode.net",
Command: "NOTICE",
CmdParams: []string{"*"},
Trailing: []string{"***", "Looking", "up", "your", "hostname..."},
},
},
{
":zbitest MODE zbitest :+i ",
&IrcMsg{
Prefix: "zbitest",
Command: "MODE",
CmdParams: []string{"zbitest"},
Trailing: []string{"+i"},
},
},
{
":[email protected] PRIVMSG #zbitest :.h",
&IrcMsg{
Prefix: "[email protected]",
Command: "PRIVMSG",
CmdParams: []string{"#zbitest"},
Trailing: []string{".h"},
},
},
{
":[email protected] JOIN #zbitest",
&IrcMsg{
Prefix: "[email protected]",
Command: "JOIN",
CmdParams: []string{"#zbitest"},
Trailing: []string{""},
},
},
}
func TestParseLine(t *testing.T) {
for _, tt := range parseLineTestTable {
actual := &IrcMsg{}
actual.parseline(tt.input)
if !equal(actual, tt.expect) {
t.Errorf("\ninput %s\nexpected %+v\nactual %+v\n", tt.input, tt.expect, actual)
}
}
}
var nickTestTable = []struct {
input string
expect string
}{
{
":weber.freenode.net NOTICE * :*** Looking up your hostname... ",
"",
},
{
":zbitest MODE zbitest :+i ",
"",
},
{
":[email protected] PRIVMSG #zbitest :.h",
"Zaibon",
},
}
func TestNick(t *testing.T) {
for _, tt := range nickTestTable {
actual := &IrcMsg{}
actual.parseline(tt.input)
if actual.Nick() != tt.expect {
t.Errorf("\ninput %s\nexpected %+v\nactual %+v\n", tt.input, tt.expect, actual.Nick())
}
}
}
var channelTestTable = []struct {
input string
expect string
}{
{
":weber.freenode.net NOTICE * :*** Looking up your hostname... ",
"*",
},
{
":zbitest MODE zbitest :+i ",
"zbitest",
},
{
":[email protected] PRIVMSG #zbitest :.h",
"#zbitest",
},
}
func TestChannel(t *testing.T) {
for _, tt := range channelTestTable {
actual := &IrcMsg{}
actual.parseline(tt.input)
if actual.Channel() != tt.expect {
t.Errorf("\ninput %s\nexpected %+v\nactual %+v\n", tt.input, tt.expect, actual.Channel())
}
}
}
func equal(m1, m2 *IrcMsg) bool {
if m1.Prefix != m2.Prefix {
return false
}
if m1.Command != m2.Command {
return false
}
for i := range m1.CmdParams {
if m1.CmdParams[i] != m2.CmdParams[i] {
return false
}
}
for i := range m1.Trailing {
if m1.Trailing[i] != m2.Trailing[i] {
return false
}
}
return true
}