Skip to content

Commit

Permalink
Reproduction for #1161 (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 11, 2023
1 parent d28275d commit b5f1ae3
Showing 1 changed file with 38 additions and 6 deletions.
@@ -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();
}
}

0 comments on commit b5f1ae3

Please sign in to comment.