From 305581ad75a7bcae65c5ea33056e61c771ebf4cd Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 18 Apr 2020 20:11:49 -0400 Subject: [PATCH] properly error when attempting to display map --- src/value/mod.rs | 36 ++++++++++++++++++++---------------- tests/map.rs | 4 ++++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/value/mod.rs b/src/value/mod.rs index 93e0036..a38d76e 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -47,30 +47,23 @@ impl Value { _ => false, } } + pub fn to_css_string(&self, span: Span) -> SassResult { Ok(match self { Self::Important => format!("!important"), Self::Dimension(num, unit) => match unit { Unit::Mul(..) => { - return Err(( - format!("Error: {}{} isn't a valid CSS value.", num, unit), - span, - ) - .into()); + return Err((format!("{}{} isn't a valid CSS value.", num, unit), span).into()); } _ => format!("{}{}", num, unit), }, - Self::Map(map) => format!( - "({})", - map.iter() - .map(|(k, v)| Ok(format!( - "{}: {}", - k.to_css_string(span)?, - v.to_css_string(span)? - ))) - .collect::>>()? - .join(", ") - ), + Self::Map(..) => { + return Err(( + format!("{} isn't a valid CSS value.", dbg!(self.inspect(span)?)), + span, + ) + .into()) + } Self::Function(func) => format!("get-function(\"{}\")", func.name()), Self::List(vals, sep, brackets) => match brackets { Brackets::None => format!( @@ -195,6 +188,17 @@ impl Value { }, Value::Function(f) => format!("get-function(\"{}\")", f.name()), Value::Null => "null".to_string(), + Value::Map(map) => format!( + "({})", + map.iter() + .map(|(k, v)| Ok(format!( + "{}: {}", + k.to_css_string(span)?, + v.to_css_string(span)? + ))) + .collect::>>()? + .join(", ") + ), v => v.to_css_string(span)?, }) } diff --git a/tests/map.rs b/tests/map.rs index baba436..5596d42 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -133,3 +133,7 @@ error!( duplicate_key_in_declaration, "a {\n $a: (foo: a, foo: b);;\n}\n", "Error: Duplicate key." ); +error!( + display_map, + "a {\n color: (a: b, c: d);\n}\n", "Error: (a: b, c: d) isn't a valid CSS value." +);