1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.yaml.snakeyaml;
18
19 import java.io.StringReader;
20
21 import junit.framework.TestCase;
22
23 import org.yaml.snakeyaml.nodes.MappingNode;
24 import org.yaml.snakeyaml.nodes.Node;
25 import org.yaml.snakeyaml.nodes.NodeId;
26 import org.yaml.snakeyaml.nodes.ScalarNode;
27
28 public class YamlComposeTest extends TestCase {
29
30 public void testComposeManyDocuments() {
31 try {
32 Yaml yaml = new Yaml();
33 yaml.compose(new StringReader("abc: 56\n---\n123\n---\n456"));
34 fail("YAML contans more then one document.");
35 } catch (Exception e) {
36 assertEquals("expected a single document in the stream; but found another document",
37 e.getMessage());
38 }
39 }
40
41 public void testComposeFromReader() {
42 Yaml yaml = new Yaml();
43 MappingNode node = (MappingNode) yaml.compose(new StringReader("abc: 56"));
44 ScalarNode node1 = (ScalarNode) node.getValue().get(0).getKeyNode();
45 assertEquals("abc", node1.getValue());
46 ScalarNode node2 = (ScalarNode) node.getValue().get(0).getValueNode();
47 assertEquals("56", node2.getValue());
48 }
49
50 public void testComposeAllFromReader() {
51 Yaml yaml = new Yaml();
52 boolean first = true;
53 for (Node node : yaml.composeAll(new StringReader("abc: 56\n---\n123\n---\n456"))) {
54 if (first) {
55 assertEquals(NodeId.mapping, node.getNodeId());
56 } else {
57 assertEquals(NodeId.scalar, node.getNodeId());
58 }
59 first = false;
60 }
61 }
62
63 public void testComposeAllOneDocument() {
64 Yaml yaml = new Yaml();
65 for (Node node : yaml.composeAll(new StringReader("6"))) {
66 assertEquals(NodeId.scalar, node.getNodeId());
67 }
68 }
69 }