Confirm Moshi can handle unquoted numeric keys.

See also https://github.com/google/gson/pull/809/files
This commit is contained in:
jwilson
2016-03-13 15:53:23 -04:00
parent ad3506ffed
commit 41730edd4d

View File

@@ -159,6 +159,36 @@ public final class PromoteNameToValueTest {
assertThat(reader.nextName()).isEqualTo("a");
}
@Test public void readerUnquotedIntegerValue() throws Exception {
JsonReader reader = newReader("{5:1}");
reader.setLenient(true);
reader.beginObject();
reader.promoteNameToValue();
assertThat(reader.nextInt()).isEqualTo(5);
assertThat(reader.nextInt()).isEqualTo(1);
reader.endObject();
}
@Test public void readerUnquotedLongValue() throws Exception {
JsonReader reader = newReader("{5:1}");
reader.setLenient(true);
reader.beginObject();
reader.promoteNameToValue();
assertThat(reader.nextLong()).isEqualTo(5L);
assertThat(reader.nextInt()).isEqualTo(1);
reader.endObject();
}
@Test public void readerUnquotedDoubleValue() throws Exception {
JsonReader reader = newReader("{5:1}");
reader.setLenient(true);
reader.beginObject();
reader.promoteNameToValue();
assertThat(reader.nextDouble()).isEqualTo(5d);
assertThat(reader.nextInt()).isEqualTo(1);
reader.endObject();
}
private JsonReader newReader(String s) {
return JsonReader.of(new Buffer().writeUtf8(s));
}