color addition is undefined

This commit is contained in:
ConnorSkees 2020-02-17 10:39:32 -05:00
parent 844b506872
commit fa665ae55f
2 changed files with 21 additions and 4 deletions

View File

@ -4,7 +4,7 @@ use crate::common::QuoteKind;
use crate::error::SassResult; use crate::error::SassResult;
use crate::units::Unit; use crate::units::Unit;
use crate::value::Value; use crate::value::Value;
// Undefined operation "red + white".
impl Add for Value { impl Add for Value {
type Output = SassResult<Self>; type Output = SassResult<Self>;
@ -30,16 +30,17 @@ impl Add for Value {
}; };
Value::Ident(format!("{}{}{}", num, unit, s), quotes) Value::Ident(format!("{}{}{}", num, unit, s), quotes)
} }
Self::Null => Value::Ident(format!("{}{}", num, unit), QuoteKind::None),
_ => todo!(), _ => todo!(),
}, },
// Self::List(..) => todo!(), // Self::List(..) => todo!(),
Self::Color(c) => match other { Self::Color(c) => match dbg!(&other) {
Self::Ident(s, QuoteKind::Double) | Self::Ident(s, QuoteKind::Single) => { Self::Ident(s, QuoteKind::Double) | Self::Ident(s, QuoteKind::Single) => {
Value::Ident(format!("{}{}", c, s), QuoteKind::Double) Value::Ident(format!("{}{}", c, s), QuoteKind::Double)
} }
Self::Ident(s, QuoteKind::None) => Value::Ident(format!("{}{}", c, s), QuoteKind::None),
Self::Null => Value::Ident(c.to_string(), QuoteKind::None), Self::Null => Value::Ident(c.to_string(), QuoteKind::None),
Self::Color(..) => todo!("figure out if it's possible to add colors"), _ => return Err(format!("Undefined operation \"{} + {}\".", c, other).into()),
_ => Value::Ident(format!("{}{}", c, other), QuoteKind::None),
}, },
// Self::BinaryOp(..) => todo!(), // Self::BinaryOp(..) => todo!(),
// Self::Paren(..) => todo!(), // Self::Paren(..) => todo!(),

View File

@ -321,3 +321,19 @@ test!(
); );
test!(positive_float_leading_zero, "a {\n color: 0.1;\n}\n"); test!(positive_float_leading_zero, "a {\n color: 0.1;\n}\n");
test!(negative_float_leading_zero, "a {\n color: -0.1;\n}\n"); test!(negative_float_leading_zero, "a {\n color: -0.1;\n}\n");
test!(
unitless_plus_null,
"a {\n color: 1 + null;\n}\n",
"a {\n color: 1;\n}\n"
);
// blocked on proper parsing of binary ops
// test!(
// unitless_plus_null_plus_unitless,
// "a {\n color: 1 + null + 1;\n}\n",
// "a {\n color: 11;\n}\n"
// );
test!(
unit_plus_null,
"a {\n color: 1px + null;\n}\n",
"a {\n color: 1px;\n}\n"
);