as3: added xml string substitution, variable scoping compatibility, optimizations
[swftools.git] / lib / as3 / ok / reconcile.as
1 package {
2         import flash.display.MovieClip;
3         import flash.utils.ByteArray;
4
5         public class Main extends flash.display.MovieClip {
6
7             public function test0() {
8                 // simple sanity test
9                 while(false) {
10                     var x1:String;
11                 }
12                 trace("ok 1/10");
13             }
14
15             // test whether local variables with default value "null"
16             // will be coerced to their object
17             public function test1() {
18                 var dataBuffer:Array;
19                 while(true) {
20                     dataBuffer = new Array();
21                     if(dataBuffer)
22                         break;
23                 }
24                 trace("ok 2/10");
25             }
26
27             public function test2() {
28                 var output:String = "";
29                 while(output.length<1) {
30                     output += "abc".charAt(0);
31                 }
32                 trace("ok 3/10");
33             }
34
35             public function test3() {
36                 var k:uint;
37
38                 while(true) {
39                     for (var k:uint = 0; k < 4; k++) {
40                     }
41                     break;
42                 }
43                 trace("ok 4/10");
44             }
45
46             public var b:Boolean = false;
47
48             public function test4() {
49                 var x:int;
50                 var y:uint;
51                 if(b) {
52                     x = x+y;
53                     y = y+x;
54                 }
55                 trace("ok 5/10");
56             }
57             public function test5() {
58                 var x:int;
59                 var y:uint;
60                 var z:int;
61                 if(b) {
62                     x = x*y;
63                     z = x*z;
64                 }
65                 trace("ok 6/10");
66             }
67             public function test6() {
68                 var i:int = b?3.0:3;
69                 var j:uint = b?3:"abc";
70                 trace("ok 7/10");
71             }
72             public function test7() {
73                 var j:Number = 0;
74                 if(b) {
75                     j += 8;
76                 }
77                 trace("ok 8/10");
78             }
79             public function s():String {
80                 return "x";
81             }
82             public function test8() {
83                 var x:String = "abcd";
84
85                 var i:String = "test";
86                 // test return types of system libraries
87                 if(!b) {
88                     i = x.charAt(0);
89                 }
90                 var a = "test";
91                 // test return types of system libraries
92                 if(!b) {
93                     a = x.charAt(0);
94                 }
95
96                 // ...and local functions
97                 if(!b) {
98                     i = s();
99                 }
100                 trace("ok 9/10");
101             }
102             
103             public function test_add() {
104                 var i:int = 3;
105                 var s:String = "4";
106                 var any1 = "any1";
107                 var any2 = "any2";
108                 var xml:XML = <test/>
109                 var xmllist:XMLList = XMLList(<test/>)
110                 var d1:Date = new Date();
111                 var d2:Date = new Date();
112                 var array1:Array = [1];
113                 var array2:Array = [1,2];
114
115                 /* int+String */
116                 var z1a:Object;
117                 var z1b:String;
118                 if(b) {
119                     z1a = i+s;
120                     z1b = i+s;
121                 }
122
123                 /* String+int */
124                 var z2a:Object;
125                 var z2b:String;
126                 if(b) {
127                     z2a = s+i;
128                     z2b = s+i;
129                 }
130
131                 /* any+any */
132                 var z3a:*;
133                 var z3b:Object;
134                 if(b) {
135                     z3a = any1+any2;
136                     z3b = any1+any2;
137                 }
138                 
139                 /* any+String */
140                 var z4a:Object;
141                 var z4b:*;
142                 if(b) {
143                     z4a = any1+s;
144                     z4b = any1+s;
145                 }
146
147                 /* xml+xmllist */
148                 var z5a:Object;
149                 var z5b:XMLList;
150                 if(b) {
151                     z5a = xml+xmllist;
152                     z5b = xml+xmllist;
153                 }
154
155                 /* xmllist+xml */
156                 var z6:Object;
157                 if(b) {
158                     z6 = xmllist+xml;
159                 }
160                 
161                 /* xml+any */
162                 var z7a:*;
163                 var z7b:XMLList;
164                 if(b) {
165                     z7a = xml+any1;
166                     z7b = xml+any1;
167                 }
168                 
169                 /* date+date */
170                 var z8a:Object;
171                 var z8b:String;
172                 if(b) {
173                     z8a = d1+d2;
174                     z8b = d1+d2;
175                 }
176                 
177                 /* date+any */
178                 var z9a:Object;
179                 var z9b:String;
180                 if(b) {
181                     z9a = d1+any1;
182                     z9b = d1+any1;
183                 }
184                 
185                 /* any+date */
186                 var z10a:Object;
187                 var z10b:*;
188                 if(b) {
189                     z10a = any1+d1;
190                     z10b = any1+d1;
191                 }
192                 
193                 /* array+array */
194                 var z11a:Object;
195                 var z11b:Array;
196                 if(b) {
197                     z11a = array1+array2;
198                     z11b = array1+array2;
199                 }
200                 trace("ok 10/10");
201             }
202
203             public function Main() {
204                 test0();
205                 test1();
206                 test2();
207                 test3();
208                 test4();
209                 test5();
210                 test6();
211                 test7();
212                 test8();
213                 test_add();
214             
215                 trace("[exit]");
216             }
217         }
218 }