add tests for bools and important plus quoted string

This commit is contained in:
Connor Skees 2020-08-19 04:02:47 -04:00
parent cb1eecde74
commit d9d9777467
2 changed files with 60 additions and 4 deletions

View File

@ -174,14 +174,25 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
) )
.into()) .into())
} }
Value::Important | Value::True | Value::False => match right { Value::True | Value::False => match right {
Value::String(s, QuoteKind::Quoted) => Value::String( Value::String(s, QuoteKind::Quoted) => Value::String(
format!("{}{}", left.to_css_string(self.span)?, s), format!("{}{}", left.to_css_string(self.span)?, s),
QuoteKind::Quoted, QuoteKind::Quoted,
), ),
Value::Null => { _ => Value::String(
Value::String(left.to_css_string(self.span)?.into_owned(), QuoteKind::None) 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( _ => Value::String(
format!( format!(
"{}{}", "{}{}",

View File

@ -161,11 +161,41 @@ test!(
"a {\n color: true + false;\n}\n", "a {\n color: true + false;\n}\n",
"a {\n color: truefalse;\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!( test!(
false_plus_null, false_plus_null,
"a {\n color: false + null;\n}\n", "a {\n color: false + null;\n}\n",
"a {\n color: false;\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!( test!(
false_plus_null_is_string, false_plus_null_is_string,
"a {\n color: type-of(false + null);\n}\n", "a {\n color: type-of(false + null);\n}\n",
@ -297,6 +327,21 @@ test!(
"a {\n color: foo + red;\n}\n", "a {\n color: foo + red;\n}\n",
"a {\n color: foored;\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!( error!(
map_lhs_add, map_lhs_add,
"a {color: (a: b) + 1;}", "Error: (a: b) isn't a valid CSS value." "a {color: (a: b) + 1;}", "Error: (a: b) isn't a valid CSS value."