1 | var vows = require('vows'),
|
2 | assert = require('assert'),
|
3 | yuiPath = require('../lib/yui-path'),
|
4 | suite = vows.describe('yui-path');
|
5 |
|
6 | suite.addBatch({
|
7 | 'given an invalid filter': {
|
8 | topic: function () {
|
9 | return yuiPath.format('3.12.0', 'shishi', 'tora', 'js');
|
10 | },
|
11 | 'the filter defaults to min': function (path) {
|
12 | assert.equal(path, '3.12.0/shishi/shishi-min.js');
|
13 | }
|
14 | },
|
15 | 'given a min filter': {
|
16 | topic: function () {
|
17 | return yuiPath.format('3.12.0', 'foo-bar', 'min', 'js');
|
18 | },
|
19 | 'the min filter is applied': function (path) {
|
20 | assert.equal(path, '3.12.0/foo-bar/foo-bar-min.js');
|
21 | }
|
22 | },
|
23 | 'given a raw filter': {
|
24 | topic: function () {
|
25 | return yuiPath.format('3.12.0', 'yui', 'raw', 'js');
|
26 | },
|
27 | 'the raw filter is applied': function (path) {
|
28 | assert.equal(path, '3.12.0/yui/yui.js');
|
29 | }
|
30 | },
|
31 | 'given a debug filter': {
|
32 | topic: function () {
|
33 | return yuiPath.format('3.12.0', 'foo-bar', 'debug', 'js');
|
34 | },
|
35 | 'the debug filter is applied': function (path) {
|
36 | assert.equal(path, '3.12.0/foo-bar/foo-bar-debug.js');
|
37 | }
|
38 | },
|
39 | 'given path components of a skin module': {
|
40 | topic: function () {
|
41 | return [
|
42 | yuiPath.format('3.12.0', 'skin-sam-bar-baz', 'min', 'css'),
|
43 | yuiPath.format('3.12.0', 'skin-sam-hoge_piyo', 'min', 'css'),
|
44 | yuiPath.format('3.12.0', 'skin-sam-hoge--hoge', 'min', 'css')
|
45 | ];
|
46 | },
|
47 | 'the paths are formatted as expected': function (paths) {
|
48 | assert.deepEqual(paths, [
|
49 | '3.12.0/bar-baz/assets/skins/sam/bar-baz.css',
|
50 | '3.12.0/hoge_piyo/assets/skins/sam/hoge_piyo.css',
|
51 | '3.12.0/hoge--hoge/assets/skins/sam/hoge--hoge.css'
|
52 | ]);
|
53 | }
|
54 | },
|
55 | 'given an invalid file type': {
|
56 | topic: function () {
|
57 | return yuiPath.format('3.12.0', 'foo', 'debug', 'html');
|
58 | },
|
59 | 'an error is returned': function (path) {
|
60 | assert(path instanceof Error);
|
61 | }
|
62 | },
|
63 | 'given path components of a lang pack': {
|
64 | topic: function () {
|
65 | return [
|
66 | yuiPath.format('3.12.0', 'lang/foo_sr-Latn-RS', 'min', 'js'),
|
67 | yuiPath.format('3.12.0', 'lang/foo_es-419', 'min', 'js'),
|
68 | yuiPath.format('3.12.0', 'lang/foo_de-CH-1996', 'min', 'js'),
|
69 | yuiPath.format('3.12.0', 'lang/foo_i-klingon', 'min', 'js'),
|
70 | yuiPath.format('3.12.0', 'lang/foo_x-fr-CH', 'min', 'js'),
|
71 | yuiPath.format('3.12.0', 'lang/foo_sgn-BE-FR', 'min', 'js'),
|
72 | yuiPath.format('3.12.0', 'lang/autocomplete-list', 'min', 'js'),
|
73 | yuiPath.format('3.12.0', 'lang/baz-bif_en', 'min', 'js'),
|
74 | yuiPath.format('3.12.0', 'lang/piyo-hoge-fuga_ja-JP', 'min', 'js'),
|
75 | yuiPath.format('3.12.0', 'lang/has_underscore_in_name_es', 'min', 'js'),
|
76 | yuiPath.format('3.12.0', 'lang/has_underscore_in_name', 'min', 'js'),
|
77 | yuiPath.format('3.12.0', 'lang/ni-hao_zh-Hans-CN', 'min', 'js')
|
78 | ];
|
79 | },
|
80 | 'the paths are formatted as expected': function (paths) {
|
81 | assert.deepEqual(paths, [
|
82 | '3.12.0/foo/lang/foo_sr-Latn-RS.js',
|
83 | '3.12.0/foo/lang/foo_es-419.js',
|
84 | '3.12.0/foo/lang/foo_de-CH-1996.js',
|
85 | '3.12.0/foo/lang/foo_i-klingon.js',
|
86 | '3.12.0/foo/lang/foo_x-fr-CH.js',
|
87 | '3.12.0/foo/lang/foo_sgn-BE-FR.js',
|
88 | '3.12.0/autocomplete-list/lang/autocomplete-list.js',
|
89 | '3.12.0/baz-bif/lang/baz-bif_en.js',
|
90 | '3.12.0/piyo-hoge-fuga/lang/piyo-hoge-fuga_ja-JP.js',
|
91 | '3.12.0/has_underscore_in_name/lang/has_underscore_in_name_es.js',
|
92 | '3.12.0/has_underscore_in_name/lang/has_underscore_in_name.js',
|
93 | '3.12.0/ni-hao/lang/ni-hao_zh-Hans-CN.js'
|
94 | ]);
|
95 | }
|
96 | },
|
97 | 'when missing a path component': {
|
98 | topic: function () {
|
99 | return [
|
100 | yuiPath.format(undefined, 'foo-bar', 'min', 'js'),
|
101 | yuiPath.format('3.12.0', undefined, 'min', 'js'),
|
102 | yuiPath.format('3.12.0', 'foo-bar', undefined, 'js'),
|
103 | yuiPath.format('3.12.0', 'foo-bar', 'min', undefined)
|
104 | ];
|
105 | },
|
106 | 'an error is returned': function (paths) {
|
107 | paths.forEach(function (path) {
|
108 | assert(path instanceof Error);
|
109 | });
|
110 | }
|
111 | }
|
112 | });
|
113 |
|
114 | suite.export(module);
|