-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathirc_test.go
40 lines (37 loc) · 1.3 KB
/
irc_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
package soju
import (
"testing"
)
func TestIsHighlight(t *testing.T) {
nick := "SojuUser"
testCases := []struct {
name string
text string
hl bool
}{
{"noContains", "hi there Soju User!", false},
{"standalone", "SojuUser", true},
{"middle", "hi there SojuUser!", true},
{"start", "SojuUser: how are you doing?", true},
{"end", "maybe ask SojuUser", true},
{"inWord", "but OtherSojuUserSan is a different nick", false},
{"startWord", "and OtherSojuUser is another different nick", false},
{"endWord", "and SojuUserSan is yet a different nick", false},
{"underscore", "and SojuUser_san has nothing to do with me", false},
{"zeroWidthSpace", "writing S\u200BojuUser shouldn't trigger a highlight", false},
{"url", "https://SojuUser.example", false},
{"startURL", "https://SojuUser.example is a nice website", false},
{"endURL", "check out my website: https://SojuUser.example", false},
{"parenthesizedURL", "see my website (https://SojuUser.example)", false},
{"afterURL", "see https://SojuUser.example (cc SojuUser)", true},
}
for _, tc := range testCases {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
hl := isHighlight(tc.text, nick)
if hl != tc.hl {
t.Errorf("isHighlight(%q, %q) = %v, but want %v", tc.text, nick, hl, tc.hl)
}
})
}
}