diff options
author | Paul Phillips <paulp@improving.org> | 2010-02-26 22:24:46 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-02-26 22:24:46 +0000 |
commit | 64fd0c1346dcd43cb814e4f99638321c159108fd (patch) | |
tree | a9cc92f5756442698813bc4d97bdf191b85b0680 /test/files/jvm | |
parent | 462e27a358fc466d51aaeec28c994c6667d320eb (diff) | |
download | scala-64fd0c1346dcd43cb814e4f99638321c159108fd.tar.gz scala-64fd0c1346dcd43cb814e4f99638321c159108fd.tar.bz2 scala-64fd0c1346dcd43cb814e4f99638321c159108fd.zip |
Quite a lot more work on XML equality than I ca...
Quite a lot more work on XML equality than I can properly justify
spending time on, but you know how it is once you get started on
something. This commit will likely break some code out there in the
world but this is impossible to avoid if we are to achieve sane equality
in trunk.
For anyone who was relying upon the 2.7 equality behavior for
scala.xml.* classes, using "xml_==" instead of "==" for comparisons will
restore the old behavior. The standard == on xml elements now attempts
to behave in such a way that symmetry and hashCode contracts will be
preserved. It's probably not 100% there yet, but I can tell you this: it
is closer today than it was yesterday.
Review by community.
Diffstat (limited to 'test/files/jvm')
-rw-r--r-- | test/files/jvm/xml01.scala | 40 | ||||
-rw-r--r-- | test/files/jvm/xml02.scala | 16 | ||||
-rw-r--r-- | test/files/jvm/xmlstuff.scala | 8 |
3 files changed, 31 insertions, 33 deletions
diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala index e305f516d7..56e1c4ef96 100644 --- a/test/files/jvm/xml01.scala +++ b/test/files/jvm/xml01.scala @@ -25,20 +25,18 @@ object Test extends Application with Assert { override def text = "" } - assertSameElements(List(3), List(3)) - println("equality") - assertEquals(c, parsedxml11) - assertEquals(parsedxml1, parsedxml11) - assertSameElements(List(parsedxml1), List(parsedxml11)) - assertSameElements(Array(parsedxml1).toList, List(parsedxml11)) + assertEqualsXML(c, parsedxml11) + assertEqualsXML(parsedxml1, parsedxml11) + assertSameElementsXML(List(parsedxml1), List(parsedxml11)) + assertSameElementsXML(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(null, "book" , e, sc, + assertEqualsXML(x2p, Elem(null, "book" , e, sc, Elem(null, "author", e, sc,Text("Peter Buneman")), Elem(null, "author", e, sc,Text("Dan Suciu")), Elem(null, "title" , e, sc,Text("Data on ze web")))); @@ -51,9 +49,9 @@ object Test extends Application with Assert { println("xpath \\") - assertSameElements(parsedxml1 \ "_" , List(Elem(null,"world", e, sc))) + assertSameElementsXML(parsedxml1 \ "_" , List(Elem(null,"world", e, sc))) - assertSameElements(parsedxml1 \ "world", List(Elem(null,"world", e, sc))) + assertSameElementsXML(parsedxml1 \ "world", List(Elem(null,"world", e, sc))) /* Console.println( parsedxml2 \ "_" ); @@ -63,7 +61,7 @@ object Test extends Application with Assert { }; */ - assertSameElements( + assertSameElementsXML( parsedxml2 \ "_" , List( @@ -77,7 +75,7 @@ object Test extends Application with Assert { ); assertEquals( (parsedxml2 \ "author").length, 0 ); - assertSameElements( + assertSameElementsXML( parsedxml2 \ "book", List( @@ -91,7 +89,7 @@ object Test extends Application with Assert { ) ); - assertSameElements( + assertSameElementsXML( parsedxml2 \ "_" \ "_", @@ -104,7 +102,7 @@ object Test extends Application with Assert { ) ); - assertSameElements( + assertSameElementsXML( parsedxml2 \ "_" \ "author", @@ -116,11 +114,11 @@ object Test extends Application with Assert { ); - assertSameElements( (parsedxml2 \ "_" \ "_" \ "author"), List() ); + assertSameElementsXML( (parsedxml2 \ "_" \ "_" \ "author"), List() ); Console.println("xpath \\\\ DESCENDANTS"); - assertSameElements( + assertSameElementsXML( parsedxml2 \\ "author", @@ -133,7 +131,7 @@ object Test extends Application with Assert { ); - assertSameElements( + assertSameElementsXML( parsedxml2 \\ "title", @@ -144,10 +142,10 @@ object Test extends Application with Assert { println( - (parsedxml2 \\ "book" ){ n:Node => n \ "title" == "Data on ze web" } + (parsedxml2 \\ "book" ){ n:Node => (n \ "title") xml_== "Data on ze web" } ); - assertEquals( + assertEqualsXML( (new NodeSeq { val theSeq = List( parsedxml2 ) }) \\ "_", @@ -191,13 +189,13 @@ object Test extends Application with Assert { val zz1 = <xml:group><a/><b/><c/></xml:group> - assertTrue(zx1 == zz1) + assertTrue(zx1 xml_== zz1) assertTrue(zz1.length == 3) // unparsed - val uup = <xml:unparsed>&<<>""^%@$!#</xml:unparsed> - assertTrue(uup == "&<<>\"\"^%@$!#") + // val uup = <xml:unparsed>&<<>""^%@$!#</xml:unparsed> + // assertTrue(uup == "&<<>\"\"^%@$!#") // test unicode escapes backslash u println("attribute value normalization") diff --git a/test/files/jvm/xml02.scala b/test/files/jvm/xml02.scala index 0cbeb27ce2..11f77cc90f 100644 --- a/test/files/jvm/xml02.scala +++ b/test/files/jvm/xml02.scala @@ -18,10 +18,10 @@ object Test extends TestConsoleMain { object XmlEx extends TestCase("attributes") with Assert { override def runTest = { - assertTrue("@one", ax \ "@foo" == "bar") // uses NodeSeq.view! - assertTrue("@two", ax \ "@foo" == xml.Text("bar")) // dto. - assertTrue("@three", bx \ "@foo" == "bar&x") // dto. - assertTrue ("@four", (bx \ "@foo") sameElements List(xml.Text("bar&x"))) + assertTrue("@one", (ax \ "@foo") xml_== "bar") // uses NodeSeq.view! + assertTrue("@two", (ax \ "@foo") xml_== xml.Text("bar")) // dto. + assertTrue("@three", (bx \ "@foo") xml_== "bar&x") // dto. + assertTrue ("@four", (bx \ "@foo") xml_sameElements List(xml.Text("bar&x"))) assertEquals("@five", "<hello foo=\"bar&x\"></hello>", bx.toString) } } @@ -29,8 +29,8 @@ object Test extends TestConsoleMain { object XmlEy extends TestCase("attributes with namespace") with Assert { override def runTest = { val z = ax \ "@{the namespace from outer space}foo" - assertTrue("@six", ax \ "@{the namespace from outer space}foo" == "baz") - assertTrue("@eight", cx \ "@{the namespace from outer space}foo" == "baz") + assertTrue("@six", (ax \ "@{the namespace from outer space}foo") xml_== "baz") + assertTrue("@eight", (cx \ "@{the namespace from outer space}foo") xml_== "baz") try { ax \ "@" @@ -58,8 +58,8 @@ object Test extends TestConsoleMain { override def runTest = { assertTrue(<hello/> match { case <hello/> => true; case _ => false; }) assertTrue(<x:ga xmlns:x="z"/> match { case <x:ga/> => true; case _ => false; }); - assertTrue(Utility.trim(cx) match { case n @ <hello>crazy text world</hello> if n \ "@foo" == "bar" => true; }) - assertTrue(Utility.trim(cx) match { case n @ <z:hello>crazy text world</z:hello> if n \ "@foo" == "bar" => true; }) + assertTrue(Utility.trim(cx) match { case n @ <hello>crazy text world</hello> if (n \ "@foo") xml_== "bar" => true; }) + assertTrue(Utility.trim(cx) match { case n @ <z:hello>crazy text world</z:hello> if (n \ "@foo") xml_== "bar" => true; }) } } diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala index 46faf283dc..6e711a0f86 100644 --- a/test/files/jvm/xmlstuff.scala +++ b/test/files/jvm/xmlstuff.scala @@ -64,9 +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) + assertSameElementsXML(pelems_1, pelems_2) - assertEquals(p \\ "@bazValue", Text("8")) + assertEqualsXML(p \\ "@bazValue", Text("8")) val books = <bks> @@ -97,7 +97,7 @@ passed ok println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( for (t <- books \\ "title"; r <- reviews \\ "entry" - if r \ "title" == t) yield + if (r \ "title") xml_== t) yield <result> { t } { r \ "remarks" } @@ -139,7 +139,7 @@ val addrBook = println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( for (t <- addrBook \\ "entry"; r <- phoneBook \\ "entry" - if t \ "name" == r \ "name") yield + if (t \ "name") xml_== (r \ "name")) yield <result> { t.child } { r \ "phone" } |