Write empty nested arrays properly.

This commit is contained in:
Jonathan Wood 2015-07-03 13:57:09 -07:00
parent 50522d6a8c
commit 8a8319b5f9
3 changed files with 19 additions and 17 deletions

View file

@ -1,12 +1,12 @@
package com.moandjiezana.toml;
import static com.moandjiezana.toml.ValueWriters.WRITERS;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import static com.moandjiezana.toml.ValueWriters.WRITERS;
abstract class ArrayValueWriter implements ValueWriter {
static protected boolean isArrayish(Object value) {
return value instanceof Collection || value.getClass().isArray();
@ -24,7 +24,7 @@ abstract class ArrayValueWriter implements ValueWriter {
return valueWriter.isPrimitiveType() || isArrayish(first);
}
return false;
return true;
}
@SuppressWarnings("unchecked")

View file

@ -1,6 +1,10 @@
package com.moandjiezana.toml;
import static org.junit.Assert.assertEquals;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.junit.*;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -15,15 +19,15 @@ import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.junit.Test;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import static org.junit.Assert.*;
public class BurntSushiValidEncoderTest {
@Test
public void array_empty() throws Exception {
runEncoder("array-empty");
}
@Test
public void arrays_hetergeneous() throws Exception {
runEncoder("arrays-hetergeneous");

View file

@ -1,6 +1,8 @@
package com.moandjiezana.toml;
import static org.junit.Assert.assertEquals;
import org.hamcrest.Matchers;
import org.junit.*;
import org.junit.rules.*;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@ -23,11 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import static org.junit.Assert.*;
@SuppressWarnings("unused")
public class TomlWriterTest {
@ -219,7 +217,7 @@ public class TomlWriterTest {
List<Integer> aList = new LinkedList<Integer>();
Float[] anArray = new Float[0];
}
assertEquals("", new TomlWriter().write(new TestClass()));
assertEquals("aList = []\nanArray = []\n", new TomlWriter().write(new TestClass()));
}
@Test