Skip to content

Commit

Permalink
Fix #394: unitless-zero vs fractions
Browse files Browse the repository at this point in the history
Don't remove units from values starting from zero, like `0.5em`
  • Loading branch information
tonyganch committed Jul 11, 2016
1 parent 3b3eafa commit da18af6
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 82 deletions.
82 changes: 0 additions & 82 deletions lib/options/unitless-zero.js

This file was deleted.

115 changes: 115 additions & 0 deletions test/options/unitless-zero/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
var assert = require('assert');

describe('options/unitless-zero', function() {
describe('process', function() {
it('Should remove units in zero-valued dimensions', function() {
this.comb.configure({ 'unitless-zero': true });
return this.comb.processString(
'div { margin: 0em; padding: 0px }'
).then(function(actual) {
assert.equal(actual, 'div { margin: 0; padding: 0 }');
});
});

it('Should remove units in zero-valued dimensions, test 2', function() {
this.comb.configure({ 'unitless-zero': true });
return this.comb.processString(
'div { margin: 0% }'
).then(function(actual) {
assert.equal(actual, 'div { margin: 0 }');
});
});

it('Should remove units in zero-valued media-query params', function() {
this.comb.configure({ 'unitless-zero': true });
return this.comb.processString(
'@media all and (min-width: 0px) { div { margin: 0em; padding: 0px } }'
).then(function(actual) {
assert.equal(actual, '@media all and (min-width: 0) { div { margin: 0; padding: 0 } }');
});
});

it('Should not remove units (degs) in rotate property', function() {
this.comb.configure({ 'unitless-zero': true });
return this.comb.processString(
'div { -webkit-transform: rotate(0deg); }'
).then(function(actual) {
assert.equal(actual, 'div { -webkit-transform: rotate(0deg); }');
});
});

it('Issue 394', function() {
this.comb.configure({ 'unitless-zero': true });
this.shouldBeEqual('issue-394.css', 'issue-394.expected.css');
});
});

describe('detect', function() {
it('Should detect unitless zero option', function() {
this.shouldDetect(
['unitless-zero'],
'a { width: 0 }',
{
'unitless-zero': true
}
);
});


it('Should detect zero with unit', function() {
this.shouldDetect(
['unitless-zero'],
'a { width: 0px }',
{
'unitless-zero': false
}
);
});

it('Should detect unitless zero option with multiple values', function() {
this.shouldDetect(
['unitless-zero'],
'a { padding: 0px 0 0 }',
{
'unitless-zero': true
}
);
});

it('Should detect zero with unit and multiple values', function() {
this.shouldDetect(
['unitless-zero'],
'a { padding: 0px 0 0em }',
{
'unitless-zero': false
}
);
});

it('Shouldn’t detect unitless zero option if there is no unit', function() {
this.shouldDetect(
['unitless-zero'],
'a { color: red }',
{}
);
});

it('Shouldn’t detect unitless zero option if there is `deg` unit', function() {
this.shouldDetect(
['unitless-zero'],
'a { transform: rotate(0deg) }',
{}
);
});

it('Should detect unitless zero option with percents', function() {
this.shouldDetect(
['unitless-zero'],
'a { padding: 0% 0 0 }',
{
'unitless-zero': true
}
);
});
});
});

0 comments on commit da18af6

Please sign in to comment.