Skip to content

Commit bcdff5f

Browse files
committed
Add test for Type[T].show
1 parent b699650 commit bcdff5f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/run/type-show/Macro_1.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.quoted._
2+
import scala.tasty._
3+
4+
object TypeToolbox {
5+
inline def show[A]: String = ~showImpl('[A])
6+
private def showImpl[A, B](a: Type[A])(implicit refl: Reflection): Expr[String] = {
7+
import refl._
8+
import scala.quoted.Toolbox.Default._
9+
a.show.toExpr
10+
}
11+
}

tests/run/type-show/Test_2.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
object Test {
3+
import TypeToolbox._
4+
def main(args: Array[String]): Unit = {
5+
val x = 5
6+
println(show[Nil.type])
7+
println(show[Int => Int])
8+
println(show[(Int, String)])
9+
println(show[x.type])
10+
assert(show[x.type] == "x.type")
11+
assert(show[Nil.type] == "scala.Nil.type")
12+
assert(show[Int] == "scala.Int")
13+
assert(show[Int => Int] == "scala.Function1[scala.Int, scala.Int]")
14+
assert(show[(Int, String)] == "scala.Tuple2[scala.Int, scala.Predef.String]")
15+
16+
// TODO: more complex types:
17+
// - implicit function types
18+
// - dependent function types
19+
// - refinement types
20+
}
21+
}

0 commit comments

Comments
 (0)