-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
206 lines (178 loc) · 6.15 KB
/
main_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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package main
import (
"regexp"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_parse_toc_filename(t *testing.T) {
cases := map[string][]string{
"Foo.toc": {"Foo", ""},
"Foo-mainline.toc": {"Foo", MainlineFlavor},
"Foo_mainline.toc": {"Foo", MainlineFlavor},
//"Foo.mainline.toc": {"Foo", MainlineFlavor}, // todo: this *should* work
"Foo-classic.toc": {"Foo", VanillaFlavor},
"Foo-bcc.toc": {"Foo", TBCFlavor},
"Foo-wrath.toc": {"Foo", WrathFlavor},
"Foo-cata.toc": {"Foo", CataFlavor},
"Foo-1.0.toc": {"Foo-1.0", ""},
"Foo-1.0-mainline.toc": {"Foo-1.0", MainlineFlavor},
"Foo-1.0_mainline.toc": {"Foo-1.0", MainlineFlavor},
//"Foo-1.0.mainline.toc": {"Foo-1.0", MainlineFlavor}, // todo: this *should* work
"Foo-1.0-classic.toc": {"Foo-1.0", VanillaFlavor},
"Foo-1.0-vanilla.toc": {"Foo-1.0", VanillaFlavor},
"Array_Vanilla.toc": {"Array", VanillaFlavor},
"Foo-1.0-bcc.toc": {"Foo-1.0", TBCFlavor},
"Foo-1.0-tbc.toc": {"Foo-1.0", TBCFlavor},
"Foo-1.0-wrath.toc": {"Foo-1.0", WrathFlavor},
"Foo-1.0-wotlk.toc": {"Foo-1.0", WrathFlavor},
"Foo-1.0-wotlkc.toc": {"Foo-1.0", WrathFlavor},
"Foo-1.0-cata.toc": {"Foo-1.0", CataFlavor},
// bit of an edgecase, filename has a space in it.
"Loot-A-Rang Matic Reforged.toc": {"Loot-A-Rang Matic Reforged", ""},
}
for given, expected := range cases {
actual_filename, actual_flavor := parse_toc_filename(given)
expected_filename, expected_flavor := expected[0], expected[1]
assert.Equal(t, expected_filename, actual_filename)
assert.Equal(t, expected_flavor, actual_flavor)
}
}
func Test_is_toc_file(t *testing.T) {
cases := map[string]bool{
"": false,
"-_!@#$%^&*(": false, // gibberish
"Foo": false, // top level file
"Foo/Bar": false, // no '.toc'
"Foo/Bar.toc": false, // 'Foo' must match 'Bar'
"Foo/Foo/Foo.toc": false, // nested
"Foo/foo.toc": true, // 'Foo' matches 'foo' ignoring case.
"Foo/fOo.toc": true, // 'Foo' matches 'fOo' ignoring case.
"Foo/Foo.toc": true,
"Foo/Foo-wrath.toc": true,
"Foo/Foo_wrath.toc": true,
"Foo-1.0/Foo-1.0.toc": true,
"Foo-1.0/Foo-1.0-cata.toc": true,
"Foo-1.0/Foo-1.0_cata.toc": true,
// case insensitive
"Foo/Foo-WRATH.toc": true,
"Foo/Foo-WrAtH.ToC": true,
// addon name contain itself contains a game track (Classic)
"JadeUI-Classic/JadeUI-Classic.toc": true,
"JadeUI-Vanilla/JadeUI-Vanilla.toc": true,
"JadeUI-Vanilla/JadeUI-Classic.toc": true, // works because flavors coerced from aliases
// space in name
"Loot-A-Rang Matic Reforged/Loot-A-Rang Matic Reforged.toc": true,
// apostrophe
"Ranoth's utility/Ranoth's utility.toc": true,
"RanothsUtility-v1.3.19/Ranoth's utility.toc": false, // version information in folder name.
// exclamation mark
"!!!GarbageProtector/!!!GarbageProtector-Mainline.toc": true,
}
for given, expected := range cases {
assert.Equal(t, expected, is_toc_file(given), given)
}
}
func Test_is_excluded(t *testing.T) {
cases := map[string]bool{
"": false, // matches nothing
"foo": false,
"foo/": true, // matches 'foo/'
"foo/bar": true, // matches 'foo/'
"foo/barbaz": true, // matches 'foo/'
}
blacklist := map[string]bool{
"foo/": true,
}
var filter *regexp.Regexp
for repo_fullname, expected := range cases {
_, actual := is_excluded(blacklist, filter, repo_fullname)
assert.Equal(t, expected, actual)
}
}
func Test_title_case(t *testing.T) {
cases := map[string]string{
"": "",
"title case": "Title Case",
"Title case": "Title Case",
"Title Case": "Title Case",
"title-case": "Title-Case",
"title_case": "Title_case",
"TITLE CASE": "Title Case",
}
for given, expected := range cases {
assert.Equal(t, expected, title_case(given))
}
}
func Test_interface_number_to_flavor(t *testing.T) {
cases := map[string]Flavor{
"10000": VanillaFlavor,
"13000": VanillaFlavor,
"20000": TBCFlavor,
"20500": TBCFlavor,
"30000": WrathFlavor,
"30400": WrathFlavor,
"30403": WrathFlavor,
"40000": CataFlavor,
"40400": CataFlavor,
"50000": MainlineFlavor,
"100206": MainlineFlavor,
"110000": MainlineFlavor,
//"120000": "",
// whitespace is ignored
" 100206 ": MainlineFlavor,
}
for interface_number, expected := range cases {
actual, err := interface_number_to_flavor(interface_number)
assert.Nil(t, err)
assert.Equal(t, expected, actual)
}
}
func Test_interface_value_to_flavor_list(t *testing.T) {
cases := map[string][]Flavor{
"10000": {VanillaFlavor},
"20000": {TBCFlavor},
"30000": {WrathFlavor},
"40000": {CataFlavor},
"50000": {MainlineFlavor},
"110000": {MainlineFlavor},
"10000, 20000": {VanillaFlavor, TBCFlavor},
"10000, 20000, 30000": {VanillaFlavor, TBCFlavor, WrathFlavor},
"10000, 20000, 30000, 40000": {VanillaFlavor, TBCFlavor, WrathFlavor, CataFlavor},
// from the wiki
"100206, 40400, 11502": {MainlineFlavor, CataFlavor, VanillaFlavor},
// whitespace is ignored
" 100206 ": {MainlineFlavor},
}
for interface_number, expected := range cases {
actual, err := interface_value_to_flavor_list(interface_number)
assert.Nil(t, err)
assert.Equal(t, expected, actual)
}
}
func Test_interface_value_to_flavor_list__bad_cases(t *testing.T) {
cases := []string{
"", // empty
"120000", // outside known range
"100206, ", // trailing comma
}
for _, given := range cases {
_, err := interface_value_to_flavor_list(given)
assert.NotNil(t, err)
}
}
func Test_guess_game_track(t *testing.T) {
cases := map[string][]string{
"": {"", ""},
"foo": {"", ""},
"classic": {"classic", VanillaFlavor},
"vanilla": {"vanilla", VanillaFlavor},
"fooclassicbar": {"classic", VanillaFlavor},
"foovanillabar": {"vanilla", VanillaFlavor},
}
for given, expected := range cases {
expected_match, expected_flavor := expected[0], expected[1]
actual_match, actual_flavor := guess_game_track(given)
assert.Equal(t, expected_match, actual_match)
assert.Equal(t, expected_flavor, actual_flavor)
}
}