Skip to content

Commit 4b5382d

Browse files
committed
Tests: Divide parsing and sorting tests
1 parent 473f019 commit 4b5382d

4 files changed

Lines changed: 626 additions & 598 deletions

File tree

test/less.js

Lines changed: 79 additions & 288 deletions
Original file line numberDiff line numberDiff line change
@@ -16,316 +16,107 @@ describe('LESS', function() {
1616
assert.equal(comb.processString(input, 'less'), expected);
1717
});
1818

19-
describe('Parsing', function() {
20-
it('Should parse nested rules', function() {
21-
config = { 'sort-order': [
22-
['top', 'color']
23-
] };
19+
it('Should parse nested rules', function() {
20+
config = { 'sort-order': [
21+
['top', 'color']
22+
] };
2423

25-
input = 'div { color: tomato; a { top: 0; } }';
24+
input = 'div { color: tomato; a { top: 0; } }';
2625

27-
expected = 'div { color: tomato; a { top: 0; } }';
28-
});
29-
30-
it('Should parse operations', function() {
31-
config = {};
32-
33-
input = 'div {\n' +
34-
' @base: 5%;\n' +
35-
' @filler: @base * 2;\n' +
36-
' @other: @base + @filler;\n' +
37-
' color: #888 / 4;\n' +
38-
' background-color: @base-color + #111;\n' +
39-
' height: 100% / 2 + @filler;\n' +
40-
' }';
41-
42-
expected = 'div {\n' +
43-
' @base: 5%;\n' +
44-
' @filler: @base * 2;\n' +
45-
' @other: @base + @filler;\n' +
46-
' color: #888 / 4;\n' +
47-
' background-color: @base-color + #111;\n' +
48-
' height: 100% / 2 + @filler;\n' +
49-
' }';
50-
});
51-
52-
it('Should parse parent selector &', function() {
53-
config = { 'sort-order': [
54-
['top', 'left', 'color']
55-
] };
56-
57-
input = 'div { color: tomato; &.top { color: nani; top: 0; } left: 0; }';
58-
59-
expected = 'div { left: 0; color: tomato; &.top {top: 0; color: nani; }}';
60-
});
61-
62-
it('Should parse variables', function() {
63-
config = {};
64-
65-
input = '@red: tomato; div { color: @tomato; top: @@foo; }';
66-
67-
expected = '@red: tomato; div { color: @tomato; top: @@foo; }';
68-
});
69-
70-
it('Should parse interpolated variables inside selectors', function() {
71-
config = { 'sort-order': [
72-
['top', 'left', 'color']
73-
] };
74-
75-
input = 'div.@{nani} {color:tomato;top:0;}';
76-
77-
expected = 'div.@{nani} {top:0;color:tomato;}';
78-
});
79-
80-
it('Should parse interpolated variables inside values', function() {
81-
config = { 'sort-order': [
82-
['top', 'left', 'color']
83-
] };
84-
85-
input = 'div {color:@{tomato};top:0;}';
86-
87-
expected = 'div {top:0;color:@{tomato};}';
88-
});
89-
90-
it('Should parse @import', function() {
91-
config = {};
92-
93-
input = 'div { @import "foo.css"; top: 0; }';
94-
95-
expected = 'div { @import "foo.css"; top: 0; }';
96-
});
97-
98-
it('Should parse included mixins', function() {
99-
config = {};
100-
101-
input = 'div { .mixin; top: 0; }';
102-
103-
expected = 'div { .mixin; top: 0; }';
104-
});
105-
106-
it('Should parse nested @media', function() {
107-
config = {};
108-
109-
input = 'div {\n' +
110-
' @media screen and (orientation: landscape) {\n' +
111-
' color: tomato;\n' +
112-
' }\n' +
113-
' top: 0;\n' +
114-
'}';
115-
116-
expected = 'div {\n' +
117-
' @media screen and (orientation: landscape) {\n' +
118-
' color: tomato;\n' +
119-
' }\n' +
120-
' top: 0;\n' +
121-
'}';
122-
});
26+
expected = 'div { color: tomato; a { top: 0; } }';
12327
});
12428

125-
describe('Sorting', function() {
126-
it('Should sort properties inside rules', function() {
127-
config = { 'sort-order': [
128-
['top', 'color']
129-
] };
130-
131-
input = 'div { color: tomato; top: 0; }';
132-
133-
expected = 'div {top: 0; color: tomato; }';
134-
});
135-
136-
it('Should sort properties inside nested rules', function() {
137-
config = { 'sort-order': [
138-
['top', 'color']
139-
] };
140-
141-
input = 'div { color: tomato; a { color: nani; top: 0; } }';
142-
143-
expected = 'div { color: tomato; a {top: 0; color: nani; } }';
144-
});
145-
146-
it('Should sort properties divided by nested rules', function() {
147-
config = { 'sort-order': [
148-
['top', 'left', 'color']
149-
] };
150-
151-
input = 'div { color: tomato; a { color: nani; top: 0; } left: 0; }';
152-
153-
expected = 'div { left: 0; color: tomato; a {top: 0; color: nani; }}';
154-
});
155-
156-
it('Should group declarations with proper comments and spaces (single line)', function() {
157-
config = { 'sort-order': [
158-
['top', 'color']
159-
] };
160-
161-
input = 'div {/* 1 */ color: tomato; /* 2 */ top: 0; /* 3 */ /* 4 */}';
162-
163-
expected = 'div {top: 0; /* 3 */ /* 4 *//* 1 */ color: tomato; /* 2 */ }';
164-
});
165-
166-
it('Should group declarations with proper comments and spaces (multiple lines). Test 1', function() {
167-
config = { 'sort-order': [
168-
['top', 'color']
169-
] };
170-
171-
input = 'div {\n' +
172-
' color: tomato; /* 1 */\n' +
173-
' /* 2 */\n' +
174-
' /* 3 */\n' +
175-
' top: 0; /* 4 */\n' +
176-
' /* 5 */\n' +
177-
'}';
178-
179-
expected = 'div {\n' +
180-
' /* 2 */\n' +
181-
' /* 3 */\n' +
182-
' top: 0; /* 4 */\n' +
183-
' color: tomato; /* 1 */\n' +
184-
' /* 5 */\n' +
185-
'}';
186-
});
187-
188-
it('Should group declarations with proper comments and spaces (multiple lines). Test 2', function() {
189-
config = { 'sort-order': [
190-
['$variable', 'color']
191-
] };
192-
193-
input = 'p {\n' +
194-
' /* One hell of a comment */\n' +
195-
' color: tomato;\n' +
196-
' // Get in line!\n' +
197-
' @var: white;\n' +
198-
' }';
199-
200-
expected = 'p {\n' +
201-
' // Get in line!\n' +
202-
' @var: white;\n' +
203-
' /* One hell of a comment */\n' +
204-
' color: tomato;\n' +
205-
' }';
206-
});
207-
208-
it('Should group declarations with proper comments and spaces (multiple lines). Test 3', function() {
209-
config = { 'sort-order': [
210-
['$variable', 'color']
211-
] };
212-
213-
input = 'p {\n' +
214-
' color: tomato; /* One hell of a comment */\n' +
215-
' @var: white; // Get in line!\n' +
216-
' }';
29+
it('Should parse operations', function() {
30+
config = {};
31+
32+
input = 'div {\n' +
33+
' @base: 5%;\n' +
34+
' @filler: @base * 2;\n' +
35+
' @other: @base + @filler;\n' +
36+
' color: #888 / 4;\n' +
37+
' background-color: @base-color + #111;\n' +
38+
' height: 100% / 2 + @filler;\n' +
39+
' }';
40+
41+
expected = 'div {\n' +
42+
' @base: 5%;\n' +
43+
' @filler: @base * 2;\n' +
44+
' @other: @base + @filler;\n' +
45+
' color: #888 / 4;\n' +
46+
' background-color: @base-color + #111;\n' +
47+
' height: 100% / 2 + @filler;\n' +
48+
' }';
49+
});
21750

218-
expected = 'p {\n' +
219-
' @var: white; // Get in line!\n' +
220-
' color: tomato; /* One hell of a comment */\n' +
221-
' }';
222-
});
51+
it('Should parse parent selector &', function() {
52+
config = { 'sort-order': [
53+
['top', 'left', 'color']
54+
] };
22355

224-
it('Should divide properties from different groups with an empty line', function() {
225-
config = { 'sort-order': [
226-
['top'], ['color']
227-
] };
56+
input = 'div { color: tomato; &.top { color: nani; top: 0; } left: 0; }';
22857

229-
input = 'div {\n' +
230-
' color: tomato;\n' +
231-
' top: 0;\n' +
232-
'}';
58+
expected = 'div { left: 0; color: tomato; &.top {top: 0; color: nani; }}';
59+
});
23360

234-
expected = 'div {\n' +
235-
' top: 0;\n' +
236-
'\n' +
237-
' color: tomato;\n' +
238-
'}';
239-
});
61+
it('Should parse variables', function() {
62+
config = {};
24063

241-
it('Should sort variables', function() {
242-
config = { 'sort-order': [
243-
['$variable', 'color']
244-
] };
64+
input = '@red: tomato; div { color: @tomato; top: @@foo; }';
24565

246-
input = 'div { color: @red; @red: tomato; }';
66+
expected = '@red: tomato; div { color: @tomato; top: @@foo; }';
67+
});
24768

248-
expected = 'div {@red: tomato; color: @red; }';
249-
});
69+
it('Should parse interpolated variables inside selectors', function() {
70+
config = { 'sort-order': [
71+
['top', 'left', 'color']
72+
] };
25073

251-
it('Should sort imports', function() {
252-
config = { 'sort-order': [
253-
['$import', 'color']
254-
] };
74+
input = 'div.@{nani} {color:tomato;top:0;}';
25575

256-
input = 'div { color: tomato; @import "foo.css"; }';
76+
expected = 'div.@{nani} {top:0;color:tomato;}';
77+
});
25778

258-
expected = 'div {@import "foo.css"; color: tomato; }';
259-
});
79+
it('Should parse interpolated variables inside values', function() {
80+
config = { 'sort-order': [
81+
['top', 'left', 'color']
82+
] };
26083

261-
it('Should sort included mixins. Test 1', function() {
262-
config = { 'sort-order': [
263-
['$include', 'color', 'border-top', 'border-bottom']
264-
] };
84+
input = 'div {color:@{tomato};top:0;}';
26585

266-
input = '.bordered {\n' +
267-
' border-bottom: solid 2px black;\n' +
268-
' border-top: dotted 1px black;\n' +
269-
' }\n' +
270-
'#menu a {\n' +
271-
' color: #111;\n' +
272-
' .bordered;\n' +
273-
' }\n' +
274-
'.post a {\n' +
275-
' color: red;\n' +
276-
' .bordered;\n' +
277-
' }';
86+
expected = 'div {top:0;color:@{tomato};}';
87+
});
27888

279-
expected = '.bordered {\n' +
280-
' border-top: dotted 1px black;\n' +
281-
' border-bottom: solid 2px black;\n' +
282-
' }\n' +
283-
'#menu a {\n' +
284-
' .bordered;\n' +
285-
' color: #111;\n' +
286-
' }\n' +
287-
'.post a {\n' +
288-
' .bordered;\n' +
289-
' color: red;\n' +
290-
' }';
291-
});
89+
it('Should parse @import', function() {
90+
config = {};
29291

293-
it('Should sort included mixins. Test 2', function() {
294-
config = { 'sort-order': [
295-
['$include', 'top', 'color']
296-
] };
92+
input = 'div { @import "foo.css"; top: 0; }';
29793

298-
input = '.test {\n' +
299-
' .test1();\n' +
300-
' color: tomato;\n' +
301-
' .test2();\n' +
302-
' top: 0;\n' +
303-
' }';
94+
expected = 'div { @import "foo.css"; top: 0; }';
95+
});
30496

305-
expected = '.test {\n' +
306-
' .test1();\n' +
307-
' .test2();\n' +
308-
' top: 0;\n' +
309-
' color: tomato;\n' +
310-
' }';
311-
});
97+
it('Should parse included mixins', function() {
98+
config = {};
31299

313-
it('Should sort included mixins. Test 3', function() {
314-
config = { 'sort-order': [
315-
['$include', 'border', 'color']
316-
] };
100+
input = 'div { .mixin; top: 0; }';
317101

318-
input = '.foo {\n' +
319-
' color: #0f0;\n' +
320-
' border: 1px solid #f00;\n' +
321-
' .linear-gradient(#fff; #000);\n' +
322-
'}';
102+
expected = 'div { .mixin; top: 0; }';
103+
});
323104

324-
expected = '.foo {\n' +
325-
' .linear-gradient(#fff; #000);\n' +
326-
' border: 1px solid #f00;\n' +
327-
' color: #0f0;\n' +
328-
'}';
329-
});
105+
it('Should parse nested @media', function() {
106+
config = {};
107+
108+
input = 'div {\n' +
109+
' @media screen and (orientation: landscape) {\n' +
110+
' color: tomato;\n' +
111+
' }\n' +
112+
' top: 0;\n' +
113+
'}';
114+
115+
expected = 'div {\n' +
116+
' @media screen and (orientation: landscape) {\n' +
117+
' color: tomato;\n' +
118+
' }\n' +
119+
' top: 0;\n' +
120+
'}';
330121
});
331122
});

0 commit comments

Comments
 (0)