Skip to content

Commit a806c30

Browse files
committed
Scala3doc: add cooking tests
1 parent 60a8b72 commit a806c30

File tree

4 files changed

+14
-37
lines changed

4 files changed

+14
-37
lines changed

scala3doc-testcases/src/tests/tests.scala

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ class A {
7373
*/
7474
final def myMethod(s: String): String = s
7575

76-
/** This is a method.
77-
*
78-
* This is foo: $foo
79-
*/
76+
/** This is foo: $foo */
8077
def method(s: String): String = s
8178

8279
class AA
@@ -121,10 +118,7 @@ object A
121118
class B extends A {
122119
/** @inheritdoc */ override def method(s: String): String = s
123120

124-
/** This is a method.
125-
*
126-
* And this is my foo: $foo
127-
*/
121+
/** This is my foo: $foo */
128122
def otherMethod(s: String): String = s
129123

130124
class BB
@@ -145,7 +139,8 @@ object B {
145139
val Z: Int = 0
146140
}
147141

148-
class C {
142+
/** This is foo: $foo */
143+
class C extends A {
149144
object CC
150145
class CC
151146
}
@@ -215,6 +210,5 @@ class Methods:
215210
*/
216211
object O:
217212

218-
/** This is foo: $foo
219-
*/
213+
/** This is foo: $foo */
220214
def method(s: String) = s

scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ trait ScaladocSupport { self: TastyParser =>
2222

2323
// println(s"Expanding comment for sym: ${tree.symbol.show}")
2424
val sym = tree.symbol.asInstanceOf[dotc.core.Symbols.Symbol]
25-
val owner =
26-
if tree.symbol.isClassDef then sym else sym.owner
2725

28-
comments.CommentExpander.cookComment(sym, owner)(using ctx)
26+
comments.CommentExpander.cookComment(sym)(using ctx)
2927
.get.asInstanceOf[Documentation]
3028
else
3129
commentPre

scala3doc/src/dotty/dokka/tasty/comments/CommentExpander.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ import reporting.ProperDefinitionNotFound
344344
}
345345

346346
object CommentExpander {
347+
348+
// TODO: handle package / non-class top-level definitions (possibly just return their comments?)
349+
def cookComment(sym: Symbol)(using Context): Option[Comment] =
350+
val owner = if sym.isClass then sym else sym.owner
351+
cookComment(sym, owner)
352+
347353
def cookComment(sym: Symbol, owner: Symbol)(using Context): Option[Comment] =
348354
ctx.docCtx.flatMap { docCtx =>
349355
expand(sym, owner)(using ctx)(using docCtx)

scala3doc/test/dotty/dokka/tasty/comments/MemberLookupTests.scala

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted.Quotes
44

55
import org.junit.{Test, Rule}
66
import org.junit.Assert.{assertSame, assertTrue}
7-
import dotty.dokka.BuildInfo
7+
import dotty.dokka.tasty.util._
88

99
class LookupTestCases[Q <: Quotes](val q: Quotes) {
1010

@@ -118,27 +118,6 @@ class MemberLookupTests {
118118
cases.testAll()
119119
}
120120

121-
Inspector().inspectTastyFiles(listOurClasses())
122-
}
123-
124-
def listOurClasses(): List[String] = {
125-
import java.io.File
126-
import scala.collection.mutable.ListBuffer
127-
128-
val classRoot = new File(BuildInfo.test_testcasesOutputDir)
129-
130-
def go(bld: ListBuffer[String])(file: File): Unit =
131-
file.listFiles.foreach { f =>
132-
if f.isFile() then
133-
if f.toString.endsWith(".tasty") then bld.append(f.toString)
134-
else go(bld)(f)
135-
}
136-
137-
if classRoot.isDirectory then
138-
val bld = new ListBuffer[String]
139-
go(bld)(classRoot)
140-
bld.result
141-
else
142-
sys.error(s"Class root could not be found: $classRoot")
121+
Inspector().inspectTastyFiles(TestUtils.listOurClasses())
143122
}
144123
}

0 commit comments

Comments
 (0)