diff options
Diffstat (limited to 'test/scaladoc')
-rw-r--r-- | test/scaladoc/scala/html/HtmlFactoryTest.scala | 106 |
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 } } |