Implement Add for more types

This commit is contained in:
ConnorSkees 2020-02-03 15:36:11 -05:00
parent ed44f125f7
commit 6607101d4d
2 changed files with 27 additions and 5 deletions

View File

@ -83,10 +83,18 @@ impl Add for Value {
fn add(self, other: Self) -> Self {
match self {
// Self::Important => todo!(),
// Self::True => todo!(),
// Self::False => todo!(),
// Self::Null => todo!(),
Self::Important
| Self::True
| Self::False => match other {
Self::Ident(s, QuoteKind::Double)
| Self::Ident(s, QuoteKind::Single) => Value::Ident(format!("{}{}", self, s), QuoteKind::Double),
Self::Null => Value::Ident(self.to_string(), QuoteKind::None),
_ => Value::Ident(format!("{}{}", self, other), QuoteKind::None)
},
Self::Null => match other {
Self::Null => Self::Null,
_ => Value::Ident(format!("{}{}", self, other), QuoteKind::None)
},
Self::Dimension(num, unit) => match other {
Self::Dimension(num2, unit2) => Value::Dimension(num + num2, unit),
_ => todo!(),
@ -234,7 +242,6 @@ impl Value {
Value::Null => "null",
Value::BinaryOp(..) => self.eval().kind(),
_ => "unknown",
}
}

View File

@ -164,6 +164,21 @@ test!(
"a {\n color: 'red' + 1px;\n}\n",
"a {\n color: \"red1px\";\n}\n"
);
test!(
adds_true_false,
"a {\n color: true + false;\n}\n",
"a {\n color: truefalse;\n}\n"
);
test!(
adds_false_null_is_string,
"a {\n color: if(false+null, 1, 2);\n}\n",
"a {\n color: 1;\n}\n"
);
test!(
adds_null_num_is_string,
"a {\n color: null + 1;\n}\n",
"a {\n color: 1;\n}\n"
);
test!(
subs_idents,
"a {\n color: red - blue;\n}\n",