1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml;
17
18 import java.util.Iterator;
19
20 import junit.framework.TestCase;
21
22 import org.yaml.snakeyaml.error.YAMLException;
23
24 public class YamlTest extends TestCase {
25
26 public void testSetNoName() {
27 Yaml yaml = new Yaml();
28 assertTrue(yaml.toString().matches("Yaml:\\d+"));
29 }
30
31 public void testSetName() {
32 Yaml yaml = new Yaml();
33 yaml.setName("REST");
34 assertEquals("REST", yaml.getName());
35 assertEquals("REST", yaml.toString());
36 }
37
38
39
40
41 public void testOneDocument() {
42 Yaml yaml = new Yaml();
43 String doc = "--- a\n--- [:]";
44 Iterator<Object> loaded = yaml.loadAll(doc).iterator();
45 assertTrue(loaded.hasNext());
46 Object obj1 = loaded.next();
47 assertEquals("a", obj1);
48 assertTrue(loaded.hasNext());
49 try {
50 loaded.next();
51 fail("Second document is invalid");
52 } catch (Exception e) {
53 assertEquals(
54 "while parsing a flow node; expected the node content, but found Value; in 'reader', line 2, column 6:\n --- [:]\n ^",
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(
67 "expected a single document in the stream; but found another document; in 'string', line 2, column 1:\n --- b\n ^",
68 e.getMessage());
69 }
70 }
71 }