2 import flash.display.MovieClip
3 public class Main extends flash.display.MovieClip {
6 function assert(b:Boolean) {
8 trace("ok "+count+"/"+num);
10 trace("error "+count+"/"+num);
15 /* ------ basic sanity tests ------ */
16 var x:XML = <test>}</test>;
18 <test>This XML doesn't do anything!
21 /Neither does this regexp!/
29 var f2 = function(s:String) {assert(true);}
30 var f3 = function(s:String) {assert(true);}
32 f2(<![CDATA[ bla bla bla /* package String uint
33 int finally try for ]]>);
37 /* ----- xml objects ----- */
39 var x1:XML = <tree name="test">
40 <branch bname="t1">Branch 1</branch>
41 <branch bname="t2">Branch 2</branch>
44 assert(typeof(x1)=="xml");
46 /* ------ access --------- */
48 assert(x1. * == x1.children())
49 assert((x1.*)[0].text() == "Branch 1")
50 assert(x1.branch[0] == x1.child("branch")[0])
51 assert((x1.*.@bname)[0] == "t1");
53 assert(x1.@name.parent() == x1);
54 assert(x1.@["name"].parent() == x1);
55 var s1= <t x="a" y="b" z="c" />
56 assert(s1.@* == s1.attributes())
58 /* ------ comments ------- */
60 var x3 = <x><!-- </x>xxxx -->Test</x>;
61 assert(x3.toString() == "Test")
63 /* ------ descendants ---- */
75 assert(x4..l3[0] == x4.l2.l3)
78 for each(var c:XML in x4..l3) {
84 for each(var e:XML in x1..@bname) {
90 for each(var e in x1..@*) {
93 assert(s=="testt1t2");
95 /* ----- filtering ----- */
97 var x5:XML = <participants>
98 <person gender="m" id="1">John Doe</person>
99 <person gender="f" id="2">Ellen Doe</person>
100 <person gender="m">John Smith</person>
101 <person gender="f" id="4">Jane Smith</person>
104 var l:XMLList = x5.*;
105 var l2:XMLList = l.(@gender=="m");
106 assert(l2.length()==2 && l2[0].text()=="John Doe" && l2[1].text()=="John Smith");
107 l2 = x5.*.(@gender=="f").(hasOwnProperty("@id") && @id>2)
108 assert(l2.text() =="Jane Smith");
110 /* ----- replacement ----- */
112 var x10:XML = <a><b a="x"><c/></b></a>
113 var x11:XML = <a><b a="y"><d/></b></a>
121 var x12:XML = <x><a/></x>;
124 assert(x12 == <x><a/><b/></x>);
127 assert(x12 == <x><c/></x>);
130 /* ----- deletion ----- */
133 assert(x12 == <x><b/></x>);
138 assert(x10 == <a><b/></a>);
143 /* ----- special characters ----- */
145 var x20 = <x> > & </x>;
146 assert(x20.toString() == ">&");
147 var x21 = <x a=""<>"/>;
148 assert(x21.@a == "\"<>");
151 /* ----- substitution ----- */
153 var x2:XML = <{"tree"} {"na"+"me"}="test">
154 <{{3: "branch"}[3]} bname={"t1"}>{"Branch" + " " + 1}</{"branch"}>
155 <branch bname="t2">Branch 2</branch>