mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-12-29 11:42:15 +00:00
Write empty nested arrays properly.
This commit is contained in:
parent
50522d6a8c
commit
8a8319b5f9
3 changed files with 19 additions and 17 deletions
|
@ -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")
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue