|
| 1 | +package com.fasterxml.jackson.dataformat.yaml.failing; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; |
| 4 | +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; |
| 5 | +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; |
| 6 | +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; |
| 7 | + |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.Map; |
| 10 | + |
| 11 | +public class SimpleGeneration366Test extends ModuleTestBase |
| 12 | +{ |
| 13 | + // [dataformats-text#366]: multiline literal block with trailing spaces does not work |
| 14 | + public void testLiteralBlockStyleMultilineWithTrailingSpace() throws Exception |
| 15 | + { |
| 16 | + YAMLFactory f = new YAMLFactory(); |
| 17 | + // verify default settings |
| 18 | + assertFalse(f.isEnabled(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)); |
| 19 | + |
| 20 | + YAMLMapper mapper = YAMLMapper.builder() |
| 21 | + .configure(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE, true) |
| 22 | + .build(); |
| 23 | + |
| 24 | + Map<String, Object> content = new HashMap<String, Object>(); |
| 25 | + content.put("text", "Hello\nWorld "); |
| 26 | + String yaml = mapper.writeValueAsString(content).trim(); |
| 27 | + |
| 28 | + assertEquals("---\n" + |
| 29 | + "text: |-\n Hello\n World ", yaml); |
| 30 | + } |
| 31 | + |
| 32 | + // [dataformats-text#366]: multiline literal block without trailing spaces actually works |
| 33 | + public void testLiteralBlockStyleMultiline() throws Exception |
| 34 | + { |
| 35 | + YAMLFactory f = new YAMLFactory(); |
| 36 | + // verify default settings |
| 37 | + assertFalse(f.isEnabled(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)); |
| 38 | + |
| 39 | + YAMLMapper mapper = YAMLMapper.builder() |
| 40 | + .configure(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE, true) |
| 41 | + .build(); |
| 42 | + |
| 43 | + Map<String, Object> content = new HashMap<String, Object>(); |
| 44 | + content.put("text", "Hello\nWorld"); |
| 45 | + String yaml = mapper.writeValueAsString(content).trim(); |
| 46 | + |
| 47 | + assertEquals("---\n" + |
| 48 | + "text: |-\n Hello\n World", yaml); |
| 49 | + } |
| 50 | +} |
0 commit comments