tests: Add tests for default parameters, type checks, and implicit typecheck coercions
This commit is contained in:
parent
abc9d0800a
commit
2d3ef5493b
|
@ -589,6 +589,9 @@ swf_tests! {
|
|||
(as3_simplebutton_constr_params, "avm2/simplebutton_constr_params", 1),
|
||||
(as3_place_object_replace, "avm2/place_object_replace", 2),
|
||||
(as3_place_object_replace_2, "avm2/place_object_replace_2", 3),
|
||||
(as3_function_call_default, "avm2/function_call_default", 1),
|
||||
(as3_function_call_types, "avm2/function_call_types", 1),
|
||||
(as3_function_call_coercion, "avm2/function_call_coercion", 1),
|
||||
}
|
||||
|
||||
// TODO: These tests have some inaccuracies currently, so we use approx_eq to test that numeric values are close enough.
|
||||
|
|
|
@ -0,0 +1,201 @@
|
|||
package {
|
||||
public class Test {}
|
||||
}
|
||||
|
||||
class CoercibleAsString {
|
||||
public function toString() {
|
||||
return "-99.13";
|
||||
}
|
||||
}
|
||||
|
||||
class CoercibleAsValue {
|
||||
public function valueOf() {
|
||||
return 23.16;
|
||||
}
|
||||
}
|
||||
|
||||
function coerces_param_into_int(i: int) {
|
||||
return i;
|
||||
}
|
||||
|
||||
function coerces_param_into_uint(i: uint) {
|
||||
return i;
|
||||
}
|
||||
|
||||
function coerces_param_into_Number(i: Number) {
|
||||
return i;
|
||||
}
|
||||
|
||||
function coerces_param_into_Boolean(i: Boolean) {
|
||||
return i;
|
||||
}
|
||||
|
||||
function coerces_param_into_String(i: String) {
|
||||
return i;
|
||||
}
|
||||
|
||||
function coerces_param_into_Object(i: Object) {
|
||||
return i;
|
||||
}
|
||||
|
||||
trace("//coerces_param_into_int(undefined);");
|
||||
trace(coerces_param_into_int(undefined));
|
||||
|
||||
trace("//coerces_param_into_int(null);");
|
||||
trace(coerces_param_into_int(null));
|
||||
|
||||
trace("//coerces_param_into_int(true);");
|
||||
trace(coerces_param_into_int(true));
|
||||
|
||||
trace("//coerces_param_into_int(false);");
|
||||
trace(coerces_param_into_int(false));
|
||||
|
||||
trace("//coerces_param_into_int(5.12);");
|
||||
trace(coerces_param_into_int(5.12));
|
||||
|
||||
trace("//coerces_param_into_int(-6);");
|
||||
trace(coerces_param_into_int(-6));
|
||||
|
||||
trace("//coerces_param_into_int(\"12.23\");");
|
||||
trace(coerces_param_into_int("12.23"));
|
||||
|
||||
trace("//coerces_param_into_int(new CoercibleAsString());");
|
||||
trace(coerces_param_into_int(new CoercibleAsString()));
|
||||
|
||||
trace("//coerces_param_into_int(new CoercibleAsValue());");
|
||||
trace(coerces_param_into_int(new CoercibleAsValue()));
|
||||
|
||||
trace("//coerces_param_into_uint(undefined);");
|
||||
trace(coerces_param_into_uint(undefined));
|
||||
|
||||
trace("//coerces_param_into_uint(null);");
|
||||
trace(coerces_param_into_uint(null));
|
||||
|
||||
trace("//coerces_param_into_uint(true);");
|
||||
trace(coerces_param_into_uint(true));
|
||||
|
||||
trace("//coerces_param_into_uint(false);");
|
||||
trace(coerces_param_into_uint(false));
|
||||
|
||||
trace("//coerces_param_into_uint(5.12);");
|
||||
trace(coerces_param_into_uint(5.12));
|
||||
|
||||
trace("//coerces_param_into_uint(-6);");
|
||||
trace(coerces_param_into_uint(-6));
|
||||
|
||||
trace("//coerces_param_into_uint(\"12.23\");");
|
||||
trace(coerces_param_into_uint("12.23"));
|
||||
|
||||
trace("//coerces_param_into_uint(new CoercibleAsString());");
|
||||
trace(coerces_param_into_uint(new CoercibleAsString()));
|
||||
|
||||
trace("//coerces_param_into_uint(new CoercibleAsValue());");
|
||||
trace(coerces_param_into_uint(new CoercibleAsValue()));
|
||||
|
||||
trace("//coerces_param_into_Number(undefined);");
|
||||
trace(coerces_param_into_Number(undefined));
|
||||
|
||||
trace("//coerces_param_into_Number(null);");
|
||||
trace(coerces_param_into_Number(null));
|
||||
|
||||
trace("//coerces_param_into_Number(true);");
|
||||
trace(coerces_param_into_Number(true));
|
||||
|
||||
trace("//coerces_param_into_Number(false);");
|
||||
trace(coerces_param_into_Number(false));
|
||||
|
||||
trace("//coerces_param_into_Number(5.12);");
|
||||
trace(coerces_param_into_Number(5.12));
|
||||
|
||||
trace("//coerces_param_into_Number(-6);");
|
||||
trace(coerces_param_into_Number(-6));
|
||||
|
||||
trace("//coerces_param_into_Number(\"12.23\");");
|
||||
trace(coerces_param_into_Number("12.23"));
|
||||
|
||||
trace("//coerces_param_into_Number(new CoercibleAsString());");
|
||||
trace(coerces_param_into_Number(new CoercibleAsString()));
|
||||
|
||||
trace("//coerces_param_into_Number(new CoercibleAsValue());");
|
||||
trace(coerces_param_into_Number(new CoercibleAsValue()));
|
||||
|
||||
trace("//coerces_param_into_Boolean(undefined);");
|
||||
trace(coerces_param_into_Boolean(undefined));
|
||||
|
||||
trace("//coerces_param_into_Boolean(null);");
|
||||
trace(coerces_param_into_Boolean(null));
|
||||
|
||||
trace("//coerces_param_into_Boolean(true);");
|
||||
trace(coerces_param_into_Boolean(true));
|
||||
|
||||
trace("//coerces_param_into_Boolean(false);");
|
||||
trace(coerces_param_into_Boolean(false));
|
||||
|
||||
trace("//coerces_param_into_Boolean(5.12);");
|
||||
trace(coerces_param_into_Boolean(5.12));
|
||||
|
||||
trace("//coerces_param_into_Boolean(-6);");
|
||||
trace(coerces_param_into_Boolean(-6));
|
||||
|
||||
trace("//coerces_param_into_Boolean(\"12.23\");");
|
||||
trace(coerces_param_into_Boolean("12.23"));
|
||||
|
||||
trace("//coerces_param_into_Boolean(new CoercibleAsString());");
|
||||
trace(coerces_param_into_Boolean(new CoercibleAsString()));
|
||||
|
||||
trace("//coerces_param_into_Boolean(new CoercibleAsValue());");
|
||||
trace(coerces_param_into_Boolean(new CoercibleAsValue()));
|
||||
|
||||
trace("//coerces_param_into_String(undefined);");
|
||||
trace(coerces_param_into_String(undefined));
|
||||
|
||||
trace("//coerces_param_into_String(null);");
|
||||
trace(coerces_param_into_String(null));
|
||||
|
||||
trace("//coerces_param_into_String(true);");
|
||||
trace(coerces_param_into_String(true));
|
||||
|
||||
trace("//coerces_param_into_String(false);");
|
||||
trace(coerces_param_into_String(false));
|
||||
|
||||
trace("//coerces_param_into_String(5.12);");
|
||||
trace(coerces_param_into_String(5.12));
|
||||
|
||||
trace("//coerces_param_into_String(-6);");
|
||||
trace(coerces_param_into_String(-6));
|
||||
|
||||
trace("//coerces_param_into_String(\"12.23\");");
|
||||
trace(coerces_param_into_String("12.23"));
|
||||
|
||||
trace("//coerces_param_into_String(new CoercibleAsString());");
|
||||
trace(coerces_param_into_String(new CoercibleAsString()));
|
||||
|
||||
trace("//coerces_param_into_String(new CoercibleAsValue());");
|
||||
trace(coerces_param_into_String(new CoercibleAsValue()));
|
||||
|
||||
trace("//coerces_param_into_Object(undefined);");
|
||||
trace(coerces_param_into_Object(undefined));
|
||||
|
||||
trace("//coerces_param_into_Object(null);");
|
||||
trace(coerces_param_into_Object(null));
|
||||
|
||||
trace("//coerces_param_into_Object(true);");
|
||||
trace(coerces_param_into_Object(true));
|
||||
|
||||
trace("//coerces_param_into_Object(false);");
|
||||
trace(coerces_param_into_Object(false));
|
||||
|
||||
trace("//coerces_param_into_Object(5.12);");
|
||||
trace(coerces_param_into_Object(5.12));
|
||||
|
||||
trace("//coerces_param_into_Object(-6);");
|
||||
trace(coerces_param_into_Object(-6));
|
||||
|
||||
trace("//coerces_param_into_Object(\"12.23\");");
|
||||
trace(coerces_param_into_Object("12.23"));
|
||||
|
||||
trace("//coerces_param_into_Object(new CoercibleAsString());");
|
||||
trace(coerces_param_into_Object(new CoercibleAsString()));
|
||||
|
||||
trace("//coerces_param_into_Object(new CoercibleAsValue());");
|
||||
trace(coerces_param_into_Object(new CoercibleAsValue()));
|
|
@ -0,0 +1,108 @@
|
|||
//coerces_param_into_int(undefined);
|
||||
0
|
||||
//coerces_param_into_int(null);
|
||||
0
|
||||
//coerces_param_into_int(true);
|
||||
1
|
||||
//coerces_param_into_int(false);
|
||||
0
|
||||
//coerces_param_into_int(5.12);
|
||||
5
|
||||
//coerces_param_into_int(-6);
|
||||
-6
|
||||
//coerces_param_into_int("12.23");
|
||||
12
|
||||
//coerces_param_into_int(new CoercibleAsString());
|
||||
-99
|
||||
//coerces_param_into_int(new CoercibleAsValue());
|
||||
23
|
||||
//coerces_param_into_uint(undefined);
|
||||
0
|
||||
//coerces_param_into_uint(null);
|
||||
0
|
||||
//coerces_param_into_uint(true);
|
||||
1
|
||||
//coerces_param_into_uint(false);
|
||||
0
|
||||
//coerces_param_into_uint(5.12);
|
||||
5
|
||||
//coerces_param_into_uint(-6);
|
||||
4294967290
|
||||
//coerces_param_into_uint("12.23");
|
||||
12
|
||||
//coerces_param_into_uint(new CoercibleAsString());
|
||||
4294967197
|
||||
//coerces_param_into_uint(new CoercibleAsValue());
|
||||
23
|
||||
//coerces_param_into_Number(undefined);
|
||||
NaN
|
||||
//coerces_param_into_Number(null);
|
||||
0
|
||||
//coerces_param_into_Number(true);
|
||||
1
|
||||
//coerces_param_into_Number(false);
|
||||
0
|
||||
//coerces_param_into_Number(5.12);
|
||||
5.12
|
||||
//coerces_param_into_Number(-6);
|
||||
-6
|
||||
//coerces_param_into_Number("12.23");
|
||||
12.23
|
||||
//coerces_param_into_Number(new CoercibleAsString());
|
||||
-99.13
|
||||
//coerces_param_into_Number(new CoercibleAsValue());
|
||||
23.16
|
||||
//coerces_param_into_Boolean(undefined);
|
||||
false
|
||||
//coerces_param_into_Boolean(null);
|
||||
false
|
||||
//coerces_param_into_Boolean(true);
|
||||
true
|
||||
//coerces_param_into_Boolean(false);
|
||||
false
|
||||
//coerces_param_into_Boolean(5.12);
|
||||
true
|
||||
//coerces_param_into_Boolean(-6);
|
||||
true
|
||||
//coerces_param_into_Boolean("12.23");
|
||||
true
|
||||
//coerces_param_into_Boolean(new CoercibleAsString());
|
||||
true
|
||||
//coerces_param_into_Boolean(new CoercibleAsValue());
|
||||
true
|
||||
//coerces_param_into_String(undefined);
|
||||
null
|
||||
//coerces_param_into_String(null);
|
||||
null
|
||||
//coerces_param_into_String(true);
|
||||
true
|
||||
//coerces_param_into_String(false);
|
||||
false
|
||||
//coerces_param_into_String(5.12);
|
||||
5.12
|
||||
//coerces_param_into_String(-6);
|
||||
-6
|
||||
//coerces_param_into_String("12.23");
|
||||
12.23
|
||||
//coerces_param_into_String(new CoercibleAsString());
|
||||
-99.13
|
||||
//coerces_param_into_String(new CoercibleAsValue());
|
||||
[object CoercibleAsValue]
|
||||
//coerces_param_into_Object(undefined);
|
||||
null
|
||||
//coerces_param_into_Object(null);
|
||||
null
|
||||
//coerces_param_into_Object(true);
|
||||
true
|
||||
//coerces_param_into_Object(false);
|
||||
false
|
||||
//coerces_param_into_Object(5.12);
|
||||
5.12
|
||||
//coerces_param_into_Object(-6);
|
||||
-6
|
||||
//coerces_param_into_Object("12.23");
|
||||
12.23
|
||||
//coerces_param_into_Object(new CoercibleAsString());
|
||||
-99.13
|
||||
//coerces_param_into_Object(new CoercibleAsValue());
|
||||
[object CoercibleAsValue]
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,19 @@
|
|||
package {
|
||||
public class Test {}
|
||||
}
|
||||
|
||||
function testfunc(v1, v2, v3 = "Default string") {
|
||||
trace(v1);
|
||||
trace(v2);
|
||||
trace(v3);
|
||||
}
|
||||
|
||||
function testfunc2(v1 = "Default string 0", v2 = "Default string 1", v3 = "Default string 2") {
|
||||
trace(v1);
|
||||
trace(v2);
|
||||
trace(v3);
|
||||
}
|
||||
|
||||
testfunc("arg1", "arg2");
|
||||
|
||||
testfunc2("arg_again_1");
|
|
@ -0,0 +1,6 @@
|
|||
arg1
|
||||
arg2
|
||||
Default string
|
||||
arg_again_1
|
||||
Default string 1
|
||||
Default string 2
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,11 @@
|
|||
package {
|
||||
public class Test {}
|
||||
}
|
||||
|
||||
function testfunc(v1: int, v2: Boolean, v3: String) {
|
||||
trace(v1);
|
||||
trace(v2);
|
||||
trace(v3);
|
||||
}
|
||||
|
||||
testfunc(5, true, "yes");
|
|
@ -0,0 +1,3 @@
|
|||
5
|
||||
true
|
||||
yes
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue