Skip to content

Commit e01f163

Browse files
committed
tests: Add avm2/array_splice_types test
This tests different types of Array.splice arguments.
1 parent 4869196 commit e01f163

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package {
2+
import flash.display.*;
3+
4+
public class Test extends MovieClip {
5+
public function Test() {
6+
var array = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
7+
8+
trace("splice():");
9+
testSplice(array, function(a:Array):Array {
10+
return a.splice();
11+
});
12+
13+
trace("splice(\"0\"):");
14+
testSplice(array, function(a:Array):Array {
15+
return a.splice("0");
16+
});
17+
18+
trace("splice(\"5\"):");
19+
testSplice(array, function(a:Array):Array {
20+
return a.splice("5");
21+
});
22+
23+
trace("splice(true):");
24+
testSplice(array, function(a:Array):Array {
25+
return a.splice(true);
26+
});
27+
28+
trace("splice(false):");
29+
testSplice(array, function(a:Array):Array {
30+
return a.splice(false);
31+
});
32+
33+
trace("splice(new Object()):");
34+
testSplice(array, function(a:Array):Array {
35+
return a.splice(new Object());
36+
});
37+
38+
trace("splice(1, \"2\"):");
39+
testSplice(array, function(a:Array):Array {
40+
return a.splice(1, "2");
41+
});
42+
43+
trace("splice(-1, 2):");
44+
testSplice(array, function(a:Array):Array {
45+
return a.splice(-1, 2);
46+
});
47+
48+
trace("splice(\"-5\", 3):");
49+
testSplice(array, function(a:Array):Array {
50+
return a.splice("-5", 3);
51+
});
52+
53+
trace("splice(1, -2):");
54+
testSplice(array, function(a:Array):Array {
55+
return a.splice(1, -2);
56+
});
57+
58+
trace("splice(1, true):");
59+
testSplice(array, function(a:Array):Array {
60+
return a.splice(1, true);
61+
});
62+
63+
trace("splice(1, false):");
64+
testSplice(array, function(a:Array):Array {
65+
return a.splice(1, false);
66+
});
67+
68+
trace("splice(1, \"true\"):");
69+
testSplice(array, function(a:Array):Array {
70+
return a.splice(1, "true");
71+
});
72+
73+
trace("splice(1, \"false\"):");
74+
testSplice(array, function(a:Array):Array {
75+
return a.splice(1, "false");
76+
});
77+
78+
trace("splice(1, new Object()):");
79+
testSplice(array, function(a:Array):Array {
80+
return a.splice(1, new Object());
81+
});
82+
83+
trace("splice(1, \"5\"):");
84+
testSplice(array, function(a:Array):Array {
85+
return a.splice(1, "5");
86+
});
87+
}
88+
89+
private function testSplice(array:Array, f:Function):void {
90+
array = array.concat();
91+
var ret:Array = f(array);
92+
93+
trace(" returned: " + arrToString(ret));
94+
trace(" after: " + arrToString(array));
95+
}
96+
97+
private function arrToString(array:*):String {
98+
if (array == null) {
99+
return "null";
100+
} else if (!(array is Array)) {
101+
return "" + array;
102+
} else if (array.length > 1000) {
103+
return "<len(" + array.length + ")>";
104+
} else if (array.length == 0) {
105+
return "<empty>";
106+
} else {
107+
return "[" + array.map(function(el:*, ...rest):String {
108+
return arrToString(el);
109+
}) + "]";
110+
}
111+
}
112+
}
113+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
splice():
2+
returned: null
3+
after: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
4+
splice("0"):
5+
returned: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
6+
after: <empty>
7+
splice("5"):
8+
returned: [5,6,7,8,9,10,11,12,13,14,15]
9+
after: [0,1,2,3,4]
10+
splice(true):
11+
returned: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
12+
after: [0]
13+
splice(false):
14+
returned: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
15+
after: <empty>
16+
splice(new Object()):
17+
returned: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
18+
after: <empty>
19+
splice(1, "2"):
20+
returned: [1,2]
21+
after: [0,3,4,5,6,7,8,9,10,11,12,13,14,15]
22+
splice(-1, 2):
23+
returned: [15]
24+
after: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
25+
splice("-5", 3):
26+
returned: [11,12,13]
27+
after: [0,1,2,3,4,5,6,7,8,9,10,14,15]
28+
splice(1, -2):
29+
returned: <empty>
30+
after: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
31+
splice(1, true):
32+
returned: [1]
33+
after: [0,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
34+
splice(1, false):
35+
returned: <empty>
36+
after: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
37+
splice(1, "true"):
38+
returned: <empty>
39+
after: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
40+
splice(1, "false"):
41+
returned: <empty>
42+
after: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
43+
splice(1, new Object()):
44+
returned: <empty>
45+
after: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
46+
splice(1, "5"):
47+
returned: [1,2,3,4,5]
48+
after: [0,6,7,8,9,10,11,12,13,14,15]
1.7 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
num_ticks = 1

0 commit comments

Comments
 (0)