summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-03-12 20:08:43 +0000
committerburaq <buraq@epfl.ch>2004-03-12 20:08:43 +0000
commit6c1888cb456c1fd87594399ca9cdeec4485dfaac (patch)
tree8dfedddd4afde23835a83ec476d66935620ddccd /test/files
parentc1df3809c679310c5acd6316ef7092792ae1f31c (diff)
downloadscala-6c1888cb456c1fd87594399ca9cdeec4485dfaac.tar.gz
scala-6c1888cb456c1fd87594399ca9cdeec4485dfaac.tar.bz2
scala-6c1888cb456c1fd87594399ca9cdeec4485dfaac.zip
changes to xml api
Diffstat (limited to 'test/files')
-rw-r--r--test/files/jvm/xmlstuff.check10
-rw-r--r--test/files/jvm/xmlstuff.scala140
2 files changed, 94 insertions, 56 deletions
diff --git a/test/files/jvm/xmlstuff.check b/test/files/jvm/xmlstuff.check
index fafc444191..8fb144e796 100644
--- a/test/files/jvm/xmlstuff.check
+++ b/test/files/jvm/xmlstuff.check
@@ -1,11 +1,21 @@
+equality
passed ok
passed ok
passed ok
passed ok
passed ok
+xpath \
passed ok
passed ok
passed ok
passed ok
passed ok
passed ok
+case _
+passed ok
+case _
+passed ok
+xpath \\
+passed ok
+passed ok
+passed ok
diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala
index db6e3f90a0..ebd140d301 100644
--- a/test/files/jvm/xmlstuff.scala
+++ b/test/files/jvm/xmlstuff.scala
@@ -2,70 +2,93 @@ import java.io.StringReader;
import org.xml.sax.InputSource;
import scala.xml.nobinding.XML;
import scala.testing.UnitTest._ ;
-import scala.xml.{Node,NodeSeq};
+import scala.xml.{Node,NodeSeq,Text};
object Test with Application {
-
- def eq( a:Seq[Node], b:Seq[Node] ) = {
- if( a.length == b.length ) {
- val ita = a.elements;
- val itb = b.elements;
- var res = true;
- while( ita.hasNext ) {
- res = res &&( ita.next == itb.next );
- };
- res
- } else {
- false
- }
+/*
+ def eq( a:Seq[Node], b:Seq[Node] ):boolean = {
+ (a.length == b.length) && eq(a.elements,b.elements)
+ }
+ def eq( ita:Iterator[Node], itb:Iterator[Node] ) = {
+ var res = true;
+ while( ita.hasNext && itb.hasNext && res ) {
+ res = (ita.next == itb.next);
+ };
+ !ita.hasNext && !itb.hasNext && res
}
+ */
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 child = List('world());
+ def attribute = List();
+ };
+
+ Console.println("equality");
+ assertEquals( c, parsedxml11 );
+ assertEquals( parsedxml1, parsedxml11 );
+ assertSimilar( List(parsedxml1), List(parsedxml11));
+ assertSimilar( Iterator.fromArray(Predef.Array(parsedxml1)).toSeq(1), 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 );
+
+ assertSimilar(x2p, 'book('author(Text("Peter Buneman")),
+ 'author(Text("Dan Suciu")),
+ 'title(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 \\");
- assertEquals( eq( parsedxml1/'_ ,List('world()) ), true);
- assertEquals( eq( parsedxml1/'world ,List('world()) ), true);
- assertEquals(
- eq(
+ assertSimilar( parsedxml1 \ '_ , List( 'world() ) );
- parsedxml2/'_,
+ assertSimilar( parsedxml1 \ 'world, List( 'world() ) );
+
+/*
+ Console.println( parsedxml2 \ '_ );
+ Console.println( (parsedxml2 \ '_).elements);
+ for( val i <- (parsedxml2 \ '_).elements) {
+ Console.println( i );
+ };
+ */
+ assertSimilar(
+ parsedxml2 \ '_ ,
List(
'book('author(Text("Peter Buneman")),
'author(Text("Dan Suciu")),
'title(Text("Data on ze web"))),
'book('author(Text("John Mitchell")),
- 'title(Text("Foundations of Programming Languages")))
- )), true );
-
+ 'title(Text("Foundations of Programming Languages"))))
+ );
+ assertEquals( (parsedxml2 \ 'author).length, 0 );
- assertEquals( (parsedxml2/'author).length == 0, true );
-
-
- assertEquals(
- eq(
-
- parsedxml2/'book,
+ assertSimilar(
+ parsedxml2 \ 'book,
List(
'book('author(Text("Peter Buneman")),
'author(Text("Dan Suciu")),
'title(Text("Data on ze web"))),
'book('author(Text("John Mitchell")),
- 'title(Text("Foundations of Programming Languages")))
- )), true );
+ 'title(Text("Foundations of Programming Languages"))))
+ );
- assertEquals(
- eq(
+ assertSimilar(
- parsedxml2/'_/'_,
+ parsedxml2 \ '_ \ '_,
List('author(Text("Peter Buneman")),
'author(Text("Dan Suciu")),
@@ -73,41 +96,48 @@ object Test with Application {
'author(Text("John Mitchell")),
'title(Text("Foundations of Programming Languages")))
- ), true);
+ );
- assertEquals(
- eq(
+ assertSimilar(
- parsedxml2/'_/'author,
+ parsedxml2 \ '_ \ 'author,
List('author(Text("Peter Buneman")),
'author(Text("Dan Suciu")),
'author(Text("John Mitchell")))
- ), true);
+ );
+
+ assertSimilar( (parsedxml2 \ '_ \ '_ \ 'author), List() );
- assertEquals( (parsedxml2/'_/'_/'author).length == 0, true );
+ Console.println("xpath \\\\");
- assertEquals(
- eq(
+ assertSimilar(
- parsedxml2/#'author,
+ parsedxml2 \\ 'author,
List('author(Text("Peter Buneman")),
'author(Text("Dan Suciu")),
'author(Text("John Mitchell")))
- ), true );
+ );
- assertEquals(
- eq(
+ assertSimilar(
- parsedxml2/#'_,
+ new NodeSeq(List( parsedxml2 ))\\ '_,
List(
- 'book('author(Text("Peter Buneman")),
- 'author(Text("Dan Suciu")),
- 'title(Text("Data on ze web"))),
+ 'bib(
+ 'book(
+ 'author(Text("Peter Buneman")),
+ 'author(Text("Dan Suciu")),
+ 'title(Text("Data on ze web"))),
+ 'book('author(Text("John Mitchell")),
+ 'title(Text("Foundations of Programming Languages")))),
+ 'book(
+ 'author(Text("Peter Buneman")),
+ 'author(Text("Dan Suciu")),
+ 'title(Text("Data on ze web"))),
'author(Text("Peter Buneman")),
Text("Peter Buneman"),
'author(Text("Dan Suciu")),
@@ -120,17 +150,15 @@ object Test with Application {
Text("John Mitchell"),
'title(Text("Foundations of Programming Languages")),
Text("Foundations of Programming Languages"))
- ) , true);
+ );
- assertEquals(
- eq(
+ assertSimilar(
- parsedxml2/#'title,
+ parsedxml2 \\ 'title,
List(
'title(Text("Data on ze web")),
'title(Text("Foundations of Programming Languages")))
- ) , true);
-
+);
}