Add test for truthiness.

As compiled by Adobe Animate CC 2020, this test appears to only use `iffalse`. However, both `op_is_false` and `op_is_true` coerce in the same manner, so I'm not entirely sure this is a problem for now.
This commit is contained in:
David Wendt 2020-06-23 19:28:33 -04:00 committed by Mike Welsh
parent e5c8c5b340
commit 850ebc88a2
5 changed files with 88 additions and 0 deletions

View File

@ -273,6 +273,7 @@ swf_tests! {
(as3_es4_interfaces, "avm2/es4_interfaces", 1),
(as3_istype, "avm2/istype", 1),
(as3_instanceof, "avm2/instanceof", 1),
(as3_truthiness, "avm2/truthiness", 1),
}
// TODO: These tests have some inaccuracies currently, so we use approx_eq to test that numeric values are close enough.

View File

@ -0,0 +1,57 @@
package {
public class Test {
}
}
function assert_truthiness(val) {
if (val) {
trace("Value is truthy");
} else {
trace("Value is falsy");
}
}
trace("//if (true)");
assert_truthiness(true);
trace("//if (false)");
assert_truthiness(false);
trace("//if (null)");
assert_truthiness(null);
trace("//if (undefined)");
assert_truthiness(undefined);
trace("//if (\"\")");
assert_truthiness("");
trace("//if (\"str\")");
assert_truthiness("str");
trace("//if (\"true\")");
assert_truthiness("true");
trace("//if (\"false\")");
assert_truthiness("false");
trace("//if (0.0)");
assert_truthiness(0.0);
trace("//if (NaN)");
assert_truthiness(NaN);
trace("//if (-0.0)");
assert_truthiness(-0.0);
trace("//if (Infinity)");
assert_truthiness(Infinity);
trace("//if (1.0)");
assert_truthiness(1.0);
trace("//if (-1.0)");
assert_truthiness(-1.0);
trace("//if (new Object())");
assert_truthiness({});

View File

@ -0,0 +1,30 @@
//if (true)
Value is truthy
//if (false)
Value is falsy
//if (null)
Value is falsy
//if (undefined)
Value is falsy
//if ("")
Value is falsy
//if ("str")
Value is truthy
//if ("true")
Value is truthy
//if ("false")
Value is truthy
//if (0.0)
Value is falsy
//if (NaN)
Value is falsy
//if (-0.0)
Value is falsy
//if (Infinity)
Value is truthy
//if (1.0)
Value is truthy
//if (-1.0)
Value is truthy
//if (new Object())
Value is truthy

Binary file not shown.

Binary file not shown.