diff options
Diffstat (limited to 'test/scaladoc')
-rw-r--r-- | test/scaladoc/resources/Trac3790.scala | 11 | ||||
-rw-r--r-- | test/scaladoc/scala/IndexTest.scala (renamed from test/scaladoc/IndexTest.scala) | 0 | ||||
-rw-r--r-- | test/scaladoc/scala/html/HtmlFactoryTest.scala | 97 | ||||
-rw-r--r-- | test/scaladoc/scala/model/CommentFactoryTest.scala (renamed from test/scaladoc/model/CommentFactoryTest.scala) | 0 |
4 files changed, 108 insertions, 0 deletions
diff --git a/test/scaladoc/resources/Trac3790.scala b/test/scaladoc/resources/Trac3790.scala new file mode 100644 index 0000000000..1ca80955a0 --- /dev/null +++ b/test/scaladoc/resources/Trac3790.scala @@ -0,0 +1,11 @@ +class Trac3790 { + /** + * A lazy String + */ + lazy val lazyString= "lazy" + + /** + * A non-lazy String + */ + val nonLazyString= "non-lazy" +} diff --git a/test/scaladoc/IndexTest.scala b/test/scaladoc/scala/IndexTest.scala index 5e3d02e045..5e3d02e045 100644 --- a/test/scaladoc/IndexTest.scala +++ b/test/scaladoc/scala/IndexTest.scala diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala new file mode 100644 index 0000000000..98f0c94805 --- /dev/null +++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala @@ -0,0 +1,97 @@ +import org.scalacheck._ +import org.scalacheck.Prop._ + +import java.net.URLClassLoader + +object XMLUtil { + import scala.xml._ + + def stripGroup(seq: Node): Node = { + seq match { + case group: Group => { + <div class="group">{ group.nodes.map(stripGroup _) }</div> + } + case e: Elem => { + val child = e.child.map(stripGroup _) + Elem(e.prefix, e.label, e.attributes, e.scope, child : _*) + } + 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") { + import scala.tools.nsc.doc.{DocFactory, Settings} + import scala.tools.nsc.doc.model.IndexModelFactory + import scala.tools.nsc.doc.html.HtmlFactory + + def getClasspath = { + // these things can be tricky + // this test previously relied on the assumption that the current thread's classloader is an url classloader and contains all the classpaths + // does partest actually guarantee this? to quote Leonard Nimoy: The answer, of course, is no. + // this test _will_ fail again some time in the future. + val paths = Thread.currentThread.getContextClassLoader.asInstanceOf[URLClassLoader].getURLs.map(_.getPath) + val morepaths = Thread.currentThread.getContextClassLoader.getParent.asInstanceOf[URLClassLoader].getURLs.map(_.getPath) + (paths ++ morepaths).mkString(java.io.File.pathSeparator) + } + + val docFactory = { + val settings = new Settings({Console.err.println(_)}) + settings.classpath.value = getClasspath + + 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]() + + docFactory.makeUniverse(List("test/scaladoc/resources/"+basename)) match { + case Some(universe) => { + val index = IndexModelFactory.makeIndex(universe) + (new HtmlFactory(universe, index)).writeTemplates((page) => { + result += (page.path.mkString("") -> page.body) + }) + } + case _ => ; + } + + result + } + + property("Trac #3790") = { + import XMLUtil._ + + val files = createTemplates("Trac3790.scala") + files("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")(_) } + + comments.filter(textIs("A lazy String")(_)).length == 1 && + comments.filter(textIs("A non-lazy String")(_)).length == 1 + } + case _ => false + } + } + +} diff --git a/test/scaladoc/model/CommentFactoryTest.scala b/test/scaladoc/scala/model/CommentFactoryTest.scala index 204baaa05b..204baaa05b 100644 --- a/test/scaladoc/model/CommentFactoryTest.scala +++ b/test/scaladoc/scala/model/CommentFactoryTest.scala |