Skip to content

Commit 2452601

Browse files
committed
Add a failing test for YAML issue #50; also tested that 1.19 of SnakeYAML does not help with the problem
1 parent fdc7320 commit 2452601

File tree

7 files changed

+189
-178
lines changed

7 files changed

+189
-178
lines changed

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/MissingColumnsTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,6 @@ public void testFailOnMissingColumns() throws Exception
131131
verifyException(e, "expected 3, found 1");
132132
}
133133
assertFalse(it.hasNextValue());
134+
it.close();
134135
}
135136
}

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/UnicodeWritingTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fasterxml.jackson.dataformat.csv.ser;
22

33
import java.io.ByteArrayOutputStream;
4-
import java.util.Map;
54

65
import com.fasterxml.jackson.databind.*;
76

properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/SimpleParsingTest.java

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
import java.util.Map;
44

5-
import org.junit.Assert;
6-
7-
import com.fasterxml.jackson.core.Base64Variants;
8-
import com.fasterxml.jackson.core.JsonParser;
9-
import com.fasterxml.jackson.core.JsonToken;
105
import com.fasterxml.jackson.databind.ObjectMapper;
116

127
public class SimpleParsingTest extends ModuleTestBase
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fasterxml.jackson.dataformat.yaml;
2+
3+
public class GeneratorWithSplitLinesTest extends ModuleTestBase
4+
{
5+
public void testSplitLines() throws Exception
6+
{
7+
final String TEXT = "1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890";
8+
final String[] INPUT = new String[] { TEXT };
9+
YAMLFactory f = new YAMLFactory();
10+
11+
// verify default settings
12+
assertTrue(f.isEnabled(YAMLGenerator.Feature.SPLIT_LINES));
13+
14+
// and first write with splitting enabled
15+
YAMLMapper mapper = new YAMLMapper(f);
16+
String yaml = mapper.writeValueAsString(INPUT).trim();
17+
18+
assertEquals("---\n" +
19+
"- \"1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890\\\n" +
20+
" \\ 1234567890\"",
21+
yaml);
22+
23+
// and then with splitting disabled
24+
f.disable(YAMLGenerator.Feature.SPLIT_LINES);
25+
26+
yaml = mapper.writeValueAsString(INPUT).trim();
27+
assertEquals("---\n" +
28+
"- \"1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890\"",
29+
yaml);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package com.fasterxml.jackson.dataformat.yaml;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class GeratorWithMinimizeTest extends ModuleTestBase
7+
{
8+
private final static YAMLMapper MINIM_MAPPER = new YAMLMapper();
9+
static {
10+
MINIM_MAPPER.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES);
11+
}
12+
13+
public void testDefaultSetting() {
14+
YAMLFactory f = new YAMLFactory();
15+
assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
16+
f.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);
17+
assertTrue(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
18+
}
19+
20+
public void testLiteralStringsSingleLine() throws Exception
21+
{
22+
Map<String, Object> content = new HashMap<String, Object>();
23+
content.put("key", "some value");
24+
String yaml = MINIM_MAPPER.writeValueAsString(content).trim();
25+
26+
assertEquals("---\n" +
27+
"key: some value", yaml);
28+
}
29+
30+
public void testMinimizeQuotesWithBooleanContent() throws Exception
31+
{
32+
Map<String, Object> content = new HashMap<String, Object>();
33+
content.put("key", "true");
34+
String yaml = MINIM_MAPPER.writeValueAsString(content).trim();
35+
36+
assertEquals("---\n" +
37+
"key: \"true\"", yaml);
38+
39+
content.clear();
40+
content.put("key", "false");
41+
yaml = MINIM_MAPPER.writeValueAsString(content).trim();
42+
43+
assertEquals("---\n" +
44+
"key: \"false\"", yaml);
45+
46+
content.clear();
47+
content.put("key", "something else");
48+
yaml = MINIM_MAPPER.writeValueAsString(content).trim();
49+
50+
assertEquals("---\n" +
51+
"key: something else", yaml);
52+
53+
content.clear();
54+
content.put("key", Boolean.TRUE);
55+
yaml = MINIM_MAPPER.writeValueAsString(content).trim();
56+
57+
assertEquals("---\n" +
58+
"key: true", yaml);
59+
}
60+
61+
public void testLiteralStringsMultiLine() throws Exception
62+
{
63+
Map<String, Object> content = new HashMap<String, Object>();
64+
content.put("key", "first\nsecond\nthird");
65+
String yaml = MINIM_MAPPER.writeValueAsString(content).trim();
66+
67+
assertEquals("---\n" +
68+
"key: |-\n first\n second\n third", yaml);
69+
}
70+
71+
public void testQuoteNumberStoredAsString() throws Exception
72+
{
73+
YAMLFactory f = new YAMLFactory();
74+
// verify default settings
75+
assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
76+
assertFalse(f.isEnabled(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS));
77+
78+
f.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);
79+
f.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true);
80+
81+
YAMLMapper mapper = new YAMLMapper(f);
82+
83+
Map<String, Object> content = new HashMap<String, Object>();
84+
content.put("key", "20");
85+
String yaml = mapper.writeValueAsString(content).trim();
86+
87+
assertEquals("---\n" +
88+
"key: \"20\"", yaml);
89+
90+
content.clear();
91+
content.put("key", "2.0");
92+
yaml = mapper.writeValueAsString(content).trim();
93+
94+
assertEquals("---\n" +
95+
"key: \"2.0\"", yaml);
96+
97+
content.clear();
98+
content.put("key", "2.0.1.2.3");
99+
yaml = mapper.writeValueAsString(content).trim();
100+
101+
assertEquals("---\n" +
102+
"key: 2.0.1.2.3", yaml);
103+
}
104+
105+
public void testNonQuoteNumberStoredAsString() throws Exception
106+
{
107+
Map<String, Object> content = new HashMap<String, Object>();
108+
content.put("key", "20");
109+
String yaml = MINIM_MAPPER.writeValueAsString(content).trim();
110+
111+
assertEquals("---\n" +
112+
"key: 20", yaml);
113+
114+
content.clear();
115+
content.put("key", "2.0");
116+
yaml = MINIM_MAPPER.writeValueAsString(content).trim();
117+
118+
assertEquals("---\n" +
119+
"key: 2.0", yaml);
120+
121+
content.clear();
122+
content.put("key", "2.0.1.2.3");
123+
yaml = MINIM_MAPPER.writeValueAsString(content).trim();
124+
125+
assertEquals("---\n" +
126+
"key: 2.0.1.2.3", yaml);
127+
}
128+
}

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/SimpleGenerationTest.java

+3-172
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ public void testStreamingNested() throws Exception
6565
BufferedReader br = new BufferedReader(new StringReader(yaml));
6666
assertEquals("ob:", br.readLine());
6767

68-
/* 27-Jan-2015, tatu: Not 100% if those items ought to (or not) be indented.
69-
* SnakeYAML doesn't do that; yet some libs expect it. Strange.
70-
*/
68+
// 27-Jan-2015, tatu: Not 100% if those items ought to (or not) be indented.
69+
// SnakeYAML doesn't do that; yet some libs expect it. Strange.
7170
assertEquals("- \"a\"", br.readLine());
7271
assertEquals("- \"b\"", br.readLine());
7372
assertNull(br.readLine());
@@ -164,173 +163,6 @@ public void testStartMarker() throws Exception
164163
assertEquals("name: \"Brad\"\nage: 39", yaml);
165164
}
166165

167-
public void testSplitLines() throws Exception
168-
{
169-
final String TEXT = "1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890";
170-
final String[] INPUT = new String[] { TEXT };
171-
YAMLFactory f = new YAMLFactory();
172-
173-
// verify default settings
174-
assertTrue(f.isEnabled(YAMLGenerator.Feature.SPLIT_LINES));
175-
176-
// and first write with splitting enabled
177-
YAMLMapper mapper = new YAMLMapper(f);
178-
String yaml = mapper.writeValueAsString(INPUT).trim();
179-
180-
assertEquals("---\n" +
181-
"- \"1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890\\\n" +
182-
" \\ 1234567890\"",
183-
yaml);
184-
185-
// and then with splitting disabled
186-
f.disable(YAMLGenerator.Feature.SPLIT_LINES);
187-
188-
yaml = mapper.writeValueAsString(INPUT).trim();
189-
assertEquals("---\n" +
190-
"- \"1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890\"",
191-
yaml);
192-
}
193-
194-
public void testLiteralStringsSingleLine() throws Exception
195-
{
196-
YAMLFactory f = new YAMLFactory();
197-
// verify default settings
198-
assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
199-
200-
f.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);
201-
202-
YAMLMapper mapper = new YAMLMapper(f);
203-
204-
Map<String, Object> content = new HashMap<String, Object>();
205-
content.put("key", "some value");
206-
String yaml = mapper.writeValueAsString(content).trim();
207-
208-
assertEquals("---\n" +
209-
"key: some value", yaml);
210-
}
211-
212-
public void testMinimizeQuotesWithBooleanContent() throws Exception
213-
{
214-
YAMLFactory f = new YAMLFactory();
215-
f.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);
216-
217-
YAMLMapper mapper = new YAMLMapper(f);
218-
219-
Map<String, Object> content = new HashMap<String, Object>();
220-
content.put("key", "true");
221-
String yaml = mapper.writeValueAsString(content).trim();
222-
223-
assertEquals("---\n" +
224-
"key: \"true\"", yaml);
225-
226-
content.clear();
227-
content.put("key", "false");
228-
yaml = mapper.writeValueAsString(content).trim();
229-
230-
assertEquals("---\n" +
231-
"key: \"false\"", yaml);
232-
233-
content.clear();
234-
content.put("key", "something else");
235-
yaml = mapper.writeValueAsString(content).trim();
236-
237-
assertEquals("---\n" +
238-
"key: something else", yaml);
239-
240-
content.clear();
241-
content.put("key", Boolean.TRUE);
242-
yaml = mapper.writeValueAsString(content).trim();
243-
244-
assertEquals("---\n" +
245-
"key: true", yaml);
246-
247-
}
248-
249-
public void testLiteralStringsMultiLine() throws Exception
250-
{
251-
YAMLFactory f = new YAMLFactory();
252-
// verify default settings
253-
assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
254-
255-
f.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);
256-
257-
YAMLMapper mapper = new YAMLMapper(f);
258-
259-
Map<String, Object> content = new HashMap<String, Object>();
260-
content.put("key", "first\nsecond\nthird");
261-
String yaml = mapper.writeValueAsString(content).trim();
262-
263-
assertEquals("---\n" +
264-
"key: |-\n first\n second\n third", yaml);
265-
}
266-
267-
public void testQuoteNumberStoredAsString() throws Exception
268-
{
269-
YAMLFactory f = new YAMLFactory();
270-
// verify default settings
271-
assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
272-
assertFalse(f.isEnabled(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS));
273-
274-
f.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);
275-
f.configure(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS, true);
276-
277-
YAMLMapper mapper = new YAMLMapper(f);
278-
279-
Map<String, Object> content = new HashMap<String, Object>();
280-
content.put("key", "20");
281-
String yaml = mapper.writeValueAsString(content).trim();
282-
283-
assertEquals("---\n" +
284-
"key: \"20\"", yaml);
285-
286-
content.clear();
287-
content.put("key", "2.0");
288-
yaml = mapper.writeValueAsString(content).trim();
289-
290-
assertEquals("---\n" +
291-
"key: \"2.0\"", yaml);
292-
293-
content.clear();
294-
content.put("key", "2.0.1.2.3");
295-
yaml = mapper.writeValueAsString(content).trim();
296-
297-
assertEquals("---\n" +
298-
"key: 2.0.1.2.3", yaml);
299-
}
300-
301-
public void testNonQuoteNumberStoredAsString() throws Exception
302-
{
303-
YAMLFactory f = new YAMLFactory();
304-
// verify default settings
305-
assertFalse(f.isEnabled(YAMLGenerator.Feature.MINIMIZE_QUOTES));
306-
assertFalse(f.isEnabled(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS));
307-
308-
f.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);
309-
310-
YAMLMapper mapper = new YAMLMapper(f);
311-
312-
Map<String, Object> content = new HashMap<String, Object>();
313-
content.put("key", "20");
314-
String yaml = mapper.writeValueAsString(content).trim();
315-
316-
assertEquals("---\n" +
317-
"key: 20", yaml);
318-
319-
content.clear();
320-
content.put("key", "2.0");
321-
yaml = mapper.writeValueAsString(content).trim();
322-
323-
assertEquals("---\n" +
324-
"key: 2.0", yaml);
325-
326-
content.clear();
327-
content.put("key", "2.0.1.2.3");
328-
yaml = mapper.writeValueAsString(content).trim();
329-
330-
assertEquals("---\n" +
331-
"key: 2.0.1.2.3", yaml);
332-
}
333-
334166
public void testLiteralBlockStyle() throws Exception
335167
{
336168
YAMLFactory f = new YAMLFactory();
@@ -362,8 +194,7 @@ public void testLiteralBlockStyle() throws Exception
362194
/**********************************************************************
363195
*/
364196

365-
366-
protected void _writeBradDoc(JsonGenerator gen) throws IOException
197+
private void _writeBradDoc(JsonGenerator gen) throws IOException
367198
{
368199
gen.writeStartObject();
369200
gen.writeStringField("name", "Brad");

0 commit comments

Comments
 (0)