dumping long string values are not split over multiple lines
Issue #355
resolved
Hi,
Perhaps my expectation is incorrect, but I'd expect that when dumping long non-quoted string scalars, those are split over multiple lines. The below test fails using SnakeYaml 1.17.
Cheers, Oscar
@Test
public void expect_long_string_is_split() throws Exception {
final StringWriter stringWriter = new StringWriter();
final Node key = new ScalarNode(Tag.STR, "key", null, null, null);
final Node value = new ScalarNode(
Tag.STR,
"0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789",
null,
null,
null);
final NodeTuple tuple = new NodeTuple(key, value);
final List<NodeTuple> children = new ArrayList<>(1);
children.add(tuple);
final Node node = new MappingNode(Tag.MAP, children, false);
final DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setSplitLines(true);
dumperOptions.setWidth(80);
final Resolver resolver = new Resolver();
final Serializer serializer = new Serializer(new Emitter(stringWriter, dumperOptions), resolver, dumperOptions, null);
serializer.open();
serializer.serialize(node);
serializer.close();
final String expected =
"key: 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789\n 0123456789 0123456789\n";
assertEquals(expected, stringWriter.toString());
}
Comments (3)
-
-
reporter Thanks for pointing me at the DumperOptionsTest class. I've created a fix and just sent you a pull request.
-
- changed status to resolved
Thank you. Your fix will be delivered in version 1.18: https://bitbucket.org/asomov/snakeyaml/wiki/Changes
- Log in to comment
Feel free to check the tests in https://bitbucket.org/asomov/snakeyaml/src/62e2312ce5104c871b9ae2b6e4038383014a63a8/src/test/java/org/yaml/snakeyaml/DumperOptionsTest.java?at=default&fileviewer=file-view-default
This is what you are looking for: dumperOptions.setSplitLines(true);
Feel free to contribute an improvement.