Scala XML equality issues

notobtumoc

New Member
I want to write a test case for a \[code\]case class\[/code\], that has a \[code\]toXML\[/code\] method.\[code\]import java.net.URIcase class Person( label: String = "author", name: String, email: Option[String] = None, uri: Option[URI] = None) { // author must be either "author" or "contributor" assert(label == "author" || label == "contributor") def toXML = { val res = <author> <name>{ name }</name> { email match { case Some(email) => <email>{ email }</email> case None => Null } } { uri match { case Some(uri) => <uri>{ uri }</uri> case None => Null } } </author> label match { case "author" => res case _ => res.copy(label = label) // rename element } }}\[/code\]Now, I want to assert, that the output is correct. Therefor I use \[code\]scala.xml.Utility.trim\[/code\]\[code\]import scala.xml.Utility.trimval p1 = Person("author", "John Doe", Some("[email protected]"), Some(new URI("http://example.com/john")))val p2 = <author> <name>John Doe</name> <email>[email protected]</name> <uri>http://example.com/john</uri> </author>assert(trim(p1.toXML) == trim(p2))\[/code\]But this will cause an assertion error. If I try to assert equality by comparing the String representations\[code\]assert(trim(p1.toXML).toString == trim(p2).toString)\[/code\]there
 
Back
Top