-
Notifications
You must be signed in to change notification settings - Fork 6
/
regex_test.go
148 lines (144 loc) · 2.74 KB
/
regex_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
package karmabot
import (
"regexp"
"testing"
)
type regexTestSuite map[bool][]string
type regexPattern struct {
Regex *regexp.Regexp
Name string
}
var regexTests = map[regexPattern]regexTestSuite{
regexPattern{
Regex: karmaReg.GetGive(),
Name: "karma operations",
}: regexTestSuite{
true: []string{
"user++",
"user--",
"user+++++++",
"user-------",
"@user---",
"user+++ for reason",
"user--- because why not",
"user: ---- autocomplete test",
"user ++++ another autocomplete test",
"<@U147391>++++ slack formatting test",
"middle of the sentence--",
"middle of the sentence-- for karma reasons",
"middle of the sentence: ++++ for karma reasons",
},
false: []string{
"user+-",
"@user-+",
"middle of the sentence -- test",
"middle of the sentence ++",
"middle of the sentence ---- another test",
},
},
regexPattern{
Regex: karmaReg.GetQuery(),
Name: "print current karma points",
}: regexTestSuite{
true: []string{
"user==",
"@user==",
"<@U1384>==",
},
false: []string{
"user=",
"user===",
"@user=",
"@user===",
"middle of the sentence user==",
},
},
regexPattern{
Regex: karmaReg.GetMotivate(),
Name: "motivate.im",
}: regexTestSuite{
true: []string{
"!m user",
"?m user",
"?m <@U1384>",
},
false: []string{
"?m user for work",
"middle of the sentence ?m user",
"?muser",
"!!muser",
},
},
regexPattern{
Regex: regexps.Leaderboard,
Name: "leaderboard",
}: regexTestSuite{
true: []string{
"karma highscores",
"karmabot top 10",
"karmabot top 1001",
"karmabot top ",
},
false: []string{
"karmabot top 913f",
"karmabot karma highscores",
},
},
regexPattern{
Regex: regexps.SlackUser,
Name: "slack user",
}: regexTestSuite{
true: []string{
"<@U1934>",
"<@P1934>",
"<@whatever>",
},
false: []string{
"<@user",
"<user>",
"user>",
"<@>",
},
},
regexPattern{
Regex: regexps.URL,
Name: "karmabot web ui",
}: regexTestSuite{
true: []string{
"karmabot web",
"karma link",
"karmabot link",
},
false: []string{
"karmabot web 194",
},
},
regexPattern{
Regex: regexps.Throwback,
Name: "karmabot throwback",
}: regexTestSuite{
true: []string{
"karmabot throwback <@U3494519>",
"karmabot throwback <@B34839>",
"karmabot throwback @name",
"karmabot throwback user",
"karmabot throwback",
},
},
}
func TestRegexes(t *testing.T) {
for regex, suite := range regexTests {
for res, lines := range suite {
for _, line := range lines {
if regex.Regex.MatchString(line) != res {
t.Error(
`For regex "`, regex.Name,
`" and line "`, line,
`" expected [`, res,
`] got [`, !res, `]`,
)
}
}
}
}
}