Oh look, I figured out how to emit `istrue`, so that's tested, too.

This commit is contained in:
David Wendt 2020-06-23 21:39:38 -04:00 committed by Mike Welsh
parent 850ebc88a2
commit b972c24f7e
5 changed files with 88 additions and 0 deletions

View File

@ -274,6 +274,7 @@ swf_tests! {
(as3_istype, "avm2/istype", 1),
(as3_instanceof, "avm2/instanceof", 1),
(as3_truthiness, "avm2/truthiness", 1),
(as3_falsiness, "avm2/falsiness", 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_falsiness(val) {
if (!val) {
trace("Value is falsy");
} else {
trace("Value is truthy");
}
}
trace("//if (!true)");
assert_falsiness(true);
trace("//if (!false)");
assert_falsiness(false);
trace("//if (!null)");
assert_falsiness(null);
trace("//if (!undefined)");
assert_falsiness(undefined);
trace("//if (!\"\")");
assert_falsiness("");
trace("//if (!\"str\")");
assert_falsiness("str");
trace("//if (!\"true\")");
assert_falsiness("true");
trace("//if (!\"false\")");
assert_falsiness("false");
trace("//if (!0.0)");
assert_falsiness(0.0);
trace("//if (!NaN)");
assert_falsiness(NaN);
trace("//if (!-0.0)");
assert_falsiness(-0.0);
trace("//if (!Infinity)");
assert_falsiness(Infinity);
trace("//if (!1.0)");
assert_falsiness(1.0);
trace("//if (!-1.0)");
assert_falsiness(-1.0);
trace("//if (!new Object())");
assert_falsiness({});

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.