handle map-merge key overlaps

This commit is contained in:
ConnorSkees 2020-03-30 16:33:43 -04:00
parent c8a21f3500
commit 4b1dc39705
2 changed files with 18 additions and 1 deletions

View File

@ -1,4 +1,5 @@
use std::slice::Iter;
use std::vec::IntoIter;
use super::Value;
use crate::error::SassResult;
@ -30,7 +31,9 @@ impl SassMap {
}
pub fn merge(&mut self, other: SassMap) {
self.0.extend(other.0);
for (key, value) in other.into_iter() {
self.insert(key, value);
}
}
pub fn iter(&self) -> Iter<(Value, Value)> {
@ -55,3 +58,12 @@ impl SassMap {
self.0.push((key, value));
}
}
impl IntoIterator for SassMap {
type Item = (Value, Value);
type IntoIter = IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

View File

@ -78,6 +78,11 @@ test!(
"a {\n color: inspect(map-merge((), ()));\n}\n",
"a {\n color: ();\n}\n"
);
test!(
map_merge_same_keys,
"a {\n color: inspect(map-merge((c: d, e: f), (c: 1, e: 2)));\n}\n",
"a {\n color: (c: 1, e: 2);\n}\n"
);
error!(
map_merge_map1_non_map,
"a {\n color: map-merge(foo, (a: b));\n}\n", "Error: $map1: foo is not a map."