From fa665ae55f8ea1a3004ec7737b8218a973189774 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 17 Feb 2020 10:39:32 -0500 Subject: [PATCH] color addition is undefined --- src/value/ops.rs | 9 +++++---- tests/values.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/value/ops.rs b/src/value/ops.rs index a3192ee..5ae5580 100644 --- a/src/value/ops.rs +++ b/src/value/ops.rs @@ -4,7 +4,7 @@ use crate::common::QuoteKind; use crate::error::SassResult; use crate::units::Unit; use crate::value::Value; -// Undefined operation "red + white". + impl Add for Value { type Output = SassResult; @@ -30,16 +30,17 @@ impl Add for Value { }; Value::Ident(format!("{}{}{}", num, unit, s), quotes) } + Self::Null => Value::Ident(format!("{}{}", num, unit), QuoteKind::None), _ => 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) => { 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::Color(..) => todo!("figure out if it's possible to add colors"), - _ => Value::Ident(format!("{}{}", c, other), QuoteKind::None), + _ => return Err(format!("Undefined operation \"{} + {}\".", c, other).into()), }, // Self::BinaryOp(..) => todo!(), // Self::Paren(..) => todo!(), diff --git a/tests/values.rs b/tests/values.rs index dbcc2f6..0bee0d4 100644 --- a/tests/values.rs +++ b/tests/values.rs @@ -321,3 +321,19 @@ test!( ); 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!( + 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" +);