-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdoc_test.go
90 lines (87 loc) · 2.01 KB
/
doc_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
package main
import "testing"
func TestParseQuery(t *testing.T) {
cases := []struct {
name string
query string
module string
parts []string
}{
{
name: "stdlib basic",
query: "strings",
module: "strings",
parts: nil,
},
{
name: "stdlib type",
query: "strings.Split",
module: "strings",
parts: []string{"split"},
},
{
name: "stdlib method",
query: "strings.Builder.Grow",
module: "strings",
parts: []string{"builder", "grow"},
},
{
name: "stdlib redirect basic",
query: "json",
module: "encoding/json",
parts: nil,
},
{
name: "stdlib redirect type",
query: "json.Unmarshal",
module: "encoding/json",
parts: []string{"unmarshal"},
},
{
name: "stdlib redirect method",
query: "json.NewDecoder.Decode",
module: "encoding/json",
parts: []string{"newdecoder", "decode"},
},
{
name: "custom basic",
query: "github.com/golang/go",
module: "github.com/golang/go",
parts: nil,
},
{
name: "custom type",
query: "github.com/bwmarrin/discordgo.Session",
module: "github.com/bwmarrin/discordgo",
parts: []string{"session"},
},
{
name: "custom method",
query: "github.com/bwmarrin/discordgo.Session.AddHandler",
module: "github.com/bwmarrin/discordgo",
parts: []string{"session", "addhandler"},
},
{
name: "custom method with space",
query: "github.com/bwmarrin/discordgo Session AddHandler",
module: "github.com/bwmarrin/discordgo",
parts: []string{"session", "addhandler"},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
module, parts := parseQuery(c.query)
if module != c.module {
t.Errorf("INVALID MODULE:\nGOT:%s\nEXPECTED:%s", module, c.module)
}
if len(parts) != len(c.parts) {
t.Errorf("INVALID PARTS:\nGOT:%v\nEXPECTED:%v", parts, c.parts)
}
for i, part := range parts {
if part != c.parts[i] {
t.Errorf("INVALID PARTS(%d):\nGOT:%v\nEXPECTED:%v", i, part, c.parts[i])
}
}
})
}
}