properly emit 0 in compressed mode

This commit is contained in:
Connor Skees 2021-09-19 16:31:34 -04:00
parent 537ba67cc9
commit a6eb1fb88a
2 changed files with 18 additions and 3 deletions

View File

@ -444,15 +444,24 @@ impl Number {
} }
} }
if self.is_negative() && (!whole.is_zero() || !dec.is_empty()) { let has_decimal = !dec.is_empty();
if self.is_negative() && (!whole.is_zero() || has_decimal) {
buf.push('-'); buf.push('-');
} }
if !(whole.is_zero() && is_compressed) { // if the entire number is just zero, we always want to emit it
if whole.is_zero() && !has_decimal {
return "0".to_owned();
// otherwise, if the number is not 0, or the number before the decimal
// _is_ 0 and we aren't in compressed mode, emit the number before the
// decimal
} else if !(whole.is_zero() && is_compressed) {
buf.push_str(&whole.to_string()); buf.push_str(&whole.to_string());
} }
if !dec.is_empty() { if has_decimal {
buf.push('.'); buf.push('.');
buf.push_str(&dec); buf.push_str(&dec);
} }

View File

@ -116,3 +116,9 @@ test!(
"a{color:grayscale(0.5)}", "a{color:grayscale(0.5)}",
grass::Options::default().style(grass::OutputStyle::Compressed) grass::Options::default().style(grass::OutputStyle::Compressed)
); );
test!(
retains_zero_without_decimal,
"a {\n color: 0.0;\n color: 0;\n}\n",
"a{color:0;color:0}",
grass::Options::default().style(grass::OutputStyle::Compressed)
);