ident equality ignores quotekind
This commit is contained in:
parent
9630343676
commit
103781e420
@ -138,13 +138,23 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn equals(self, other: Value) -> SassResult<bool> {
|
||||||
|
Ok(match self.eval()? {
|
||||||
|
Self::Ident(s1, ..) => match other {
|
||||||
|
Self::Ident(s2, ..) => s1 == s2,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
s @ _ => s == other.eval()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn eval(self) -> SassResult<Self> {
|
pub fn eval(self) -> SassResult<Self> {
|
||||||
match self {
|
match self {
|
||||||
Self::BinaryOp(lhs, op, rhs) => match op {
|
Self::BinaryOp(lhs, op, rhs) => match op {
|
||||||
Op::Plus => *lhs + *rhs,
|
Op::Plus => *lhs + *rhs,
|
||||||
Op::Minus => *lhs - *rhs,
|
Op::Minus => *lhs - *rhs,
|
||||||
Op::Equal => Ok(Self::bool(*lhs == *rhs)),
|
Op::Equal => Ok(Self::bool(lhs.equals(*rhs)?)),
|
||||||
Op::NotEqual => Ok(Self::bool(*lhs != *rhs)),
|
Op::NotEqual => Ok(Self::bool(!lhs.equals(*rhs)?)),
|
||||||
Op::Mul => *lhs * *rhs,
|
Op::Mul => *lhs * *rhs,
|
||||||
Op::Div => *lhs / *rhs,
|
Op::Div => *lhs / *rhs,
|
||||||
Op::Rem => *lhs % *rhs,
|
Op::Rem => *lhs % *rhs,
|
||||||
|
@ -358,3 +358,28 @@ test!(
|
|||||||
"a {\n color: '\\\'';\n}\n",
|
"a {\n color: '\\\'';\n}\n",
|
||||||
"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"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user