aboutsummaryrefslogtreecommitdiff
path: root/dottydoc/test
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-08-09 18:42:54 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-08-19 15:37:33 +0200
commit5cd1d51c3cb44b2c9b2c1abd433da50a00e5219e (patch)
tree2f87a0e18b2c44cce28a2b424f2b3b1e97ac1732 /dottydoc/test
parent079e3db0f157ee6eae9e8a34b3bbf7a75cdaa929 (diff)
downloaddotty-5cd1d51c3cb44b2c9b2c1abd433da50a00e5219e.tar.gz
dotty-5cd1d51c3cb44b2c9b2c1abd433da50a00e5219e.tar.bz2
dotty-5cd1d51c3cb44b2c9b2c1abd433da50a00e5219e.zip
Remove client from dottydoc - no more Scala.JS deps!
Diffstat (limited to 'dottydoc/test')
-rw-r--r--dottydoc/test/BaseTest.scala58
-rw-r--r--dottydoc/test/PackageStructure.scala89
-rw-r--r--dottydoc/test/SimpleComments.scala29
-rw-r--r--dottydoc/test/WhitelistedStdLib.scala32
-rw-r--r--dottydoc/test/WhitelistedStdLibMain.scala47
5 files changed, 255 insertions, 0 deletions
diff --git a/dottydoc/test/BaseTest.scala b/dottydoc/test/BaseTest.scala
new file mode 100644
index 000000000..0c6fad1c8
--- /dev/null
+++ b/dottydoc/test/BaseTest.scala
@@ -0,0 +1,58 @@
+package dotty.tools
+package dottydoc
+
+import dotc.core.Contexts
+import Contexts.{ Context, ContextBase, FreshContext }
+import dotc.util.SourceFile
+import dotc.core.Phases.Phase
+import dotc.typer.FrontEnd
+import dottydoc.core.DocASTPhase
+
+trait DottyTest {
+ dotty.tools.dotc.parsing.Scanners // initialize keywords
+
+ implicit var ctx: FreshContext = {
+ val base = new ContextBase
+ import base.settings._
+ val ctx = base.initialCtx.fresh
+ ctx.setSetting(ctx.settings.language, List("Scala2"))
+ ctx.setSetting(ctx.settings.YkeepComments, true)
+ ctx.setSetting(ctx.settings.YDocNoWrite, true)
+ base.initialize()(ctx)
+ ctx
+ }
+
+ private def compilerWithChecker(assertion: DocASTPhase => Unit) = new DottyDocCompiler {
+ private[this] val docPhase = new DocASTPhase
+
+ override def phases =
+ List(new FrontEnd) ::
+ List(docPhase) ::
+ List(new Phase {
+ def phaseName = "assertionPhase"
+ override def run(implicit ctx: Context): Unit = assertion(docPhase)
+ }) ::
+ Nil
+ }
+
+ def checkSource(source: String)(assertion: DocASTPhase => Unit): Unit = {
+ val c = compilerWithChecker(assertion)
+ c.rootContext(ctx)
+ val run = c.newRun
+ run.compile(source)
+ }
+
+ def checkFiles(sources: List[String])(assertion: DocASTPhase => Unit): Unit = {
+ val c = compilerWithChecker(assertion)
+ c.rootContext(ctx)
+ val run = c.newRun
+ run.compile(sources)
+ }
+
+ def checkSources(sourceFiles: List[SourceFile])(assertion: DocASTPhase => Unit): Unit = {
+ val c = compilerWithChecker(assertion)
+ c.rootContext(ctx)
+ val run = c.newRun
+ run.compileSources(sourceFiles)
+ }
+}
diff --git a/dottydoc/test/PackageStructure.scala b/dottydoc/test/PackageStructure.scala
new file mode 100644
index 000000000..af6e52184
--- /dev/null
+++ b/dottydoc/test/PackageStructure.scala
@@ -0,0 +1,89 @@
+package dotty.tools
+package dottydoc
+
+import org.junit.Test
+import org.junit.Assert._
+
+import dotc.util.SourceFile
+import model.internal._
+
+class PackageStructure extends DottyTest {
+ @Test def multipleCompilationUnits = {
+ val source1 = new SourceFile(
+ "<test>",
+ """
+ |package scala
+ |
+ |trait A
+ """.stripMargin
+ )
+
+ val source2 = new SourceFile(
+ "<test>",
+ """
+ |package scala
+ |
+ |trait B
+ """.stripMargin
+ )
+
+ checkSources(source1 :: source2 :: Nil) { doc =>
+ doc.packages("scala") match {
+ case PackageImpl(_, List(tA, tB), _, _) =>
+ assert(
+ tA.name == "A" && tB.name == "B",
+ s"trait A had name '${tA.name}' and trait B had name '${tB.name}'"
+ )
+ case _ => fail("Incorrect package structure after run")
+ }
+ }
+ }
+
+
+ @Test def multiplePackages = {
+ val source1 = new SourceFile(
+ "<test>",
+ """
+ |package scala
+ |package collection
+ |
+ |trait A
+ """.stripMargin)
+
+ val source2 = new SourceFile(
+ "<test>",
+ """
+ |package scala
+ |package collection
+ |
+ |trait B
+ """.stripMargin)
+
+ checkSources(source1 :: source2 :: Nil) { doc =>
+ doc.packages("scala") match {
+ case PackageImpl(
+ "scala",
+ List(PackageImpl("scala.collection", List(tA, tB), _, _)),
+ _, _
+ ) =>
+ assert(
+ tA.name == "A" && tB.name == "B",
+ s"trait A had name '${tA.name}' and trait B had name '${tB.name}'"
+ )
+
+ case _ =>
+ fail(s"""Incorrect package structure for 'scala' package: ${doc.packages("scala")}""")
+ }
+
+ doc.packages("scala.collection") match {
+ case PackageImpl("scala.collection", List(tA, tB), _, _) =>
+ assert(
+ tA.name == "A" && tB.name == "B",
+ s"trait A had name '${tA.name}' and trait B had name '${tB.name}'"
+ )
+
+ case _ => fail("Incorrect package structure for 'scala.collection' package")
+ }
+ }
+ }
+}
diff --git a/dottydoc/test/SimpleComments.scala b/dottydoc/test/SimpleComments.scala
new file mode 100644
index 000000000..ad9b7b1a6
--- /dev/null
+++ b/dottydoc/test/SimpleComments.scala
@@ -0,0 +1,29 @@
+package dotty.tools
+package dottydoc
+
+import org.junit.Test
+import org.junit.Assert._
+
+class TestSimpleComments extends DottyTest {
+
+ @Test def simpleComment = {
+ val source =
+ """
+ |package scala
+ |
+ |/** Hello, world! */
+ |trait HelloWorld
+ """.stripMargin
+
+ checkSource(source) { doc =>
+ val traitCmt = doc
+ .packages("scala")
+ .children.find(_.path.mkString(".") == "scala.HelloWorld")
+ .flatMap(_.comment.map(_.body))
+ .get
+
+ assertEquals(traitCmt, "<p>Hello, world!</p>")
+ }
+ }
+
+}
diff --git a/dottydoc/test/WhitelistedStdLib.scala b/dottydoc/test/WhitelistedStdLib.scala
new file mode 100644
index 000000000..88dc67e99
--- /dev/null
+++ b/dottydoc/test/WhitelistedStdLib.scala
@@ -0,0 +1,32 @@
+package dotty.tools
+package dottydoc
+
+import org.junit.Test
+import org.junit.Assert._
+
+class TestWhitelistedCollections extends DottyTest {
+ @Test def arrayHasDocumentation =
+ checkFiles(WhitelistedStandardLib.files) { doc =>
+ val array = doc
+ .packages("scala")
+ .children.find(_.path.mkString(".") == "scala.Array")
+ .get
+
+ assert(array.comment.get.body.length > 0)
+ }
+
+ @Test def traitImmutableHasDocumentation =
+ checkFiles(WhitelistedStandardLib.files) { doc =>
+ val imm = doc
+ .packages("scala")
+ .children.find(_.path.mkString(".") == "scala.Immutable")
+ .get
+
+ assert(
+ imm.kind == "trait" && imm.name == "Immutable",
+ "Found wrong `Immutable`")
+ assert(
+ imm.comment.map(_.body).get.length > 0,
+ "Imm did not have a comment with length > 0")
+ }
+}
diff --git a/dottydoc/test/WhitelistedStdLibMain.scala b/dottydoc/test/WhitelistedStdLibMain.scala
new file mode 100644
index 000000000..b4ea34d2c
--- /dev/null
+++ b/dottydoc/test/WhitelistedStdLibMain.scala
@@ -0,0 +1,47 @@
+package dotty.tools
+package dottydoc
+
+import scala.io.Source
+
+object WhitelistedStandardLib extends dottydoc.java.Dottydoc {
+ import scala.collection.JavaConverters._
+
+ val files: List[String] = {
+ val whitelist = "../test/dotc/scala-collections.whitelist"
+
+ Source.fromFile(whitelist, "UTF8")
+ .getLines()
+ .map(_.trim) // allow identation
+ .filter(!_.startsWith("#")) // allow comment lines prefixed by #
+ .map(_.takeWhile(_ != '#').trim) // allow comments in the end of line
+ .filter(_.nonEmpty)
+ .filterNot(_.endsWith("package.scala"))
+ .map("." + _)
+ .toList
+ }
+
+ private val resources = List(
+ "../js-dottydoc/resources/MaterialIcons-Regular.eot",
+ "../js-dottydoc/resources/MaterialIcons-Regular.ijmap",
+ "../js-dottydoc/resources/MaterialIcons-Regular.svg",
+ "../js-dottydoc/resources/MaterialIcons-Regular.ttf",
+ "../js-dottydoc/resources/MaterialIcons-Regular.woff",
+ "../js-dottydoc/resources/MaterialIcons-Regular.woff2",
+ "../js-dottydoc/resources/codepoints",
+ "../js-dottydoc/resources/github.css",
+ "../js-dottydoc/resources/highlight.pack.js",
+ "../js-dottydoc/resources/index.css",
+ "../js-dottydoc/resources/material-icons.css",
+ "../js-dottydoc/resources/material.min.css",
+ "../js-dottydoc/resources/material.min.js"/*,
+ "resources/dottydoc-fastopt.js"*/
+ )
+
+ override def main(args: Array[String]) = {
+ val compilerArgs =
+ "-language:Scala2" +: "-Ydoc-output" +: "../build/dottydoc" +: files.toArray
+
+ val index = createIndex(compilerArgs)
+ buildDocs("../build/dottydoc", "../js-dottydoc/template.html", resources.asJava, index)
+ }
+}