Merge pull request #139 from square/jwilson_0313_promote_unquoted_keys

Confirm Moshi can handle unquoted numeric keys.
This commit is contained in:
Jake Wharton
2016-03-13 16:01:38 -04:00

View File

@@ -159,6 +159,36 @@ public final class PromoteNameToValueTest {
assertThat(reader.nextName()).isEqualTo("a"); 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) { private JsonReader newReader(String s) {
return JsonReader.of(new Buffer().writeUtf8(s)); return JsonReader.of(new Buffer().writeUtf8(s));
} }