From 1d6a8505afb732f72bbba09c753721384e2b02a4 Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Fri, 25 Nov 2005 09:17:39 +0000 Subject: test case for verifying attribu value --- test/files/jvm/xmlstuff.check | 10 +++++++++ test/files/jvm/xmlstuff.scala | 52 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/files/jvm/xmlstuff.check b/test/files/jvm/xmlstuff.check index a4902e1264..a46f4c8c7a 100644 --- a/test/files/jvm/xmlstuff.check +++ b/test/files/jvm/xmlstuff.check @@ -1,3 +1,13 @@ +checking wellformed attributes +< not allowed in attribute value +passed ok +malformed entity reference in attribute value [&] +passed ok +malformed entity reference in attribute value [a&a] +passed ok +malformed entity reference in attribute value [a&a;&] +passed ok +passed ok NodeSeq passed ok passed ok diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala index 441a91c3e4..e9db999828 100644 --- a/test/files/jvm/xmlstuff.scala +++ b/test/files/jvm/xmlstuff.scala @@ -4,6 +4,20 @@ import scala.testing.UnitTest._ ; import scala.xml.{Node, NodeSeq, Elem, Text, XML}; object Test { + + /** returns true if exception was thrown */ + def catcher(att:Function1[Unit,scala.xml.MetaData]): Boolean = { + var ex = false; + try { + val x = att.apply({}); + } catch { + case scala.xml.MalformedAttributeException(msg) => + Console.println(msg); + ex = true; + } + return ex; + } + def main(args:Array[String]) = { //val e: scala.xml.MetaData = null; //Node.NoAttributes; @@ -11,6 +25,18 @@ object Test { // ------------------------------------------ tests for class NodeSeq + Console.println("checking wellformed attributes"); + { + import scala.xml.{ UnprefixedAttribute, Null } + assertTrue(catcher {x:Unit => new UnprefixedAttribute("key", "<", Null)}); // < illegal + assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "&", Null))); // & illegal + assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "a&a", Null))); // & illegal + assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "a&a;&", Null))); // 2nd & + + assertFalse(catcher(x:Unit => new UnprefixedAttribute("key", "a&a; <<", Null))); + } + + Console.println("NodeSeq"); import scala.xml.Utility.view ; @@ -29,6 +55,28 @@ object Test { p \\ "@value", new NodeSeq { val theSeq = List(Text("3"), Text("5")) } ); + + /* // more test cases !!! + val test = ; + + Console.println(test \ "@name"); + + val x = test.attributes.nodes; + Console.println("trying to print"); + val it = x.elements; + while(it.hasNext) { + val c = it.next; + Console.println(c); + Console.println("c.label == @name? "+(c.label == "@name")); + } + */ + + /* + for(val c <- x) { + Console.println(x); + } + */ + val books = Blabla @@ -115,9 +163,9 @@ val addrBook = assertEquals( - match { case + match { case x @ - => true; + if x.attribute("foo") == "bar" => true; case _ => false; }, true); -- cgit v1.2.3