diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2012-12-12 15:05:47 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2012-12-12 15:05:47 -0800 |
commit | a6f10cf7f4245f2dfcf2fef5fab5255b6fca119f (patch) | |
tree | cbad4b40dc2e471234dad0fec55a643f9bbdae93 /test/files | |
parent | 59c2649ae074364a9a2d171d58d47612c92bf1c1 (diff) | |
parent | e5e6d673cf669e3c9a7643aedd02213e4f7bbddf (diff) | |
download | scala-a6f10cf7f4245f2dfcf2fef5fab5255b6fca119f.tar.gz scala-a6f10cf7f4245f2dfcf2fef5fab5255b6fca119f.tar.bz2 scala-a6f10cf7f4245f2dfcf2fef5fab5255b6fca119f.zip |
Merge pull request #1722 from vigdorchik/ide.api
Extract base scaladoc functionality for the IDE.
Diffstat (limited to 'test/files')
-rwxr-xr-x | test/files/presentation/doc.check | 48 | ||||
-rwxr-xr-x | test/files/presentation/doc.scala | 71 | ||||
-rwxr-xr-x | test/files/presentation/doc/src/Test.scala | 1 | ||||
-rw-r--r-- | test/files/presentation/memory-leaks/MemoryLeaksTest.scala | 5 |
4 files changed, 124 insertions, 1 deletions
diff --git a/test/files/presentation/doc.check b/test/files/presentation/doc.check new file mode 100755 index 0000000000..62b3bfc2e3 --- /dev/null +++ b/test/files/presentation/doc.check @@ -0,0 +1,48 @@ +body:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(This is a test comment), Text(.)))), Text( +)))))) +@example:Body(List(Paragraph(Chain(List(Summary(Monospace(Text("abb".permutations = Iterator(abb, bab, bba))))))))) +@version: +@since: +@todo: +@note: +@see: +body:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(This is a test comment), Text(.)))), Text( +)))))) +@example:Body(List(Paragraph(Chain(List(Summary(Monospace(Text("abb".permutations = Iterator(abb, bab, bba))))))))) +@version:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(1), Text(.)))), Text(0, 09/07/2012)))))) +@since: +@todo: +@note: +@see: +body:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(This is a test comment), Text(.)))), Text( +)))))) +@example:Body(List(Paragraph(Chain(List(Summary(Monospace(Text("abb".permutations = Iterator(abb, bab, bba))))))))) +@version:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(1), Text(.)))), Text(0, 09/07/2012)))))) +@since:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(2), Text(.)))), Text(10)))))) +@todo: +@note: +@see: +body:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(This is a test comment), Text(.)))), Text( +)))))) +@example:Body(List(Paragraph(Chain(List(Summary(Monospace(Text("abb".permutations = Iterator(abb, bab, bba))))))))) +@version:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(1), Text(.)))), Text(0, 09/07/2012)))))) +@since:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(2), Text(.)))), Text(10)))))) +@todo:Body(List(Paragraph(Chain(List(Summary(Text(this method is unsafe))))))) +@note: +@see: +body:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(This is a test comment), Text(.)))), Text( +)))))) +@example:Body(List(Paragraph(Chain(List(Summary(Monospace(Text("abb".permutations = Iterator(abb, bab, bba))))))))) +@version:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(1), Text(.)))), Text(0, 09/07/2012)))))) +@since:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(2), Text(.)))), Text(10)))))) +@todo:Body(List(Paragraph(Chain(List(Summary(Text(this method is unsafe))))))) +@note:Body(List(Paragraph(Chain(List(Summary(Text(Don't inherit!))))))) +@see: +body:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(This is a test comment), Text(.)))), Text( +)))))) +@example:Body(List(Paragraph(Chain(List(Summary(Monospace(Text("abb".permutations = Iterator(abb, bab, bba))))))))) +@version:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(1), Text(.)))), Text(0, 09/07/2012)))))) +@since:Body(List(Paragraph(Chain(List(Summary(Chain(List(Text(2), Text(.)))), Text(10)))))) +@todo:Body(List(Paragraph(Chain(List(Summary(Text(this method is unsafe))))))) +@note:Body(List(Paragraph(Chain(List(Summary(Text(Don't inherit!))))))) +@see:Body(List(Paragraph(Chain(List(Summary(Text(some other method))))))) diff --git a/test/files/presentation/doc.scala b/test/files/presentation/doc.scala new file mode 100755 index 0000000000..4b0d6baa1f --- /dev/null +++ b/test/files/presentation/doc.scala @@ -0,0 +1,71 @@ +import scala.tools.nsc.doc +import scala.tools.nsc.doc.base.LinkTo +import scala.tools.nsc.doc.base.comment._ +import scala.tools.nsc.interactive._ +import scala.tools.nsc.interactive.tests._ +import scala.tools.nsc.util._ +import scala.tools.nsc.io._ + +object Test extends InteractiveTest { + override val settings: doc.Settings = docSettings + + val tags = Seq( + "@example `\"abb\".permutations = Iterator(abb, bab, bba)`", + "@version 1.0, 09/07/2012", + "@since 2.10", + "@todo this method is unsafe", + "@note Don't inherit!", + "@see some other method" + ) + + val comment = "This is a test comment." + val caret = "<caret>" + + def text(nTags: Int) = + """|/** %s + | + | * %s */ + |trait Commented {} + |class User(c: %sCommented)""".stripMargin.format(comment, tags take nTags mkString "\n", caret) + + override def main(args: Array[String]) { + val documenter = new Doc(settings) { + val global: compiler.type = compiler + + def chooseLink(links: List[LinkTo]): LinkTo = links.head + } + for (i <- 1 to tags.length) { + val markedText = text(i) + val idx = markedText.indexOf(caret) + val fileText = markedText.substring(0, idx) + markedText.substring(idx + caret.length) + val source = sourceFiles(0) + val batch = new BatchSourceFile(source.file, fileText.toCharArray) + val reloadResponse = new Response[Unit] + compiler.askReload(List(batch), reloadResponse) + reloadResponse.get.left.toOption match { + case None => + reporter.println("Couldn't reload") + case Some(_) => + val treeResponse = new compiler.Response[compiler.Tree] + val pos = compiler.rangePos(batch, idx, idx, idx) + compiler.askTypeAt(pos, treeResponse) + treeResponse.get.left.toOption match { + case Some(tree) => + val sym = tree.tpe.typeSymbol + documenter.retrieve(sym, sym.owner) match { + case Some(HtmlResult(comment)) => + import comment._ + val tags: List[(String, Iterable[Body])] = + List(("@example", example), ("@version", version), ("@since", since.toList), ("@todo", todo), ("@note", note), ("@see", see)) + val str = ("body:" + body + "\n") + + tags.map{ case (name, bodies) => name + ":" + bodies.mkString("\n") }.mkString("\n") + reporter.println(str) + case Some(_) => reporter.println("Got unexpected result") + case None => reporter.println("Got no result") + } + case None => reporter.println("Couldn't find a typedTree") + } + } + } + } +} diff --git a/test/files/presentation/doc/src/Test.scala b/test/files/presentation/doc/src/Test.scala new file mode 100755 index 0000000000..fcc1554994 --- /dev/null +++ b/test/files/presentation/doc/src/Test.scala @@ -0,0 +1 @@ +object Test
\ No newline at end of file diff --git a/test/files/presentation/memory-leaks/MemoryLeaksTest.scala b/test/files/presentation/memory-leaks/MemoryLeaksTest.scala index a5533a623a..159097cc10 100644 --- a/test/files/presentation/memory-leaks/MemoryLeaksTest.scala +++ b/test/files/presentation/memory-leaks/MemoryLeaksTest.scala @@ -5,6 +5,7 @@ import java.util.Calendar import scala.tools.nsc.interactive.tests._ import scala.tools.nsc.util._ import scala.tools.nsc.io._ +import scala.tools.nsc.doc /** This test runs the presentation compiler on the Scala compiler project itself and records memory consumption. * @@ -24,6 +25,8 @@ import scala.tools.nsc.io._ object Test extends InteractiveTest { final val mega = 1024 * 1024 + override val settings: doc.Settings = docSettings + override def execute(): Unit = memoryConsumptionTest() def batchSource(name: String) = @@ -120,4 +123,4 @@ object Test extends InteractiveTest { r.totalMemory() - r.freeMemory() } -}
\ No newline at end of file +} |