-
-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
517b1bf
commit ebdc0b5
Showing
3 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/com/fasterxml/jackson/failing/NonStandardNumbers611Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import com.fasterxml.jackson.core.*; | ||
import com.fasterxml.jackson.core.json.JsonReadFeature; | ||
|
||
public class NonStandardNumbers611Test | ||
extends com.fasterxml.jackson.core.BaseTest | ||
{ | ||
/** | ||
* The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail | ||
*/ | ||
public void testLeadingDotInDecimal() throws Exception { | ||
for (int mode : ALL_MODES) { | ||
JsonParser p = createParser(mode, " .123 "); | ||
try { | ||
p.nextToken(); | ||
fail("Should not pass"); | ||
} catch (JsonParseException e) { | ||
verifyException(e, "Unexpected character ('.'"); | ||
} | ||
p.close(); | ||
} | ||
} | ||
|
||
public void testLeadingDotInDecimalAllowed() throws Exception { | ||
final JsonFactory f = JsonFactory.builder() | ||
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS) | ||
.build(); | ||
|
||
// TODO: | ||
/* | ||
for (int mode : ALL_MODES) { | ||
_testLeadingDotInDecimalAllowed(f, mode); | ||
} | ||
*/ | ||
|
||
|
||
_testLeadingDotInDecimalAllowed(f, MODE_INPUT_STREAM); | ||
_testLeadingDotInDecimalAllowed(f, MODE_INPUT_STREAM_THROTTLED); | ||
_testLeadingDotInDecimalAllowed(f, MODE_READER); | ||
_testLeadingDotInDecimalAllowed(f, MODE_DATA_INPUT); | ||
} | ||
|
||
private void _testLeadingDotInDecimalAllowed(JsonFactory f, int mode) throws Exception | ||
{ | ||
JsonParser p = createParser(f, mode, " .123 "); | ||
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken()); | ||
assertEquals(0.123, p.getValueAsDouble()); | ||
assertEquals("0.123", p.getDecimalValue().toString()); | ||
p.close(); | ||
} | ||
} |