-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
62 lines (57 loc) · 878 Bytes
/
main_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
package main
import (
"goirc/bot"
"strings"
"testing"
)
func TestMain(t *testing.T) {
var b bot.Bot
addHandlers(&b)
for _, tc := range []struct {
message string
want []string
}{
{
"69",
[]string{"Nice"},
},
{
"691",
nil,
},
{
"169",
nil,
},
{
"69.",
[]string{"Nice"},
},
{
"69th",
[]string{"Nice"},
},
{
"x69",
nil,
},
} {
t.Run(tc.message, func(t *testing.T) {
var got []string
for _, handler := range b.Handlers {
matches := handler.Regexp().FindStringSubmatch(tc.message)
if len(matches) > 0 {
got = append(got, strings.Fields(handler.String())[1])
}
}
if len(tc.want) != len(got) {
t.Fatalf("wanted %v, got %v", tc.want, got)
}
for i := range tc.want {
if tc.want[i] != got[i] {
t.Fatalf("wanted %v, got %v", tc.want, got)
}
}
})
}
}