From d9d9777467ad483307e8c0c1c38dfce8bc5ba198 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Wed, 19 Aug 2020 04:02:47 -0400 Subject: [PATCH] add tests for bools and `important` plus quoted string --- src/parse/value/eval.rs | 19 +++++++++++++---- tests/addition.rs | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/parse/value/eval.rs b/src/parse/value/eval.rs index e56425d..a2d49b3 100644 --- a/src/parse/value/eval.rs +++ b/src/parse/value/eval.rs @@ -174,14 +174,25 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> { ) .into()) } - Value::Important | Value::True | Value::False => match right { + Value::True | Value::False => match right { Value::String(s, QuoteKind::Quoted) => Value::String( format!("{}{}", left.to_css_string(self.span)?, s), QuoteKind::Quoted, ), - Value::Null => { - Value::String(left.to_css_string(self.span)?.into_owned(), QuoteKind::None) - } + _ => Value::String( + format!( + "{}{}", + left.to_css_string(self.span)?, + right.to_css_string(self.span)? + ), + QuoteKind::None, + ), + }, + Value::Important => match right { + Value::String(s, ..) => Value::String( + format!("{}{}", left.to_css_string(self.span)?, s), + QuoteKind::None, + ), _ => Value::String( format!( "{}{}", diff --git a/tests/addition.rs b/tests/addition.rs index a766748..8ebe0a8 100644 --- a/tests/addition.rs +++ b/tests/addition.rs @@ -161,11 +161,41 @@ test!( "a {\n color: true + false;\n}\n", "a {\n color: truefalse;\n}\n" ); +test!( + true_plus_dblquoted, + "a {\n color: true + \"foo\";\n}\n", + "a {\n color: \"truefoo\";\n}\n" +); +test!( + false_plus_dblquoted, + "a {\n color: false + \"foo\";\n}\n", + "a {\n color: \"falsefoo\";\n}\n" +); +test!( + true_plus_unquoted, + "a {\n color: true + foo;\n}\n", + "a {\n color: truefoo;\n}\n" +); +test!( + false_plus_unquoted, + "a {\n color: false + foo;\n}\n", + "a {\n color: falsefoo;\n}\n" +); +test!( + true_plus_null, + "a {\n color: true + null;\n}\n", + "a {\n color: true;\n}\n" +); test!( false_plus_null, "a {\n color: false + null;\n}\n", "a {\n color: false;\n}\n" ); +test!( + true_plus_null_is_string, + "a {\n color: type-of(true + null);\n}\n", + "a {\n color: string;\n}\n" +); test!( false_plus_null_is_string, "a {\n color: type-of(false + null);\n}\n", @@ -297,6 +327,21 @@ test!( "a {\n color: foo + red;\n}\n", "a {\n color: foored;\n}\n" ); +test!( + important_plus_dblquoted, + "a {\n color: !important + \"foo\";\n}\n", + "a {\n color: !importantfoo;\n}\n" +); +test!( + important_plus_null, + "a {\n color: !important + null;\n}\n", + "a {\n color: !important;\n}\n" +); +test!( + important_plus_unquoted, + "a {\n color: !important + foo;\n}\n", + "a {\n color: !importantfoo;\n}\n" +); error!( map_lhs_add, "a {color: (a: b) + 1;}", "Error: (a: b) isn't a valid CSS value."