dumping long string values are not split over multiple lines

Issue #355 resolved
Oscar Scholten created an issue

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)

  1. Oscar Scholten reporter

    Thanks for pointing me at the DumperOptionsTest class. I've created a fix and just sent you a pull request.

  2. Log in to comment