Skip to content

Commit 540da80

Browse files
committed
Merge pull request #13 from csscomb/tests
Tests for all present options
2 parents 499a9cc + 801374c commit 540da80

File tree

8 files changed

+152
-20
lines changed

8 files changed

+152
-20
lines changed

lib/csscomb.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Comb.prototype = {
3232
for (var option in config) {
3333
if (config.hasOwnProperty(option) && config[option] && this._options[option]) {
3434
try {
35-
this._config[option] = require('./options/' + option).setValue(config[option]);
35+
var handler = require('./options/' + option).setValue(config[option]);
36+
if (handler) this._config[option] = handler;
3637
} catch (e) {}
3738
}
3839
}
@@ -84,7 +85,7 @@ Comb.prototype = {
8485
} catch (e) {
8586
throw new Error('Parsing error at ' + filename + ': ' + e.message);
8687
}
87-
return cssp.translate(cssp.transform(tree));
88+
return cssp.translate(tree);
8889
},
8990

9091
/**

lib/options/colon-space.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
module.exports = {
22

3-
_value: false,
4-
53
/**
64
* Sets handler value.
75
*
86
* @param {String|Boolean} value Option value
97
* @returns {Object}
108
*/
119
setValue: function(value) {
12-
if (!value) return this;
13-
if (typeof value === 'string') {
14-
this._value = value;
15-
} else {
16-
this._value = 'after'; // default
17-
}
10+
if (value === true) this._value = 'after';
11+
if (typeof value === 'string' && value.match(/after|before|both/)) this._value = value;
12+
if (!this._value) return;
1813
return this;
1914
},
2015

lib/options/stick-brace.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
module.exports = {
22

3-
_value: false,
4-
53
/**
64
* Sets handler value.
75
*
86
* @param {String|Number|Boolean} value Option value
97
* @returns {Object}
108
*/
119
setValue: function(value) {
12-
if (!value) return this;
13-
if (value === true) value = ' '; // 1 space by default
14-
if (typeof value === 'number') this._value = new Array(Math.round(value) + 1).join(' ');
10+
if (value === true) value = ' ';
1511
if (typeof value === 'string' && value.match(/^[ \t\n]*$/)) this._value = value;
12+
if (!this._value) return;
1613
return this;
1714
},
1815

lib/options/strip-spaces.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
module.exports = {
22

3-
value: false,
4-
53
/**
64
* Sets handler value.
75
*
86
* @param {String|Boolean} value Option value
97
* @returns {Object}
108
*/
119
setValue: function(value) {
12-
this._value = Boolean(value);
10+
this._value = value === true;
11+
if (!this._value) return;
1312
return this;
1413
},
1514

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
"devDependencies": {
3131
"jshint-groups": "0.5.1",
3232
"jshint": "2.1.7",
33-
"jscs": "1.0.2"
33+
"jscs": "1.0.2",
34+
"mocha": "1.11.0"
3435
},
3536
"bin": {
3637
"csscomb": "./bin/csscomb"
3738
},
3839
"scripts": {
39-
"test": "./node_modules/.bin/jshint-groups; ./node_modules/.bin/jscs ."
40+
"test": "./node_modules/.bin/jshint-groups . && ./node_modules/.bin/jscs . && ./node_modules/.bin/mocha -u bdd -R spec"
4041
}
4142
}

test/colon-space.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
var Comb = require('../lib/csscomb');
2+
var assert = require('assert');
3+
4+
describe('options/colon-space', function() {
5+
var comb;
6+
beforeEach(function() {
7+
comb = new Comb();
8+
});
9+
it('Invalid String should not change space around colon', function() {
10+
comb.configure({ 'colon-space': 'foobar' });
11+
assert.equal(
12+
comb.processString('a { color: red }'),
13+
'a { color: red }'
14+
);
15+
});
16+
it('True Boolean value should set space after colon', function() {
17+
comb.configure({ 'colon-space': true });
18+
assert.equal(
19+
comb.processString(
20+
'a { color: red }\n' +
21+
'b{color:blue}\n' +
22+
'i {font : 0/0 a}'
23+
),
24+
'a { color: red }\n' +
25+
'b{color: blue}\n' +
26+
'i {font: 0/0 a}'
27+
);
28+
});
29+
it('`before` value should set space before colon', function() {
30+
comb.configure({ 'colon-space': 'before' });
31+
assert.equal(
32+
comb.processString(
33+
'a { color: red }\n' +
34+
'b{color:blue}\n' +
35+
'i {font : 0/0 a}'
36+
),
37+
'a { color :red }\n' +
38+
'b{color :blue}\n' +
39+
'i {font :0/0 a}'
40+
);
41+
});
42+
it('`after` value should set space before colon', function() {
43+
comb.configure({ 'colon-space': 'after' });
44+
assert.equal(
45+
comb.processString(
46+
'a { color: red }\n' +
47+
'b{color:blue}\n' +
48+
'i {font : 0/0 a}'
49+
),
50+
'a { color: red }\n' +
51+
'b{color: blue}\n' +
52+
'i {font: 0/0 a}'
53+
);
54+
});
55+
it('`both` value should set spaces around colon', function() {
56+
comb.configure({ 'colon-space': 'both' });
57+
assert.equal(
58+
comb.processString(
59+
'a { color: red }\n' +
60+
'b{color:blue}\n' +
61+
'i {font : 0/0 a}'
62+
),
63+
'a { color : red }\n' +
64+
'b{color : blue}\n' +
65+
'i {font : 0/0 a}'
66+
);
67+
});
68+
});

test/stick-brace.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var Comb = require('../lib/csscomb');
2+
var assert = require('assert');
3+
4+
describe('options/stick-brace', function() {
5+
var comb;
6+
beforeEach(function() {
7+
comb = new Comb();
8+
});
9+
it('Invalid String should not change space after brace', function() {
10+
comb.configure({ 'stick-brace': 'foobar' });
11+
assert.equal(
12+
comb.processString('a { color: red }'),
13+
'a { color: red }'
14+
);
15+
});
16+
it('True Boolean value should set 1 space after brace', function() {
17+
comb.configure({ 'stick-brace': true });
18+
assert.equal(
19+
comb.processString(
20+
'a { color: red }\n' +
21+
'b{color:blue}\n' +
22+
'i \t\t \n{font:0/0 a}'
23+
),
24+
'a { color: red }\n' +
25+
'b {color:blue}\n' +
26+
'i {font:0/0 a}'
27+
);
28+
});
29+
it('Valid String value should set equal space after brace', function() {
30+
comb.configure({ 'stick-brace': '\n' });
31+
assert.equal(
32+
comb.processString(
33+
'a { color: red }\n' +
34+
'b{color:blue}\n' +
35+
'i \t\t \n{font:0/0 a}'
36+
),
37+
'a\n{ color: red }\n' +
38+
'b\n{color:blue}\n' +
39+
'i\n{font:0/0 a}'
40+
);
41+
});
42+
});

test/strip-space.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var Comb = require('../lib/csscomb');
2+
var assert = require('assert');
3+
4+
describe('options/strip-space', function() {
5+
var comb;
6+
beforeEach(function() {
7+
comb = new Comb();
8+
});
9+
it('Invalid value should not change trim trailing brace', function() {
10+
comb.configure({ 'strip-spaces': 'foobar' });
11+
assert.equal(
12+
comb.processString('a { color: red }'),
13+
'a { color: red }'
14+
);
15+
});
16+
it('True Boolean value should trim all trailing spaces', function() {
17+
comb.configure({ 'strip-spaces': true });
18+
assert.equal(
19+
comb.processString(
20+
'a { color: red } \n' +
21+
'b{color:blue}\t \n' +
22+
'i {font:0/0 a}'
23+
),
24+
'a { color: red }\n' +
25+
'b{color:blue}\n' +
26+
'i {font:0/0 a}\n'
27+
);
28+
});
29+
});

0 commit comments

Comments
 (0)