From 942bb20d7584c8065ab95f4723548bcbd0cc39e6 Mon Sep 17 00:00:00 2001 From: connorskees Date: Wed, 1 Feb 2023 02:42:17 +0000 Subject: [PATCH] revert float formatting change this change does fix more number tests, but i'm not certain that it doesn't break cases we don't test for. it only solves extremely niche edge cases, so for now reverting until we can be more certain in a later release --- crates/compiler/src/serializer.rs | 22 +++++----------------- crates/lib/tests/compressed.rs | 2 +- crates/lib/tests/number.rs | 1 + 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/crates/compiler/src/serializer.rs b/crates/compiler/src/serializer.rs index 0552678..d2d28fc 100644 --- a/crates/compiler/src/serializer.rs +++ b/crates/compiler/src/serializer.rs @@ -590,23 +590,11 @@ impl<'a> Serializer<'a> { .trim_end_matches('.'), ); } else { - let p = 10.0_f64.powi(10); - - let n = (num * p).round() / p; - - let formatted = n.to_string(); - - if formatted.ends_with(".0") { - buffer.push_str(formatted.trim_end_matches('0').trim_end_matches('.')); - } else if n.is_infinite() { - buffer.push_str( - format!("{:.10}", num) - .trim_end_matches('0') - .trim_end_matches('.'), - ); - } else { - buffer.push_str(&formatted); - } + buffer.push_str( + format!("{:.10}", num) + .trim_end_matches('0') + .trim_end_matches('.'), + ); } if buffer.is_empty() || buffer == "-" || buffer == "-0" { diff --git a/crates/lib/tests/compressed.rs b/crates/lib/tests/compressed.rs index a5a2549..04b5275 100644 --- a/crates/lib/tests/compressed.rs +++ b/crates/lib/tests/compressed.rs @@ -147,7 +147,7 @@ test!( grass::Options::default().style(grass::OutputStyle::Compressed) ); test!( - calc, + retains_space_between_calc_operations, "a {\n width: calc(100% + 32px);\n}\n", "a{width:calc(100% + 32px)}", grass::Options::default().style(grass::OutputStyle::Compressed) diff --git a/crates/lib/tests/number.rs b/crates/lib/tests/number.rs index f99af94..6e21a0f 100644 --- a/crates/lib/tests/number.rs +++ b/crates/lib/tests/number.rs @@ -205,6 +205,7 @@ test!( "a {\n color: 0;\n color: true;\n}\n" ); test!( + #[ignore = "float formatting isn't feature complete"] scientific_notation_very_large_positive, "a {\n color: 1e100;\n}\n", "a {\n color: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;\n}\n" );