Search in sources :

Example 6 with YamlConfig

use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.

the class EmitterTest method testEmptySequence.

@Test
public void testEmptySequence() throws YamlException {
    YamlConfig yamlConfig = new YamlConfig();
    yamlConfig.writeConfig.setFlowStyle(true);
    YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
    List<String> list = new ArrayList<String>();
    yamlWriter.write(list);
    yamlWriter.close();
    assertEquals("[]" + LINE_SEPARATOR, stringWriter.toString());
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) ArrayList(java.util.ArrayList) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Example 7 with YamlConfig

use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.

the class EmitterTest method testStateFlowMapingKeyCanonicalIsTrue.

@Test
public void testStateFlowMapingKeyCanonicalIsTrue() throws EmitterException, IOException {
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    YamlConfig yamlConfig = new YamlConfig();
    yamlConfig.writeConfig.setFlowStyle(true);
    yamlConfig.writeConfig.setWriteRootTags(false);
    yamlConfig.writeConfig.setCanonical(true);
    YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
    yamlWriter.write(map);
    yamlWriter.close();
    assertEquals("--- " + LINE_SEPARATOR + "{" + LINE_SEPARATOR + "   ? !java.lang.String \"key1\"" + LINE_SEPARATOR + "   : !java.lang.String \"value1\"," + LINE_SEPARATOR + "   ? !java.lang.String \"key2\"" + LINE_SEPARATOR + "   : !java.lang.String \"value2\"" + LINE_SEPARATOR + "}" + LINE_SEPARATOR, stringWriter.toString());
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) LinkedHashMap(java.util.LinkedHashMap) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Example 8 with YamlConfig

use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.

the class EmitterWriterTest method testWriteDoubleQuoted.

@Test
public void testWriteDoubleQuoted() throws YamlException {
    YamlConfig yamlConfig = new YamlConfig();
    yamlConfig.writeConfig.setQuoteChar(Quote.DOUBLE);
    StringWriter stringWriter = new StringWriter();
    YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
    yamlWriter.write("\u0001\u0011\u0111\u1111\u0007");
    yamlWriter.close();
    assertEquals("\"\\u0001\\u0011\\u0111\\u1111\\a\"" + LINE_SEPARATOR, stringWriter.toString());
    stringWriter = new StringWriter();
    yamlConfig.writeConfig.setWrapColumn(5);
    yamlWriter = new YamlWriter(stringWriter, yamlConfig);
    yamlWriter.write("testt est");
    yamlWriter.close();
    assertEquals("\"testt\\" + LINE_SEPARATOR + "   \\ e\\" + LINE_SEPARATOR + "   st\"" + LINE_SEPARATOR, stringWriter.toString());
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) StringWriter(java.io.StringWriter) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Example 9 with YamlConfig

use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.

the class EmitterWriterTest method testWriteSingleQuoted.

@Test
public void testWriteSingleQuoted() throws YamlException {
    YamlConfig yamlConfig = new YamlConfig();
    yamlConfig.writeConfig.setQuoteChar(Quote.SINGLE);
    StringWriter stringWriter = new StringWriter();
    YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
    yamlWriter.write("\ntest");
    yamlWriter.close();
    assertEquals("\'" + LINE_SEPARATOR + "   test\'" + LINE_SEPARATOR, stringWriter.toString());
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) StringWriter(java.io.StringWriter) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Aggregations

YamlConfig (com.esotericsoftware.yamlbeans.YamlConfig)9 YamlWriter (com.esotericsoftware.yamlbeans.YamlWriter)9 Test (org.junit.Test)8 StringWriter (java.io.StringWriter)6 LinkedHashMap (java.util.LinkedHashMap)2 YamlReader (com.esotericsoftware.yamlbeans.YamlReader)1 ArrayList (java.util.ArrayList)1