summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKato Kazuyoshi <kato.kazuyoshi@gmail.com>2011-03-26 03:26:40 +0000
committerKato Kazuyoshi <kato.kazuyoshi@gmail.com>2011-03-26 03:26:40 +0000
commitcaba14ff4b5d99bf5e43734798d285970f275ce3 (patch)
treef1a7df88174f0d7c2860dc1764740c55ad4fc17f
parent408fe0dc4b61d18c53f32853b25b1ca5c743335d (diff)
downloadscala-caba14ff4b5d99bf5e43734798d285970f275ce3.tar.gz
scala-caba14ff4b5d99bf5e43734798d285970f275ce3.tar.bz2
scala-caba14ff4b5d99bf5e43734798d285970f275ce3.zip
[scaladoc] Cleanup tests. No review.
-rw-r--r--test/scaladoc/scala/html/HtmlFactoryTest.scala106
1 files changed, 35 insertions, 71 deletions
diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala
index bc4c51a0b7..40d9c96f94 100644
--- a/test/scaladoc/scala/html/HtmlFactoryTest.scala
+++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala
@@ -18,23 +18,6 @@ object XMLUtil {
case _ => seq
}
}
-
- def attributeIs(key: String, value: String) = {
- (element: Node) => {
- element.attribute(key) match {
- case Some(v) =>
- v.toString == value
- case _ =>
- false
- }
- }
- }
-
- def textIs(value: String) = {
- (node: Node) => {
- node.descendant.exists((n) => n.toString.trim == value)
- }
- }
}
object Test extends Properties("HtmlFactory") {
@@ -52,18 +35,18 @@ object Test extends Properties("HtmlFactory") {
(paths ++ morepaths).mkString(java.io.File.pathSeparator)
}
- def createTemplates(basename: String) = {
- val result = scala.collection.mutable.Map[String, scala.xml.NodeSeq]()
+ def createFactory = {
+ val settings = new Settings({Console.err.println(_)})
+ settings.classpath.value = getClasspath
- val factory = {
- val settings = new Settings({Console.err.println(_)})
- settings.classpath.value = getClasspath
+ val reporter = new scala.tools.nsc.reporters.ConsoleReporter(settings)
+ new DocFactory(reporter, settings)
+ }
- val reporter = new scala.tools.nsc.reporters.ConsoleReporter(settings)
- new DocFactory(reporter, settings)
- }
+ def createTemplates(basename: String) = {
+ val result = scala.collection.mutable.Map[String, scala.xml.NodeSeq]()
- factory.makeUniverse(List("test/scaladoc/resources/"+basename)) match {
+ createFactory.makeUniverse(List("test/scaladoc/resources/"+basename)) match {
case Some(universe) => {
val index = IndexModelFactory.makeIndex(universe)
(new HtmlFactory(universe, index)).writeTemplates((page) => {
@@ -76,19 +59,25 @@ object Test extends Properties("HtmlFactory") {
result
}
- property("Trac #3790") = {
- import XMLUtil._
+ def shortComments(root: scala.xml.Node) =
+ XMLUtil.stripGroup(root).descendant.flatMap {
+ case e: scala.xml.Elem => {
+ if (e.attribute("class").toString.contains("shortcomment")) {
+ Some(e)
+ } else {
+ None
+ }
+ }
+ case _ => None
+ }
- val files = createTemplates("Trac3790.scala")
- files("Trac3790.html") match {
+ property("Trac #3790") = {
+ createTemplates("Trac3790.scala")("Trac3790.html") match {
case node: scala.xml.Node => {
- val comments = (stripGroup(node) \\ "div").flatMap {
- case e: scala.xml.Elem => Some(e)
- case _ => None
- }.filter { attributeIs("class", "fullcomment")(_) }
+ val comments = shortComments(node)
- comments.filter(textIs("A lazy String")(_)).length == 1 &&
- comments.filter(textIs("A non-lazy String")(_)).length == 1
+ comments.exists { _.toString.contains(">A lazy String\n</p>") } &&
+ comments.exists { _.toString.contains(">A non-lazy String\n</p>") }
}
case _ => false
}
@@ -100,53 +89,28 @@ object Test extends Properties("HtmlFactory") {
}
property("Trac #4366") = {
- val files = createTemplates("Trac4366.scala")
- files("Trac4366.html") match {
+ createTemplates("Trac4366.scala")("Trac4366.html") match {
case node: scala.xml.Node => {
- val comments = XMLUtil.stripGroup(node).descendant.flatMap {
- case e: scala.xml.Elem => {
- if (e.attribute("class").toString.contains("shortcomment")) {
- Some(e)
- } else {
- None
- }
- }
- case _ => None
- }
-
- comments.exists {
- (e) => {
- val s = e.toString
- s.contains("<code>foo</code>") && s.contains("</strong>")
- }
- }
+ shortComments(node).exists { n => {
+ val str = n.toString
+ str.contains("<code>foo</code>") && str.contains("</strong>")
+ } }
}
case _ => false
}
}
property("Trac #4358") = {
- val files = createTemplates("Trac4358.scala")
- files("EasyMockSugar.html") match {
- case node: scala.xml.Node => {
- val comments = XMLUtil.stripGroup(node).descendant.flatMap {
- case e: scala.xml.Elem => {
- if (e.attribute("class").toString.contains("shortcomment")) {
- Some(e)
- } else {
- None
- }
- }
- case _ => None
+ createTemplates("Trac4358.scala")("EasyMockSugar.html") match {
+ case node: scala.xml.Node =>
+ ! shortComments(node).exists {
+ _.toString.contains("<em>i.</em>")
}
- ! comments.exists { _.toString.contains("<em>i.</em>") }
- }
case _ => false
}
}
property("Trac #4180") = {
- val files = createTemplates("Trac4180.scala")
- files("Test.html") != None
+ createTemplates("Trac4180.scala")("Test.html") != None
}
}