bit of test refactoring
diff --git a/src/test/java/com/fasterxml/jackson/core/read/ParserErrorHandlingTest.java b/src/test/java/com/fasterxml/jackson/core/read/ParserErrorHandlingTest.java
index bb84134..14b2f1c 100644
--- a/src/test/java/com/fasterxml/jackson/core/read/ParserErrorHandlingTest.java
+++ b/src/test/java/com/fasterxml/jackson/core/read/ParserErrorHandlingTest.java
@@ -14,22 +14,34 @@
_testInvalidKeywords(MODE_INPUT_STREAM_THROTTLED);
_testInvalidKeywords(MODE_DATA_INPUT);
}
-
+
public void testInvalidKeywordsChars() throws Exception {
_testInvalidKeywords(MODE_READER);
}
// Tests for [core#105] ("eager number parsing misses errors")
- public void testMangledNumbersBytes() throws Exception {
- _testMangledNumbers(MODE_INPUT_STREAM);
- _testMangledNumbers(MODE_INPUT_STREAM_THROTTLED);
- _testInvalidKeywords(MODE_DATA_INPUT);
+ public void testMangledIntsBytes() throws Exception {
+ _testMangledNumbersInt(MODE_INPUT_STREAM);
+ _testMangledNumbersInt(MODE_INPUT_STREAM_THROTTLED);
+
+ // 02-Jun-2017, tatu: Fails to fail; should check whether this is expected
+ // (since DataInput can't do look-ahead)
+// _testMangledNumbersInt(MODE_DATA_INPUT);
+ }
+
+ public void testMangledFloatsBytes() throws Exception {
+ _testMangledNumbersFloat(MODE_INPUT_STREAM);
+ _testMangledNumbersFloat(MODE_INPUT_STREAM_THROTTLED);
+
+ // 02-Jun-2017, tatu: Fails as expected, unlike int one. Bit puzzling...
+ _testMangledNumbersFloat(MODE_DATA_INPUT);
}
public void testMangledNumbersChars() throws Exception {
- _testMangledNumbers(MODE_READER);
+ _testMangledNumbersInt(MODE_READER);
+ _testMangledNumbersFloat(MODE_READER);
}
-
+
/*
/**********************************************************
/* Helper methods
@@ -85,10 +97,9 @@
}
}
- private void _testMangledNumbers(int mode) throws Exception
+ private void _testMangledNumbersInt(int mode) throws Exception
{
- String doc = "123true";
- JsonParser p = createParser(mode, doc);
+ JsonParser p = createParser(mode, "123true");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: "+t);
@@ -96,10 +107,12 @@
verifyException(e, "expected space");
}
p.close();
+ }
+ private void _testMangledNumbersFloat(int mode) throws Exception
+ {
// Also test with floats
- doc = "1.5false";
- p = createParser(mode, doc);
+ JsonParser p = createParser(mode, "1.5false");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: "+t);
diff --git a/src/test/java/com/fasterxml/jackson/failing/ParserErrorHandlingTest.java b/src/test/java/com/fasterxml/jackson/failing/ParserErrorHandlingTest.java
new file mode 100644
index 0000000..1e22f19
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/failing/ParserErrorHandlingTest.java
@@ -0,0 +1,63 @@
+package com.fasterxml.jackson.failing;
+
+import com.fasterxml.jackson.core.*;
+
+// Failing tests for non-root-token problem
+public class ParserErrorHandlingTest
+ extends com.fasterxml.jackson.core.BaseTest
+{
+ // Tests for [core#105] ("eager number parsing misses errors")
+ public void testMangledIntsBytes() throws Exception {
+ _testMangledNonRootInts(MODE_INPUT_STREAM);
+ _testMangledNonRootInts(MODE_INPUT_STREAM_THROTTLED);
+
+ // 02-Jun-2017, tatu: Fails to fail; should check whether this is expected
+ // (since DataInput can't do look-ahead)
+// _testMangledNonRootInts(MODE_DATA_INPUT);
+ }
+
+ public void testMangledFloatsBytes() throws Exception {
+ _testMangledNonRootFloats(MODE_INPUT_STREAM);
+ _testMangledNonRootFloats(MODE_INPUT_STREAM_THROTTLED);
+
+ // 02-Jun-2017, tatu: Fails as expected, unlike int one. Bit puzzling...
+ _testMangledNonRootFloats(MODE_DATA_INPUT);
+ }
+
+ public void testMangledNumbersChars() throws Exception {
+ _testMangledNonRootInts(MODE_READER);
+ _testMangledNonRootFloats(MODE_READER);
+ }
+
+ /*
+ /**********************************************************
+ /* Helper methods
+ /**********************************************************
+ */
+
+ private void _testMangledNonRootInts(int mode) throws Exception
+ {
+ JsonParser p = createParser(mode, "[ 123true ]");
+ assertToken(JsonToken.START_ARRAY, p.nextToken());
+ try {
+ JsonToken t = p.nextToken();
+ fail("Should have gotten an exception; instead got token: "+t);
+ } catch (JsonParseException e) {
+ verifyException(e, "expected space");
+ }
+ p.close();
+ }
+
+ private void _testMangledNonRootFloats(int mode) throws Exception
+ {
+ JsonParser p = createParser(mode, "[ 1.5false ]");
+ assertToken(JsonToken.START_ARRAY, p.nextToken());
+ try {
+ JsonToken t = p.nextToken();
+ fail("Should have gotten an exception; instead got token: "+t);
+ } catch (JsonParseException e) {
+ verifyException(e, "expected space");
+ }
+ p.close();
+ }
+}
diff --git a/src/test/java/com/fasterxml/jackson/failing/async/AsyncTokenErrorTest.java b/src/test/java/com/fasterxml/jackson/failing/async/AsyncTokenErrorTest.java
index 6262fcb..f4a353f 100644
--- a/src/test/java/com/fasterxml/jackson/failing/async/AsyncTokenErrorTest.java
+++ b/src/test/java/com/fasterxml/jackson/failing/async/AsyncTokenErrorTest.java
@@ -9,27 +9,31 @@
public class AsyncTokenErrorTest extends AsyncTestBase
{
private final JsonFactory JSON_F = new JsonFactory();
-
- public void testInvalidKeywords() throws Exception
+
+ public void testInvalidKeywordsStartOk() throws Exception
{
- doTestInvalidKeyword1("nul");
- doTestInvalidKeyword1("Null");
- doTestInvalidKeyword1("nulla");
- doTestInvalidKeyword1("fal");
- doTestInvalidKeyword1("False");
- doTestInvalidKeyword1("fals0");
- doTestInvalidKeyword1("falsett0");
- doTestInvalidKeyword1("tr");
- doTestInvalidKeyword1("truE");
- doTestInvalidKeyword1("treu");
- doTestInvalidKeyword1("trueenough");
- doTestInvalidKeyword1("C");
+ _doTestInvalidKeyword("nul");
+ _doTestInvalidKeyword("nulla");
+ _doTestInvalidKeyword("fal");
+ _doTestInvalidKeyword("fals0");
+ _doTestInvalidKeyword("falsett0");
+ _doTestInvalidKeyword("tr");
+ _doTestInvalidKeyword("truE");
+ _doTestInvalidKeyword("treu");
+ _doTestInvalidKeyword("trueenough");
}
- private void doTestInvalidKeyword1(String value) throws IOException
+ public void testInvalidKeywordsStartFail() throws Exception
+ {
+ _doTestInvalidKeyword("Null");
+ _doTestInvalidKeyword("False");
+ _doTestInvalidKeyword("C");
+ }
+
+ private void _doTestInvalidKeyword(String value) throws IOException
{
String doc = "{ \"key1\" : "+value+" }";
- AsyncReaderWrapper p = createParser(doc);
+ AsyncReaderWrapper p = _createParser(doc);
assertToken(JsonToken.START_OBJECT, p.nextToken());
// Note that depending on parser impl, we may
// get the exception early or late...
@@ -46,7 +50,7 @@
// Try as root-level value as well:
doc = value + " "; // may need space after for DataInput
- p = createParser(doc);
+ p = _createParser(doc);
try {
p.nextToken();
fail("Expected an exception for malformed value keyword");
@@ -58,21 +62,35 @@
}
}
- public void testMangledNumbers() throws Exception
+ public void testMangledRootInts() throws Exception
{
- String doc = "123true";
- AsyncReaderWrapper p = createParser(doc);
+ AsyncReaderWrapper p = _createParser("123true");
try {
JsonToken t = p.nextToken();
- fail("Should have gotten an exception; instead got token: "+t);
+ fail("Should have gotten an exception; instead got token: "+t+"; number: "+p.getNumberValue());
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
+ }
+ public void testMangledRootFloats() throws Exception
+ {
// Also test with floats
- doc = "1.5false";
- p = createParser(doc);
+ AsyncReaderWrapper p = _createParser("1.5false");
+ try {
+ JsonToken t = p.nextToken();
+ fail("Should have gotten an exception; instead got token: "+t+"; number: "+p.getNumberValue());
+ } catch (JsonParseException e) {
+ verifyException(e, "expected space");
+ }
+ p.close();
+ }
+
+ public void testMangledNonRootInts() throws Exception
+ {
+ AsyncReaderWrapper p = _createParser("[ 123true ]");
+ assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: "+t);
@@ -82,7 +100,20 @@
p.close();
}
- private AsyncReaderWrapper createParser(String doc) throws IOException
+ public void testMangledNonRootFloats() throws Exception
+ {
+ AsyncReaderWrapper p = _createParser("[ 1.5false ]");
+ assertToken(JsonToken.START_ARRAY, p.nextToken());
+ try {
+ JsonToken t = p.nextToken();
+ fail("Should have gotten an exception; instead got token: "+t);
+ } catch (JsonParseException e) {
+ verifyException(e, "expected space");
+ }
+ p.close();
+ }
+
+ private AsyncReaderWrapper _createParser(String doc) throws IOException
{
return asyncForBytes(JSON_F, 1, _jsonDoc(doc), 1);
}