forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinvites_test.go
45 lines (38 loc) · 1.03 KB
/
invites_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
package common
import (
"testing"
)
func TestDiscordInviteRegex(t *testing.T) {
testcases := []struct {
input string
inviteID string
}{
{input: "https://discordapp.com/invite/FPxNX2", inviteID: "FPxNX2"},
{input: "discordapp.com/developers/docs/reference#message-formatting", inviteID: ""},
{input: "https://discord.gg/FPxNX2", inviteID: "FPxNX2"},
{input: "https://discord.gg/landfall", inviteID: "landfall"},
{input: "HElllo there", inviteID: ""},
{input: "Jajajaj", inviteID: ""},
}
for _, v := range testcases {
t.Run("Case "+v.input, func(t *testing.T) {
matches := DiscordInviteSource.Regex.FindAllStringSubmatch(v.input, -1)
if len(matches) < 1 && v.inviteID != "" {
t.Error("No matches")
}
if len(matches) < 1 {
return
}
if len(matches[0]) < 2 {
if v.inviteID != "" {
t.Error("ID Not found!")
}
return
}
id := matches[0][2]
if id != v.inviteID {
t.Errorf("Found ID %q, expected %q", id, v.inviteID)
}
})
}
}