Skip to content

Commit

Permalink
Test #5: Test case for unescaped control char in non-strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-voorberg committed Feb 24, 2023
1 parent 09f1552 commit a7ad175
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions gson/src/test/java/com/google/gson/stream/JsonReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ public void testEscapedNewlineAllowedInDefaultMode() throws IOException {
assertThat(reader.nextString()).isEqualTo("\n");
}

@Test
public void testStrictModeFailsToParseUnespacedControlCharacter() {
String json = "\"\t\"";
JsonReader reader = new JsonReader(reader(json));
reader.setStrict(true);
try {
reader.nextString();
fail();
} catch (IOException e) {
assertThat(e.getMessage()).contains("strict");
}
}

@Test
public void testNonStrictModeParsesUnespacedControlCharacter() throws IOException {
String json = "\"\t\"";
JsonReader reader = new JsonReader(reader(json));
assertThat(reader.nextString()).isEqualTo("\t");
}

@Test
public void testReadArray() throws IOException {
JsonReader reader = new JsonReader(reader("[true, true]"));
Expand Down Expand Up @@ -122,19 +142,6 @@ public void testSkipArray() throws IOException {
assertThat(reader.peek()).isEqualTo(JsonToken.END_DOCUMENT);
}

@Test
public void testStrictModeFailsToParseUnespacedControlCharacter() {
String json = "\"\t\"";
JsonReader reader = new JsonReader(reader(json));
reader.setStrict(true);
try {
reader.nextString();
fail();
} catch (IOException e) {
assertThat(e.getMessage()).contains("strict");
}
}

@Test
public void testSkipArrayAfterPeek() throws Exception {
JsonReader reader = new JsonReader(reader(
Expand Down

0 comments on commit a7ad175

Please sign in to comment.