package {
import flash.display.MovieClip
public class Main extends flash.display.MovieClip {
var count:int = 1;
var num:int = 31;
function assert(b:Boolean) {
if(b) {
trace("ok "+count+"/"+num);
} else {
trace("error "+count+"/"+num);
}
count = count + 1
}
function Main() {
/* ------ basic sanity tests ------ */
var x:XML = };
This XML doesn't do anything!
;
/Neither does this regexp!/
;
var y = 3;
test
assert(true);
var f2 = function(s:String) {assert(true);}
var f3 = function(s:String) {assert(true);}
f2();
//f3();
/* ----- xml objects ----- */
var x1:XML =
Branch 1
Branch 2
assert(typeof(x1)=="xml");
/* ------ access --------- */
assert(x1. * == x1.children())
assert((x1.*)[0].text() == "Branch 1")
assert(x1.branch[0] == x1.child("branch")[0])
assert((x1.*.@bname)[0] == "t1");
assert(x1.@name.parent() == x1);
assert(x1.@["name"].parent() == x1);
var s1=
assert(s1.@* == s1.attributes())
/* ------ comments ------- */
var x3 = Test;
assert(x3.toString() == "Test")
/* ------ descendants ---- */
var x4 =
v1
e1
e2
v2
assert(x4..l3[0] == x4.l2.l3)
var s:String="";
for each(var c:XML in x4..l3) {
s += c.toString();
}
assert(s=="v1v2");
s="";
for each(var e:XML in x1..@bname) {
s += e.toString();
}
assert(s=="t1t2");
s="";
for each(var e in x1..@*) {
s += e.toString();
}
assert(s=="testt1t2");
/* ----- filtering ----- */
var x5:XML =
John Doe
Ellen Doe
John Smith
Jane Smith
var l:XMLList = x5.*;
var l2:XMLList = l.(@gender=="m");
assert(l2.length()==2 && l2[0].text()=="John Doe" && l2[1].text()=="John Smith");
l2 = x5.*.(@gender=="f").(hasOwnProperty("@id") && @id>2)
assert(l2.text() =="Jane Smith");
/* ----- replacement ----- */
var x10:XML =
var x11:XML =
assert(x10 != x11);
x11.b.d = ;
assert(x10 != x11);
x11.b.@a = "x";
assert(x10 == x11);
x11.b.@["a"] = "y";
assert(x10 != x11);
x11.b.@["a"] = "x";
assert(x10 == x11);
var x12:XML = ;
x12.a += ;
assert(x12 == );
x12.* = ;
assert(x12 == );
x12.* = ;
/* ----- deletion ----- */
delete x12.a
assert(x12 == );
delete x12.*
assert(x12 == );
delete x10.b.c
delete x10.b.@a
assert(x10 == );
delete x11.b.c
delete x11.b.@*
assert(x10 == x11);
/* ----- special characters ----- */
trace("[special characters]");
var x20 = >& ;
assert(x20.toString() == ">&");
var x21 = ;
assert(x21.@a == "\"<>");
var x22 = ;
/* ----- substitution ----- */
trace("[substitution]");
x1.@t = "x";
var x2:XML = <{"tree"} {"na"+"me"}="test" {"t=\"x\""}>
<{{three: "branch"}["three"]} bname={"t1"}>{"Branch" + " " + 1}{"branch"}>
Branch 2
assert(x1 == x2);
trace("[exit]");
}
}
}