From 103781e4208509e425ee27dc9711b212bb55b467 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Wed, 18 Mar 2020 17:23:38 -0400 Subject: [PATCH] ident equality ignores quotekind --- src/value/mod.rs | 14 ++++++++++++-- tests/values.rs | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/value/mod.rs b/src/value/mod.rs index 0c62dad..0c9e0d5 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -138,13 +138,23 @@ impl Value { } } + pub fn equals(self, other: Value) -> SassResult { + Ok(match self.eval()? { + Self::Ident(s1, ..) => match other { + Self::Ident(s2, ..) => s1 == s2, + _ => false, + } + s @ _ => s == other.eval()?, + }) + } + pub fn eval(self) -> SassResult { match self { Self::BinaryOp(lhs, op, rhs) => match op { Op::Plus => *lhs + *rhs, Op::Minus => *lhs - *rhs, - Op::Equal => Ok(Self::bool(*lhs == *rhs)), - Op::NotEqual => Ok(Self::bool(*lhs != *rhs)), + Op::Equal => Ok(Self::bool(lhs.equals(*rhs)?)), + Op::NotEqual => Ok(Self::bool(!lhs.equals(*rhs)?)), Op::Mul => *lhs * *rhs, Op::Div => *lhs / *rhs, Op::Rem => *lhs % *rhs, diff --git a/tests/values.rs b/tests/values.rs index 44d9728..f383b44 100644 --- a/tests/values.rs +++ b/tests/values.rs @@ -358,3 +358,28 @@ test!( "a {\n color: '\\\'';\n}\n", "a {\n color: \"'\";\n}\n" ); +test!( + color_equals_color, + "a {\n color: red == red;\n}\n", + "a {\n color: true;\n}\n" +); +test!( + color_does_not_equal_color, + "a {\n color: red != red;\n}\n", + "a {\n color: false;\n}\n" +); +test!( + unquoted_ident_eq_unquoted_ident, + "a {\n color: foo == foo;\n}\n", + "a {\n color: true;\n}\n" +); +test!( + dblquoted_ident_eq_unquoted_ident, + "a {\n color: \"foo\" == foo;\n}\n", + "a {\n color: true;\n}\n" +); +test!( + dblquoted_ident_eq_sglquoted_ident, + "a {\n color: \"foo\" == 'foo';\n}\n", + "a {\n color: true;\n}\n" +);