diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-11-03 16:20:28 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2016-11-22 01:35:07 +0100 |
commit | 94a8177f208418682b86934eb3f0b8edab99b1f0 (patch) | |
tree | ef2018006aee9af3f3afb9a92037ec605d835cd1 /dottydoc/test | |
parent | fcdb1c984c4b32c0c1b13337d9bd50a3883cb3b3 (diff) | |
download | dotty-94a8177f208418682b86934eb3f0b8edab99b1f0.tar.gz dotty-94a8177f208418682b86934eb3f0b8edab99b1f0.tar.bz2 dotty-94a8177f208418682b86934eb3f0b8edab99b1f0.zip |
Move `dottydoc` -> `doc-tool`
Diffstat (limited to 'dottydoc/test')
-rw-r--r-- | dottydoc/test/BaseTest.scala | 64 | ||||
-rw-r--r-- | dottydoc/test/ConstructorTest.scala | 211 | ||||
-rw-r--r-- | dottydoc/test/PackageStructure.scala | 90 | ||||
-rw-r--r-- | dottydoc/test/SimpleComments.scala | 29 | ||||
-rw-r--r-- | dottydoc/test/UsecaseTest.scala | 234 | ||||
-rw-r--r-- | dottydoc/test/WhitelistedStdLib.scala | 45 |
6 files changed, 0 insertions, 673 deletions
diff --git a/dottydoc/test/BaseTest.scala b/dottydoc/test/BaseTest.scala deleted file mode 100644 index e439c6eca..000000000 --- a/dottydoc/test/BaseTest.scala +++ /dev/null @@ -1,64 +0,0 @@ -package dotty.tools -package dottydoc - -import dotc.core.Contexts.{ Context, ContextBase, FreshContext } -import dotc.core.Comments.{ ContextDoc, ContextDocstrings } -import dotc.util.SourceFile -import dotc.core.Phases.Phase -import dotc.typer.FrontEnd -import dottydoc.core.{ DocASTPhase, ContextDottydoc } -import model.Package -import dotty.tools.dottydoc.util.syntax._ - -trait DottyTest { - dotty.tools.dotc.parsing.Scanners // initialize keywords - - implicit val 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.YnoInline, true) - ctx.setProperty(ContextDoc, new ContextDottydoc) - ctx.setSetting( - ctx.settings.classpath, - "./library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar" - ) - base.initialize()(ctx) - ctx - } - - private def compilerWithChecker(assertion: Map[String, Package] => Unit) = new DocCompiler { - private[this] val assertionPhase: List[List[Phase]] = - List(new Phase { - def phaseName = "assertionPhase" - override def run(implicit ctx: Context): Unit = - assertion(ctx.docbase.packages) - }) :: Nil - - override def phases = - super.phases ++ assertionPhase - } - - def checkSource(source: String)(assertion: Map[String, Package] => Unit): Unit = { - val c = compilerWithChecker(assertion) - c.rootContext(ctx) - val run = c.newRun - run.compile(source) - } - - def checkFiles(sources: List[String])(assertion: Map[String, Package] => Unit): Unit = { - val c = compilerWithChecker(assertion) - c.rootContext(ctx) - val run = c.newRun - run.compile(sources) - } - - def checkSources(sourceFiles: List[SourceFile])(assertion: Map[String, Package] => Unit): Unit = { - val c = compilerWithChecker(assertion) - c.rootContext(ctx) - val run = c.newRun - run.compileSources(sourceFiles) - } -} diff --git a/dottydoc/test/ConstructorTest.scala b/dottydoc/test/ConstructorTest.scala deleted file mode 100644 index 44a05acad..000000000 --- a/dottydoc/test/ConstructorTest.scala +++ /dev/null @@ -1,211 +0,0 @@ -package dotty.tools -package dottydoc - -import org.junit.Test -import org.junit.Assert._ - -import dotc.util.SourceFile -import model._ -import model.internal._ -import model.references._ - -class Constructors extends DottyTest { - @Test def singleClassConstructor = { - val source = new SourceFile ( - "Class.scala", - """ - |package scala - | - |class Class(val str: String) - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(cls: Class), _, _) => - cls.constructors.headOption match { - case Some(ParamListImpl(NamedReference("str", _, false, false) :: Nil, false) :: Nil) => - // success! - case _ => assert(false, s"Incorrect constructor found: ${cls.constructors}") - } - } - } - } - - @Test def constructorPlusImplicitArgList = { - val source = new SourceFile ( - "Class.scala", - """ - |package scala - | - |class Class(val str1: String)(implicit str2: String) - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(cls: Class), _, _) => - cls.constructors match { - case ( - ParamListImpl(NamedReference("str1", _, false, false) :: Nil, false) :: - ParamListImpl(NamedReference("str2", _, false, false) :: Nil, true) :: Nil - ) :: Nil => - // success! - case _ => assert(false, s"Incorrect constructor found: ${cls.constructors}") - } - } - } - } - - @Test def multipleArgumentListsForConstructor = { - val source = new SourceFile ( - "Class.scala", - """ - |package scala - | - |class Class(val str1: String)(val str2: String)(implicit str3: String) - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(cls: Class), _, _) => - cls.constructors match { - case ( - ParamListImpl(NamedReference("str1", _, false, false) :: Nil, false) :: - ParamListImpl(NamedReference("str2", _, false, false) :: Nil, false) :: - ParamListImpl(NamedReference("str3", _, false, false) :: Nil, true) :: Nil - ) :: Nil => - // success! - case _ => assert(false, s"Incorrect constructor found: ${cls.constructors}") - } - } - } - } - - @Test def multipleConstructors = { - val source = new SourceFile ( - "Class.scala", - """ - |package scala - | - |class Class(val main: String) { - | def this(alt1: Int) = - | this("String") - | - | def this(alt2: List[String]) = - | this(alt2.head) - |} - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(cls: Class), _, _) => - cls.constructors match { - case ( - ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil - ) :: ( - ParamListImpl(NamedReference("alt1", _, false, false) :: Nil, false) :: Nil - ) :: ( - ParamListImpl(NamedReference("alt2", _, false, false) :: Nil, false) :: Nil - ) :: Nil => - // success! - case _ => - assert( - false, - s"""Incorrect constructor found:\n${cls.constructors.mkString("\n")}""" - ) - } - } - } - } - - @Test def multipleConstructorsCC = { - val source = new SourceFile ( - "Class.scala", - """ - |package scala - | - |case class Class(val main: String) { - | def this(alt1: Int) = - | this("String") - | - | def this(alt2: List[String]) = - | this(alt2.head) - |} - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(cls: CaseClass, obj: Object), _, _) => - cls.constructors match { - case ( - ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil - ) :: ( - ParamListImpl(NamedReference("alt1", _, false, false) :: Nil, false) :: Nil - ) :: ( - ParamListImpl(NamedReference("alt2", _, false, false) :: Nil, false) :: Nil - ) :: Nil => - // success! - case _ => - println(obj.members.map(x => x.kind + " " + x.name)) - assert( - false, - s"""Incorrect constructor found:\n${cls.constructors.mkString("\n")}""" - ) - } - } - } - } - - @Test def traitParameters = { - val source = new SourceFile ( - "Trait.scala", - """ - |package scala - | - |trait Trait(val main: String) - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(trt: Trait), _, _) => - trt.traitParams match { - case ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil => - case _ => - assert( - false, - s"""Incorrect constructor found:\n${trt.traitParams.mkString("\n")}""" - ) - } - } - } - } - - @Test def testJson = { - val actualSource = - """ - |package scala - | - |trait Trait(val main: String) - |class Class(val main: String) - |case class CaseClass(main: String) - """.stripMargin - - val source = new SourceFile ("JsonTest.scala", actualSource) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(cc: CaseClass, _, cls: Class, trt: Trait), _, _) => - import model.json._ - lazy val incorrectJson = s"The json generated for:\n$actualSource\n\nIs not correct" - assert(cc.json.contains(s""""constructors":[[{"list":[{"title":"main""""), incorrectJson) - assert(cls.json.contains(s""""constructors":[[{"list":[{"title":"main""""), incorrectJson) - assert(trt.json.contains(s""""traitParams":[{"list":[{"title":"main""""), incorrectJson) - } - } - } -} diff --git a/dottydoc/test/PackageStructure.scala b/dottydoc/test/PackageStructure.scala deleted file mode 100644 index 4e7006bfe..000000000 --- a/dottydoc/test/PackageStructure.scala +++ /dev/null @@ -1,90 +0,0 @@ -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( - "TraitA.scala", - """ - |package scala - | - |trait A - """.stripMargin - ) - - val source2 = new SourceFile( - "TraitB.scala", - """ - |package scala - | - |trait B - """.stripMargin - ) - - checkSources(source1 :: source2 :: Nil) { packages => - 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( - "TraitA.scala", - """ - |package scala - |package collection - | - |trait A - """.stripMargin) - - val source2 = new SourceFile( - "TraitB.scala", - """ - |package scala - |package collection - | - |trait B - """.stripMargin) - - checkSources(source1 :: source2 :: Nil) { packages => - 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: ${packages("scala")}""") - } - - 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 deleted file mode 100644 index 959eb1745..000000000 --- a/dottydoc/test/SimpleComments.scala +++ /dev/null @@ -1,29 +0,0 @@ -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) { packages => - val traitCmt = - packages("scala") - .children.find(_.path.mkString(".") == "scala.HelloWorld") - .flatMap(_.comment.map(_.body)) - .get - - assertEquals(traitCmt, "<p>Hello, world!</p>") - } - } - -} diff --git a/dottydoc/test/UsecaseTest.scala b/dottydoc/test/UsecaseTest.scala deleted file mode 100644 index b5d47e4b6..000000000 --- a/dottydoc/test/UsecaseTest.scala +++ /dev/null @@ -1,234 +0,0 @@ -package dotty.tools -package dottydoc - -import org.junit.Test -import org.junit.Assert._ - -import dotc.util.SourceFile -import model._ -import model.internal._ -import model.references._ -import util.syntax._ - -class UsecaseTest extends DottyTest { - @Test def simpleUsecase = { - val source = new SourceFile( - "DefWithUseCase.scala", - """ - |package scala - | - |trait Test[A] { - | /** Definition with a "disturbing" signature - | * - | * @usecase def foo: A - | */ - | def foo[B]: A => B - |} - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(trt: Trait), _, _) => - val List(foo: Def) = trt.members - - assert(foo.comment.isDefined, "Lost comment in transformations") - - val returnValue = foo.returnValue match { - case ref: TypeReference => ref.title - case _ => - assert( - false, - "Incorrect return value after usecase transformation" - ) - "" - } - - assert( - foo.typeParams.isEmpty, - "Type parameters were not stripped by usecase" - ) - assert(returnValue == "A", "Incorrect return type after usecase") - - assert(foo.name == "foo", s"Incorrect name after transform: ${foo.name}") - } - } - } - - @Test def simpleUsecaseAddedArg = { - val source = new SourceFile( - "DefWithUseCase.scala", - """ - |package scala - | - |trait Test[A] { - | /** Definition with a "disturbing" signature - | * - | * @usecase def foo(a: A): A - | */ - | def foo[B]: A => B - |} - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(trt: Trait), _, _) => - val List(foo: Def) = trt.members - - val returnValue = foo.returnValue match { - case ref: TypeReference => ref.title - case _ => - assert( - false, - "Incorrect return value after usecase transformation" - ) - "" - } - - assert( - foo.typeParams.isEmpty, - "Type parameters were not stripped by usecase" - ) - assert(returnValue == "A", "Incorrect return type after usecase") - assert( - foo.paramLists.head.list.head.title == "a", - "Incorrect parameter to function after usecase transformation" - ) - assert(foo.name == "foo", s"Incorrect name after transform: ${foo.name}") - } - } - } - - @Test def simpleTparamUsecase = { - val source = new SourceFile( - "DefWithUseCase.scala", - """ - |package scala - | - |trait Test[A] { - | /** Definition with a "disturbing" signature - | * - | * @usecase def foo[C]: A - | */ - | def foo[B]: A => B - |} - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(trt: Trait), _, _) => - val List(foo: Def) = trt.members - - val returnValue = foo.returnValue match { - case ref: TypeReference => ref.title - case _ => - assert( - false, - "Incorrect return value after usecase transformation" - ) - "" - } - - assert( - foo.typeParams.nonEmpty, - "Type parameters were incorrectly stripped by usecase" - ) - - assert(foo.typeParams.head == "C", "Incorrectly switched tparam") - assert(returnValue == "A", "Incorrect return type after usecase") - - assert(foo.name == "foo", s"Incorrect name after transform: ${foo.name}") - } - } - } - - @Test def expandColl = { - val source = new SourceFile( - "ExpandColl.scala", - """ - |package scala - | - |/** The trait $Coll - | * - | * @define Coll Iterable - | */ - |trait Iterable[A] { - | /** Definition with a "disturbing" signature - | * - | * @usecase def map[B](f: A => B): $Coll[B] - | */ - | def map[B, M[B]](f: A => B): M[B] = ??? - |} - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(trt: Trait), _, _) => - val List(map: Def) = trt.members - - val returnValue = map.returnValue match { - case ref: TypeReference => ref.title - case _ => - assert( - false, - "Incorrect return value after usecase transformation" - ) - "" - } - - assert( - returnValue == "Iterable", - "Incorrect return type after usecase transformation" - ) - } - } - } - - @Test def checkStripping = { - val source = new SourceFile( - "CheckStripping.scala", - """ - |package scala - | - |/** The trait $Coll - | * - | * @define Coll Iterable - | */ - |trait Iterable[A] { - | /** Definition with a "disturbing" signature - | * - | * @usecase def map[B](f: A => B): $Coll[B] - | */ - | def map[B, M[B]](f: A => B): M[B] = ??? - |} - """.stripMargin - ) - - checkSources(source :: Nil) { packages => - packages("scala") match { - case PackageImpl(_, _, List(trt: Trait), _, _) => - val List(map: Def) = trt.members - assert(map.comment.isDefined, "Lost comment in transformations") - - val docstr = ctx.docbase.docstring(map.symbol).get.raw - assert( - !docstr.contains("@usecase"), - s"Comment should not contain usecase after stripping, but was:\n$docstr" - ) - } - } - } - - @Test def checkIterator = - checkFiles("./scala-scala/src/library/scala/collection/Iterator.scala" :: Nil) { _ => - // success if typer throws no errors! :) - } - - @Test def checkIterableLike = - checkFiles("./scala-scala/src/library/scala/collection/IterableLike.scala" :: Nil) { _ => - // success if typer throws no errors! :) - } -} diff --git a/dottydoc/test/WhitelistedStdLib.scala b/dottydoc/test/WhitelistedStdLib.scala deleted file mode 100644 index 48697ea7f..000000000 --- a/dottydoc/test/WhitelistedStdLib.scala +++ /dev/null @@ -1,45 +0,0 @@ -package dotty.tools -package dottydoc - -import org.junit.Test -import org.junit.Assert._ - -class TestWhitelistedCollections extends DottyTest { - val files: List[String] = { - val whitelist = "./test/dotc/scala-collections.whitelist" - - scala.io.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")) - .toList - } - - @Test def arrayHasDocumentation = - checkFiles(files) { packages => - val array = - packages("scala") - .children.find(_.path.mkString(".") == "scala.Array") - .get - - assert(array.comment.get.body.length > 0) - } - - @Test def traitImmutableHasDocumentation = - checkFiles(files) { packages => - val imm = - 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") - } -} |