Skip to content

Commit 7f4dd15

Browse files
committed
Tests: Use external files for parsing/sorting test
1 parent 4b5382d commit 7f4dd15

95 files changed

Lines changed: 621 additions & 503 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/less.js

Lines changed: 24 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,62 @@
11
var Comb = require('../lib/csscomb');
22
var assert = require('assert');
3+
var fs = require('fs');
34

45
describe('LESS', function() {
56
var comb;
6-
var config;
77
var input;
8-
var expected;
8+
9+
function readFile(path) {
10+
return fs.readFileSync('test/less/' + path, 'utf8');
11+
}
912

1013
beforeEach(function() {
1114
comb = new Comb();
12-
});
13-
14-
afterEach(function() {
15-
comb.configure(config);
16-
assert.equal(comb.processString(input, 'less'), expected);
15+
comb.configure({});
1716
});
1817

1918
it('Should parse nested rules', function() {
20-
config = { 'sort-order': [
21-
['top', 'color']
22-
] };
23-
24-
input = 'div { color: tomato; a { top: 0; } }';
25-
26-
expected = 'div { color: tomato; a { top: 0; } }';
19+
input = readFile('nested-rule.less');
20+
assert.equal(comb.processString(input, 'less'), input);
2721
});
2822

2923
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-
' }';
24+
input = readFile('operation.less');
25+
assert.equal(comb.processString(input, 'less'), input);
4926
});
5027

5128
it('Should parse parent selector &', function() {
52-
config = { 'sort-order': [
53-
['top', 'left', 'color']
54-
] };
55-
56-
input = 'div { color: tomato; &.top { color: nani; top: 0; } left: 0; }';
57-
58-
expected = 'div { left: 0; color: tomato; &.top {top: 0; color: nani; }}';
29+
input = readFile('parent-selector.less');
30+
assert.equal(comb.processString(input, 'less'), input);
5931
});
6032

6133
it('Should parse variables', function() {
62-
config = {};
63-
64-
input = '@red: tomato; div { color: @tomato; top: @@foo; }';
65-
66-
expected = '@red: tomato; div { color: @tomato; top: @@foo; }';
34+
input = readFile('variable.less');
35+
assert.equal(comb.processString(input, 'less'), input);
6736
});
6837

6938
it('Should parse interpolated variables inside selectors', function() {
70-
config = { 'sort-order': [
71-
['top', 'left', 'color']
72-
] };
73-
74-
input = 'div.@{nani} {color:tomato;top:0;}';
75-
76-
expected = 'div.@{nani} {top:0;color:tomato;}';
39+
input = readFile('interpolated-variable-1.less');
40+
assert.equal(comb.processString(input, 'less'), input);
7741
});
7842

7943
it('Should parse interpolated variables inside values', function() {
80-
config = { 'sort-order': [
81-
['top', 'left', 'color']
82-
] };
83-
84-
input = 'div {color:@{tomato};top:0;}';
85-
86-
expected = 'div {top:0;color:@{tomato};}';
44+
input = readFile('interpolated-variable-2.less');
45+
assert.equal(comb.processString(input, 'less'), input);
8746
});
8847

8948
it('Should parse @import', function() {
90-
config = {};
91-
92-
input = 'div { @import "foo.css"; top: 0; }';
93-
94-
expected = 'div { @import "foo.css"; top: 0; }';
49+
input = readFile('import.less');
50+
assert.equal(comb.processString(input, 'less'), input);
9551
});
9652

9753
it('Should parse included mixins', function() {
98-
config = {};
99-
100-
input = 'div { .mixin; top: 0; }';
101-
102-
expected = 'div { .mixin; top: 0; }';
54+
input = readFile('mixin.less');
55+
assert.equal(comb.processString(input, 'less'), input);
10356
});
10457

10558
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-
'}';
59+
input = readFile('nested-media.less');
60+
assert.equal(comb.processString(input, 'less'), input);
12161
});
12262
});

test/less/import.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
div {
2+
@import "foo.css";
3+
top: 0;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
div.@{nani} {
2+
color:tomato;
3+
top:0;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
div {
2+
color: @{tomato};
3+
top:0;
4+
}

test/less/mixin.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
div {
2+
.mixin;
3+
top: 0;
4+
}

test/less/nested-media.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
div {
2+
@media screen and (orientation: landscape) {
3+
color: tomato;
4+
}
5+
top: 0;
6+
}

test/less/nested-rule.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
div {
2+
color: tomato;
3+
a {
4+
top: 0;
5+
}
6+
}

test/less/operation.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
div {
2+
@base: 5%;
3+
@filler: @base * 2;
4+
@other: @base + @filler;
5+
color: #888 / 4;
6+
background-color: @base-color + #111;
7+
height: 100% / 2 + @filler;
8+
}

test/less/parent-selector.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
div {
2+
color: tomato;
3+
&.top {
4+
color: nani;
5+
top: 0;
6+
}
7+
left: 0;
8+
}

test/less/variable.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@red: tomato;
2+
div {
3+
color: @tomato;
4+
top: @@foo;
5+
}

0 commit comments

Comments
 (0)