|
1 | 1 | var Comb = require('../lib/csscomb'); |
2 | 2 | var assert = require('assert'); |
| 3 | +var fs = require('fs'); |
3 | 4 |
|
4 | 5 | describe('LESS', function() { |
5 | 6 | var comb; |
6 | | - var config; |
7 | 7 | var input; |
8 | | - var expected; |
| 8 | + |
| 9 | + function readFile(path) { |
| 10 | + return fs.readFileSync('test/less/' + path, 'utf8'); |
| 11 | + } |
9 | 12 |
|
10 | 13 | beforeEach(function() { |
11 | 14 | comb = new Comb(); |
12 | | - }); |
13 | | - |
14 | | - afterEach(function() { |
15 | | - comb.configure(config); |
16 | | - assert.equal(comb.processString(input, 'less'), expected); |
| 15 | + comb.configure({}); |
17 | 16 | }); |
18 | 17 |
|
19 | 18 | 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); |
27 | 21 | }); |
28 | 22 |
|
29 | 23 | 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); |
49 | 26 | }); |
50 | 27 |
|
51 | 28 | 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); |
59 | 31 | }); |
60 | 32 |
|
61 | 33 | 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); |
67 | 36 | }); |
68 | 37 |
|
69 | 38 | 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); |
77 | 41 | }); |
78 | 42 |
|
79 | 43 | 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); |
87 | 46 | }); |
88 | 47 |
|
89 | 48 | 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); |
95 | 51 | }); |
96 | 52 |
|
97 | 53 | 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); |
103 | 56 | }); |
104 | 57 |
|
105 | 58 | 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); |
121 | 61 | }); |
122 | 62 | }); |
0 commit comments