UNPKG

16.3 kBJavaScriptView Raw
1var vows = require('vows'),
2 assert = require('assert'),
3 strategy = require('../lib/pathogen-decoder'),
4 suite = vows.describe('pathogen-decoder');
5
6suite.addBatch({
7 'when decoding a hash module group with module names of length 1': {
8 topic: function () {
9 return strategy.decode('/nobi/shizu+1xabcde.debug.js');
10 },
11 'module group is decoded as expected': function (decoded) {
12 var group = decoded.groups[0],
13 modules = group.modules;
14
15 assert.strictEqual(decoded.filter, 'debug', 'unexpected filter');
16 assert.strictEqual(decoded.type, 'js', 'unexpected type');
17 assert.strictEqual(decoded.groups.length, 1, 'unexpected number of groups');
18 assert.strictEqual(group.name, 'hash', 'unexpected group name');
19 assert.strictEqual(modules.length, 5, 'unexpected number of modules');
20 assert.strictEqual(group.version, 'nobi/shizu', 'unexpected version');
21
22 ['a', 'b', 'c', 'd', 'e'].forEach(function (name, index) {
23 assert.strictEqual(modules[index], name, 'unexpected module name');
24 });
25 }
26 }
27});
28
29suite.addBatch({
30 'when decoding a hash module group with module names of length 3': {
31 topic: function () {
32 return strategy.decode('/nobi/dora+3xaaabbbcccdddeee.js');
33 },
34 'module group is decoded as expected': function (decoded) {
35 var group = decoded.groups[0],
36 modules = group.modules;
37
38 assert.strictEqual(decoded.filter, 'min', 'unexpected filter');
39 assert.strictEqual(decoded.type, 'js', 'unexpected type');
40 assert.strictEqual(decoded.groups.length, 1, 'unexpected number of groups');
41 assert.strictEqual(group.name, 'hash', 'unexpected group name');
42 assert.strictEqual(modules.length, 5, 'unexpected number of modules');
43 assert.strictEqual(group.version, 'nobi/dora', 'unexpected version');
44
45 ['aaa', 'bbb', 'ccc', 'ddd', 'eee'].forEach(function (name, index) {
46 assert.strictEqual(modules[index], name, 'unexpected module name');
47 });
48 }
49 }
50});
51
52suite.addBatch({
53 'when decoding two hash module groups with module name lengths of 2 and 4': {
54 topic: function () {
55 return strategy.decode('/nobi/dora+4xaaaabbbbccccddddeeee;nobi/shizu+2x44dd00.raw.js');
56 },
57 'module groups are decoded as expected': function (decoded) {
58 var group,
59 modules;
60
61 assert.strictEqual(decoded.filter, 'raw', 'unexpected filter');
62 assert.strictEqual(decoded.type, 'js', 'unexpected type');
63 assert.strictEqual(decoded.groups.length, 2, 'unexpected number of groups');
64
65 group = decoded.groups[0];
66 modules = group.modules;
67
68 assert.strictEqual(group.name, 'hash', 'unexpected group name');
69 assert.strictEqual(modules.length, 5, 'unexpected number of modules');
70 assert.strictEqual(group.version, 'nobi/dora', 'unexpected version');
71
72 ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee'].forEach(function (name, index) {
73 assert.strictEqual(modules[index], name, 'unexpected module name');
74 });
75
76 group = decoded.groups[1];
77 modules = group.modules;
78
79 assert.strictEqual(group.name, 'hash', 'unexpected group name');
80 assert.strictEqual(modules.length, 3, 'unexpected number of modules');
81 assert.strictEqual(group.version, 'nobi/shizu', 'unexpected version');
82
83 ['44', 'dd', '00'].forEach(function (name, index) {
84 assert.strictEqual(modules[index], name, 'unexpected module name');
85 });
86 }
87 }
88});
89
90suite.addBatch({
91 'when decoding a hash module group with module names of length 0': {
92 topic: function () {
93 return strategy.decode('/0+nobi/dora+aaabbbcccdddeee.js');
94 },
95 'an error is returned': function (decoded) {
96 assert(decoded instanceof Error, 'expected an error');
97 }
98 },
99 'when decoding a hash module group with module names of negative length': {
100 topic: function () {
101 return strategy.decode('/-2+nobi/dora+aaabbbcccdddeee.js');
102 },
103 'an error is returned': function (decoded) {
104 assert(decoded instanceof Error, 'expected an error');
105 }
106 }
107});
108
109suite.addBatch({
110 'when decoding a core module group': {
111 topic: function () {
112 return strategy.decode('/core+3.14.0-rc-1+oop,node-base.debug.js');
113 },
114 'module group is decoded as expected': function (decoded) {
115 var group = decoded.groups[0];
116
117 assert.strictEqual(decoded.filter, 'debug', 'unexpected filter');
118 assert.strictEqual(decoded.type, 'js', 'unexpected type');
119 assert.strictEqual(decoded.groups.length, 1, 'unexpected number of groups');
120 assert.strictEqual(group.name, 'core', 'unexpected group name');
121 assert.strictEqual(group.modules.length, 2, 'unexpected number of modules');
122 assert.strictEqual(group.version, '3.14.0-rc-1', 'unexpected version');
123 }
124 }
125});
126
127suite.addBatch({
128 'when decoding a gallery module group': {
129 topic: function () {
130 return strategy.decode('/gallery+2013.09.04-21-56+pathogen-encoder.js');
131 },
132 'module group is decoded as expected': function (decoded) {
133 var group = decoded.groups[0];
134
135 assert.strictEqual(decoded.filter, 'min', 'unexpected filter');
136 assert.strictEqual(decoded.type, 'js', 'unexpected type');
137 assert.strictEqual(decoded.groups.length, 1, 'unexpected number of groups');
138 assert.strictEqual(group.name, 'gallery', 'unexpected group name');
139 assert.strictEqual(group.modules.length, 1, 'unexpected number of modules');
140 assert.strictEqual(group.version, 'gallery-2013.09.04-21-56', 'unexpected version');
141 }
142 }
143});
144
145suite.addBatch({
146 'when decoding a shifter module group': {
147 topic: function () {
148 return strategy.decode('/s+os/mit/td/ape-applet-0.0.35+ape-applet-templates-applet-remove,af-applet-removeview.js');
149 },
150 'module group is decoded as expected': function (decoded) {
151 var group = decoded.groups[0];
152
153 assert.strictEqual(decoded.filter, 'min', 'unexpected filter');
154 assert.strictEqual(decoded.type, 'js', 'unexpected type');
155 assert.strictEqual(decoded.groups.length, 1, 'unexpected number of groups');
156 assert.strictEqual(group.name, 'shifter', 'unexpected group name');
157 assert.strictEqual(group.modules.length, 2, 'unexpected number of modules');
158 assert.strictEqual(group.version, 'os/mit/td/ape-applet-0.0.35', 'unexpected version');
159 }
160 }
161});
162
163suite.addBatch({
164 'when decoding a relative path module group': {
165 topic: function () {
166 return strategy.decode('/os/mit/td/ape-applet-0.0.35+ape-applet-templates-applet-remove,af-applet-removeview.js');
167 },
168 'module group is decoded as expected': function (decoded) {
169 var group = decoded.groups[0];
170
171 assert.strictEqual(decoded.filter, 'min', 'unexpected filter');
172 assert.strictEqual(decoded.type, 'js', 'unexpected type');
173 assert.strictEqual(decoded.groups.length, 1, 'unexpected number of groups');
174 assert.strictEqual(group.name, undefined, 'unexpected group name');
175 assert.strictEqual(group.modules.length, 2, 'unexpected number of modules');
176 assert.strictEqual(group.version, 'os/mit/td/ape-applet-0.0.35', 'unexpected version');
177 }
178 }
179});
180
181suite.addBatch({
182 'when decoding a full path module group': {
183 topic: function () {
184 var path = [
185 'os/mit/td/ape-applet-0.0.35',
186 'os/mit/td/ape-applet-templates-applet-remove',
187 'os/mit/td/af-applet-removeview'
188 ].join(';');
189
190 return strategy.decode('/' + path + '.js');
191 },
192 'module groups are decoded as expected': function (decoded) {
193 assert.strictEqual(decoded.filter, 'min', 'unexpected filter');
194 assert.strictEqual(decoded.type, 'js', 'unexpected type');
195 assert.strictEqual(decoded.groups.length, 3, 'unexpected number of groups');
196 assert.strictEqual(decoded.groups[0].name, undefined, 'unexpected group name');
197 assert.strictEqual(decoded.groups[0].modules.length, 1, 'unexpected number of modules');
198 assert.strictEqual(decoded.groups[0].version, undefined, 'unexpected version');
199 assert.strictEqual(decoded.groups[1].name, undefined, 'unexpected group name');
200 assert.strictEqual(decoded.groups[1].modules.length, 1, 'unexpected number of modules');
201 assert.strictEqual(decoded.groups[1].version, undefined, 'unexpected version');
202 assert.strictEqual(decoded.groups[2].name, undefined, 'unexpected group name');
203 assert.strictEqual(decoded.groups[2].modules.length, 1, 'unexpected number of modules');
204 assert.strictEqual(decoded.groups[2].version, undefined, 'unexpected version');
205 }
206 }
207});
208
209suite.addBatch({
210 'when decoding a mixed module groups': {
211 topic: function () {
212 var path = [
213 'core+3.15.0+oop,get',
214 'gallery+2013.09.04-21-56+pathogen-encoder',
215 'os/mit/td/ape-applet-0.0.35+kamen,rider,os',
216 'kamen-rider/wizard',
217 'kamen-rider/fourze',
218 'kamen-rider-os'
219 ].join(';');
220
221 return strategy.decode('/' + path + '.js');
222 },
223 'module groups are decoded as expected': function (decoded) {
224 assert.strictEqual(decoded.filter, 'min', 'unexpected filter');
225 assert.strictEqual(decoded.type, 'js', 'unexpected type');
226 assert.strictEqual(decoded.groups.length, 6, 'unexpected number of groups');
227
228 assert.strictEqual(decoded.groups[0].name, 'core', 'unexpected group name');
229 assert.strictEqual(decoded.groups[0].modules.length, 2, 'unexpected number of modules');
230 assert.strictEqual(decoded.groups[0].version, '3.15.0', 'unexpected version');
231
232 assert.strictEqual(decoded.groups[1].name, 'gallery', 'unexpected group name');
233 assert.strictEqual(decoded.groups[1].modules.length, 1, 'unexpected number of modules');
234 assert.strictEqual(decoded.groups[1].version, 'gallery-2013.09.04-21-56', 'unexpected version');
235
236 assert.strictEqual(decoded.groups[2].name, undefined, 'unexpected group name');
237 assert.strictEqual(decoded.groups[2].modules.length, 3, 'unexpected number of modules');
238 assert.strictEqual(decoded.groups[2].version, 'os/mit/td/ape-applet-0.0.35', 'unexpected version');
239
240 assert.strictEqual(decoded.groups[3].name, undefined, 'unexpected group name');
241 assert.strictEqual(decoded.groups[3].modules.length, 1, 'unexpected number of modules');
242 assert.strictEqual(decoded.groups[3].version, undefined, 'unexpected version');
243
244 assert.strictEqual(decoded.groups[4].name, undefined, 'unexpected group name');
245 assert.strictEqual(decoded.groups[4].modules.length, 1, 'unexpected number of modules');
246 assert.strictEqual(decoded.groups[4].version, undefined, 'unexpected version');
247
248 assert.strictEqual(decoded.groups[5].name, undefined, 'unexpected group name');
249 assert.strictEqual(decoded.groups[5].modules.length, 1, 'unexpected number of modules');
250 assert.strictEqual(decoded.groups[5].version, undefined, 'unexpected version');
251 }
252 }
253});
254
255suite.addBatch({
256 'when decoding module groups with short names': {
257 topic: function () {
258 var path = [
259 'c+3.15.0+oop,get',
260 'g+2013.09.04-21-56+pathogen-encoder',
261 's+os/mit/td/ape-applet-0.0.35+kamen,rider,os'
262 ].join(';');
263
264 return strategy.decode('/' + path + '.debug.js');
265 },
266 'module group names should be expanded': function (decoded) {
267 assert.strictEqual(decoded.filter, 'debug', 'unexpected filter');
268 assert.strictEqual(decoded.type, 'js', 'unexpected type');
269 assert.strictEqual(decoded.groups.length, 3, 'unexpected number of groups');
270
271 assert.strictEqual(decoded.groups[0].name, 'core', 'unexpected group name');
272 assert.strictEqual(decoded.groups[0].modules.length, 2, 'unexpected number of modules');
273 assert.strictEqual(decoded.groups[0].version, '3.15.0', 'unexpected version');
274
275 assert.strictEqual(decoded.groups[1].name, 'gallery', 'unexpected group name');
276 assert.strictEqual(decoded.groups[1].modules.length, 1, 'unexpected number of modules');
277 assert.strictEqual(decoded.groups[1].version, 'gallery-2013.09.04-21-56', 'unexpected version');
278
279 assert.strictEqual(decoded.groups[2].name, 'shifter', 'unexpected group name');
280 assert.strictEqual(decoded.groups[2].modules.length, 3, 'unexpected number of modules');
281 assert.strictEqual(decoded.groups[2].version, 'os/mit/td/ape-applet-0.0.35', 'unexpected version');
282 }
283 }
284});
285
286suite.addBatch({
287 'when decoding a js asset with an invalid filter': {
288 topic: function () {
289 return strategy.decode('/c+3.15.0+yui.foo.js');
290 },
291 'decoded filter should default to `min`': function (decoded) {
292 assert.strictEqual(decoded.filter, 'min');
293 }
294 },
295 'when decoding a path with a valid `min` filter': {
296 topic: function () {
297 return strategy.decode('/c+3.15.0+yui.min.js');
298 },
299 'decoded filter should be `min`': function (decoded) {
300 assert.strictEqual(decoded.filter, 'min');
301 }
302 },
303 'when decoding a path with a valid `raw` filter': {
304 topic: function () {
305 return strategy.decode('/c+3.15.0+yui.raw.js');
306 },
307 'decoded filter should be `raw`': function (decoded) {
308 assert.strictEqual(decoded.filter, 'raw');
309 }
310 },
311 'when decoding a path with a valid `debug` filter': {
312 topic: function () {
313 return strategy.decode('/c+3.15.0+yui.debug.js');
314 },
315 'decoded filter should be `debug`': function (decoded) {
316 assert.strictEqual(decoded.filter, 'debug');
317 }
318 }
319});
320
321suite.addBatch({
322 'when decoding a css asset with an invalid filter': {
323 topic: function () {
324 return strategy.decode('/c+3.15.0+yui.bar.css');
325 },
326 'decoded filter should default to `min`': function (decoded) {
327 assert.strictEqual(decoded.filter, 'min');
328 }
329 },
330 'when decoding a path with a valid `min` filter': {
331 topic: function () {
332 return strategy.decode('/c+3.15.0+yui.min.css');
333 },
334 'decoded filter should be `min`': function (decoded) {
335 assert.strictEqual(decoded.filter, 'min');
336 }
337 },
338 'when decoding a path with a valid `raw` filter': {
339 topic: function () {
340 return strategy.decode('/c+3.15.0+yui.raw.css');
341 },
342 'decoded filter should be `raw`': function (decoded) {
343 assert.strictEqual(decoded.filter, 'raw');
344 }
345 }
346});
347
348suite.addBatch({
349 'when a module group has too many subgroups': {
350 topic: function () {
351 return strategy.decode('/c+3.15.0+yui+oops.css');
352 },
353 'an error should be returned': function (decoded) {
354 assert(decoded instanceof Error);
355 }
356 },
357 'when an invalid module group name is encountered': {
358 topic: function () {
359 return strategy.decode('/ny+jamaica/queens+ps131,jhs216,bronxscience.js');
360 },
361 'an error should be returned': function (decoded) {
362 assert(decoded instanceof Error);
363 }
364 }
365});
366
367suite.export(module);