Skip to content

Commit

Permalink
Fix override key bug (#19)
Browse files Browse the repository at this point in the history
* Fix override key bug

* Fix check

Signed-off-by: Xuanwo <github@xuanwo.io>

Signed-off-by: Xuanwo <github@xuanwo.io>
Co-authored-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
kgtkr and Xuanwo authored Sep 15, 2022
1 parent 7e47c76 commit 9cf94c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ mod tests {
}

/// This test is ported from [softprops/envy](https://github.com/softprops/envy/blob/801d81e7c3e443470e110bf4e34460acba113476/src/lib.rs#L410)
#[derive(Deserialize, Debug, PartialEq)]
#[derive(Deserialize, Debug, PartialEq, Eq)]
pub struct Foo {
bar: String,
baz: bool,
Expand All @@ -554,7 +554,7 @@ mod tests {
8080
}

#[derive(Deserialize, Debug, PartialEq, Default)]
#[derive(Deserialize, Debug, PartialEq, Eq, Default)]
pub struct CustomNewType(u32);

#[test]
Expand Down
8 changes: 6 additions & 2 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ impl Node {

match k.split_once('_') {
None => {
self.1.insert(k.to_string(), Self::new(v));
self.1
.entry(k.to_string())
.or_insert_with(|| Node::new(""))
.0 = v.to_string();
}
Some((k, remain)) => match self.1.get_mut(k) {
None => {
Expand Down Expand Up @@ -162,6 +165,7 @@ mod tests {
root.push("a_b_c_d", "Hello, World!");
root.push("a_b_c_e", "Hello, Mars!");
root.push("a_b_f", "Hello, Moon!");
root.push("a", "Hello, Earth!");

assert_eq!(
root,
Expand All @@ -170,7 +174,7 @@ mod tests {
BTreeMap::from([(
"a".to_string(),
Node(
"".to_string(),
"Hello, Earth!".to_string(),
BTreeMap::from([(
"b".to_string(),
Node(
Expand Down

0 comments on commit 9cf94c8

Please sign in to comment.