diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-10-31 13:50:10 +0100 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-11-12 14:04:42 +0100 |
commit | 3b4d8c0c0b71db160c0d031f34274977446e815a (patch) | |
tree | e0089da4d0270f1b38e8a10b0cd1d9562bc3b5e6 /test/files | |
parent | 538cc136f5f4595cccf15b4b0f496096ab675c13 (diff) | |
download | scala-3b4d8c0c0b71db160c0d031f34274977446e815a.tar.gz scala-3b4d8c0c0b71db160c0d031f34274977446e815a.tar.bz2 scala-3b4d8c0c0b71db160c0d031f34274977446e815a.zip |
add some post-typecheck tests for quasiquotes
Typecheck trees with toolbox and check that they are still matched
by corresponding quasiquote. Fix tuples and function types matchers
to account for different shape of trees after typing.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala | 16 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/Test.scala | 1 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/TypecheckedProps.scala | 30 |
3 files changed, 45 insertions, 2 deletions
diff --git a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala b/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala index 6a531071bf..2286bb3a0a 100644 --- a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala +++ b/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala @@ -18,8 +18,8 @@ trait Helpers { * if no exception has been thrown while executing code * block. This is useful for simple one-off tests. */ - def test[T](block: => T)= - Prop { (params) => + def test[T](block: => T) = + Prop { params => block Result(Prop.Proof) } @@ -68,6 +68,18 @@ trait Helpers { val compile = toolbox.compile(_) val eval = toolbox.eval(_) + def typecheck(tree: Tree) = toolbox.typeCheck(tree) + + def typecheckTyp(tree: Tree) = { + val q"type $_ = $res" = typecheck(q"type T = $tree") + res + } + + def typecheckPat(tree: Tree) = { + val q"$_ match { case $res => }" = typecheck(q"((): Any) match { case $tree => }") + res + } + def fails(msg: String, block: String) = { def result(ok: Boolean, description: String = "") = { val status = if (ok) Prop.Proof else Prop.False diff --git a/test/files/scalacheck/quasiquotes/Test.scala b/test/files/scalacheck/quasiquotes/Test.scala index f41d961888..73cac0368c 100644 --- a/test/files/scalacheck/quasiquotes/Test.scala +++ b/test/files/scalacheck/quasiquotes/Test.scala @@ -12,4 +12,5 @@ object Test extends Properties("quasiquotes") { include(DefinitionConstructionProps) include(DefinitionDeconstructionProps) include(DeprecationProps) + include(TypecheckedProps) } diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala new file mode 100644 index 0000000000..8e93422e77 --- /dev/null +++ b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala @@ -0,0 +1,30 @@ +import org.scalacheck._, Prop._, Gen._, Arbitrary._ +import scala.reflect.runtime.universe._, Flag._, build.{Ident => _, _} + +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) + } +}
\ No newline at end of file |