diff options
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/jvm/xml02.check | 13 | ||||
-rw-r--r-- | test/files/jvm/xml02.scala | 55 | ||||
-rw-r--r-- | test/files/jvm/xml03syntax.check | 24 | ||||
-rw-r--r-- | test/files/jvm/xml03syntax.scala | 62 | ||||
-rw-r--r-- | test/files/jvm/xml04embed.check | 3 | ||||
-rw-r--r-- | test/files/jvm/xml04embed.scala | 17 |
6 files changed, 174 insertions, 0 deletions
diff --git a/test/files/jvm/xml02.check b/test/files/jvm/xml02.check new file mode 100644 index 0000000000..dc9e15dd2b --- /dev/null +++ b/test/files/jvm/xml02.check @@ -0,0 +1,13 @@ +attributes +one +passed ok +two +passed ok +three +passed ok +four +passed ok +five +passed ok +patterns +passed ok diff --git a/test/files/jvm/xml02.scala b/test/files/jvm/xml02.scala new file mode 100644 index 0000000000..cbc9b5041b --- /dev/null +++ b/test/files/jvm/xml02.scala @@ -0,0 +1,55 @@ +object Test { +def main(args:Array[String]) = { + import scala.xml.NodeSeq + import NodeSeq.view + import testing.UnitTest._ + + + val ax = <hello foo="bar"> + <world/> + </hello> + + Console.println("attributes"); + + Console.println("one"); + assertEquals(ax \ "@foo", "bar") + Console.println("two"); + assertEquals(ax \ "@foo", xml.Text("bar")) + + val bx = <hello foo="bar&x"></hello> + + Console.println("three"); + assertEquals(bx \ "@foo", "bar&x") + Console.println("four"); + assertSameElements(bx \ "@foo", List(xml.Text("bar"),xml.EntityRef("amp"),xml.Text("x"))) + + Console.println("five"); + assertEquals(bx.toString, "<hello foo=\"bar&x\"></hello>") + + + /* patterns */ + Console.println("patterns"); + assertEquals(<hello/> match { case <hello/> => true; case _ => false; }, + true); + + + + /* + assertEquals(ax match { case x @ <hello> + <world/> + </hello> if x \ "@foo" == "bar" => true; + case _ => false; }, + true); + + assertEquals( + <hello foo="bar"> + crazy text world + </hello> match { case <hello> + crazy text world + </hello> => true; + case _ => false; }, + true); + */ +} + +} diff --git a/test/files/jvm/xml03syntax.check b/test/files/jvm/xml03syntax.check new file mode 100644 index 0000000000..b81c53e9b1 --- /dev/null +++ b/test/files/jvm/xml03syntax.check @@ -0,0 +1,24 @@ +<hello>()</hello> +passed ok +<hello>()</hello> +passed ok +<hello>world</hello> +passed ok +<hello>1.5</hello> +passed ok +<hello>5</hello> +passed ok +<hello>true</hello> +passed ok +<hello>5</hello> +passed ok +<hello>27</hello> +passed ok +<hello>1 2 3 4</hello> +1 +2 +3 +4 +<hello>2 4</hello> +2 +4 diff --git a/test/files/jvm/xml03syntax.scala b/test/files/jvm/xml03syntax.scala new file mode 100644 index 0000000000..7ae6473302 --- /dev/null +++ b/test/files/jvm/xml03syntax.scala @@ -0,0 +1,62 @@ +object Test { + + import scala.testing.UnitTest._ + import scala.xml._ + + def handle[A](x:Node): A = { + Console println x + x.child(0).asInstanceOf[Atom[A]].data + } + + def main(args:Array[String]) = { + import scala.xml.NodeSeq + import NodeSeq.view + import testing.UnitTest._ + + val x0 = <hello>{}</hello> + val x00 = <hello>{ }</hello> + val xa = <hello>{ "world" }</hello> + + + assertEquals( handle[Unit](x0), {} ) + assertEquals( handle[Unit](x00), {} ) + assertEquals( handle[String](xa),"world" ) + + val xb = <hello>{ 1.5 }</hello> + + assertEquals( handle[Double](xb), 1.5 ) + + val xc = <hello>{ 5 }</hello> + + assertEquals( handle[Int](xc), 5 ) + + val xd = <hello>{ true }</hello> + + assertEquals( handle[Boolean](xd), true ) + + val xe = <hello>{ 5:short }</hello> + + assertEquals( handle[Short](xe), 5:short ) + + val xf = <hello>{ val x = 27; x }</hello> + + assertEquals( handle[Int](xf), 27 ) + + val xg = <hello>{ List(1,2,3,4) }</hello> + + Console println xg + for(val z <- xg.child) { + Console println z.toString() + {if (z.isInstanceOf[Text]) "(is text node ' ')" else ""} + } + + val xh = <hello>{ for(val x <- List(1,2,3,4); x % 2 == 0) yield x }</hello> + + Console println xh + for(val z <- xh.child) { + Console println z.toString() + {if (z.isInstanceOf[Text]) "(is text node ' ')" else ""} + } + + +} + +} diff --git a/test/files/jvm/xml04embed.check b/test/files/jvm/xml04embed.check new file mode 100644 index 0000000000..9c9ba2b8d5 --- /dev/null +++ b/test/files/jvm/xml04embed.check @@ -0,0 +1,3 @@ +passed ok +passed ok +passed ok diff --git a/test/files/jvm/xml04embed.scala b/test/files/jvm/xml04embed.scala new file mode 100644 index 0000000000..807610a3b1 --- /dev/null +++ b/test/files/jvm/xml04embed.scala @@ -0,0 +1,17 @@ +object Test { + + import scala.testing.UnitTest._ + import scala.xml._ + + def main(args:Array[String]) = { + val ya = <x>{{</x> + assertEquals(ya.text, "{"); + + val ua = <x>}}</x> + assertEquals(ua.text, "}"); + + val za = <x>{{}}{{}}{{}}</x> + assertEquals(za.text, "{}{}{}"); + + } +} |