implement length for maps
This commit is contained in:
parent
eb478b632d
commit
23f7301a25
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user