1147f7fe6d67bd8282815c97cc6fe7330263de178Andrey Somov/**
211a89b445f3bde56bf07e6a0d04f0b0256dcb215Andrey Somov * Copyright (c) 2008, http://www.snakeyaml.org
31adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov *
41adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov * Licensed under the Apache License, Version 2.0 (the "License");
51adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov * you may not use this file except in compliance with the License.
61adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov * You may obtain a copy of the License at
71adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov *
81adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov *     http://www.apache.org/licenses/LICENSE-2.0
91adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov *
101adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov * Unless required by applicable law or agreed to in writing, software
111adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov * distributed under the License is distributed on an "AS IS" BASIS,
121adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov * See the License for the specific language governing permissions and
141adf3a94fce500e0bda933e4b495a004d5789bd7Andrey Somov * limitations under the License.
15147f7fe6d67bd8282815c97cc6fe7330263de178Andrey Somov */
169629be70863521bead138c295351f3dec926ab1Andrey Somovpackage org.yaml.snakeyaml;
179629be70863521bead138c295351f3dec926ab1Andrey Somov
18390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somovimport java.util.ArrayList;
1937f2f1c81f4a5be14db404db4e73f3dca6aa82f2Andrey Somovimport java.util.LinkedHashMap;
209629be70863521bead138c295351f3dec926ab1Andrey Somovimport java.util.List;
219629be70863521bead138c295351f3dec926ab1Andrey Somovimport java.util.Map;
229629be70863521bead138c295351f3dec926ab1Andrey Somov
239629be70863521bead138c295351f3dec926ab1Andrey Somovimport junit.framework.TestCase;
249629be70863521bead138c295351f3dec926ab1Andrey Somov
259629be70863521bead138c295351f3dec926ab1Andrey Somovimport org.yaml.snakeyaml.emitter.Emitter;
269629be70863521bead138c295351f3dec926ab1Andrey Somovimport org.yaml.snakeyaml.error.YAMLException;
2787ff57908e8ccf62ef984bb067a61b815a9a1074Andrey Somovimport org.yaml.snakeyaml.nodes.Tag;
28b900be137196b0528076fa46620a1c481229fcfaAndrey Somovimport org.yaml.snakeyaml.representer.Representer;
299629be70863521bead138c295351f3dec926ab1Andrey Somov
309629be70863521bead138c295351f3dec926ab1Andrey Somovpublic class DumperOptionsTest extends TestCase {
319629be70863521bead138c295351f3dec926ab1Andrey Somov
329629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testDefaultStyle() {
339629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
34def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml(options);
359629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("abc\n", yaml.dump("abc"));
369629be70863521bead138c295351f3dec926ab1Andrey Somov        // string which looks like integer
379629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("'123'\n", yaml.dump("123"));
389629be70863521bead138c295351f3dec926ab1Andrey Somov        //
39eeb19af1d1bacf12b955cf4a93773294a98b6de1as        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
40def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
419629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("\"123\"\n", yaml.dump("123"));
429629be70863521bead138c295351f3dec926ab1Andrey Somov        //
43eeb19af1d1bacf12b955cf4a93773294a98b6de1as        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.SINGLE_QUOTED);
44def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
459629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("'123'\n", yaml.dump("123"));
469629be70863521bead138c295351f3dec926ab1Andrey Somov        //
47eeb19af1d1bacf12b955cf4a93773294a98b6de1as        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
48def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
499629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("'123'\n", yaml.dump("123"));
509629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("abc\n", yaml.dump("abc"));
519629be70863521bead138c295351f3dec926ab1Andrey Somov        // null check
529629be70863521bead138c295351f3dec926ab1Andrey Somov        try {
53eeb19af1d1bacf12b955cf4a93773294a98b6de1as            options.setDefaultScalarStyle(null);
549629be70863521bead138c295351f3dec926ab1Andrey Somov            fail("Null must not be accepted.");
559629be70863521bead138c295351f3dec926ab1Andrey Somov        } catch (NullPointerException e) {
56eeb19af1d1bacf12b955cf4a93773294a98b6de1as            assertEquals("Use ScalarStyle enum.", e.getMessage());
579629be70863521bead138c295351f3dec926ab1Andrey Somov        }
589629be70863521bead138c295351f3dec926ab1Andrey Somov    }
599629be70863521bead138c295351f3dec926ab1Andrey Somov
609629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testDefaultFlowStyle() {
61def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
62390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
639629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(1);
649629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(2);
659629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(3);
669629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("[1, 2, 3]\n", yaml.dump(list));
679629be70863521bead138c295351f3dec926ab1Andrey Somov        //
689629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
699629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
70eeb19af1d1bacf12b955cf4a93773294a98b6de1as        options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
71def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
729629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("[1, 2, 3]\n", yaml.dump(list));
739629be70863521bead138c295351f3dec926ab1Andrey Somov        //
749629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
758cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
768cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        options.setPrettyFlow(true);
77def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
788cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        assertEquals("[\n  1,\n  2,\n  3]\n", yaml.dump(list));
798cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        //
808cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        options = new DumperOptions();
81eeb19af1d1bacf12b955cf4a93773294a98b6de1as        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
82def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
839629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("- 1\n- 2\n- 3\n", yaml.dump(list));
849629be70863521bead138c295351f3dec926ab1Andrey Somov        // null check
859629be70863521bead138c295351f3dec926ab1Andrey Somov        try {
869629be70863521bead138c295351f3dec926ab1Andrey Somov            options.setDefaultFlowStyle(null);
879629be70863521bead138c295351f3dec926ab1Andrey Somov            fail("Null must not be accepted.");
889629be70863521bead138c295351f3dec926ab1Andrey Somov        } catch (NullPointerException e) {
89eeb19af1d1bacf12b955cf4a93773294a98b6de1as            assertEquals("Use FlowStyle enum.", e.getMessage());
909629be70863521bead138c295351f3dec926ab1Andrey Somov        }
919629be70863521bead138c295351f3dec926ab1Andrey Somov    }
929629be70863521bead138c295351f3dec926ab1Andrey Somov
939629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testDefaultFlowStyleNested() {
94def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
95390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
969629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(1);
979629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(2);
989629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(3);
999629be70863521bead138c295351f3dec926ab1Andrey Somov        Map<String, Object> map = new LinkedHashMap<String, Object>();
1009629be70863521bead138c295351f3dec926ab1Andrey Somov        map.put("a", "b");
1019629be70863521bead138c295351f3dec926ab1Andrey Somov        map.put("c", list);
102fd03e2da32bb87716104bcdfc5b454ae970b277aAndrey Somov        String result = yaml.dump(map);
1038cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        assertEquals("a: b\nc: [1, 2, 3]\n", result);
1049629be70863521bead138c295351f3dec926ab1Andrey Somov        //
1059629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
1069629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
107eeb19af1d1bacf12b955cf4a93773294a98b6de1as        options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
108def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
1099629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("{a: b, c: [1, 2, 3]}\n", yaml.dump(map));
1109629be70863521bead138c295351f3dec926ab1Andrey Somov        //
1119629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
1128cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
1138cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        options.setPrettyFlow(true);
114def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
115fd03e2da32bb87716104bcdfc5b454ae970b277aAndrey Somov        result = yaml.dump(map);
1168cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        assertEquals("{\n  a: b,\n  c: [\n    1,\n    2,\n    3]\n  \n}\n", result);
1178cda6fba9cc20d9210a50e13a81b37affb84b39bobastard        //
118fd03e2da32bb87716104bcdfc5b454ae970b277aAndrey Somov        options = new DumperOptions();
119eeb19af1d1bacf12b955cf4a93773294a98b6de1as        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
120def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
1219629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("a: b\nc:\n- 1\n- 2\n- 3\n", yaml.dump(map));
1229629be70863521bead138c295351f3dec926ab1Andrey Somov    }
1239629be70863521bead138c295351f3dec926ab1Andrey Somov
1249629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testCanonical() {
125def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
1269629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("123\n", yaml.dump(123));
1279629be70863521bead138c295351f3dec926ab1Andrey Somov        //
1289629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
1299629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
1309629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setCanonical(true);
131def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
1329629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("---\n!!int \"123\"\n", yaml.dump(123));
1339629be70863521bead138c295351f3dec926ab1Andrey Somov        //
1349629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
1359629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setCanonical(false);
136def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
1379629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("123\n", yaml.dump(123));
1389629be70863521bead138c295351f3dec926ab1Andrey Somov    }
1399629be70863521bead138c295351f3dec926ab1Andrey Somov
1409629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testIndent() {
141def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
142390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
1439629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(1);
1449629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(2);
1459629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
1469629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setCanonical(true);
147def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
1489629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("---\n!!seq [\n  !!int \"1\",\n  !!int \"2\",\n]\n", yaml.dump(list));
1499629be70863521bead138c295351f3dec926ab1Andrey Somov        //
1509629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setIndent(4);
151def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
1529629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("---\n!!seq [\n    !!int \"1\",\n    !!int \"2\",\n]\n", yaml.dump(list));
1539629be70863521bead138c295351f3dec926ab1Andrey Somov        //
1549629be70863521bead138c295351f3dec926ab1Andrey Somov        try {
1559629be70863521bead138c295351f3dec926ab1Andrey Somov            options.setIndent(0);
1569629be70863521bead138c295351f3dec926ab1Andrey Somov            fail();
1579629be70863521bead138c295351f3dec926ab1Andrey Somov        } catch (YAMLException e) {
1589629be70863521bead138c295351f3dec926ab1Andrey Somov            assertTrue(true);
1599629be70863521bead138c295351f3dec926ab1Andrey Somov        }
1609629be70863521bead138c295351f3dec926ab1Andrey Somov        try {
1619629be70863521bead138c295351f3dec926ab1Andrey Somov            options.setIndent(-2);
1629629be70863521bead138c295351f3dec926ab1Andrey Somov            fail();
1639629be70863521bead138c295351f3dec926ab1Andrey Somov        } catch (YAMLException e) {
1649629be70863521bead138c295351f3dec926ab1Andrey Somov            assertTrue(true);
1659629be70863521bead138c295351f3dec926ab1Andrey Somov        }
1669629be70863521bead138c295351f3dec926ab1Andrey Somov        try {
1679629be70863521bead138c295351f3dec926ab1Andrey Somov            options.setIndent(11);
1689629be70863521bead138c295351f3dec926ab1Andrey Somov            fail();
1699629be70863521bead138c295351f3dec926ab1Andrey Somov        } catch (YAMLException e) {
1709629be70863521bead138c295351f3dec926ab1Andrey Somov            assertTrue(true);
1719629be70863521bead138c295351f3dec926ab1Andrey Somov        }
1729629be70863521bead138c295351f3dec926ab1Andrey Somov        //
1739629be70863521bead138c295351f3dec926ab1Andrey Somov        assertTrue(Emitter.MIN_INDENT > 0);
1749629be70863521bead138c295351f3dec926ab1Andrey Somov        assertTrue(Emitter.MIN_INDENT < Emitter.MAX_INDENT);
1759629be70863521bead138c295351f3dec926ab1Andrey Somov        assertTrue(Emitter.MAX_INDENT < 20);
1769629be70863521bead138c295351f3dec926ab1Andrey Somov    }
1779629be70863521bead138c295351f3dec926ab1Andrey Somov
1789629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testLineBreak() {
179def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
180390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
1819629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(1);
1829629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(2);
1839629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
1849629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setCanonical(true);
185def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
1869629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("---\n!!seq [\n  !!int \"1\",\n  !!int \"2\",\n]\n", yaml.dump(list));
1879629be70863521bead138c295351f3dec926ab1Andrey Somov        //
1889629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setLineBreak(DumperOptions.LineBreak.WIN);
189def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
1909629be70863521bead138c295351f3dec926ab1Andrey Somov        String output = yaml.dump(list);
1919629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("---\r\n!!seq [\r\n  !!int \"1\",\r\n  !!int \"2\",\r\n]\r\n", output);
1929629be70863521bead138c295351f3dec926ab1Andrey Somov        // null check
1939629be70863521bead138c295351f3dec926ab1Andrey Somov        try {
1949629be70863521bead138c295351f3dec926ab1Andrey Somov            options.setLineBreak(null);
1959629be70863521bead138c295351f3dec926ab1Andrey Somov            fail("Null must not be accepted.");
1969629be70863521bead138c295351f3dec926ab1Andrey Somov        } catch (NullPointerException e) {
1979629be70863521bead138c295351f3dec926ab1Andrey Somov            assertEquals("Specify line break.", e.getMessage());
1989629be70863521bead138c295351f3dec926ab1Andrey Somov        }
1999629be70863521bead138c295351f3dec926ab1Andrey Somov    }
2009629be70863521bead138c295351f3dec926ab1Andrey Somov
2013c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov    public void testLineBreakForPlatform() {
2023c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov        DumperOptions.LineBreak lineBreak = DumperOptions.LineBreak.getPlatformLineBreak();
203964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov        assertEquals("Line break must match platform's default.",
204964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov                System.getProperty("line.separator"), lineBreak.getString());
2053c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov        //
206def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
207390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
2083c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov        list.add(1);
2093c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov        list.add(2);
2103c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov        DumperOptions options = new DumperOptions();
2113c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov        options.setLineBreak(DumperOptions.LineBreak.getPlatformLineBreak());
212def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
2133c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov        assertEquals("[1, 2]", yaml.dump(list).trim());
2143c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov    }
2153c764a3c7b5174be3395d3b62eaa92ae0750d0d8Andrey Somov
216fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov    public void testLineBreakForPlatformUnix() {
217fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        System.setProperty("line.separator", "\n");
218fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        assertEquals("\n", System.getProperty("line.separator"));
219fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        DumperOptions.LineBreak lineBreak = DumperOptions.LineBreak.getPlatformLineBreak();
220964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov        assertEquals("Line break must match platform's default.",
221964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov                System.getProperty("line.separator"), lineBreak.getString());
222fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        assertEquals("Unknown Line break must match UNIX line break.", "\n", lineBreak.getString());
223fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov    }
224fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov
225fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov    public void testLineBreakForPlatformMac() {
226fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        System.setProperty("line.separator", "\r");
227fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        assertEquals("\r", System.getProperty("line.separator"));
228fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        DumperOptions.LineBreak lineBreak = DumperOptions.LineBreak.getPlatformLineBreak();
229964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov        assertEquals("Line break must match platform's default.",
230964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov                System.getProperty("line.separator"), lineBreak.getString());
231fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        assertEquals("Unknown Line break must match UNIX line break.", "\r", lineBreak.getString());
232fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov    }
233fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov
234fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov    public void testLineBreakForPlatformWin() {
235fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        System.setProperty("line.separator", "\r\n");
236fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        assertEquals("\r\n", System.getProperty("line.separator"));
237fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        DumperOptions.LineBreak lineBreak = DumperOptions.LineBreak.getPlatformLineBreak();
238964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov        assertEquals("Line break must match platform's default.",
239964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov                System.getProperty("line.separator"), lineBreak.getString());
240964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov        assertEquals("Unknown Line break must match UNIX line break.", "\r\n",
241964a641db77777caf35e57328e5c0d7d2a49e1baAndrey Somov                lineBreak.getString());
242fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov    }
243fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov
244fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov    public void testLineBreakForPlatformUnknown() {
245fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        System.setProperty("line.separator", "\n\r");
246fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        assertEquals("\n\r", System.getProperty("line.separator"));
247fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        DumperOptions.LineBreak lineBreak = DumperOptions.LineBreak.getPlatformLineBreak();
248fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        assertEquals("Unknown Line break must match UNIX line break.", "\n", lineBreak.getString());
249fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov    }
250fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov
2519629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testExplicitStart() {
252def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
253390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
2549629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(1);
2559629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(2);
2569629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(3);
2579629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("[1, 2, 3]\n", yaml.dump(list));
2589629be70863521bead138c295351f3dec926ab1Andrey Somov        //
2599629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
2609629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
2619629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setExplicitStart(true);
262def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
2639629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("--- [1, 2, 3]\n", yaml.dump(list));
2649629be70863521bead138c295351f3dec926ab1Andrey Somov        //
2659629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setExplicitEnd(true);
266def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
2679629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("--- [1, 2, 3]\n...\n", yaml.dump(list));
2689629be70863521bead138c295351f3dec926ab1Andrey Somov    }
2699629be70863521bead138c295351f3dec926ab1Andrey Somov
2709629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testVersion() {
271def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
272390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
2739629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(1);
2749629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(2);
2759629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(3);
2769629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("[1, 2, 3]\n", yaml.dump(list));
2779629be70863521bead138c295351f3dec926ab1Andrey Somov        //
2789629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
2799629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
2809629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setVersion(DumperOptions.Version.V1_1);
281def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
2829629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("%YAML 1.1\n--- [1, 2, 3]\n", yaml.dump(list));
2839629be70863521bead138c295351f3dec926ab1Andrey Somov        //
2849629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setVersion(DumperOptions.Version.V1_0);
285def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
2869629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("%YAML 1.0\n--- [1, 2, 3]\n", yaml.dump(list));
287fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        //
288fd5bf069edabec1beb31f3ba7c5f0212b36648c9Andrey Somov        assertEquals("Version: 1.1", DumperOptions.Version.V1_1.toString());
2899629be70863521bead138c295351f3dec926ab1Andrey Somov    }
2909629be70863521bead138c295351f3dec926ab1Andrey Somov
2919629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testTags() {
292def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
293390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
2949629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(1);
2959629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(2);
2969629be70863521bead138c295351f3dec926ab1Andrey Somov        list.add(3);
2979629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("[1, 2, 3]\n", yaml.dump(list));
2989629be70863521bead138c295351f3dec926ab1Andrey Somov        //
2999629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
3009629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
3019629be70863521bead138c295351f3dec926ab1Andrey Somov        Map<String, String> tags = new LinkedHashMap<String, String>();
3029629be70863521bead138c295351f3dec926ab1Andrey Somov        tags.put("!foo!", "bar");
3039629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setTags(tags);
304def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
3059629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("%TAG !foo! bar\n--- [1, 2, 3]\n", yaml.dump(list));
3069629be70863521bead138c295351f3dec926ab1Andrey Somov        //
3079629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
30887ff57908e8ccf62ef984bb067a61b815a9a1074Andrey Somov        tags.put("!yaml!", Tag.PREFIX);
309def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
3109629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("foo\n", yaml.dump("foo"));
3119629be70863521bead138c295351f3dec926ab1Andrey Somov    }
3129629be70863521bead138c295351f3dec926ab1Andrey Somov
3139629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testAllowUnicode() {
314def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        Yaml yaml = new Yaml();
3159629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("out: " + yaml.dump("\u00DCber"), "\u00DCber\n", yaml.dump("\u00DCber"));
3169629be70863521bead138c295351f3dec926ab1Andrey Somov        //
3179629be70863521bead138c295351f3dec926ab1Andrey Somov        DumperOptions options = new DumperOptions();
3189629be70863521bead138c295351f3dec926ab1Andrey Somov        options = new DumperOptions();
3199629be70863521bead138c295351f3dec926ab1Andrey Somov        options.setAllowUnicode(false);
320def9635e03df5f547cda12693af495d24d1b0a5bAndrey Somov        yaml = new Yaml(options);
3219629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("\"\\xdcber\"\n", yaml.dump("\u00DCber"));
3229629be70863521bead138c295351f3dec926ab1Andrey Somov    }
3239629be70863521bead138c295351f3dec926ab1Andrey Somov
3249629be70863521bead138c295351f3dec926ab1Andrey Somov    public void testToString() {
325eeb19af1d1bacf12b955cf4a93773294a98b6de1as        DumperOptions.ScalarStyle scalarStyle = DumperOptions.ScalarStyle.LITERAL;
3269629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("Scalar style: '|'", scalarStyle.toString());
3279629be70863521bead138c295351f3dec926ab1Andrey Somov        //
328eeb19af1d1bacf12b955cf4a93773294a98b6de1as        DumperOptions.FlowStyle flowStyle = DumperOptions.FlowStyle.BLOCK;
3299629be70863521bead138c295351f3dec926ab1Andrey Somov        assertEquals("Flow style: 'false'", flowStyle.toString());
3309629be70863521bead138c295351f3dec926ab1Andrey Somov        //
3310fb13a7243e99e536c01399986795bb1b3e13175Andrey Somov        DumperOptions.LineBreak lb = DumperOptions.LineBreak.UNIX;
3320fb13a7243e99e536c01399986795bb1b3e13175Andrey Somov        assertEquals("Line break: UNIX", lb.toString());
3339629be70863521bead138c295351f3dec926ab1Andrey Somov    }
334b900be137196b0528076fa46620a1c481229fcfaAndrey Somov
335b900be137196b0528076fa46620a1c481229fcfaAndrey Somov    public void testWithRepresenter() {
336b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        Representer representer = new Representer();
337b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        DumperOptions options = new DumperOptions();
338b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        options.setIndent(4);
339eeb19af1d1bacf12b955cf4a93773294a98b6de1as        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
3404efdcdc34840aa22eb58e536d4f111b17b13a4c0Andrey Somov        Yaml yaml = new Yaml(representer, options);
341390b38428af1c1ce0ffb422aa3c57440e64a9b15Andrey Somov        List<Integer> list = new ArrayList<Integer>();
342b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        list.add(1);
343b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        list.add(2);
344b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        list.add(3);
345b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        Map<String, Object> map = new LinkedHashMap<String, Object>();
346b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        map.put("a", "b");
347b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        map.put("c", list);
348b900be137196b0528076fa46620a1c481229fcfaAndrey Somov        assertEquals("a: b\nc:\n- 1\n- 2\n- 3\n", yaml.dump(map));
349b900be137196b0528076fa46620a1c481229fcfaAndrey Somov    }
3507fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
3517fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    public void testSplitLinesDoubleQuoted() {
3527fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        DumperOptions options = new DumperOptions();
3537fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
3547fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        Yaml yaml;
3557fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        String output;
3567fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
3577fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        // Split lines enabled (default)
3587fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertTrue(options.getSplitLines());
3597fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        yaml = new Yaml(options);
3607fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        output = yaml.dump("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000");
3617fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertEquals("\"1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888\\\n  \\ 9999999999 0000000000\"\n", output);
3627fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
3637fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        // Split lines disabled
3647fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        options.setSplitLines(false);
3657fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertFalse(options.getSplitLines());
3667fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        yaml = new Yaml(options);
3677fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        output = yaml.dump("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000");
3687fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertEquals("\"1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000\"\n", output);
3697fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    }
3707fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
3717fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    public void testSplitLinesSingleQuoted() {
3727fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        DumperOptions options = new DumperOptions();
3737fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.SINGLE_QUOTED);
3747fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        Yaml yaml;
3757fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        String output;
3767fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
3777fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        // Split lines enabled (default)
3787fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertTrue(options.getSplitLines());
3797fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        yaml = new Yaml(options);
3807fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        output = yaml.dump("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000");
3817fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertEquals("'1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888\n  9999999999 0000000000'\n", output);
3827fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
3837fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        // Split lines disabled
3847fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        options.setSplitLines(false);
3857fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertFalse(options.getSplitLines());
3867fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        yaml = new Yaml(options);
3877fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        output = yaml.dump("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000");
3887fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertEquals("'1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000'\n", output);
3897fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    }
3907fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
3917fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    public void testSplitLinesFolded() {
3927fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        DumperOptions options = new DumperOptions();
3937fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.FOLDED);
3947fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        Yaml yaml;
3957fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        String output;
3967fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
3977fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        // Split lines enabled (default)
3987fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertTrue(options.getSplitLines());
3997fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        yaml = new Yaml(options);
4007fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        output = yaml.dump("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000");
4017fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertEquals(">-\n  1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888\n  9999999999 0000000000\n", output);
4027fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
4037fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        // Split lines disabled
4047fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        options.setSplitLines(false);
4057fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertFalse(options.getSplitLines());
4067fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        yaml = new Yaml(options);
4077fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        output = yaml.dump("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000");
4087fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertEquals(">-\n  1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000\n", output);
4097fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    }
4107fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
4117fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    public void testSplitLinesLiteral() {
4127fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        DumperOptions options = new DumperOptions();
4137fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.LITERAL);
4147fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        Yaml yaml;
4157fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        String output;
4167fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
4177fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        // Split lines enabled (default) -- split lines does not apply to literal style
4187fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertTrue(options.getSplitLines());
4197fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        yaml = new Yaml(options);
4207fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        output = yaml.dump("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000");
4217fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertEquals("|-\n  1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000\n", output);
4227fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    }
4237fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
4247fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    public void testSplitLinesPlain() {
4257fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        DumperOptions options = new DumperOptions();
4267fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
4277fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        Yaml yaml;
4287fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        String output;
4297fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela
4307fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        // Split lines enabled (default) -- split lines does not apply to plain style
4317fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertTrue(options.getSplitLines());
4327fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        yaml = new Yaml(options);
4337fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        output = yaml.dump("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000");
4347fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela        assertEquals("1111111111 2222222222 3333333333 4444444444 5555555555 6666666666 7777777777 8888888888 9999999999 0000000000\n", output);
4357fbc6562f9ae67c2b9de8b8c5c74c62c42006cebVille Koskela    }
4367b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov
4377b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov    public void testSetIndicatorIndentNegative() {
4387b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        DumperOptions options = new DumperOptions();
4397b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        try {
4407b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        options.setIndicatorIndent(-1);
4417b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov            fail("Negative indent must not be accepted.");
4427b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        } catch (YAMLException e) {
4437b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov            assertEquals("Indicator indent must be non-negative.", e.getMessage());
4447b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        }
4457b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov    }
4467b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov
4477b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov    public void testSetIndicatorIndentTooBig() {
4487b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        DumperOptions options = new DumperOptions();
4497b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        try {
4507b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov            options.setIndicatorIndent(100);
4517b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov            fail("Negative indent must not be accepted.");
4527b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        } catch (YAMLException e) {
4537b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov            assertEquals("Indicator indent must be at most Emitter.MAX_INDENT-1: 9", e.getMessage());
4547b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        }
4557b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov    }
4567b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov
4577b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov    public void testCreateUnknownStyle() {
4587b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        try {
4597b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov            DumperOptions.ScalarStyle.createStyle(' ');
4607b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov            fail("Negative indent must not be accepted.");
4617b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        } catch (YAMLException e) {
4627b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov            assertEquals("Unknown scalar style character:  ", e.getMessage());
4637b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        }
4647b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov    }
4657b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov
4667b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov    public void testCreateStyle() {
4677b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        assertEquals(DumperOptions.ScalarStyle.DOUBLE_QUOTED, DumperOptions.ScalarStyle.createStyle('"'));
4687b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        assertEquals(DumperOptions.ScalarStyle.SINGLE_QUOTED, DumperOptions.ScalarStyle.createStyle('\''));
4697b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        assertEquals(DumperOptions.ScalarStyle.LITERAL, DumperOptions.ScalarStyle.createStyle('|'));
4707b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        assertEquals(DumperOptions.ScalarStyle.FOLDED, DumperOptions.ScalarStyle.createStyle('>'));
4717b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov        assertEquals(DumperOptions.ScalarStyle.PLAIN, DumperOptions.ScalarStyle.createStyle(null));
4727b2eda235d9b7a421a4a5ec440834781de5155b7Andrey Somov    }
4739629be70863521bead138c295351f3dec926ab1Andrey Somov}
474