implement length for maps

This commit is contained in:
ConnorSkees 2020-03-30 16:01:44 -04:00
parent eb478b632d
commit 23f7301a25
3 changed files with 10 additions and 0 deletions

View File

@ -14,6 +14,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
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))

View File

@ -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);

View File

@ -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"
);