1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.issues.issue124;
17
18 import junit.framework.TestCase;
19
20 import org.yaml.snakeyaml.DumperOptions;
21 import org.yaml.snakeyaml.DumperOptions.FlowStyle;
22 import org.yaml.snakeyaml.Yaml;
23 import org.yaml.snakeyaml.nodes.Tag;
24
25 public class DumpTest extends TestCase {
26
27 public void testDumperOptionsSideEffect() {
28 Yaml yaml = new Yaml();
29 Bean124 bean = new Bean124();
30 String output0 = yaml.dump(bean);
31
32 assertEquals("!!org.yaml.snakeyaml.issues.issue124.Bean124\na: aaa\nnumbers: [1, 2, 3]\n",
33 output0);
34 String output1 = yaml.dumpAsMap(bean);
35
36 assertEquals("a: aaa\nnumbers:\n- 1\n- 2\n- 3\n", output1);
37 String output2 = yaml.dump(bean);
38
39 assertEquals("Yaml.dumpAs() should not have any side effects.", output0, output2);
40 }
41
42 public void testDumperDifferentTag() {
43 Yaml yaml = new Yaml();
44 Bean124 bean = new Bean124();
45 String output1 = yaml.dumpAs(bean, new Tag("!!foo.bar"), FlowStyle.BLOCK);
46 assertEquals("!!foo.bar\na: aaa\nnumbers:\n- 1\n- 2\n- 3\n", output1);
47 }
48
49 public void testDumperFlowStyle() {
50 Yaml yaml = new Yaml();
51 Bean124 bean = new Bean124();
52 String output1 = yaml.dumpAs(bean, new Tag("!!foo.bar"), FlowStyle.FLOW);
53 assertEquals("!!foo.bar {a: aaa, numbers: [1, 2, 3]}\n", output1);
54 }
55
56 public void testDumperAutoStyle() {
57 Yaml yaml = new Yaml();
58 Bean124 bean = new Bean124();
59 String output1 = yaml.dumpAs(bean, new Tag("!!foo.bar"), FlowStyle.AUTO);
60 assertEquals("!!foo.bar\na: aaa\nnumbers: [1, 2, 3]\n", output1);
61 }
62
63 public void testDumperNullStyle() {
64 Yaml yaml = new Yaml();
65 Bean124 bean = new Bean124();
66 String output1 = yaml.dumpAs(bean, new Tag("!!foo.bar"), null);
67 assertEquals("!!foo.bar\na: aaa\nnumbers: [1, 2, 3]\n", output1);
68 }
69
70 public void testDumperNullStyle2() {
71 DumperOptions options = new DumperOptions();
72 options.setDefaultFlowStyle(FlowStyle.BLOCK);
73 Yaml yaml = new Yaml(options);
74 Bean124 bean = new Bean124();
75 String output1 = yaml.dumpAs(bean, new Tag("!!foo2.bar2"), null);
76 assertEquals("!!foo2.bar2\na: aaa\nnumbers:\n- 1\n- 2\n- 3\n", output1);
77 }
78
79 public void testDumperNullTag() {
80 Yaml yaml = new Yaml();
81 Bean124 bean = new Bean124();
82 String output1 = yaml.dumpAs(bean, null, FlowStyle.BLOCK);
83 assertEquals(
84 "!!org.yaml.snakeyaml.issues.issue124.Bean124\na: aaa\nnumbers:\n- 1\n- 2\n- 3\n",
85 output1);
86 }
87 }