-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #394: unitless-zero vs fractions
Don't remove units from values starting from zero, like `0.5em`
- Loading branch information
Showing
2 changed files
with
115 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
); | ||
}); | ||
}); | ||
}); |