diff --git a/src/builtin/list.rs b/src/builtin/list.rs index 705beb3..1019e31 100644 --- a/src/builtin/list.rs +++ b/src/builtin/list.rs @@ -14,6 +14,7 @@ pub(crate) fn register(f: &mut HashMap) { max_args!(args, 1); let len = match arg!(args, 0, "list") { Value::List(v, ..) => Number::from(v.len()), + Value::Map(m) => Number::from(m.len()), _ => Number::one(), }; Ok(Value::Dimension(len, Unit::None)) diff --git a/src/value/map.rs b/src/value/map.rs index c98c0b7..0e3fe80 100644 --- a/src/value/map.rs +++ b/src/value/map.rs @@ -20,6 +20,10 @@ impl SassMap { Ok(None) } + pub fn len(&self) -> usize { + self.0.len() + } + #[allow(dead_code)] pub fn remove(&mut self, key: &Value) { self.0.retain(|(ref k, ..)| k != key); diff --git a/tests/map.rs b/tests/map.rs index 8f909e5..352a09e 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -76,3 +76,8 @@ test!( "a {\n color: inspect((a: b, c: d, e: f, g: h, i: j, h: k, l: m, n: o));\n}\n", "a {\n color: (a: b, c: d, e: f, g: h, i: j, h: k, l: m, n: o);\n}\n" ); +test!( + map_length, + "a {\n color: length((a: b, c: d, e: f));\n}\n", + "a {\n color: 3;\n}\n" +);