org.yaml.snakeyaml.DumperOptions.ScalarStyle Java Examples

The following examples show how to use org.yaml.snakeyaml.DumperOptions.ScalarStyle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LineBreakDooubleQuotedTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testDoubleQuotedStyle() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
    options.setWidth(20);
    options.setIndent(4);
    Yaml yaml = new Yaml(options);
    String etalon = "12345678901234567890\n\n123  456";
    String output = yaml.dump(etalon);
    // System.out.println(output);
    assertEquals("\"12345678901234567890\\n\\\n    \\n123  456\"\n", output);
    String parsed = (String) yaml.load(output);
    assertEquals(etalon, parsed);
}
 
Example #2
Source File: EmitterTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testWriteDoubleQuoted() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
    String folded = "0123456789 0123456789\n0123456789 0123456789";
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("aaa", folded);
    map.put("bbb", "\nbla-bla");
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(map);
    String etalon = "\"aaa\": \"0123456789 0123456789\\n0123456789 0123456789\"\n\"bbb\": \"\\nbla-bla\"\n";
    assertEquals(etalon, output);
}
 
Example #3
Source File: EmitterTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testWriteSingleQuoted() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.SINGLE_QUOTED);
    String folded = "0123456789 0123456789\n0123456789 0123456789";
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("aaa", folded);
    map.put("bbb", "\nbla-bla");
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(map);
    String etalon = "'aaa': '0123456789 0123456789\n\n  0123456789 0123456789'\n'bbb': '\n\n  bla-bla'\n";
    assertEquals(etalon, output);
}
 
Example #4
Source File: EmitterTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testWritePlainPretty() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.PLAIN);
    options.setPrettyFlow(true);

    String folded = "0123456789 0123456789\n0123456789 0123456789";
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("aaa", folded);
    map.put("bbb", "\nbla-bla");

    Yaml yaml = new Yaml(options);
    String output = yaml.dump(map);
    String etalon = "aaa: |-\n  0123456789 0123456789\n  0123456789 0123456789\nbbb: |2-\n\n  bla-bla\n";
    assertEquals(etalon, output);
}
 
Example #5
Source File: EmitterTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testWritePlain() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.PLAIN);
    String folded = "0123456789 0123456789\n0123456789 0123456789";
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("aaa", folded);
    map.put("bbb", "\nbla-bla");
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(map);
    String etalon = "aaa: |-\n  0123456789 0123456789\n  0123456789 0123456789\nbbb: |2-\n\n  bla-bla\n";
    assertEquals(etalon, output);
}
 
Example #6
Source File: EmitterTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testWriteLiteral() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.LITERAL);
    String folded = "0123456789 0123456789 0123456789 0123456789";
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("aaa", folded);
    map.put("bbb", "\nbla-bla\n");
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(map);
    String etalon = "\"aaa\": |-\n  0123456789 0123456789 0123456789 0123456789\n\"bbb\": |2\n\n  bla-bla\n";
    assertEquals(etalon, output);
}
 
Example #7
Source File: EmitterTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testWriteFolded() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.FOLDED);
    String folded = "0123456789 0123456789\n0123456789 0123456789";
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put("aaa", folded);
    map.put("bbb", "\nbla-bla\n");
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(map);
    String etalon = "\"aaa\": >-\n  0123456789 0123456789\n\n  0123456789 0123456789\n\"bbb\": >2\n\n  bla-bla\n";
    assertEquals(etalon, output);
}
 
Example #8
Source File: Chapter2_3Test.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testExample_2_15() {
    String etalon = "Sammy Sosa completed another fine season with great stats.\n\n  63 Home Runs\n  0.288 Batting Average\n\nWhat a year!\n";
    InputStream input = YamlDocument.class.getClassLoader().getResourceAsStream(
            YamlDocument.ROOT + "example2_15.yaml");
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.FOLDED);
    Yaml yaml = new Yaml(options);
    String data = (String) yaml.load(input);
    assertEquals(etalon, data);
    //
    String dumped = yaml.dump(data);
    String etalonDumped = Util.getLocalResource("specification/example2_15_dumped.yaml");
    assertEquals(etalonDumped, dumped);
}
 
Example #9
Source File: FlexibleScalarStyleTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
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);
    assertTrue(result.startsWith(">\n"));
    assertEquals(
            ">\n  qqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqq\n  qqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqq 111111111111111111111111\n   qqqqqqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqq\n",
            result);
}
 
Example #10
Source File: LineBreakDooubleQuotedTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testDoubleQuotedStyleNoLineSplit() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
    options.setWidth(20);
    options.setSplitLines(false);
    options.setIndent(4);
    Yaml yaml = new Yaml(options);
    String etalon = "12345678901234567890\n\n123  456";
    String output = yaml.dump(etalon);
    // System.out.println(output);
    assertEquals("\"12345678901234567890\\n\\n123  456\"\n", output);
    String parsed = (String) yaml.load(output);
    assertEquals(etalon, parsed);
}
 
Example #11
Source File: UnicodeStyleTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testDoubleQuotedStyle() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
    Yaml yaml = new Yaml(options);
    String output = yaml.dump("í");
    // System.out.println(output);
    assertEquals("\"í\"\n", output);
}
 
Example #12
Source File: Emitter.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void processScalar() throws IOException {
    ScalarEvent ev = (ScalarEvent) event;
    if (analysis == null) {
        analysis = analyzeScalar(ev.getValue());
    }
    if (style == null) {
        style = chooseScalarStyle();
    }
    // TODO the next line should be removed
    style = options.calculateScalarStyle(analysis, ScalarStyle.createStyle(style)).getChar();
    boolean split = !simpleKeyContext;
    if (style == null) {
        writePlain(analysis.scalar, split);
    } else {
        switch (style) {
        case '"':
            writeDoubleQuoted(analysis.scalar, split);
            break;
        case '\'':
            writeSingleQuoted(analysis.scalar, split);
            break;
        case '>':
            writeFolded(analysis.scalar);
            break;
        case '|':
            writeLiteral(analysis.scalar);
            break;
        default:
            throw new YAMLException("Unexpected style: " + style);
        }
    }
    analysis = null;
    style = null;
}
 
Example #13
Source File: ScalarNode.java    From onedev with MIT License 5 votes vote down vote up
public ScalarNode(Tag tag, boolean resolved, String value, Mark startMark, Mark endMark,
                  DumperOptions.ScalarStyle style) {
    super(tag, startMark, endMark);
    if (value == null) {
        throw new NullPointerException("value in a Node is required.");
    }
    this.value = value;
    if (style == null) throw new NullPointerException("Scalar style must be provided.");
    this.style = style;
    this.resolved = resolved;
}
 
Example #14
Source File: ScalarNode.java    From onedev with MIT License 4 votes vote down vote up
public ScalarNode(Tag tag, String value) {
    this(tag, value, null, null, ScalarStyle.PLAIN);
}
 
Example #15
Source File: PrintableUnicodeTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
private Yaml createYaml() {
    DumperOptions options = new DumperOptions();
    options.setAllowUnicode(false);
    options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
    return new Yaml(options);
}
 
Example #16
Source File: BaseRepresenter.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public void setDefaultScalarStyle(ScalarStyle defaultStyle) {
    this.defaultScalarStyle = defaultStyle.getChar();
}
 
Example #17
Source File: BaseRepresenter.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public void setDefaultScalarStyle(ScalarStyle defaultStyle) {
    this.defaultScalarStyle = defaultStyle.getChar();
}
 
Example #18
Source File: ScalarNode.java    From onedev with MIT License 4 votes vote down vote up
public boolean isPlain() {
    return  style == DumperOptions.ScalarStyle.PLAIN;
}
 
Example #19
Source File: ScalarNode.java    From onedev with MIT License 4 votes vote down vote up
public ScalarNode(Tag tag, String value, Mark startMark, Mark endMark, DumperOptions.ScalarStyle style) {
    this(tag, true, value, startMark, endMark, style);
}
 
Example #20
Source File: ScalarNode.java    From onedev with MIT License 2 votes vote down vote up
/**
 * Get scalar style of this node.
 *
 * @see org.yaml.snakeyaml.events.ScalarEvent
 * @see <a href="http://yaml.org/spec/1.1/#id903915">Chapter 9. Scalar
 *      Styles</a>
 * @return style of this scalar node
 */
public DumperOptions.ScalarStyle getStyle() {
    return style;
}