diff --git a/src/builtin/list.rs b/src/builtin/list.rs index 6d3f004..6063bbf 100644 --- a/src/builtin/list.rs +++ b/src/builtin/list.rs @@ -225,7 +225,10 @@ pub(crate) fn register(f: &mut HashMap) { v => vec![v], }; let value = arg!(args, 1, "value"); - let index = match list.into_iter().position(|v| v == value) { + let index = match list + .into_iter() + .position(|v| v.equals(value.clone()).unwrap()) + { Some(v) => Number::from(v + 1), None => return Ok(Value::Null), }; diff --git a/src/value/mod.rs b/src/value/mod.rs index aec30ca..7d4d46f 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -189,6 +189,21 @@ impl Value { Self::Ident(s2, ..) => s1 == s2, _ => false, }, + Self::Dimension(n, unit) => match other { + Self::Dimension(n2, unit2) => { + if !unit.comparable(&unit2) { + false + } else if unit == unit2 { + n == n2 + } else if unit == Unit::None || unit2 == Unit::None { + false + } else { + n == (n2 + * UNIT_CONVERSION_TABLE[&unit.to_string()][&unit2.to_string()].clone()) + } + } + _ => false, + }, s => s == other.eval()?, }) } diff --git a/tests/list.rs b/tests/list.rs index 56ca1a9..303aca1 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -293,3 +293,8 @@ test!( "a {\n color: index((width: 10px, height: 20px), (height 20px));\n}\n", "a {\n color: 2;\n}\n" ); +test!( + index_unit_conversions, + "a {\n color: index(1px 1in 1cm, 96px);\n}\n", + "a {\n color: 2;\n}\n" +); diff --git a/tests/number.rs b/tests/number.rs index a85b7c3..69775e0 100644 --- a/tests/number.rs +++ b/tests/number.rs @@ -86,3 +86,8 @@ test!( "a {\n color: -0.000000000001;\n}\n", "a {\n color: 0;\n}\n" ); +test!( + equality_unit_conversions, + "a {\n color: 1in == 96px;\n}\n", + "a {\n color: true;\n}\n" +);