forked from clockworksoul/mediawiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_test.go
More file actions
150 lines (136 loc) · 4.8 KB
/
Copy pathquery_test.go
File metadata and controls
150 lines (136 loc) · 4.8 KB
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
149
150
package mediawiki
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestResponsePageFullPageName(t *testing.T) {
cc := []struct {
Name string
Expected string
}{
{"Main page", "Main page"},
{"Main_page", "Main page"},
{"Talk:Main page", "Talk:Main page"},
{"YP:FOO", "YP:FOO"},
{"User:Mtitmus", "User:Mtitmus"},
{"User talk:Mtitmus", "User talk:Mtitmus"},
{"User_talk:Mtitmus", "User talk:Mtitmus"},
{"User_talk:Foo_bar", "User talk:Foo bar"},
}
for _, c := range cc {
p := QueryResponseQueryPage{Title: c.Name}
assert.Equal(t, c.Expected, p.FullPageName())
}
}
func TestResponsePagePageName(t *testing.T) {
cc := []struct {
Name string
Namespace Namespace
Expected string
}{
{"Main page", NamespaceMain, "Main page"},
{"Main_page", NamespaceMain, "Main page"},
{"Talk:Main page", NamespaceTalk, "Main page"},
{"YP:FOO", NamespaceMain, "YP:FOO"}, // In main namespace
{"User:Mtitmus", NamespaceUser, "Mtitmus"},
{"User talk:Mtitmus", NamespaceUserTalk, "Mtitmus"},
{"User_talk:Mtitmus", NamespaceUserTalk, "Mtitmus"},
{"User_talk:Foo_bar", NamespaceUserTalk, "Foo bar"},
{"User:Mtitmus/sandbox", NamespaceUser, "Mtitmus/sandbox"},
{"Help:Title/Foo/Bar", NamespaceHelp, "Title/Foo/Bar"},
}
for _, c := range cc {
p := QueryResponseQueryPage{Title: c.Name, Namespace: c.Namespace}
assert.Equal(t, c.Expected, p.PageName())
}
}
func TestResponsePageBasePageName(t *testing.T) {
cc := []struct {
Name string
Namespace Namespace
Expected string
}{
{"Main page", NamespaceMain, "Main page"},
{"Main_page", NamespaceMain, "Main page"},
{"Talk:Main page", NamespaceTalk, "Main page"},
{"YP:FOO", NamespaceMain, "YP:FOO"}, // In main namespace
{"User:Mtitmus", NamespaceUser, "Mtitmus"},
{"User talk:Mtitmus", NamespaceUserTalk, "Mtitmus"},
{"User_talk:Mtitmus", NamespaceUserTalk, "Mtitmus"},
{"User_talk:Foo_bar", NamespaceUserTalk, "Foo bar"},
{"User:Mtitmus/sandbox", NamespaceUser, "Mtitmus"},
{"Help:Title/Foo/Bar", NamespaceHelp, "Title/Foo"},
}
for _, c := range cc {
p := QueryResponseQueryPage{Title: c.Name, Namespace: c.Namespace}
assert.Equal(t, c.Expected, p.BasePageName())
}
}
func TestResponsePageRootPageName(t *testing.T) {
cc := []struct {
Name string
Namespace Namespace
Expected string
}{
{"Main page", NamespaceMain, "Main page"},
{"Main_page", NamespaceMain, "Main page"},
{"Talk:Main page", NamespaceTalk, "Main page"},
{"YP:FOO", NamespaceMain, "YP:FOO"}, // In main namespace
{"User:Mtitmus", NamespaceUser, "Mtitmus"},
{"User talk:Mtitmus", NamespaceUserTalk, "Mtitmus"},
{"User_talk:Mtitmus", NamespaceUserTalk, "Mtitmus"},
{"User_talk:Foo_bar", NamespaceUserTalk, "Foo bar"},
{"User:Mtitmus/sandbox", NamespaceUser, "Mtitmus"},
{"Help:Title/Foo/Bar", NamespaceHelp, "Title"},
}
for _, c := range cc {
p := QueryResponseQueryPage{Title: c.Name, Namespace: c.Namespace}
assert.Equal(t, c.Expected, p.RootPageName())
}
}
func TestResponsePageArticlePageName(t *testing.T) {
cc := []struct {
Name string
Namespace Namespace
Expected string
}{
{"Main page", NamespaceMain, "Main page"},
{"Main_page", NamespaceMain, "Main page"},
{"Talk:Main page", NamespaceTalk, "Main page"},
{"YP:FOO", NamespaceMain, "YP:FOO"}, // In main namespace
{"User:Mtitmus", NamespaceUser, "User:Mtitmus"},
{"User talk:Mtitmus", NamespaceUserTalk, "User:Mtitmus"},
{"User_talk:Mtitmus", NamespaceUserTalk, "User:Mtitmus"},
{"User_talk:Foo_bar", NamespaceUserTalk, "User:Foo bar"},
{"User:Mtitmus/sandbox", NamespaceUser, "User:Mtitmus/sandbox"},
{"Help:Title/Foo/Bar", NamespaceHelp, "Help:Title/Foo/Bar"},
{"Help talk:Title/Foo/Bar", NamespaceHelpTalk, "Help:Title/Foo/Bar"},
}
for _, c := range cc {
p := QueryResponseQueryPage{Title: c.Name, Namespace: c.Namespace}
assert.Equal(t, c.Expected, p.ArticlePageName())
}
}
func TestResponsePageTalkPageName(t *testing.T) {
cc := []struct {
Name string
Namespace Namespace
Expected string
}{
{"Main page", NamespaceMain, "Talk:Main page"},
{"Main_page", NamespaceMain, "Talk:Main page"},
{"Talk:Main page", NamespaceTalk, "Talk:Main page"},
{"YP:FOO", NamespaceMain, "Talk:YP:FOO"}, // In main namespace
{"User:Mtitmus", NamespaceUser, "User talk:Mtitmus"},
{"User talk:Mtitmus", NamespaceUserTalk, "User talk:Mtitmus"},
{"User_talk:Mtitmus", NamespaceUserTalk, "User talk:Mtitmus"},
{"User_talk:Foo_bar", NamespaceUserTalk, "User talk:Foo bar"},
{"User:Mtitmus/sandbox", NamespaceUser, "User talk:Mtitmus/sandbox"},
{"Help:Title/Foo/Bar", NamespaceHelp, "Help talk:Title/Foo/Bar"},
{"Help talk:Title/Foo/Bar", NamespaceHelpTalk, "Help talk:Title/Foo/Bar"},
}
for _, c := range cc {
p := QueryResponseQueryPage{Title: c.Name, Namespace: c.Namespace}
assert.Equal(t, c.Expected, p.TalkPageName())
}
}