treat glyphs with alpha=0 differently than normal glyphs (remove outlines)
[swftools.git] / lib / as3 / ok / precedence.as
1 package {
2     
3     import flash.display.MovieClip
4
5     class C {
6         function f() {return new Array(1,2,3);}
7     }
8     public class Main extends flash.display.MovieClip {
9         var count:int = 1;
10         var num:int = 53;
11         function assert(b) {
12             if(b) {
13                 trace("ok "+count+"/"+num);
14             } else {
15                 trace("error "+count+"/"+num);
16             }
17             count = count + 1
18         }
19         function compare(x,y) {
20             assert(x==y);
21         }
22             
23         var a:Array = new Array(1,2,3);
24         var b:int=10;
25         function f() {return a;}
26         function g() {return b;}
27         var i=0;
28
29         function Main() {
30
31             // test that ., [], (), @, ::, .. {x:y}, new all have the same precedence
32             // TODO: @, ::, ..
33
34             compare(this.f()[2] , (((this).f)())[2])
35             //compare(new C.f()[1],2); //breaks
36             compare(new C().f()[1],2);
37
38             // test that ., [], () have higher precedence than ++, --, -, ~, !, delete, typeof
39             // TODO: @, delete, typeof
40             var i:int=5,j:int;
41             this.i=0;
42             this.i++;compare(this.i,1);compare(i,5);
43             ++(this.a)[2]; compare(this.a[2],4);
44             delete this.f()[0];compare(String(this.a[0]), "undefined");
45
46             // test that ++ has higher precedence than unary -,~,!
47             compare(-i++,-5);
48             compare(!i++,false);
49             compare(~i++,~7);
50
51             // test that * / % have the same precedence
52             compare(3*10/15%4, 2)
53             
54             // test that ++,--,~ have higher precedence than * / %
55             i = 0;j = 1;compare(++i*j++, 1)
56             i = 0;j = 1;compare(++i/j++, 1)
57             i = 2;j = 2;compare(++i%j++, 1)
58             compare( (~1*2) & 1, 0);
59
60             // test that +,- have lower precedence than * / %
61             compare(1+1*2, 3)
62             compare(5-4/2, 3)
63             compare(3-4%2, 3)
64             compare(2+1%2, 3)
65
66             // test that +, - have higher precedence than >>,<<,>>>
67             compare(4>>1+1, 1)
68             compare(4>>1-1, 4)
69             compare(4>>>1+1, 1)
70             compare(4>>>1-1, 4)
71             compare(1<<1+1, 4)
72             compare(4<<1-1, 4)
73             
74             // test that >>,<< have higher precedence than <,>,<=,>=,==
75             compare(3 < 1<<2, true)
76             compare(4 <= 1<<2, true)
77             compare(2 > 8>>3, true)
78             compare(1 >= 8>>3, true)
79             compare(1 == 1<<0, true)
80             compare(1 == 1>>0, true)
81             
82             // test that <,>,<=,>= have higher precedence than as, in
83             compare(1<2 as Boolean, true)
84             //compare(1<2 in [true,true,true], true)
85             
86             // test that as,in have higher precedence than ==,!=
87             compare(1==1 as Boolean, false);
88             compare(1!=1 as Boolean, true);
89             compare(false == true is Boolean, false);
90             compare(true != true is Boolean, false);
91
92             // test that >,<,>=,<= have higher precedence than ==, !=, ===, !==
93             compare(true == 3<4, true)
94             compare(true != 3>4, true)
95             compare(true === 3<=4, true)
96             compare(true !== 3>=4, true)
97             
98             // test that ==,!= have higher precedence than &
99             compare(3&4==4, 1)
100             compare(3&0!=4, 1)
101
102             // test that & has higher precedence than ^
103             compare(1^1&4, 1)
104             
105             // test that ^ has higher precedence than |
106             compare(5|4^4, 5)
107             
108             // test that | has higher precedence than &&
109             compare(false && 0|5, false)
110             
111             // test that && has higher precedence than ||
112             compare(false && true || true, true)
113             
114             // test that || has higher precedence than ?:
115             compare(true || false?11:0, 11)
116             
117             // test that ?: and = have same precedence 
118             var y = 0;
119             var x = false ? y=3 : y=4;
120             compare(y,4)
121             false ? y=3 : y=5;
122             compare(y,5)
123             
124             // test that = is right-associative
125             x = y = 3;
126             compare(x,3)
127             compare(y,3)
128             
129             // test that = has higher precedence than +=,-=,*=,/=,%=
130             x=4;y=10;
131             x += y = 4;
132             compare(x,8);
133
134             // test that +=,-=,*=,/=,%=,>>=,<<=,>>>= all have the same associativity
135             // TODO: %=,/=,-=,>>=,<<=,>>>=
136             x=2;y=3;
137             x *= y += 4;
138             assert(x==14 && y==7);
139
140             // test that , has lower precedence than +=
141             x=0;
142             var v=0;
143             v += 3,4;
144             compare(v,3)
145
146             trace("[exit]");
147         }
148
149     }
150 }
151