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.util.Iterator;
20
21 import junit.framework.TestCase;
22
23 import org.yaml.snakeyaml.error.YAMLException;
24
25 public class YamlTest extends TestCase {
26
27 public void testSetNoName() {
28 Yaml yaml = new Yaml();
29 assertTrue(yaml.toString().matches("Yaml:\\d+"));
30 }
31
32 public void testSetName() {
33 Yaml yaml = new Yaml();
34 yaml.setName("REST");
35 assertEquals("REST", yaml.getName());
36 assertEquals("REST", yaml.toString());
37 }
38
39
40
41
42 public void testOneDocument() {
43 Yaml yaml = new Yaml();
44 String doc = "--- a\n--- [:]";
45 Iterator<Object> loaded = yaml.loadAll(doc).iterator();
46 assertTrue(loaded.hasNext());
47 Object obj1 = loaded.next();
48 assertEquals("a", obj1);
49 assertTrue(loaded.hasNext());
50 try {
51 loaded.next();
52 fail("Second document is invalid");
53 } catch (Exception e) {
54 assertEquals("while parsing a flow node; expected the node content, but found Value",
55 e.getMessage());
56 }
57 }
58
59 public void testOnlyOneDocument() {
60 Yaml yaml = new Yaml();
61 String doc = "--- a\n--- b";
62 try {
63 yaml.load(doc);
64 fail("It must be only one document.");
65 } catch (YAMLException e) {
66 assertEquals("expected a single document in the stream; but found another document",
67 e.getMessage());
68 }
69 }
70 }