summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2005-04-11 17:10:12 +0000
committerburaq <buraq@epfl.ch>2005-04-11 17:10:12 +0000
commit51fcef17d61451116c6349ba4bffacc5aa82e48c (patch)
treeeb57c2c3c2aa140af48538c4e3d8cbe9638b3d5d /test/files/jvm
parentbca179b89557e3e374281ec47f16d7aa9d64e32f (diff)
downloadscala-51fcef17d61451116c6349ba4bffacc5aa82e48c.tar.gz
scala-51fcef17d61451116c6349ba4bffacc5aa82e48c.tar.bz2
scala-51fcef17d61451116c6349ba4bffacc5aa82e48c.zip
hello
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/xml01.check20
-rw-r--r--test/files/jvm/xml01.scala174
2 files changed, 194 insertions, 0 deletions
diff --git a/test/files/jvm/xml01.check b/test/files/jvm/xml01.check
new file mode 100644
index 0000000000..57a788c6a1
--- /dev/null
+++ b/test/files/jvm/xml01.check
@@ -0,0 +1,20 @@
+passed ok
+equality
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+xpath \
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+xpath \\ DESCENDANTS
+passed ok
+passed ok
+passed ok
diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala
new file mode 100644
index 0000000000..bd73a0fd7d
--- /dev/null
+++ b/test/files/jvm/xml01.scala
@@ -0,0 +1,174 @@
+import java.io.StringReader;
+import org.xml.sax.InputSource;
+import scala.xml._;
+import scala.xml.nobinding._;
+import scala.util.logging._;
+
+import scala.testing.UnitTest._ ;
+
+object Test with Application {
+ val e: scala.xml.MetaData = Null; //Node.NoAttributes;
+ val sc: scala.xml.NamespaceBinding = null;
+
+ val xmlFile1 = "<hello><world/></hello>";
+ val isrc1 = new InputSource( new StringReader( xmlFile1 ) );
+ val parsedxml1 = XML.load( isrc1 );
+ val isrc11 = new InputSource( new StringReader( xmlFile1 ) );
+ val parsedxml11 = XML.load( isrc11 );
+
+ val c = new Node {
+ def label = "hello";
+ //def namespace = "";
+ def child = List(Elem("","world",e,sc));
+ //def attributes = e;
+ };
+
+ assertSameElements( List( 3 ), List( 3 ));
+
+ Console.println("equality");
+ assertEquals( c, parsedxml11 );
+ assertEquals( parsedxml1, parsedxml11 );
+ assertSameElements( List(parsedxml1), List(parsedxml11));
+ assertSameElements( Iterator.fromArray(Predef.Array(parsedxml1)).toList, List(parsedxml11));
+
+ val x2 = "<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>";
+
+ val i = new InputSource( new StringReader( x2 ));
+ val x2p = XML.load( i );
+
+ assertEquals(x2p, Elem("","book",e,sc,
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Elem("","title",e,sc,Text("Data on ze web"))));
+
+ val xmlFile2 = "<bib><book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book><book><author>John Mitchell</author><title>Foundations of Programming Languages</title></book></bib>";
+ val isrc2 = new InputSource( new StringReader( xmlFile2 ) );
+ val parsedxml2 = XML.load( isrc2 );
+
+ // xmlFile2/book -> book,book
+ Console.println("xpath \\");
+
+
+ assertSameElements( parsedxml1 \ "_" , List( Elem("","world",e,sc) ) );
+
+ assertSameElements( parsedxml1 \ "world", List( Elem("","world",e,sc) ) );
+
+/*
+ Console.println( parsedxml2 \ "_" );
+ Console.println( (parsedxml2 \ "_" ).elements);
+ for( val i <- (parsedxml2 \ "_" ).elements) {
+ Console.println( i );
+ };
+ */
+
+ assertSameElements(
+ parsedxml2 \ "_" ,
+
+ List(
+ Elem("","book", e,sc,
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Elem("","title",e,sc,Text("Data on ze web"))),
+ Elem("","book",e,sc,
+ Elem("","author",e,sc,Text("John Mitchell")),
+ Elem("","title",e,sc,Text("Foundations of Programming Languages"))))
+ );
+ assertEquals( (parsedxml2 \ "author").length, 0 );
+
+ assertSameElements(
+ parsedxml2 \ "book",
+
+ List(
+ Elem("","book",e,sc,
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Elem("","title",e,sc,Text("Data on ze web"))),
+ Elem("","book",e,sc,
+ Elem("","author",e,sc,Text("John Mitchell")),
+ Elem("","title",e,sc,Text("Foundations of Programming Languages")))
+ )
+ );
+
+ assertSameElements(
+
+ parsedxml2 \ "_" \ "_",
+
+ List(
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Elem("","title",e,sc,Text("Data on ze web")),
+ Elem("","author",e,sc,Text("John Mitchell")),
+ Elem("","title",e,sc,Text("Foundations of Programming Languages"))
+ )
+ );
+
+ assertSameElements(
+
+ parsedxml2 \ "_" \ "author",
+
+ List(
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Elem("","author",e,sc,Text("John Mitchell"))
+ )
+
+ );
+
+ assertSameElements( (parsedxml2 \ "_" \ "_" \ "author"), List() );
+
+ Console.println("xpath \\\\ DESCENDANTS");
+
+ assertSameElements(
+
+ parsedxml2 \\ "author",
+
+ List(
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Elem("","author",e,sc,Text("John Mitchell"))
+ )
+
+ );
+ assertEquals(
+
+ (new NodeSeq { val theSeq = List( parsedxml2 ) }) \\ "_",
+
+ List(
+ Elem("","bib",e,sc,
+ Elem("","book",e,sc,
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Elem("","title",e,sc,Text("Data on ze web"))),
+ Elem("","book",e,sc,
+ Elem("","author",e,sc,Text("John Mitchell")),
+ Elem("","title",e,sc,Text("Foundations of Programming Languages")))),
+ Elem("","book",e,sc,
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Elem("","title",e,sc,Text("Data on ze web"))),
+ Elem("","author",e,sc,Text("Peter Buneman")),
+ Text("Peter Buneman"),
+ Elem("","author",e,sc,Text("Dan Suciu")),
+ Text("Dan Suciu"),
+ Elem("","title",e,sc,Text("Data on ze web")),
+ Text("Data on ze web"),
+ Elem("","book",e,sc,
+ Elem("","author",e,sc,Text("John Mitchell")),
+ Elem("","title",e,sc,Text("Foundations of Programming Languages"))),
+ Elem("","author",e,sc,Text("John Mitchell")),
+ Text("John Mitchell"),
+ Elem("","title",e,sc,Text("Foundations of Programming Languages")),
+ Text("Foundations of Programming Languages")
+ )
+ );
+
+
+ assertSameElements(
+
+ parsedxml2 \\ "title",
+
+ List(
+ Elem("","title",e,sc,Text("Data on ze web")),
+ Elem("","title",e,sc,Text("Foundations of Programming Languages")))
+ );
+}