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