diff --git a/core/tests/regression_tests.rs b/core/tests/regression_tests.rs index 5e75139da..9966572c4 100644 --- a/core/tests/regression_tests.rs +++ b/core/tests/regression_tests.rs @@ -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. diff --git a/core/tests/swfs/avm2/falsiness/Test.as b/core/tests/swfs/avm2/falsiness/Test.as new file mode 100644 index 000000000..6ea70f22d --- /dev/null +++ b/core/tests/swfs/avm2/falsiness/Test.as @@ -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({}); \ No newline at end of file diff --git a/core/tests/swfs/avm2/falsiness/output.txt b/core/tests/swfs/avm2/falsiness/output.txt new file mode 100644 index 000000000..fe59e382f --- /dev/null +++ b/core/tests/swfs/avm2/falsiness/output.txt @@ -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 diff --git a/core/tests/swfs/avm2/falsiness/test.fla b/core/tests/swfs/avm2/falsiness/test.fla new file mode 100644 index 000000000..c41c9f293 Binary files /dev/null and b/core/tests/swfs/avm2/falsiness/test.fla differ diff --git a/core/tests/swfs/avm2/falsiness/test.swf b/core/tests/swfs/avm2/falsiness/test.swf new file mode 100644 index 000000000..acd9cd117 Binary files /dev/null and b/core/tests/swfs/avm2/falsiness/test.swf differ