remove remaining binop todo!()s

This commit is contained in:
Connor Skees 2020-07-04 08:37:35 -04:00
parent efc5f91348
commit fb24d4db4f
5 changed files with 132 additions and 24 deletions

View File

@ -167,7 +167,6 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
)
.into())
}
Value::ArgList(..) => todo!(),
Value::Important | Value::True | Value::False => match right {
Value::String(s, QuoteKind::Quoted) => Value::String(
format!("{}{}", left.to_css_string(self.span)?, s),
@ -266,7 +265,7 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
Value::String(text2, ..) => Value::String(text + &text2, quotes),
_ => Value::String(text + &right.to_css_string(self.span)?, quotes),
},
Value::List(..) => match right {
Value::List(..) | Value::ArgList(..) => match right {
Value::String(s, q) => {
Value::String(format!("{}{}", left.to_css_string(self.span)?, s), q)
}
@ -325,7 +324,12 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
)
}
}
Value::List(..) | Value::String(..) => Value::String(
Value::List(..)
| Value::String(..)
| Value::Important
| Value::True
| Value::False
| Value::ArgList(..) => Value::String(
format!("{}{}-{}", num, unit, right.to_css_string(self.span)?),
QuoteKind::None,
),
@ -336,7 +340,19 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
)
.into())
}
_ => todo!(),
Value::Color(..) => {
return Err((
format!(
"Undefined operation \"{}{} - {}\".",
num,
unit,
right.inspect(self.span)?
),
self.span,
)
.into())
}
Value::Null => Value::String(format!("{}{}-", num, unit), QuoteKind::None),
},
Value::Color(c) => match right {
Value::String(s, q) => {
@ -367,20 +383,6 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
),
QuoteKind::None,
),
Value::List(..) => match right {
Value::String(s, q) => Value::String(
format!("{}-{}{}{}", left.to_css_string(self.span)?, q, s, q),
QuoteKind::None,
),
_ => Value::String(
format!(
"{}-{}",
left.to_css_string(self.span)?,
right.to_css_string(self.span)?
),
QuoteKind::None,
),
},
_ => match right {
Value::String(s, q) => Value::String(
format!("{}-{}{}{}", left.to_css_string(self.span)?, q, s, q),
@ -416,7 +418,6 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
v => panic!("{:?}", v),
};
Ok(match left {
Value::Null => todo!(),
Value::Dimension(num, unit) => match right {
Value::Dimension(num2, unit2) => {
if unit == Unit::None {
@ -479,7 +480,10 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
v => panic!("{:?}", v),
};
Ok(match left {
Value::Null => todo!(),
Value::Null => Value::String(
format!("/{}", right.to_css_string(self.span)?),
QuoteKind::None,
),
Value::Dimension(num, unit) => match right {
Value::Dimension(num2, unit2) => {
if !unit.comparable(&unit2) {
@ -512,7 +516,8 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
| Value::True
| Value::False
| Value::Important
| Value::Color(..) => Value::String(
| Value::Color(..)
| Value::ArgList(..) => Value::String(
format!("{}{}/{}", num, unit, right.to_css_string(self.span)?),
QuoteKind::None,
),
@ -524,7 +529,6 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
)
.into())
}
Value::ArgList(..) => todo!(),
},
Value::Color(c) => match right {
Value::String(s, q) => {
@ -556,12 +560,20 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
| Value::True
| Value::False
| Value::Dimension(..)
| Value::Color(..) => Value::String(
| Value::Color(..)
| Value::List(..)
| Value::ArgList(..) => Value::String(
format!("{}{}{}/{}", q1, s1, q1, right.to_css_string(self.span)?),
QuoteKind::None,
),
Value::Null => Value::String(format!("{}{}{}/", q1, s1, q1), QuoteKind::None),
_ => todo!(),
Value::Map(..) | Value::FunctionRef(..) => {
return Err((
format!("{} isn't a valid CSS value.", right.inspect(self.span)?),
self.span,
)
.into())
}
},
_ => match right {
Value::String(s, q) => Value::String(

View File

@ -278,6 +278,17 @@ test!(
"a {\n color: 1+/2;\n}\n",
"a {\n color: 1/2;\n}\n"
);
test!(
arglist_plus_number,
"@function foo($a...) {
@return $a + 1;
}
a {
color: foo(a, b);
}",
"a {\n color: a, b1;\n}\n"
);
error!(
map_lhs_add,
"a {color: (a: b) + 1;}", "Error: (a: b) isn't a valid CSS value."

View File

@ -63,6 +63,52 @@ test!(
"a {\n color: 1 / red;\n}\n",
"a {\n color: 1/red;\n}\n"
);
test!(
dblquoted_string_div_space_separated_list,
"a {\n color: \"foo\"/(a b);\n}\n",
"a {\n color: \"foo\"/a b;\n}\n"
);
test!(
null_div_number,
"a {\n color: null / 1;\n}\n",
"a {\n color: /1;\n}\n"
);
test!(
null_div_dblquoted_string,
"a {\n color: null / \"foo\";\n}\n",
"a {\n color: /\"foo\";\n}\n"
);
test!(
number_div_arglist,
"@function foo($a...) {
@return 1 / $a;
}
a {
color: foo(a, b);
}",
"a {\n color: 1/a, b;\n}\n"
);
test!(
string_div_arglist,
"@function foo($a...) {
@return foo / $a;
}
a {
color: foo(a, b);
}",
"a {\n color: foo/a, b;\n}\n"
);
error!(
string_div_map,
"a {\n color: foo / (a: b);\n}\n", "Error: (a: b) isn't a valid CSS value."
);
error!(
string_div_function,
"a {\n color: foo / get-function(lighten);\n}\n",
"Error: get-function(\"lighten\") isn't a valid CSS value."
);
error!(
num_div_map,
"a {\n color: 1 / (a: b);\n}\n", "Error: (a: b) isn't a valid CSS value."

View File

@ -21,3 +21,7 @@ error!(
"a {color: 1 * get-function(lighten);}",
"Error: Undefined operation \"1 * get-function(\"lighten\")\"."
);
error!(
null_mul_number,
"a {color: null * 1;}", "Error: Undefined operation \"null * 1\"."
);

View File

@ -224,6 +224,41 @@ test!(
"a {\n color: null - foo;\n}\n",
"a {\n color: -foo;\n}\n"
);
test!(
number_minus_true,
"a {\n color: 1 - true;\n}\n",
"a {\n color: 1-true;\n}\n"
);
test!(
number_minus_false,
"a {\n color: 1 - false;\n}\n",
"a {\n color: 1-false;\n}\n"
);
test!(
number_minus_important,
"a {\n color: 1 - !important;\n}\n",
"a {\n color: 1-!important;\n}\n"
);
test!(
number_minus_null,
"a {\n color: 1 - null;\n}\n",
"a {\n color: 1-;\n}\n"
);
test!(
number_minus_arglist,
"@function foo($a...) {
@return 1 - $a;
}
a {
color: foo(a, b);
}",
"a {\n color: 1-a, b;\n}\n"
);
error!(
number_minus_color,
"a {\n color: 1 - #abc;\n}\n", "Error: Undefined operation \"1 - #abc\"."
);
error!(
null_minus_function,
"a {\n color: null - get-function(lighten);\n}\n",