Trailing comma tests
This commit is contained in:
parent
62675b7f46
commit
937019651a
@ -16,8 +16,15 @@
|
||||
|
||||
package com.google.gson.functional;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.io.StringReader;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@ -107,4 +114,24 @@ public class JsonParserTest extends TestCase {
|
||||
assertEquals(20, target.longValue);
|
||||
assertEquals("fooBar", target.stringValue);
|
||||
}
|
||||
|
||||
public void testExtraCommasInArrays() {
|
||||
Type type = new TypeToken<List<String>>() {}.getType();
|
||||
assertEquals(list("a", null, "b", null, null), gson.fromJson("[a,,b,,]", type));
|
||||
assertEquals(list(null, null), gson.fromJson("[,]", type));
|
||||
assertEquals(list("a", null), gson.fromJson("[a,]", type));
|
||||
}
|
||||
|
||||
public void testExtraCommasInMaps() {
|
||||
Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
try {
|
||||
gson.fromJson("{a:b,}", type);
|
||||
fail();
|
||||
} catch (JsonSyntaxException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
private <T> List<T> list(T... elements) {
|
||||
return Arrays.asList(elements);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user