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

View file

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

View file

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