diff options
author | Burak Emir <emir@epfl.ch> | 2005-11-25 09:17:39 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2005-11-25 09:17:39 +0000 |
commit | 1d6a8505afb732f72bbba09c753721384e2b02a4 (patch) | |
tree | 993835cd9d20634d342e0d28049810b020d2b8d9 /test | |
parent | 61befc9bdea2fe934391ce004e0432db8c93dce3 (diff) | |
download | scala-1d6a8505afb732f72bbba09c753721384e2b02a4.tar.gz scala-1d6a8505afb732f72bbba09c753721384e2b02a4.tar.bz2 scala-1d6a8505afb732f72bbba09c753721384e2b02a4.zip |
test case for verifying attribu value
Diffstat (limited to 'test')
-rw-r--r-- | test/files/jvm/xmlstuff.check | 10 | ||||
-rw-r--r-- | test/files/jvm/xmlstuff.scala | 52 |
2 files changed, 60 insertions, 2 deletions
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 = <a name="bar"/>; + + 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 = <bks> <book><title>Blabla</title></book> @@ -115,9 +163,9 @@ val addrBook = assertEquals( <hello foo="bar"> <world/> - </hello> match { case <hello> + </hello> match { case x @ <hello> <world/> - </hello> => true; + </hello> if x.attribute("foo") == "bar" => true; case _ => false; }, true); |