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

digits

Add Byte test case
This commit is contained in:
Gary Gregory 2024-04-24 16:03:13 -04:00
parent aacc467954
commit e4aba3f828
1 changed files with 39 additions and 15 deletions

View File

@ -97,7 +97,23 @@ public class NumberUtilsTest extends AbstractLangTest {
assertTrue(NumberUtils.compare((short) 213, (short) 32) > 0);
}
private boolean isIntegerParsable(final String s) {
private boolean isParsableByte(final String s) {
final NumberFormat instance = NumberFormat.getInstance();
instance.setParseIntegerOnly(false);
try {
instance.parse(s);
} catch (final ParseException e) {
return false;
}
try {
Byte.parseByte(s);
} catch (final NumberFormatException e) {
return false;
}
return NumberUtils.isParsable(s);
}
private boolean isParsableInteger(final String s) {
final NumberFormat instance = NumberFormat.getInstance();
instance.setParseIntegerOnly(false);
try {
@ -113,7 +129,7 @@ public class NumberUtilsTest extends AbstractLangTest {
return NumberUtils.isParsable(s);
}
private boolean isLongParsable(final String s) {
private boolean isParsableLong(final String s) {
final NumberFormat instance = NumberFormat.getInstance();
instance.setParseIntegerOnly(false);
try {
@ -129,7 +145,7 @@ public class NumberUtilsTest extends AbstractLangTest {
return NumberUtils.isParsable(s);
}
private boolean isShortParsable(final String s) {
private boolean isParsableShort(final String s) {
final NumberFormat instance = NumberFormat.getInstance();
instance.setParseIntegerOnly(false);
try {
@ -1007,28 +1023,36 @@ public class NumberUtilsTest extends AbstractLangTest {
compareIsCreatableWithCreateNumber("+2.0", true);
}
@Test
public void testLang1729IsParsableByte() {
assertTrue(isParsableByte("1"));
assertFalse(isParsableByte("1 2 3"));
assertTrue(isParsableByte(""));
assertFalse(isParsableByte(" "));
}
@Test
public void testLang1729IsParsableInteger() {
assertTrue(isIntegerParsable("1"));
assertFalse(isIntegerParsable("1 2 3"));
assertTrue(isIntegerParsable(""));
assertFalse(isIntegerParsable(" "));
assertTrue(isParsableInteger("1"));
assertFalse(isParsableInteger("1 2 3"));
assertTrue(isParsableInteger(""));
assertFalse(isParsableInteger(" "));
}
@Test
public void testLang1729IsParsableLong() {
assertTrue(isLongParsable("1"));
assertFalse(isLongParsable("1 2 3"));
assertTrue(isLongParsable(""));
assertFalse(isLongParsable(" "));
assertTrue(isParsableLong("1"));
assertFalse(isParsableLong("1 2 3"));
assertTrue(isParsableLong(""));
assertFalse(isParsableLong(" "));
}
@Test
public void testLang1729IsParsableShort() {
assertTrue(isShortParsable("1"));
assertFalse(isShortParsable("1 2 3"));
assertTrue(isShortParsable(""));
assertFalse(isShortParsable(" "));
assertTrue(isParsableShort("1"));
assertFalse(isParsableShort("1 2 3"));
assertTrue(isParsableShort(""));
assertFalse(isParsableShort(" "));
}
@Test