Skip to content

Commit

Permalink
Update YamlTest.java (#1041)
Browse files Browse the repository at this point in the history
Add tests from the [YAML Merge Key Draft](https://yaml.org/type/merge.html)
  • Loading branch information
zstadler authored Sep 28, 2024
1 parent d36dad3 commit 086e284
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,76 @@ void testMergeOperatorSecond() {
""");
}

@Test
void testMergeOperatorFromDraft1() {
assertSameYaml("""
- { x: 1, y: 2 }
- { x: 0, y: 2 }
- { r: 10 }
- { r: 1 }
- # Explicit keys
x: 1
y: 2
r: 10
label: center/big
""", """
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }
- # Merge one map
<< : *CENTER
r: 10
label: center/big
""");

@Test
void testMergeOperatorFromDraft2() {
assertSameYaml("""
- { x: 1, y: 2 }
- { x: 0, y: 2 }
- { r: 10 }
- { r: 1 }
- # Explicit keys
x: 1
y: 2
r: 10
label: center/big
""", """
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }
- # Merge multiple maps
<< : [ *CENTER, *BIG ]
label: center/big
""");
}

@Test
void testMergeOperatorFromDraft3() {
assertSameYaml("""
- { x: 1, y: 2 }
- { x: 0, y: 2 }
- { r: 10 }
- { r: 1 }
- # Explicit keys
x: 1
y: 2
r: 10
label: center/big
""", """
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }
- # Override
<< : [ *BIG, *LEFT, *SMALL ]
x: 1
label: center/big
""");
}

private static void assertSameYaml(String a, String b) {
assertEquals(
YAML.load(b, Object.class),
Expand Down

0 comments on commit 086e284

Please sign in to comment.