From 405b34baaf82f7d8b118e49236976add44406f30 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Thu, 5 Feb 2009 17:44:07 +0100 Subject: [PATCH] added more exhaustive xml test cases --- lib/as3/ok/xml.as | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/as3/ok/xml_ns.as | 47 +++++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 lib/as3/ok/xml.as create mode 100644 lib/as3/ok/xml_ns.as diff --git a/lib/as3/ok/xml.as b/lib/as3/ok/xml.as new file mode 100644 index 0000000..da948ed --- /dev/null +++ b/lib/as3/ok/xml.as @@ -0,0 +1,162 @@ +package { + import flash.display.MovieClip + public class Main extends flash.display.MovieClip { + var count:int = 1; + var num:int = 29; + 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); + + 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 ----- */ + + var x20 = >&; + assert(x20.toString() == ">&"); + var x21 = ; + assert(x21.@a == "\"<>"); + var x22 = ; + + /* ----- substitution ----- */ + + var x2:XML = <{"tree"} {"na"+"me"}="test"> + <{{3: "branch"}[3]} bname={"t1"}>{"Branch" + " " + 1} + Branch 2 + + assert(x1 == x2); + + trace("[exit]"); + } + } +} diff --git a/lib/as3/ok/xml_ns.as b/lib/as3/ok/xml_ns.as new file mode 100644 index 0000000..e798d3a --- /dev/null +++ b/lib/as3/ok/xml_ns.as @@ -0,0 +1,47 @@ +package { + import flash.display.MovieClip + public class Main extends flash.display.MovieClip { + var count:int = 1; + var num:int = 9; + function assert(b:Boolean) { + if(b) { + trace("ok "+count+"/"+num); + } else { + trace("error "+count+"/"+num); + } + count = count + 1 + } + function Main() { + var x:XML = + + P1 + P2 + P3 + + + var top:Namespace = x.namespace(); + var ns1:Namespace = x.namespace("test1"); + var ns2:Namespace = x.namespace("test2"); + var ns3:Namespace = x.namespace("test3"); + assert(ns1 == new Namespace("http://www.quiss.org/test1/")); + assert(ns2 == new Namespace("http://www.quiss.org/test2/")); + assert(x.ns1::test == "P1"); + assert(x.ns2::test == "P2"); + + assert(x.ns1::* == "P1") + + default xml namespace = ns2; + assert(x.test == "P2") + + assert(x.*::* == (x.ns1::*+x.ns2::*+x.ns3::*)) + assert(x..@*::* == "b"); + + x.ns2::test = x.ns3::test; + assert(x..@a.toString() == "bb"); + + trace("[exit]"); + } + } +} -- 1.7.10.4