|
| 1 | +var Comb = require('../lib/csscomb'); |
| 2 | +var assert = require('assert'); |
| 3 | + |
| 4 | +describe('options/remove-empty-rulesets', function() { |
| 5 | + var comb; |
| 6 | + |
| 7 | + beforeEach(function() { |
| 8 | + comb = new Comb(); |
| 9 | + }); |
| 10 | + |
| 11 | + describe('configured with invalid value', function() { |
| 12 | + beforeEach(function() { |
| 13 | + comb.configure({ 'remove-empty-rulesets': 'foobar' }); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should not remove empty ruleset', function() { |
| 17 | + assert.equal(comb.processString('a { width: 10px; } b {}'), 'a { width: 10px; } b {}'); |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('configured with Boolean "true" value', function() { |
| 22 | + beforeEach(function() { |
| 23 | + comb.configure({ 'remove-empty-rulesets': true }); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should remove empty ruleset', function() { |
| 27 | + assert.equal(comb.processString(' b {} '), ' '); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should leave ruleset with declarations', function() { |
| 31 | + assert.equal(comb.processString('a { width: 10px; }\nb {} '), 'a { width: 10px; }\n '); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should leave ruleset with comments', function() { |
| 35 | + assert.equal(comb.processString('a { /* comment */ }\nb {} '), 'a { /* comment */ }\n '); |
| 36 | + }); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +describe('options/remove-empty-rulesets AST manipulation', function() { |
| 41 | + var rule; |
| 42 | + var nodeContent; |
| 43 | + |
| 44 | + beforeEach(function() { |
| 45 | + rule = require('../lib/options/remove-empty-rulesets.js'); |
| 46 | + }); |
| 47 | + |
| 48 | + describe('merge adjacent whitespace', function() { |
| 49 | + it('should do nothing with empty content', function() { |
| 50 | + nodeContent = []; |
| 51 | + rule._mergeAdjacentWhitespace(nodeContent); |
| 52 | + assert.deepEqual(nodeContent, []); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should do nothing with only one whitespace', function() { |
| 56 | + nodeContent = [['s', ' ']]; |
| 57 | + rule._mergeAdjacentWhitespace(nodeContent); |
| 58 | + assert.deepEqual(nodeContent, [['s', ' ']]); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should merge two adjacent whitespaces', function() { |
| 62 | + nodeContent = [['s', ' '], ['s', ' \n']]; |
| 63 | + rule._mergeAdjacentWhitespace(nodeContent); |
| 64 | + assert.deepEqual(nodeContent, [['s', ' \n']]); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should merge three adjacent whitespaces', function() { |
| 68 | + nodeContent = [['s', ' '], ['s', ' \n'], ['s', ' \n']]; |
| 69 | + rule._mergeAdjacentWhitespace(nodeContent); |
| 70 | + assert.deepEqual(nodeContent, [['s', ' \n \n']]); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + describe('remove empty rulesets', function() { |
| 75 | + it('should do nothing with empty content', function() { |
| 76 | + nodeContent = []; |
| 77 | + rule._removeEmptyRulesets(nodeContent); |
| 78 | + assert.deepEqual(nodeContent, []); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should do nothing with no rulesets', function() { |
| 82 | + nodeContent = [['s', ' ']]; |
| 83 | + rule._removeEmptyRulesets(nodeContent); |
| 84 | + assert.deepEqual(nodeContent, [['s', ' ']]); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should remove empty ruleset', function() { |
| 88 | + nodeContent = [['ruleset', []]]; |
| 89 | + rule._removeEmptyRulesets(nodeContent); |
| 90 | + assert.deepEqual(nodeContent, []); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should remove two empty rulesets', function() { |
| 94 | + nodeContent = [['s', ' '], ['ruleset', []], ['s', ' \n'], ['ruleset', []]]; |
| 95 | + rule._removeEmptyRulesets(nodeContent); |
| 96 | + assert.deepEqual(nodeContent, [['s', ' '], ['s', ' \n']]); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments