diff options
author | michelou <michelou@epfl.ch> | 2007-12-19 16:52:40 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-12-19 16:52:40 +0000 |
commit | 8ad43107f52b278930a663874943de9eda0c8df0 (patch) | |
tree | 2e7fa80109cdd1a2ba1053aad0ff951132f71251 /test/files/jvm/xmlstuff.scala | |
parent | 999d30eea73cc19ff1603fc57c13d937c4fc6ce2 (diff) | |
download | scala-8ad43107f52b278930a663874943de9eda0c8df0.tar.gz scala-8ad43107f52b278930a663874943de9eda0c8df0.tar.bz2 scala-8ad43107f52b278930a663874943de9eda0c8df0.zip |
removed deprecated features
Diffstat (limited to 'test/files/jvm/xmlstuff.scala')
-rw-r--r-- | test/files/jvm/xmlstuff.scala | 164 |
1 files changed, 58 insertions, 106 deletions
diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala index df0e129248..46faf283dc 100644 --- a/test/files/jvm/xmlstuff.scala +++ b/test/files/jvm/xmlstuff.scala @@ -1,24 +1,25 @@ -import java.io.StringReader; -import org.xml.sax.InputSource; -import scala.testing.UnitTest._ ; -import scala.xml.{Node, NodeSeq, Elem, Text, XML}; +import java.io.StringReader +import org.xml.sax.InputSource -object Test { +import scala.testing.SUnit.Assert +import scala.xml.{Node, NodeSeq, Elem, Text, XML} + +object Test extends AnyRef with Assert { /** 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 catcher(att: Function1[Unit, scala.xml.MetaData]): Boolean = { + var ex = false + try { + att.apply({}) + } catch { + case scala.xml.MalformedAttributeException(msg) => + println(msg) + ex = true + } + ex } - def main(args:Array[String]) = { + def main(args: Array[String]) { //val e: scala.xml.MetaData = null; //Node.NoAttributes; //val sc: scala.xml.NamespaceBinding = null; @@ -26,7 +27,7 @@ object Test { // ------------------------------------------ tests for class NodeSeq /** - Console.println("checking wellformed attributes"); + println("checking wellformed attributes"); { import scala.xml.{ UnprefixedAttribute, Null } assertTrue(catcher {x:Unit => new UnprefixedAttribute("key", "<", Null)}); // < illegal @@ -51,8 +52,7 @@ passed ok passed ok */ - Console.println("NodeSeq"); - import scala.xml.Utility.view ; + println("NodeSeq") val p = <foo> <bar gt='ga' value="3"/> @@ -64,35 +64,9 @@ passed ok Text(x.attributes("value").toString + y.attributes("bazValue").toString+ "!") }; val pelems_2 = new NodeSeq { val theSeq = List(Text("38!"),Text("58!")) }; - assertSameElements(pelems_1, pelems_2); + assertSameElements(pelems_1, pelems_2) assertEquals(p \\ "@bazValue", Text("8")) - // the following won't work anymore because of group nodes - //assertSameElements( - // 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> @@ -120,10 +94,10 @@ passed ok </entry> </reviews>; - Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( - for( val t <- books \\ "title"; - val r <- reviews \\ "entry"; - r \ "title" == t) yield + println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( + for (t <- books \\ "title"; + r <- reviews \\ "entry" + if r \ "title" == t) yield <result> { t } { r \ "remarks" } @@ -131,8 +105,8 @@ passed ok )); // example - Console.println( - for( val t @ <book><title>Blabla</title></book> <- new NodeSeq { val theSeq = books.child }.toList) + println( + for (t @ <book><title>Blabla</title></book> <- new NodeSeq { val theSeq = books.child }.toList) yield t ); val phoneBook = @@ -162,10 +136,10 @@ val addrBook = </entry> </addrbook>; - Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( - for( val t <- addrBook \\ "entry"; - val r <- phoneBook \\ "entry"; - t \ "name" == r \ "name") yield + println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( + for (t <- addrBook \\ "entry"; + r <- phoneBook \\ "entry" + if t \ "name" == r \ "name") yield <result> { t.child } { r \ "phone" } @@ -175,46 +149,24 @@ val addrBook = /* namespaces */ // begin tmp - Console.println("namespaces"); + println("namespaces") val cuckoo = <cuckoo xmlns="http://cuckoo.com"> <foo/> <bar/> </cuckoo>; - assertEquals( cuckoo.namespace, "http://cuckoo.com"); - for( val n <- cuckoo \ "_" ) { - //Console.println("n = "+n); - //Console.println("n.prefix = "+n.prefix); - //Console.println("n.scope = "+n.scope); - assertEquals( n.namespace, "http://cuckoo.com"); + assertEquals(cuckoo.namespace, "http://cuckoo.com") + for (n <- cuckoo \ "_" ) { + //println("n = "+n); + //println("n.prefix = "+n.prefix); + //.println("n.scope = "+n.scope); + assertEquals( n.namespace, "http://cuckoo.com") } - // end tmp - /* -DEPRECATED, don't support namespaces in pattern match anymore -*/ - /* - assertEquals( true, cuckoo match { - case <cuckoo xmlns="http://cuckoo.com"> - <foo/> - <bar/> - </cuckoo> => true; - case _ => false; }); -*/ - /* - // begin tmp - assertEquals( false, cuckoo match { - case <cuckoo> - <foo/> - <bar/> - </cuckoo> => true; - case _ => false; }); - // end tmp - */ - Console.println("validation - elements"); + println("validation - elements") val vtor = new scala.xml.dtd.ElementValidator(); { - import scala.xml.dtd.ELEMENTS; - import scala.xml.dtd.ContentModel._; + import scala.xml.dtd.ELEMENTS + import scala.xml.dtd.ContentModel._ vtor.setContentModel( ELEMENTS( Sequ( @@ -222,10 +174,10 @@ DEPRECATED, don't support namespaces in pattern match anymore Star(Letter(ElemName("baz"))) ))); } - assertEquals( vtor( <foo><bar/><baz/><baz/></foo> ), true ); + assertEquals(vtor( <foo><bar/><baz/><baz/></foo> ), true); { - import scala.xml.dtd.MIXED; - import scala.xml.dtd.ContentModel._; + import scala.xml.dtd.MIXED + import scala.xml.dtd.ContentModel._ vtor.setContentModel( MIXED( @@ -234,28 +186,28 @@ DEPRECATED, don't support namespaces in pattern match anymore Letter(ElemName("bal"))))); } - assertEquals( vtor( <foo><bar/><baz/><baz/></foo> ), true ); - assertEquals( vtor( <foo>ab<bar/>cd<baz/>ed<baz/>gh</foo> ), true ); - assertEquals( vtor( <foo> <ugha/> <bugha/> </foo> ), false ); + assertEquals(vtor(<foo><bar/><baz/><baz/></foo> ), true) + assertEquals(vtor(<foo>ab<bar/>cd<baz/>ed<baz/>gh</foo> ), true) + assertEquals(vtor(<foo> <ugha/> <bugha/> </foo> ), false) - Console.println("validation - attributes"); - vtor.setContentModel(null); - vtor.setMetaData(List()); - assertEquals( vtor( <foo bar="hello"/> ), false ); + println("validation - attributes") + vtor.setContentModel(null) + vtor.setMetaData(List()) + assertEquals(vtor( <foo bar="hello"/> ), false) { - import scala.xml.dtd._ ; - vtor.setMetaData(List(AttrDecl("bar","CDATA",IMPLIED))); + import scala.xml.dtd._ + vtor setMetaData List(AttrDecl("bar", "CDATA", IMPLIED)) } - assertEquals( vtor( <foo href="http://foo.com" bar="hello"/> ), false ); - assertEquals( vtor( <foo bar="hello"/> ), true ); + assertEquals(vtor(<foo href="http://foo.com" bar="hello"/>), false) + assertEquals(vtor(<foo bar="hello"/>), true) { - import scala.xml.dtd._ ; - vtor.setMetaData(List(AttrDecl("bar","CDATA",REQUIRED))); + import scala.xml.dtd._ + vtor.setMetaData(List(AttrDecl("bar","CDATA",REQUIRED))) } - assertEquals( vtor( <foo href="http://foo.com" /> ), false ); - assertEquals( vtor( <foo bar="http://foo.com" /> ), true ); + assertEquals( vtor( <foo href="http://foo.com" /> ), false ) + assertEquals( vtor( <foo bar="http://foo.com" /> ), true ) } } |