diff options
author | buraq <buraq@epfl.ch> | 2004-02-11 18:42:54 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-02-11 18:42:54 +0000 |
commit | 196d85658ba3a9b8db109b5a33adbe8b2d47c12e (patch) | |
tree | b32ca399818d5f156b95b7b7b1345562804786b4 /test/files/jvm/xmlstuff.scala | |
parent | 9de41d8e774ab45faf86e604b96e5f0bcd58de77 (diff) | |
download | scala-196d85658ba3a9b8db109b5a33adbe8b2d47c12e.tar.gz scala-196d85658ba3a9b8db109b5a33adbe8b2d47c12e.tar.bz2 scala-196d85658ba3a9b8db109b5a33adbe8b2d47c12e.zip |
better comparison of actual and expected results
Diffstat (limited to 'test/files/jvm/xmlstuff.scala')
-rw-r--r-- | test/files/jvm/xmlstuff.scala | 136 |
1 files changed, 111 insertions, 25 deletions
diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala index 28f753ce90..db6e3f90a0 100644 --- a/test/files/jvm/xmlstuff.scala +++ b/test/files/jvm/xmlstuff.scala @@ -1,10 +1,24 @@ import java.io.StringReader; import org.xml.sax.InputSource; import scala.xml.nobinding.XML; -import scala.testing.UnitTest.assertEquals ; -import scala.xml.NodeList; +import scala.testing.UnitTest._ ; +import scala.xml.{Node,NodeSeq}; 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 + } + } val xmlFile1 = "<hello><world/></hello>"; val isrc1 = new InputSource( new StringReader( xmlFile1 ) ); val parsedxml1 = XML.load( isrc1 ); @@ -15,36 +29,108 @@ object Test with Application { // xmlFile2/book -> book,book - Console.println( parsedxml1/'world ); /* List('world()) */ - Console.println( parsedxml1/'_ ); /* List('world()) */ + assertEquals( eq( parsedxml1/'_ ,List('world()) ), true); + assertEquals( eq( parsedxml1/'world ,List('world()) ), true); + + assertEquals( + eq( + + 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 ); + + + assertEquals( (parsedxml2/'author).length == 0, true ); + + + assertEquals( + eq( + + 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 ); + + assertEquals( + eq( + + parsedxml2/'_/'_, + + List('author(Text("Peter Buneman")), + 'author(Text("Dan Suciu")), + 'title(Text("Data on ze web")), + 'author(Text("John Mitchell")), + 'title(Text("Foundations of Programming Languages"))) + + ), true); + + assertEquals( + eq( + + parsedxml2/'_/'author, + + List('author(Text("Peter Buneman")), + 'author(Text("Dan Suciu")), + 'author(Text("John Mitchell"))) + + ), true); + + assertEquals( (parsedxml2/'_/'_/'author).length == 0, true ); + + assertEquals( + eq( + + parsedxml2/#'author, + + List('author(Text("Peter Buneman")), + 'author(Text("Dan Suciu")), + 'author(Text("John Mitchell"))) - Console.println( "\nparsedxml2/'_"); /* List(book,book) */ - Console.println( parsedxml2/'_); /* List(book,book) */ + ), true ); - Console.println( "\nparsedxml2/'author"); /* List() */ - Console.println( parsedxml2/'author); /* List() */ + assertEquals( + eq( - Console.println( "\nparsedxml2/'book:"); - Console.println( parsedxml2/'book); /* List(book,book) */ + parsedxml2/#'_, - Console.println( "\nparsedxml2/'_/'_"); - Console.println( parsedxml2/'_/'_ ); - Console.println( "\nparsedxml2/'_/'author"); - Console.println( parsedxml2/'_/'author ); - Console.println( "\nparsedxml2/'_/'_/'author"); - Console.println( parsedxml2/'_/'_/'author ); - /* List('author(Text("Peter Buneman")), - 'author(Text("Dan Suciu")), - 'author(Text("John Mitchell")))); */ + List( + '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")), + Text("Dan Suciu"), + 'title(Text("Data on ze web")), + Text("Data on ze web"), + 'book('author(Text("John Mitchell")), + 'title(Text("Foundations of Programming Languages"))), + 'author(Text("John Mitchell")), + Text("John Mitchell"), + 'title(Text("Foundations of Programming Languages")), + Text("Foundations of Programming Languages")) + ) , true); - Console.println( "\nparsedxml2/#'author"); - Console.println( parsedxml2/#'author ); - Console.println( "\nnew NodeList(List(parsedxml2))/#'_"); - Console.println( new NodeList( List( parsedxml2 ))/#'_ ); + assertEquals( + eq( - Console.println( "\nnew NodeList(List(parsedxml2))/#'title"); - Console.println( new NodeList( List( parsedxml2 ))/#'title ); + parsedxml2/#'title, + List( + 'title(Text("Data on ze web")), + 'title(Text("Foundations of Programming Languages"))) + ) , true); } |