1 | package suika
|
---|
2 |
|
---|
3 | import (
|
---|
4 | "testing"
|
---|
5 | )
|
---|
6 |
|
---|
7 | func TestIsHighlight(t *testing.T) {
|
---|
8 | nick := "SojuUser"
|
---|
9 | testCases := []struct {
|
---|
10 | name string
|
---|
11 | text string
|
---|
12 | hl bool
|
---|
13 | }{
|
---|
14 | {"noContains", "hi there Soju User!", false},
|
---|
15 | {"middle", "hi there SojuUser!", true},
|
---|
16 | {"start", "SojuUser: how are you doing?", true},
|
---|
17 | {"end", "maybe ask SojuUser", true},
|
---|
18 | {"inWord", "but OtherSojuUserSan is a different nick", false},
|
---|
19 | {"startWord", "and OtherSojuUser is another different nick", false},
|
---|
20 | {"endWord", "and SojuUserSan is yet a different nick", false},
|
---|
21 | {"underscore", "and SojuUser_san has nothing to do with me", false},
|
---|
22 | {"zeroWidthSpace", "writing S\u200BojuUser shouldn't trigger a highlight", false},
|
---|
23 | }
|
---|
24 |
|
---|
25 | for _, tc := range testCases {
|
---|
26 | tc := tc // capture range variable
|
---|
27 | t.Run(tc.name, func(t *testing.T) {
|
---|
28 | hl := isHighlight(tc.text, nick)
|
---|
29 | if hl != tc.hl {
|
---|
30 | t.Errorf("isHighlight(%q, %q) = %v, but want %v", tc.text, nick, hl, tc.hl)
|
---|
31 | }
|
---|
32 | })
|
---|
33 | }
|
---|
34 | }
|
---|