|
| 1 | +var Comb = require('../lib/csscomb'); |
| 2 | +var assert = require('assert'); |
| 3 | + |
| 4 | +describe('options/quotes', function() { |
| 5 | + var comb; |
| 6 | + beforeEach(function() { |
| 7 | + comb = new Comb(); |
| 8 | + }); |
| 9 | + |
| 10 | + it('Invalid String should not change quotes', function() { |
| 11 | + comb.configure({ quotes: 'foobar' }); |
| 12 | + assert.equal( |
| 13 | + comb.processString( |
| 14 | + 'a { content: "" }' + |
| 15 | + 'b { content: \'\' }' |
| 16 | + ), |
| 17 | + 'a { content: "" }' + |
| 18 | + 'b { content: \'\' }' |
| 19 | + ); |
| 20 | + }); |
| 21 | + |
| 22 | + it('`single` value should set the quotes to single', function() { |
| 23 | + comb.configure({ quotes: 'single' }); |
| 24 | + assert.equal( |
| 25 | + comb.processString( |
| 26 | + 'a { content: "" }' + |
| 27 | + 'b { content: \'\' }' |
| 28 | + ), |
| 29 | + 'a { content: \'\' }' + |
| 30 | + 'b { content: \'\' }' |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + it('`double` value should set the quotes to double', function() { |
| 35 | + comb.configure({ quotes: 'double' }); |
| 36 | + assert.equal( |
| 37 | + comb.processString( |
| 38 | + 'a { content: "" }' + |
| 39 | + 'b { content: \'\' }' |
| 40 | + ), |
| 41 | + 'a { content: "" }' + |
| 42 | + 'b { content: "" }' |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + it('`double` value should set the quotes to double in attrs and urls', function() { |
| 47 | + comb.configure({ quotes: 'double' }); |
| 48 | + assert.equal( |
| 49 | + comb.processString( |
| 50 | + 'a[class^=\'foo\'] { background: url(\'foo.png\') }' |
| 51 | + ), |
| 52 | + 'a[class^="foo"] { background: url("foo.png") }' |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it('`double` value should escape the unescaped double quotes on change', function() { |
| 57 | + comb.configure({ quotes: 'double' }); |
| 58 | + assert.equal( |
| 59 | + comb.processString( |
| 60 | + 'a { content: "\\"" }' + |
| 61 | + 'b { content: \'"\' }' |
| 62 | + ), |
| 63 | + 'a { content: "\\"" }' + |
| 64 | + 'b { content: "\\"" }' |
| 65 | + ); |
| 66 | + }); |
| 67 | + |
| 68 | + |
| 69 | + it('`single` value should unescape the escaped double quotes on change', function() { |
| 70 | + comb.configure({ quotes: 'single' }); |
| 71 | + assert.equal( |
| 72 | + comb.processString( |
| 73 | + 'a { content: "\\"" }' |
| 74 | + ), |
| 75 | + 'a { content: \'"\' }' |
| 76 | + ); |
| 77 | + }); |
| 78 | + |
| 79 | + // Helper to check the detection |
| 80 | + function should_detect(options, a, b) { |
| 81 | + assert.equal( |
| 82 | + JSON.stringify(comb.detectInString(a, options)), |
| 83 | + JSON.stringify(b) |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + it('Should not detect quotes when there are none', function() { |
| 88 | + should_detect( |
| 89 | + ['quotes'], |
| 90 | + 'a { color:red }', |
| 91 | + {} |
| 92 | + ); |
| 93 | + }); |
| 94 | + |
| 95 | + it('Should detect double quotes', function() { |
| 96 | + should_detect( |
| 97 | + ['quotes'], |
| 98 | + 'a { content: "foo" }', |
| 99 | + { |
| 100 | + quotes: 'double' |
| 101 | + } |
| 102 | + ); |
| 103 | + }); |
| 104 | + |
| 105 | + it('Should detect single quotes', function() { |
| 106 | + should_detect( |
| 107 | + ['quotes'], |
| 108 | + 'a { content: \'foo\' }', |
| 109 | + { |
| 110 | + quotes: 'single' |
| 111 | + } |
| 112 | + ); |
| 113 | + }); |
| 114 | + |
| 115 | + it('Should detect single quotes in attribute', function() { |
| 116 | + should_detect( |
| 117 | + ['quotes'], |
| 118 | + 'a[class^=\'foo\'] { color: red }', |
| 119 | + { |
| 120 | + quotes: 'single' |
| 121 | + } |
| 122 | + ); |
| 123 | + }); |
| 124 | + |
| 125 | + it('Should detect double quotes in url', function() { |
| 126 | + should_detect( |
| 127 | + ['quotes'], |
| 128 | + 'a { background: url("foo.png") }', |
| 129 | + { |
| 130 | + quotes: 'double' |
| 131 | + } |
| 132 | + ); |
| 133 | + }); |
| 134 | +}); |
0 commit comments