From 6c1888cb456c1fd87594399ca9cdeec4485dfaac Mon Sep 17 00:00:00 2001 From: buraq Date: Fri, 12 Mar 2004 20:08:43 +0000 Subject: changes to xml api --- test/files/jvm/xmlstuff.check | 10 +++ test/files/jvm/xmlstuff.scala | 140 +++++++++++++++++++++++++----------------- 2 files changed, 94 insertions(+), 56 deletions(-) (limited to 'test/files') 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 = ""; 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 = "Peter BunemanDan SuciuData on ze web"; + + 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 = "Peter BunemanDan SuciuData on ze webJohn MitchellFoundations of Programming Languages"; 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); - +); } -- cgit v1.2.3