1 |
|
2 | 'use strict';
|
3 |
|
4 | var assert = require('chai').assert,
|
5 | BEM = require('..'),
|
6 | U = BEM.require('./util'),
|
7 | PATH = BEM.require('./path');
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | describe('util', function() {
|
21 |
|
22 | var bemLib = process.env.COVER? 'bem/lib-cov/' : 'bem/lib/';
|
23 |
|
24 | describe('getBemTechPath()', function() {
|
25 |
|
26 | it("'css' resolves to 'bem/lib/techs/css'", function() {
|
27 | assert.equal(U.getBemTechPath('css'), PATH.unixToOs(bemLib + 'techs/css.js'));
|
28 | });
|
29 |
|
30 | it("'css' resolves to 'bem/lib/techs/v2/css' when opts.version === 2", function () {
|
31 | assert.equal(U.getBemTechPath('css', {version: 2}),
|
32 | PATH.unixToOs(bemLib + 'techs/v2/css.js'));
|
33 | });
|
34 |
|
35 | it("'level-proto' resolves to 'bem/lib/techs/v2/level-proto.js'", function () {
|
36 | assert.equal(U.getBemTechPath('level-proto'),
|
37 | PATH.unixToOs(bemLib + 'techs/v2/level-proto.js'));
|
38 | });
|
39 |
|
40 | it("'custom' resolves to 'bem/lib/tech'", function() {
|
41 | assert.equal(U.getBemTechPath('custom'), PATH.unixToOs(bemLib + 'tech'));
|
42 | });
|
43 |
|
44 | it("throws an error when unable to resolve tech and throwWhenUnresolved===true", function() {
|
45 | assert.throws(function() {
|
46 | U.getBemTechPath('custom', {throwWhenUnresolved: true});
|
47 | });
|
48 | });
|
49 |
|
50 | });
|
51 |
|
52 | describe('isRequireable()', function() {
|
53 |
|
54 | it("'path' returns true", function() {
|
55 | assert.isTrue(U.isRequireable('path'));
|
56 | });
|
57 |
|
58 | it("'unexistent-module' returns false", function() {
|
59 | assert.isFalse(U.isRequireable('unexistent-module'));
|
60 | });
|
61 |
|
62 | });
|
63 |
|
64 | describe('isPath()', function() {
|
65 |
|
66 | it("'/path/to/file' returns true", function() {
|
67 | assert.isTrue(U.isPath(PATH.unixToOs('/path/to/file')));
|
68 | });
|
69 |
|
70 | it("'./path/to/file' returns true", function() {
|
71 | assert.isTrue(U.isPath('.' + PATH.unixToOs('/path/to/file')));
|
72 | });
|
73 |
|
74 | it("'path/to/file' returns true", function() {
|
75 | assert.isTrue(U.isPath(PATH.unixToOs('path/to/file')));
|
76 | });
|
77 |
|
78 | it("'file' returns false", function() {
|
79 | assert.isFalse(U.isPath('file'));
|
80 | });
|
81 |
|
82 | it("'file.ext' returns false", function() {
|
83 | assert.isFalse(U.isPath('file.ext'));
|
84 | });
|
85 |
|
86 | });
|
87 |
|
88 | describe('bemParseKey()', function() {
|
89 |
|
90 | it('block', function() {
|
91 | assert.deepEqual(U.bemParseKey('block'), { block: 'block' });
|
92 | });
|
93 |
|
94 | it('block_mod', function() {
|
95 | assert.deepEqual(U.bemParseKey('block_mod'), { block: 'block', mod: 'mod' });
|
96 | });
|
97 |
|
98 | it('block_mod_val', function() {
|
99 | assert.deepEqual(U.bemParseKey('block_mod_val'), {
|
100 | block: 'block',
|
101 | mod: 'mod',
|
102 | val: 'val'
|
103 | });
|
104 | });
|
105 |
|
106 | it('block__elem', function() {
|
107 | assert.deepEqual(U.bemParseKey('block__elem'), { block: 'block', elem: 'elem' });
|
108 | });
|
109 |
|
110 | it('block__elem_mod', function() {
|
111 | assert.deepEqual(U.bemParseKey('block__elem_mod'), {
|
112 | block: 'block',
|
113 | elem: 'elem',
|
114 | mod: 'mod'
|
115 | });
|
116 | });
|
117 |
|
118 | it('block__elem_mod_val', function() {
|
119 | assert.deepEqual(U.bemParseKey('block__elem_mod_val'), {
|
120 | block: 'block',
|
121 | elem: 'elem',
|
122 | mod: 'mod',
|
123 | val: 'val'
|
124 | });
|
125 | });
|
126 |
|
127 | it('block.css', function() {
|
128 | assert.deepEqual(U.bemParseKey('block.css'), { block: 'block', tech: 'css' });
|
129 | });
|
130 |
|
131 | it('block.decl.js', function() {
|
132 | assert.deepEqual(U.bemParseKey('block.decl.js'), { block: 'block', tech: 'decl.js' });
|
133 | });
|
134 |
|
135 | it('block_mod.css', function() {
|
136 | assert.deepEqual(U.bemParseKey('block_mod.css'), {
|
137 | block: 'block',
|
138 | mod: 'mod',
|
139 | tech: 'css'
|
140 | });
|
141 | });
|
142 |
|
143 | it('block_mod_val.css', function() {
|
144 | assert.deepEqual(U.bemParseKey('block_mod_val.css'), {
|
145 | block: 'block',
|
146 | mod: 'mod',
|
147 | val: 'val',
|
148 | tech: 'css'
|
149 | });
|
150 | });
|
151 |
|
152 | it('block__elem.css', function() {
|
153 | assert.deepEqual(U.bemParseKey('block__elem.css'), {
|
154 | block: 'block',
|
155 | elem: 'elem',
|
156 | tech: 'css'
|
157 | });
|
158 | });
|
159 |
|
160 | it('block__elem_mod.css', function() {
|
161 | assert.deepEqual(U.bemParseKey('block__elem_mod.css'), {
|
162 | block: 'block',
|
163 | elem: 'elem',
|
164 | mod: 'mod',
|
165 | tech: 'css'
|
166 | });
|
167 | });
|
168 |
|
169 | it('block__elem_mod_val.css', function() {
|
170 | assert.deepEqual(U.bemParseKey('block__elem_mod_val.css'), {
|
171 | block: 'block',
|
172 | elem: 'elem',
|
173 | mod: 'mod',
|
174 | val: 'val',
|
175 | tech: 'css'
|
176 | });
|
177 | });
|
178 |
|
179 | });
|
180 |
|
181 | });
|