From 6e7938f969313410ad0fcb1f8c3907e094d17f19 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 25 May 2020 14:44:46 -0400 Subject: [PATCH] increase code coverage for bit integers --- src/value/number/mod.rs | 5 ++++- tests/math.rs | 20 ++++++++++++++++++++ tests/number.rs | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/value/number/mod.rs b/src/value/number/mod.rs index 0f6dd12..d8db35a 100644 --- a/src/value/number/mod.rs +++ b/src/value/number/mod.rs @@ -229,7 +229,10 @@ from_smaller_integer!(u8); impl fmt::Debug for Number { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Number {{ {} }}", self) + match self { + Self::Machine(..) => write!(f, "Number::Machine( {} )", self), + Self::Big(..) => write!(f, "Number::Big( {} )", self), + } } } diff --git a/tests/math.rs b/tests/math.rs index e35a89d..07e67f6 100644 --- a/tests/math.rs +++ b/tests/math.rs @@ -38,6 +38,11 @@ test!( "a {\n color: floor(10.6px);\n}\n", "a {\n color: 10px;\n}\n" ); +test!( + floor_big_int, + "a {\n color: floor(1.000000000000000001);\n}\n", + "a {\n color: 1;\n}\n" +); test!( ceil_below_pt_5, "a {\n color: ceil(10.4px);\n}\n", @@ -48,6 +53,11 @@ test!( "a {\n color: ceil(10.6px);\n}\n", "a {\n color: 11px;\n}\n" ); +test!( + ceil_big_int, + "a {\n color: ceil(1.000000000000000001);\n}\n", + "a {\n color: 2;\n}\n" +); test!( abs_positive, "a {\n color: abs(10);\n}\n", @@ -93,3 +103,13 @@ test!( "a {\n color: comparable($number1: 1, $number2: 2);\n}\n", "a {\n color: true;\n}\n" ); +test!( + random_limit_one, + "a {\n color: random(1);\n}\n", + "a {\n color: 1;\n}\n" +); +test!( + random_limit_big_one, + "a {\n color: random(1000000000000000001 - 1000000000000000000);\n}\n", + "a {\n color: 1;\n}\n" +); diff --git a/tests/number.rs b/tests/number.rs index 1d40a8d..5bcff80 100644 --- a/tests/number.rs +++ b/tests/number.rs @@ -168,3 +168,22 @@ error!( scientific_notation_ident_char_after_dash, "a {\n color: 1e-a;\n}\n", "Error: Expected digit." ); +test!( + number_overflow_from_addition, + "a {\n color: 999999999999999999 + + 999999999999999999 + + 999999999999999999 + + 999999999999999999 + + 999999999999999999 + + 999999999999999999 + + 999999999999999999 + + 999999999999999999 + + 999999999999999999 + + 999999999999999999;\n}\n", + "a {\n color: 9999999999999999990;\n}\n" +); +test!( + number_overflow_from_multiplication, + "a {\n color: 999999999999999999 * 10;\n}\n", + "a {\n color: 9999999999999999990;\n}\n" +);