Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Add yaml merge test from draft spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 28, 2022
1 parent d87b671 commit 4de6b48
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_value.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::derive_partial_eq_without_eq, clippy::eq_op)]

use indoc::indoc;
use serde::de::IntoDeserializer;
use serde::Deserialize;
use serde_derive::Deserialize;
Expand Down Expand Up @@ -52,3 +53,43 @@ fn test_into_deserializer() {
}
);
}

#[test]
fn test_merge() {
// From https://yaml.org/type/merge.html.
let yaml = indoc! {"
---
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }
# All the following maps are equal:
- # Explicit keys
x: 1
y: 2
r: 10
label: center/big
- # Merge one map
<< : *CENTER
r: 10
label: center/big
- # Merge multiple maps
<< : [ *CENTER, *BIG ]
label: center/big
- # Override
<< : [ *BIG, *LEFT, *SMALL ]
x: 1
label: center/big
"};

let mut value: Value = serde_yaml::from_str(yaml).unwrap();
value.apply_merge().unwrap();
for i in 5..=7 {
assert_eq!(value[4], value[i]);
}
}

0 comments on commit 4de6b48

Please sign in to comment.