Add another test for issue 139
diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue139/MergeValueTest.java b/src/test/java/org/yaml/snakeyaml/issues/issue139/MergeValueTest.java
index 6a47af3..460ba84 100644
--- a/src/test/java/org/yaml/snakeyaml/issues/issue139/MergeValueTest.java
+++ b/src/test/java/org/yaml/snakeyaml/issues/issue139/MergeValueTest.java
@@ -40,6 +40,7 @@
private void check(String name) {
String input = Util.getLocalResource(name);
+ // System.out.println(input);
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) yaml.load(input);
@@ -48,4 +49,22 @@
assertTrue(map.containsKey("production"));
assertEquals(map.get("common"), map.get("production"));
}
+
+ /**
+ * http://yaml.org/type/merge.html: If the value associated with the key is
+ * a single mapping node, each of its key/value pairs is inserted into the
+ * current mapping, <b>unless the key already exists in it</b>.
+ */
+ @SuppressWarnings("unchecked")
+ public void testMergeUnlessAlreadyExists() {
+ String input = Util.getLocalResource("issues/issue139-3.yaml");
+ // System.out.println(input);
+ Yaml yaml = new Yaml();
+ Map<String, Object> map = (Map<String, Object>) yaml.load(input);
+ assertEquals(2, map.size());
+ Map<String, Integer> common = (Map<String, Integer>) map.get("common");
+ Map<String, Integer> production = (Map<String, Integer>) map.get("production");
+ assertEquals(new Integer(2), common.get("key"));
+ assertEquals(new Integer(3), production.get("key"));
+ }
}
diff --git a/src/test/resources/issues/issue139-2.yaml b/src/test/resources/issues/issue139-2.yaml
index 179122e..ca2967c 100644
--- a/src/test/resources/issues/issue139-2.yaml
+++ b/src/test/resources/issues/issue139-2.yaml
@@ -1,6 +1,6 @@
common: &id_common
key: 1
- key: 2
+ key: 2 # this value must overwrite the previous. Is it specified ?
production:
<<: *id_common
\ No newline at end of file
diff --git a/src/test/resources/issues/issue139-3.yaml b/src/test/resources/issues/issue139-3.yaml
new file mode 100644
index 0000000..3b5d0d9
--- /dev/null
+++ b/src/test/resources/issues/issue139-3.yaml
@@ -0,0 +1,7 @@
+common: &id_common
+ key: 1
+ key: 2
+
+production:
+ <<: *id_common
+ key: 3 # this value must stay
\ No newline at end of file