[LANG-1729] NumberUtils.isParsable() returns true for Fullwidth Unicode

digits

Add Long test case
This commit is contained in:
Gary Gregory 2024-04-24 15:59:16 -04:00
parent aad9a675b3
commit 96c211eb1b
1 changed files with 32 additions and 9 deletions

View File

@ -114,6 +114,22 @@ public class NumberUtilsTest extends AbstractLangTest {
return NumberUtils.isParsable(s);
}
private boolean isLongParsable(final String s) {
final NumberFormat instance = NumberFormat.getInstance();
instance.setParseIntegerOnly(false);
try {
instance.parse(s);
} catch (final ParseException e) {
return false;
}
try {
Long.parseLong(s);
} catch (final NumberFormatException e) {
return false;
}
return NumberUtils.isParsable(s);
}
/**
* Test for {@link NumberUtils#toDouble(BigDecimal)}
*/
@ -826,6 +842,22 @@ public class NumberUtilsTest extends AbstractLangTest {
assertFalse(NumberUtils.isDigits("abc"), "isDigits(String) neg 4 failed");
}
@Test
public void testIsIntParsableLang1729() {
assertTrue(isIntParsable("1"));
assertFalse(isIntParsable("1 2 3"));
assertTrue(isIntParsable(""));
assertFalse(isIntParsable(" "));
}
@Test
public void testIsLongParsableLang1729() {
assertTrue(isLongParsable("1"));
assertFalse(isLongParsable("1 2 3"));
assertTrue(isLongParsable(""));
assertFalse(isLongParsable(" "));
}
/**
* Tests isCreatable(String) and tests that createNumber(String) returns a valid number iff isCreatable(String)
* returns false.
@ -957,15 +989,6 @@ public class NumberUtilsTest extends AbstractLangTest {
assertTrue(NumberUtils.isParsable("-.236"));
}
@Test
@Disabled("Passes on OpenJDK 64-Bit Server VM (build 23-ea+18-1469, mixed mode, sharing)")
public void testIsParsableLang1729() {
assertTrue(isIntParsable("1"));
assertFalse(isIntParsable("1 2 3"));
assertTrue(isIntParsable(""));
assertFalse(isIntParsable(" "));
}
@Test
public void testLang1087() {
// no sign cases