Skip to content

Commit 331d332

Browse files
committed
Add minimized test
1 parent e7e1811 commit 331d332

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted.*
2+
3+
case class Position(fileName: String, filePathname: String, lineNumber: Int)
4+
5+
object Position:
6+
def withPosition[T](fun: Expr[Position => T])(using quotes: Quotes, typeOfT: Type[T]): Expr[T] =
7+
val pos = quotes.reflect.Position.ofMacroExpansion
8+
val file = pos.sourceFile
9+
val fileName: String = Option(file.path).getOrElse("<unknown>")
10+
val filePath: String = file.toString
11+
val lineNo: Int = pos.startLine + 1
12+
'{${fun}.apply(Position(${Expr(fileName)}, ${Expr(filePath)}, ${Expr(lineNo)}))}

tests/init/pos/scalatest/Test.scala

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class TestSuite:
2+
protected val it = new ItWord
3+
4+
protected final class ItWord:
5+
def should(string: String) = new ItVerbString("should", string)
6+
7+
private def registerTestToRun(fun: => Any): Unit = ()
8+
9+
protected final class ItVerbString(verb: String, name: String):
10+
inline def in(testFun: => Any): Unit =
11+
${ Position.withPosition[Unit]('{(pos: Position) => registerTestToRun(testFun) }) }
12+
13+
class MyTest extends TestSuite:
14+
it should "not cause outer select errors" in {
15+
assert(1 + 1 == 2)
16+
}
17+
18+
val n = 10

0 commit comments

Comments
 (0)