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
d28275d
commit b5f1ae3
Showing
1 changed file
with
38 additions
and
6 deletions.
There are no files selected for viewing
44 changes: 38 additions & 6 deletions
44
src/test/java/com/fasterxml/jackson/core/io/BigDecimalParserTest.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 |
---|---|---|
@@ -1,32 +1,64 @@ | ||
package com.fasterxml.jackson.core.io; | ||
|
||
public class BigDecimalParserTest extends com.fasterxml.jackson.core.BaseTest { | ||
public void testLongStringParse() { | ||
import java.math.BigDecimal; | ||
|
||
public class BigDecimalParserTest extends com.fasterxml.jackson.core.BaseTest | ||
{ | ||
public void testLongInvalidStringParse() { | ||
try { | ||
BigDecimalParser.parse(genLongString()); | ||
BigDecimalParser.parse(genLongInvalidString()); | ||
fail("expected NumberFormatException"); | ||
} catch (NumberFormatException nfe) { | ||
assertTrue("exception message starts as expected?", nfe.getMessage().startsWith("Value \"AAAAA")); | ||
assertTrue("exception message value contains truncated", nfe.getMessage().contains("truncated")); | ||
} | ||
} | ||
|
||
public void testLongStringFastParse() { | ||
public void testLongInvalidStringFastParse() { | ||
try { | ||
BigDecimalParser.parseWithFastParser(genLongString()); | ||
BigDecimalParser.parseWithFastParser(genLongInvalidString()); | ||
fail("expected NumberFormatException"); | ||
} catch (NumberFormatException nfe) { | ||
assertTrue("exception message starts as expected?", nfe.getMessage().startsWith("Value \"AAAAA")); | ||
assertTrue("exception message value contains truncated", nfe.getMessage().contains("truncated")); | ||
} | ||
} | ||
|
||
static String genLongString() { | ||
public void testLongValidStringParse() { | ||
String num = genLongValidString(500); | ||
final BigDecimal EXP = new BigDecimal(num); | ||
|
||
// Parse from String first, then char[] | ||
|
||
assertEquals(EXP, BigDecimalParser.parse(num)); | ||
assertEquals(EXP, BigDecimalParser.parse(num.toCharArray(), 0, num.length())); | ||
} | ||
|
||
public void testLongValidStringFastParse() { | ||
String num = genLongValidString(500); | ||
final BigDecimal EXP = new BigDecimal(num); | ||
|
||
// Parse from String first, then char[] | ||
assertEquals(EXP, BigDecimalParser.parseWithFastParser(num)); | ||
assertEquals(EXP, BigDecimalParser.parseWithFastParser(num.toCharArray(), 0, num.length())); | ||
} | ||
|
||
static String genLongInvalidString() { | ||
final int len = 1500; | ||
final StringBuilder sb = new StringBuilder(len); | ||
for (int i = 0; i < len; i++) { | ||
sb.append("A"); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
static String genLongValidString(int len) { | ||
final StringBuilder sb = new StringBuilder(len+5); | ||
sb.append("0."); | ||
for (int i = 0; i < len; i++) { | ||
sb.append('0'); | ||
} | ||
sb.append('1'); | ||
return sb.toString(); | ||
} | ||
} |