blob: 34269ec64c7b7b0a820c11641dcb5c3040266331 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package test
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.core.Contexts.Context
trait DottyDocTest extends DottyTest {
ctx = ctx.fresh.setSetting(ctx.settings.YkeepComments, true)
def checkDocString(actual: Option[String], expected: String): Unit = actual match {
case Some(str) =>
assert(str == expected, s"""Docstring: "$str" didn't match expected "$expected"""")
case None =>
assert(false, s"""No docstring found, expected: "$expected"""")
}
def expectNoDocString(doc: Option[String]): Unit =
doc.fold(()) { d => assert(false, s"""Expected not to find a docstring, but found: "$d"""") }
def defaultAssertion: PartialFunction[Any, Unit] = {
case t: Tree[Untyped] =>
assert(false, s"Couldn't match resulting AST to expected AST in: ${t.show}")
case x =>
assert(false, s"Couldn't match resulting AST to expected AST in: $x")
}
def checkFrontend(source: String)(docAssert: PartialFunction[Tree[Untyped], Unit]) = {
checkCompile("frontend", source) { (_, ctx) =>
implicit val c = ctx
(docAssert orElse defaultAssertion)(ctx.compilationUnit.untpdTree)
}
}
}
|