Skip to content

Commit

Permalink
And finally, async parser tests for #611 too
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 23, 2020
1 parent c1920ed commit e1e5e2b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
Expand Up @@ -7,7 +7,7 @@
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper;

public class AsyncNonStdNumbersTest extends AsyncTestBase
public class AsyncNaNHandlingTest extends AsyncTestBase
{
private final JsonFactory DEFAULT_F = new JsonFactory();

Expand Down
Expand Up @@ -7,7 +7,7 @@
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper;

public class AsyncNumberLeadingZeroesTest extends AsyncTestBase
public class AsyncNonStdNumberHandlingTest extends AsyncTestBase
{
@SuppressWarnings("deprecation")
public void testDefaultsForAsync() throws Exception {
Expand Down Expand Up @@ -77,7 +77,7 @@ public void testLeadingZeroesFloat() throws Exception
_testLeadingZeroesFloat("-000.5 ", -0.5);
}

public void _testLeadingZeroesFloat(String valueStr, double value) throws Exception
private void _testLeadingZeroesFloat(String valueStr, double value) throws Exception
{
// first: verify that we get an exception
JsonFactory f = new JsonFactory();
Expand All @@ -104,8 +104,58 @@ public void _testLeadingZeroesFloat(String valueStr, double value) throws Except
p.close();
}

public void testLeadingPeriodFloat() throws Exception
{
_testLeadingPeriodFloat(".25", 0.25, 1);
_testLeadingPeriodFloat(".25", 0.25, 100);
_testLeadingPeriodFloat(" .25 ", 0.25, 1);
_testLeadingPeriodFloat(" .25 ", 0.25, 100);

_testLeadingPeriodFloat(".1", 0.1, 1);
_testLeadingPeriodFloat(".1", 0.1, 100);

_testLeadingPeriodFloat(".6125 ", 0.6125, 1);
_testLeadingPeriodFloat(".6125 ", 0.6125, 100);
}

private void _testLeadingPeriodFloat(String valueStr, double value, int bytesPerRead)
throws Exception
{
// first: verify that we get an exception

JsonFactory f = new JsonFactory();
String JSON = valueStr;
AsyncReaderWrapper p = createParser(f, JSON, bytesPerRead);
try {
p.nextToken();
p.currentText();
fail("Should have thrown an exception for doc <"+JSON+">");
} catch (JsonParseException e) {
verifyException(e, "Unexpected character ('.'");
verifyException(e, "expected a valid value");
} finally {
p.close();
}

// and then verify it's ok when enabled
f = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS)
.build();
p = createParser(f, JSON, bytesPerRead);
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(value, p.getDoubleValue());
assertEquals(valueStr.trim(), p.currentText());
p.close();
}

private AsyncReaderWrapper createParser(JsonFactory f, String doc) throws IOException
{
return asyncForBytes(f, 1, _jsonDoc(doc), 1);
return createParser(f, doc, 1);
}

private AsyncReaderWrapper createParser(JsonFactory f, String doc, int bytesPerRead)
throws IOException
{
return asyncForBytes(f, bytesPerRead, _jsonDoc(doc), 1);
}
}
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.core.read;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.json.JsonReadFeature;

public class NonStandardNumbers611Test
public class NonStandardNumberParsingTest
extends com.fasterxml.jackson.core.BaseTest
{
private final JsonFactory JSON_F = JsonFactory.builder()
Expand Down
Expand Up @@ -145,6 +145,7 @@ private void _testLeadingZeroes(int mode, boolean appendSpace) throws Exception
// representation or not? Won't, for now:
assertEquals("0", p.getText());
assertToken(JsonToken.END_ARRAY, p.nextToken());
p.close();
}

private void _testAllowNaN(int mode) throws Exception
Expand Down

0 comments on commit e1e5e2b

Please sign in to comment.