[feature] 新增BooleanUtil.isJsFalsy以及isJsTruthy

This commit is contained in:
VampireAchao
2023-03-13 18:23:14 +08:00
parent 5b5209e801
commit 4db9c44d18
2 changed files with 53 additions and 1 deletions

View File

@@ -86,7 +86,7 @@ public class BooleanUtilTest {
@SuppressWarnings("ConstantConditions")
@Test
public void toBooleanObjectTest(){
public void toBooleanObjectTest() {
Assert.assertTrue(BooleanUtil.toBooleanObject("yes"));
Assert.assertTrue(BooleanUtil.toBooleanObject(""));
Assert.assertTrue(BooleanUtil.toBooleanObject(""));
@@ -95,4 +95,30 @@ public class BooleanUtilTest {
Assert.assertNull(BooleanUtil.toBooleanObject(null));
Assert.assertNull(BooleanUtil.toBooleanObject("不识别"));
}
@Test
public void isJsFalsyTest() {
Assert.assertTrue(BooleanUtil.isJsFalsy(false));
Assert.assertTrue(BooleanUtil.isJsFalsy(0));
Assert.assertTrue(BooleanUtil.isJsFalsy(-0));
Assert.assertTrue(BooleanUtil.isJsFalsy(0L));
Assert.assertTrue(BooleanUtil.isJsFalsy(0.0D));
Assert.assertTrue(BooleanUtil.isJsFalsy(0.00D));
Assert.assertTrue(BooleanUtil.isJsFalsy(-0.00D));
Assert.assertTrue(BooleanUtil.isJsFalsy(""));
Assert.assertTrue(BooleanUtil.isJsFalsy(null));
}
@Test
public void isJsTruthyTest() {
Assert.assertTrue(BooleanUtil.isJsTruthy(true));
Assert.assertTrue(BooleanUtil.isJsTruthy(1));
Assert.assertTrue(BooleanUtil.isJsTruthy(-1));
Assert.assertTrue(BooleanUtil.isJsTruthy("0"));
Assert.assertTrue(BooleanUtil.isJsTruthy("null"));
Assert.assertTrue(BooleanUtil.isJsTruthy("undefined"));
Assert.assertTrue(BooleanUtil.isJsTruthy(1L));
Assert.assertTrue(BooleanUtil.isJsTruthy(0.1D));
Assert.assertTrue(BooleanUtil.isJsTruthy(-0.01D));
}
}