[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); 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(); final NumberFormat instance = NumberFormat.getInstance();
instance.setParseIntegerOnly(false); instance.setParseIntegerOnly(false);
try { try {
@ -113,7 +129,7 @@ public class NumberUtilsTest extends AbstractLangTest {
return NumberUtils.isParsable(s); return NumberUtils.isParsable(s);
} }
private boolean isLongParsable(final String s) { private boolean isParsableLong(final String s) {
final NumberFormat instance = NumberFormat.getInstance(); final NumberFormat instance = NumberFormat.getInstance();
instance.setParseIntegerOnly(false); instance.setParseIntegerOnly(false);
try { try {
@ -129,7 +145,7 @@ public class NumberUtilsTest extends AbstractLangTest {
return NumberUtils.isParsable(s); return NumberUtils.isParsable(s);
} }
private boolean isShortParsable(final String s) { private boolean isParsableShort(final String s) {
final NumberFormat instance = NumberFormat.getInstance(); final NumberFormat instance = NumberFormat.getInstance();
instance.setParseIntegerOnly(false); instance.setParseIntegerOnly(false);
try { try {
@ -1007,28 +1023,36 @@ public class NumberUtilsTest extends AbstractLangTest {
compareIsCreatableWithCreateNumber("+2.0", true); compareIsCreatableWithCreateNumber("+2.0", true);
} }
@Test
public void testLang1729IsParsableByte() {
assertTrue(isParsableByte("1"));
assertFalse(isParsableByte("1 2 3"));
assertTrue(isParsableByte(""));
assertFalse(isParsableByte(" "));
}
@Test @Test
public void testLang1729IsParsableInteger() { public void testLang1729IsParsableInteger() {
assertTrue(isIntegerParsable("1")); assertTrue(isParsableInteger("1"));
assertFalse(isIntegerParsable("1 2 3")); assertFalse(isParsableInteger("1 2 3"));
assertTrue(isIntegerParsable("")); assertTrue(isParsableInteger(""));
assertFalse(isIntegerParsable(" ")); assertFalse(isParsableInteger(" "));
} }
@Test @Test
public void testLang1729IsParsableLong() { public void testLang1729IsParsableLong() {
assertTrue(isLongParsable("1")); assertTrue(isParsableLong("1"));
assertFalse(isLongParsable("1 2 3")); assertFalse(isParsableLong("1 2 3"));
assertTrue(isLongParsable("")); assertTrue(isParsableLong(""));
assertFalse(isLongParsable(" ")); assertFalse(isParsableLong(" "));
} }
@Test @Test
public void testLang1729IsParsableShort() { public void testLang1729IsParsableShort() {
assertTrue(isShortParsable("1")); assertTrue(isParsableShort("1"));
assertFalse(isShortParsable("1 2 3")); assertFalse(isParsableShort("1 2 3"));
assertTrue(isShortParsable("")); assertTrue(isParsableShort(""));
assertFalse(isShortParsable(" ")); assertFalse(isParsableShort(" "));
} }
@Test @Test