import testing.SUnit._
object Test extends TestConsoleMain {
import scala.xml.{NodeSeq, Utility}
import NodeSeq.seqToNodeSeq
val ax =
val cx =
crazy text world
val bx =
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")))
assertEquals("@five", "", bx.toString)
}
}
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")
try {
ax \ "@"
assertTrue("wrong1", false)
} catch {
case _: IllegalArgumentException =>
}
try {
ax \ "@{"
assertTrue("wrong2", false)
} catch {
case _: IllegalArgumentException =>
}
try {
ax \ "@{}"
assertTrue("wrong3", false)
} catch {
case _: IllegalArgumentException =>
}
}
}
object XmlPat extends TestCase("patterns") with Assert {
override def runTest = {
assertTrue( match { case => true; case _ => false; })
assertTrue( match { case => true; case _ => false; });
assertTrue(Utility.trim(cx) match { case n @ crazy text world if n \ "@foo" == "bar" => true; })
assertTrue(Utility.trim(cx) match { case n @ crazy text world if n \ "@foo" == "bar" => true; })
}
}
object DodgyNamespace extends TestCase("DodgyNamespace") with Assert {
override def runTest = {
val x =
assertTrue(x.toString.matches(".*xmlns:dog=\"http://dog.com\".*"));
}
}
def suite = new TestSuite(
XmlEx,
XmlEy,
XmlPat,
DodgyNamespace
)
}