Package org.yaml.snakeyaml

Examples of org.yaml.snakeyaml.Yaml.dump()


        car.setWheels(wheels);
        Representer representer = new Representer();
        representer.addClassTag(Car.class, new Tag("!car"));
        representer.addClassTag(Wheel.class, Tag.MAP);
        Yaml yaml = new Yaml(representer);
        String output = yaml.dump(car);
        assertEquals(Util.getLocalResource("constructor/car-without-tags.yaml"), output);
    }

    public void testLoadUnknounClassTag() {
        try {
View Full Code Here


        assertTrue(output, output.contains("boolean: true"));
    }

    public void testBoolOutAsYes() {
        Yaml yaml = new Yaml(new BoolRepresenter("YES"));
        String output = yaml.dump(true);
        assertEquals("YES\n", output);
    }

    /**
     * test flow style
View Full Code Here

    public void testBoolOutAsEmpty2() {
        Yaml yaml = new Yaml(new BoolRepresenter("on"));
        Map<String, Boolean> map = new HashMap<String, Boolean>();
        map.put("aaa", false);
        map.put("bbb", true);
        String output = yaml.dump(map);
        assertEquals("{aaa: false, bbb: on}\n", output);
    }

    /**
     * test block style
View Full Code Here

        options.setDefaultFlowStyle(FlowStyle.BLOCK);
        Yaml yaml = new Yaml(new BoolRepresenter("True"), options);
        Map<String, Boolean> map = new HashMap<String, Boolean>();
        map.put("aaa", false);
        map.put("bbb", true);
        String output = yaml.dump(map);
        assertEquals("aaa: false\nbbb: True\n", output);
    }

    private class BoolRepresenter extends Representer {
        private String value;
View Full Code Here

        assertEquals("[This is an 'example'., This is an \"example\"., '123']\n", output);
        // single quoted
        DumperOptions options = new DumperOptions();
        options.setDefaultScalarStyle(ScalarStyle.SINGLE_QUOTED);
        Yaml yaml = new Yaml(options);
        String output2 = yaml.dump(list);
        // System.out.println(output2);
        assertEquals("- 'This is an ''example''.'\n- 'This is an \"example\".'\n- '123'\n", output2);
        // double quoted
        DumperOptions options2 = new DumperOptions();
        options2.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
View Full Code Here

public class FlexibleScalarStyleTest extends TestCase {
    public void testLong() {
        DumperOptions options = new DumperOptions();
        options.setDefaultScalarStyle(ScalarStyle.FOLDED);
        Yaml yaml = new Yaml(options);
        String result = yaml
                .dump("qqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqq "
                        + "qqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqq "
                        + "qqqqqqqqqqqqqqqqqqqqqqqqq 111111111111111111111111\n "
                        + "qqqqqqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqq\n");
        // System.out.println(result);
View Full Code Here

        assertEquals("- 'This is an ''example''.'\n- 'This is an \"example\".'\n- '123'\n", output2);
        // double quoted
        DumperOptions options2 = new DumperOptions();
        options2.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
        yaml = new Yaml(options2);
        String output3 = yaml.dump(list);
        // System.out.println(output2);
        assertEquals("- \"This is an 'example'.\"\n- \"This is an \\\"example\\\".\"\n- \"123\"\n",
                output3);
    }
View Full Code Here

        assertEquals(3, str.toString().length());
        Yaml yaml = new Yaml();
        Charset charset = Charset.forName("UTF-16");
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        Writer writer = new OutputStreamWriter(stream, charset);
        yaml.dump(str, writer);
        assertEquals(str + "\n", stream.toString("UTF-16"));
        assertEquals("Must include BOM: " + stream.toString(), (1 + 3 + 1) * 2, stream.toString()
                .length());
    }
}
View Full Code Here

    public void testNoFoldedScalar() {
        DumperOptions options = new DumperOptions();
        options.setWidth(30);
        Yaml yaml = new Yaml(options);
        String output = yaml.dump(getData());
        // System.out.println(output);
        String etalon = Util.getLocalResource("representer/scalar-style1.yaml");
        assertEquals(etalon, output);
    }
View Full Code Here

    public void testCustomScalarStyle() {
        DumperOptions options = new DumperOptions();
        options.setWidth(30);
        Yaml yaml = new Yaml(new MyRepresenter(), options);
        String output = yaml.dump(getData());
        // System.out.println(output);
        String etalon = Util.getLocalResource("representer/scalar-style2.yaml");
        assertEquals(etalon, output);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.