Skip to content

Commit

Permalink
Remove the redundant commas (EsotericSoftware#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr14huashao authored Jul 6, 2020
1 parent b355ae9 commit e4cb67e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/com/esotericsoftware/yamlbeans/emitter/Emitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ public void expect () throws IOException {
indent = indents.remove(0);
flowLevel--;
if (config.canonical) {
writer.writeIndicator(",", false, false, false);
writer.writeIndent(indent);
}
writer.writeIndicator("]", false, false, false);
Expand Down Expand Up @@ -270,7 +269,6 @@ public void expect () throws IOException {
indent = indents.remove(0);
flowLevel--;
if (config.canonical) {
writer.writeIndicator(",", false, false, false);
writer.writeIndent(indent);
}
writer.writeIndicator("}", false, false, false);
Expand Down
27 changes: 26 additions & 1 deletion test/com/esotericsoftware/yamlbeans/YamlConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,37 @@ public void testSetTags() throws YamlException {

@Test
public void testSetCanonical() throws YamlException {
int indentSize = 3;
yamlConfig.writeConfig.setIndentSize(indentSize);
yamlConfig.writeConfig.setCanonical(true);
StringWriter stringWriter = new StringWriter();
YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
yamlWriter.write("test");
yamlWriter.close();
assertEquals("--- " + LINE_SEPARATOR + "!java.lang.String \"test\"" + LINE_SEPARATOR, stringWriter.toString());

List<String> list = new ArrayList<String>();
list.add("111");
list.add("222");
stringWriter = new StringWriter();
yamlWriter = new YamlWriter(stringWriter, yamlConfig);
yamlWriter.write(list);
yamlWriter.close();
assertEquals("--- " + LINE_SEPARATOR + "[" + LINE_SEPARATOR + multipleSpaces(indentSize)
+ "!java.lang.String \"111\"," + LINE_SEPARATOR + multipleSpaces(indentSize)
+ "!java.lang.String \"222\"" + LINE_SEPARATOR + "]" + LINE_SEPARATOR, stringWriter.toString());

Map<String, String> map = new HashMap<String, String>();
map.put("key", "value");
stringWriter = new StringWriter();
yamlWriter = new YamlWriter(stringWriter, yamlConfig);
yamlWriter.write(map);
yamlWriter.close();
assertEquals(
"--- " + LINE_SEPARATOR + "{" + LINE_SEPARATOR + multipleSpaces(indentSize)
+ "? !java.lang.String \"key\"" + LINE_SEPARATOR + multipleSpaces(indentSize)
+ ": !java.lang.String \"value\"" + LINE_SEPARATOR + "}" + LINE_SEPARATOR,
stringWriter.toString());
}

@Test
Expand All @@ -386,7 +411,7 @@ public void testSetIndentSize() throws YamlException {
yamlWriter.write(list);
yamlWriter.close();
assertEquals("--- " + LINE_SEPARATOR + "[" + LINE_SEPARATOR + multipleSpaces(indentSize)
+ "!java.lang.Integer \"1\"," + LINE_SEPARATOR + "]" + LINE_SEPARATOR, stringWriter.toString());
+ "!java.lang.Integer \"1\"" + LINE_SEPARATOR + "]" + LINE_SEPARATOR, stringWriter.toString());

try {
yamlConfig.writeConfig.setIndentSize(1);
Expand Down

0 comments on commit e4cb67e

Please sign in to comment.