diff options
author | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-03-21 12:24:48 +0000 |
---|---|---|
committer | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-03-21 12:24:48 +0000 |
commit | 4d0cd60b0e2b9071bba2641da95c75332458193b (patch) | |
tree | 7e21eec8d5716797bd2b27b37668ab29ca255e9b | |
parent | 72a0e8be61df92b15c9991d023b783e019a58916 (diff) | |
download | scala-4d0cd60b0e2b9071bba2641da95c75332458193b.tar.gz scala-4d0cd60b0e2b9071bba2641da95c75332458193b.tar.bz2 scala-4d0cd60b0e2b9071bba2641da95c75332458193b.zip |
[scaladoc] Add HtmlFactoryTest and reorganize d...
[scaladoc] Add HtmlFactoryTest and reorganize directory structure.
Reviewed by pedrofurla.
-rw-r--r-- | build.xml | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/html/HtmlFactory.scala | 14 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala | 2 | ||||
-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 |
7 files changed, 120 insertions, 8 deletions
@@ -1598,8 +1598,8 @@ BOOTRAPING TEST AND TEST SUITE <compilationpath> <path refid="pack.classpath"/> </compilationpath> - <scalachecktests dir="test/scaladoc"> - <include name="*.scala"/> + <scalachecktests dir="test/scaladoc/scala"> + <include name="*.scala"/> </scalachecktests> </partest> </target> diff --git a/src/compiler/scala/tools/nsc/doc/html/HtmlFactory.scala b/src/compiler/scala/tools/nsc/doc/html/HtmlFactory.scala index 199c184bfc..a14bacb267 100644 --- a/src/compiler/scala/tools/nsc/doc/html/HtmlFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/html/HtmlFactory.scala @@ -64,20 +64,24 @@ class HtmlFactory(val universe: doc.Universe, index: doc.Index) { new page.Index(universe, index) writeFor this + writeTemplates(page => page.writeFor(this)) + + for(letter <- index.firstLetterIndex) { + new html.page.ReferenceIndex(letter._1, index, universe) writeFor this + } + } + + def writeTemplates(writeForThis: HtmlPage => Unit): Unit = { val written = mutable.HashSet.empty[DocTemplateEntity] def writeTemplate(tpl: DocTemplateEntity): Unit = if (!(written contains tpl)) { - new page.Template(tpl) writeFor this + writeForThis(new page.Template(tpl)) written += tpl tpl.templates map (writeTemplate(_)) } writeTemplate(universe.rootPackage) - - for(letter <- index.firstLetterIndex) { - new html.page.ReferenceIndex(letter._1, index, universe) writeFor this - } } } diff --git a/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala b/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala index 95016099ff..21d6ba91a9 100644 --- a/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala +++ b/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala @@ -34,7 +34,7 @@ abstract class HtmlPage { thisPage => protected def headers: NodeSeq /** The body of this page. */ - protected def body: NodeSeq + def body: NodeSeq /** Writes this page as a file. The file's location is relative to the generator's site root, and the encoding is * also defined by the generator. 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 |