From 41730edd4d799777175d02052a42366f86551978 Mon Sep 17 00:00:00 2001 From: jwilson Date: Sun, 13 Mar 2016 15:53:23 -0400 Subject: [PATCH] Confirm Moshi can handle unquoted numeric keys. See also https://github.com/google/gson/pull/809/files --- .../moshi/PromoteNameToValueTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/moshi/src/test/java/com/squareup/moshi/PromoteNameToValueTest.java b/moshi/src/test/java/com/squareup/moshi/PromoteNameToValueTest.java index 27b1e88..284b095 100644 --- a/moshi/src/test/java/com/squareup/moshi/PromoteNameToValueTest.java +++ b/moshi/src/test/java/com/squareup/moshi/PromoteNameToValueTest.java @@ -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)); }