diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-03-28 08:35:17 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-03-28 08:35:17 +0100 |
commit | 306c9cb37acf3b72c854830abecd137c638ef67d (patch) | |
tree | d7e6a225457e72e1489aad8a1b64b7081ac0ea9f /test | |
parent | 1ced55f76a8de60a02428d3d7f1e1a44a0f61ab7 (diff) | |
parent | 0bac64d64309e2f236ba25d8e57b1ea1f62d4d8c (diff) | |
download | scala-306c9cb37acf3b72c854830abecd137c638ef67d.tar.gz scala-306c9cb37acf3b72c854830abecd137c638ef67d.tar.bz2 scala-306c9cb37acf3b72c854830abecd137c638ef67d.zip |
Merge pull request #3657 from xeno-by/ticket/8388
SI-8388 consistently match type trees by originals
Diffstat (limited to 'test')
-rw-r--r-- | test/files/scalacheck/quasiquotes/TypecheckedProps.scala | 96 |
1 files changed, 76 insertions, 20 deletions
diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala index fb2eb69321..a5d526191f 100644 --- a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala +++ b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala @@ -2,32 +2,13 @@ import org.scalacheck._, Prop._, Gen._, Arbitrary._ import scala.reflect.runtime.universe._, Flag._, internal.reificationSupport._ object TypecheckedProps extends QuasiquoteProperties("typechecked") { - def original(tree: Tree) = tree match { - case tt: TypeTree => Some(tt.original) - case _ => None - } - def originals(trees: List[Tree]) = trees.flatMap(original) - val int = ScalaDot(TypeName("Int")) - val intint = List(int, int) + property("tuple term") = test { val q"(..$elements)" = typecheck(q"(1, 2)") assert(elements ≈ List(q"1", q"2")) } - property("tuple type") = test { - val tq"(..$els0)" = typecheckTyp(tq"Unit") - assert(els0.isEmpty) - val tq"(..$els1)" = typecheckTyp(tq"(Int, Int)") - assert(originals(els1) ≈ intint) - } - - property("function type") = test { - val tq"(..$argtpes) => $restpe" = typecheckTyp(tq"(Int, Int) => Int") - assert(originals(argtpes) ≈ intint) - assert(original(restpe).get ≈ int) - } - property("for/for-yield") = test { val enums = fq"x <- xs" :: fq"x1 = x + 1" :: fq"if x1 % 2 == 0" :: Nil val body = q"x1" @@ -158,3 +139,78 @@ object TypecheckedProps extends QuasiquoteProperties("typechecked") { assert(cases ≈ q"{ case 1 => () }".cases) } } + +trait TypecheckedTypes { self: QuasiquoteProperties => + property("type ident") = test { + val q"$_; type $_ = $tpt" = typecheck(q"class C; type T = C") + val tq"C" = tpt + } + + property("type select") = test { + val tq"scala.Int" = typecheckTyp(tq"Int") + } + + property("this type select") = test { + val q"class $_ { $_; type $_ = $tpt }" = typecheck(q"class C { type A = Int; type B = this.A }") + val tq"this.$name" = tpt + val TypeName("A") = name + } + + property("super type select") = test { + val q"$_; class $_ extends $_ { type $_ = $tpt }" = + typecheck(q"class C1 { type A = Int }; class C2 extends C1 { type B = super[C1].A }") + val tq"$empty.super[$c1].$a" = tpt + val TypeName("") = empty + val TypeName("C1") = c1 + val TypeName("A") = a + } + + property("applied type") = test { + val tt = typecheckTyp(q"Map[Int, Int]") + val tq"$tpt[..$tpts]" = tt + val tq"scala.this.Predef.Map" = tpt + val List(tq"scala.Int", tq"scala.Int") = tpts + } + + property("tuple type") = test { + val tq"(..$els0)" = typecheckTyp(tq"Unit") + assert(els0.isEmpty) + val tq"(..$els1)" = typecheckTyp(tq"(Int, Int)") + val List(tq"scala.Int", tq"scala.Int") = els1 + } + + property("function type") = test { + val tq"(..$argtpes) => $restpe" = typecheckTyp(tq"(Int, Int) => Int") + val List(tq"scala.Int", tq"scala.Int") = argtpes + val tq"scala.Int" = restpe + } + + property("compound type") = test { + val tq"..$parents { ..$defns }" = typecheckTyp(tq"Int { def x: Int }") + val List(tq"Int") = parents + val List(q"def x: Int") = defns + } + + property("singleton type") = test { + val tq"$ref.type" = typecheckTyp(tq"scala.Predef.type") + val q"scala.Predef" = ref + } + + property("type projection") = test { + val tq"$tpt#$name" = typecheckTyp(tq"({ type T = Int })#T") + val TypeName("T") = name + val tq"{ type T = Int }" = tpt + } + + property("annotated type") = test { + val tq"$tpt @$annot" = typecheckTyp(tq"Int @unchecked") + val tq"scala.Int" = tpt + val q"new unchecked" = annot + } + + property("existential type") = test { + val tq"$tpt forSome { ..$defns }" = typecheckTyp(tq"T forSome { type T }") + val tq"T" = tpt + val q"type T" :: Nil = defns + } +} |