implement map-remove
This commit is contained in:
parent
8e3e23c6cd
commit
ef1177ccca
@ -81,4 +81,19 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Ok(Value::Map(map1))
|
Ok(Value::Map(map1))
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
f.insert(
|
||||||
|
"map-remove".to_owned(),
|
||||||
|
Box::new(|mut args, _| {
|
||||||
|
let mut map = match arg!(args, 0, "map") {
|
||||||
|
Value::Map(m) => m,
|
||||||
|
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
||||||
|
v => return Err(format!("$map: {} is not a map.", v).into()),
|
||||||
|
};
|
||||||
|
let keys = args.get_variadic()?;
|
||||||
|
for key in keys {
|
||||||
|
map.remove(&key);
|
||||||
|
}
|
||||||
|
Ok(Value::Map(map))
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
10
tests/map.rs
10
tests/map.rs
@ -119,3 +119,13 @@ error!(
|
|||||||
map_has_key_one_arg,
|
map_has_key_one_arg,
|
||||||
"a {\n color: map-has-key(1);\n}\n", "Error: Missing argument $key."
|
"a {\n color: map-has-key(1);\n}\n", "Error: Missing argument $key."
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
map_remove_one,
|
||||||
|
"a {\n color: inspect(map-remove((\"foo\": 1, \"bar\": 2), \"bar\"));\n}\n",
|
||||||
|
"a {\n color: (\"foo\": 1);\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
map_remove_two,
|
||||||
|
"a {\n color: inspect(map-remove((\"foo\": 1, \"bar\": 2, \"baz\": 3), \"bar\", \"baz\"));\n}\n",
|
||||||
|
"a {\n color: (\"foo\": 1);\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user