|
1 | 1 |
|
2 | 2 | object Test {
|
3 | 3 | import TypeToolbox.*
|
| 4 | + |
| 5 | + def assertEql[A](obt: A, exp: A): Unit = |
| 6 | + assert(obt == exp, s"\nexpected: $exp\nobtained: $obt") |
| 7 | + |
4 | 8 | def main(args: Array[String]): Unit = {
|
5 | 9 | val x = 5
|
6 |
| - assert(show[x.type] == "x.type") |
7 |
| - assert(show[Nil.type] == "scala.Nil.type") |
8 |
| - assert(show[Int] == "scala.Int") |
9 |
| - assert(show[Int => Int] == "scala.Function1[scala.Int, scala.Int]") |
10 |
| - assert(show[(Int, String)] == "scala.Tuple2[scala.Int, scala.Predef.String]") |
11 |
| - assert(show[[X] =>> X match { case Int => Int }] == |
| 10 | + assertEql(show[x.type], "x.type") |
| 11 | + assertEql(show[Nil.type], "scala.Nil.type") |
| 12 | + assertEql(show[Int], "scala.Int") |
| 13 | + assertEql(show[Int => Int], "scala.Function1[scala.Int, scala.Int]") |
| 14 | + assertEql(show[(Int, String)], "scala.Tuple2[scala.Int, scala.Predef.String]") |
| 15 | + assertEql(show[[X] =>> X match { case Int => Int }], |
12 | 16 | """[X >: scala.Nothing <: scala.Any] => X match {
|
13 | 17 | | case scala.Int => scala.Int
|
14 | 18 | |}""".stripMargin)
|
15 |
| - assert(showStructure[[X] =>> X match { case Int => Int }] == """TypeLambda(List(X), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing"), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any"))), MatchType(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any"), ParamRef(binder, 0), List(MatchCase(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int")))))""") |
| 19 | + assertEql(showStructure[[X] =>> X match { case Int => Int }], |
| 20 | + """TypeLambda("""+ |
| 21 | + """List(X), """+ |
| 22 | + """List(TypeBounds("""+ |
| 23 | + """TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing"), """+ |
| 24 | + """TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any"))), """+ |
| 25 | + """MatchType("""+ |
| 26 | + """TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), """+ // match type bound |
| 27 | + """ParamRef(binder, 0), """+ |
| 28 | + """List("""+ |
| 29 | + """MatchCase("""+ |
| 30 | + """TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), """+ |
| 31 | + """TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int")))))""") |
16 | 32 |
|
17 | 33 | // TODO: more complex types:
|
18 | 34 | // - implicit function types
|
|
0 commit comments