mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Confirm Moshi can handle unquoted numeric keys.
See also https://github.com/google/gson/pull/809/files
This commit is contained in:
@@ -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));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user