diff options
Diffstat (limited to 'dottydoc/jvm')
-rw-r--r-- | dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala | 18 | ||||
-rw-r--r-- | dottydoc/jvm/test/BaseTest.scala (renamed from dottydoc/jvm/test/CompilerTest.scala) | 12 | ||||
-rw-r--r-- | dottydoc/jvm/test/PackageStructure.scala | 89 | ||||
-rw-r--r-- | dottydoc/jvm/test/SimpleComments.scala (renamed from dottydoc/jvm/test/TestSimpleComments.scala) | 2 | ||||
-rw-r--r-- | dottydoc/jvm/test/TestWhitelistedStdLib.scala | 17 | ||||
-rw-r--r-- | dottydoc/jvm/test/WhitelistedStdLib.scala | 28 | ||||
-rw-r--r-- | dottydoc/jvm/test/WhitelistedStdLibMain.scala | 23 |
7 files changed, 149 insertions, 40 deletions
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala index e3aff1d71..d2a1320a2 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala @@ -94,10 +94,22 @@ object Phases { var packages: Map[String, Package] = Map.empty def addEntity(p: Package): Package = { + def mergedChildren(x1s: List[Entity], x2s: List[Entity]): List[Entity] = { + val (packs1, others1) = x1s.partition(_.kind == "package") + val (packs2, others2) = x2s.partition(_.kind == "package") + + val others = others1 ::: others2 + val packs = (packs1 ::: packs2).groupBy(_.path).map(_._2.head) + + (others ++ packs).sortBy(_.name) + } + val path = p.path.mkString(".") - val newPack = packages.get(path).map { ex => - val children = (ex.children ::: p.children).distinct.sortBy(_.name) - PackageImpl(p.name, children, p.path, None) + val newPack = packages.get(path).map { + case ex: PackageImpl => + if (!ex.comment.isDefined) ex.comment = p.comment + ex.members = mergedChildren(ex.members, p.members) + ex }.getOrElse(p) packages = packages + (path -> newPack) diff --git a/dottydoc/jvm/test/CompilerTest.scala b/dottydoc/jvm/test/BaseTest.scala index 001e4d422..2703f8169 100644 --- a/dottydoc/jvm/test/CompilerTest.scala +++ b/dottydoc/jvm/test/BaseTest.scala @@ -3,6 +3,7 @@ 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.Phases.DocPhase @@ -34,17 +35,24 @@ trait DottyTest { Nil } - def checkCompile(source: String)(assertion: DocPhase => Unit): Unit = { + def checkSource(source: String)(assertion: DocPhase => Unit): Unit = { val c = compilerWithChecker(assertion) c.rootContext(ctx) val run = c.newRun run.compile(source) } - def checkCompile(sources: List[String])(assertion: DocPhase => Unit): Unit = { + def checkFiles(sources: List[String])(assertion: DocPhase => Unit): Unit = { val c = compilerWithChecker(assertion) c.rootContext(ctx) val run = c.newRun run.compile(sources) } + + def checkSources(sourceFiles: List[SourceFile])(assertion: DocPhase => Unit): Unit = { + val c = compilerWithChecker(assertion) + c.rootContext(ctx) + val run = c.newRun + run.compileSources(sourceFiles) + } } diff --git a/dottydoc/jvm/test/PackageStructure.scala b/dottydoc/jvm/test/PackageStructure.scala new file mode 100644 index 000000000..af6e52184 --- /dev/null +++ b/dottydoc/jvm/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/jvm/test/TestSimpleComments.scala b/dottydoc/jvm/test/SimpleComments.scala index 48cdecec0..ad9b7b1a6 100644 --- a/dottydoc/jvm/test/TestSimpleComments.scala +++ b/dottydoc/jvm/test/SimpleComments.scala @@ -15,7 +15,7 @@ class TestSimpleComments extends DottyTest { |trait HelloWorld """.stripMargin - checkCompile(source) { doc => + checkSource(source) { doc => val traitCmt = doc .packages("scala") .children.find(_.path.mkString(".") == "scala.HelloWorld") diff --git a/dottydoc/jvm/test/TestWhitelistedStdLib.scala b/dottydoc/jvm/test/TestWhitelistedStdLib.scala deleted file mode 100644 index 763f41370..000000000 --- a/dottydoc/jvm/test/TestWhitelistedStdLib.scala +++ /dev/null @@ -1,17 +0,0 @@ -package dotty.tools -package dottydoc - -import org.junit.Test -import org.junit.Assert._ - -class TestWhitelistedCollections extends DottyTest { - @Test def arrayHasDocumentation = - checkCompile(WhitelistedStandardLib.files) { doc => - val array = doc - .packages("scala") - .children.find(_.path.mkString(".") == "scala.Array") - .get - - assert(array.comment.get.body.length > 0) - } -} diff --git a/dottydoc/jvm/test/WhitelistedStdLib.scala b/dottydoc/jvm/test/WhitelistedStdLib.scala index f4a2f9dc6..bbf0b4c6b 100644 --- a/dottydoc/jvm/test/WhitelistedStdLib.scala +++ b/dottydoc/jvm/test/WhitelistedStdLib.scala @@ -1,23 +1,17 @@ package dotty.tools package dottydoc -import scala.io.Source +import org.junit.Test +import org.junit.Assert._ -object WhitelistedStandardLib extends DottyDoc { - val files: List[String] = { - val whitelist = "../../test/dotc/scala-collections.whitelist" +class TestWhitelistedCollections extends DottyTest { + @Test def arrayHasDocumentation = + checkFiles(WhitelistedStandardLib.files) { doc => + val array = doc + .packages("scala") + .children.find(_.path.mkString(".") == "scala.Array") + .get - 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 - } - - override def main(args: Array[String]) = - super.main("-language:Scala2" +: files.toArray) + assert(array.comment.get.body.length > 0) + } } diff --git a/dottydoc/jvm/test/WhitelistedStdLibMain.scala b/dottydoc/jvm/test/WhitelistedStdLibMain.scala new file mode 100644 index 000000000..f4a2f9dc6 --- /dev/null +++ b/dottydoc/jvm/test/WhitelistedStdLibMain.scala @@ -0,0 +1,23 @@ +package dotty.tools +package dottydoc + +import scala.io.Source + +object WhitelistedStandardLib extends DottyDoc { + 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 + } + + override def main(args: Array[String]) = + super.main("-language:Scala2" +: files.toArray) +} |