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