Skip to content

Commit

Permalink
Add unit test for multiline literalBlockStyle with trailing space #366 (
Browse files Browse the repository at this point in the history
  • Loading branch information
njank authored Oct 4, 2024
1 parent af83ff7 commit 1da2d90
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.fasterxml.jackson.dataformat.yaml.failing;

import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;

import java.util.HashMap;
import java.util.Map;

public class SimpleGeneration366Test extends ModuleTestBase
{
// [dataformats-text#366]: multiline literal block with trailing spaces does not work
public void testLiteralBlockStyleMultilineWithTrailingSpace() throws Exception
{
YAMLFactory f = new YAMLFactory();
// verify default settings
assertFalse(f.isEnabled(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE));

YAMLMapper mapper = YAMLMapper.builder()
.configure(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE, true)
.build();

Map<String, Object> content = new HashMap<String, Object>();
content.put("text", "Hello\nWorld ");
String yaml = mapper.writeValueAsString(content).trim();

assertEquals("---\n" +
"text: |-\n Hello\n World ", yaml);
}

// [dataformats-text#366]: multiline literal block without trailing spaces actually works
public void testLiteralBlockStyleMultiline() throws Exception
{
YAMLFactory f = new YAMLFactory();
// verify default settings
assertFalse(f.isEnabled(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE));

YAMLMapper mapper = YAMLMapper.builder()
.configure(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE, true)
.build();

Map<String, Object> content = new HashMap<String, Object>();
content.put("text", "Hello\nWorld");
String yaml = mapper.writeValueAsString(content).trim();

assertEquals("---\n" +
"text: |-\n Hello\n World", yaml);
}
}

0 comments on commit 1da2d90

Please sign in to comment.