diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-10-31 12:21:28 +0100 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-11-12 14:04:42 +0100 |
commit | c62a0e78c33dda1db6e73fa5cd3c6ddbd2b238f4 (patch) | |
tree | e5b1d545931db70c83844474a802804b164f75e5 /test/files | |
parent | a4a3ab0d722412b9ecf267b178bb866087867cf9 (diff) | |
download | scala-c62a0e78c33dda1db6e73fa5cd3c6ddbd2b238f4.tar.gz scala-c62a0e78c33dda1db6e73fa5cd3c6ddbd2b238f4.tar.bz2 scala-c62a0e78c33dda1db6e73fa5cd3c6ddbd2b238f4.zip |
add support for for loops and for enumerators to quasiquotes
1. q"for (..$enums) $body", q"for (..$enums) yield $body"
2. fq"..." quote to construct/deconstruct enumerators
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/scalacheck/quasiquotes/ForProps.scala | 38 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/TypecheckedProps.scala | 12 |
2 files changed, 47 insertions, 3 deletions
diff --git a/test/files/scalacheck/quasiquotes/ForProps.scala b/test/files/scalacheck/quasiquotes/ForProps.scala index 234f4d10eb..e71822aaea 100644 --- a/test/files/scalacheck/quasiquotes/ForProps.scala +++ b/test/files/scalacheck/quasiquotes/ForProps.scala @@ -10,15 +10,15 @@ object ForProps extends QuasiquoteProperties("for") { def genForFilter: Gen[Tree] = for(cond <- genIdent(genTermName)) - yield SyntacticFilter(cond) + yield fq"if $cond" def genForFrom: Gen[Tree] = for(lhs <- genSimpleBind; rhs <- genIdent(genTermName)) - yield SyntacticValFrom(lhs, rhs) + yield fq"$lhs <- $rhs" def genForEq: Gen[Tree] = for(lhs <- genSimpleBind; rhs <- genIdent(genTermName)) - yield SyntacticValEq(lhs, rhs) + yield fq"$lhs = $rhs" def genForEnums(size: Int): Gen[ForEnums] = for(first <- genForFrom; rest <- listOfN(size, oneOf(genForFrom, genForFilter, genForEq))) @@ -35,4 +35,36 @@ object ForProps extends QuasiquoteProperties("for") { val SyntacticForYield(recoveredEnums, recoveredBody) = SyntacticForYield(enums.value, body) recoveredEnums ≈ enums.value && recoveredBody ≈ body } + + val abcde = List(fq"a <-b", fq"if c", fq"d = e") + val foobarbaz = pq"foo @ Bar(baz)" + val fv = q"f(v)" + + property("construct/deconstruct for loop with fq") = test { + val for0 = q"for(..$abcde) $fv" + assertEqAst(for0, "for(a <- b; if c; d = e) f(v)") + val q"for(..$enums) $body" = for0 + assert(enums ≈ abcde) + assert(body ≈ fv) + } + + property("construct/deconstruct valfrom with fq") = test { + assert(fq"$foobarbaz <- $fv" ≈ fq"foo @ Bar(baz) <- f(v)") + val fq"$lhs <- $rhs" = fq"$foobarbaz <- $fv" + assert(lhs ≈ foobarbaz) + assert(rhs ≈ fv) + } + + property("construct/deconstruct valeq with fq") = test { + assert(fq"$foobarbaz = $fv" ≈ fq"foo @ Bar(baz) = f(v)") + val fq"$lhs = $rhs" = fq"$foobarbaz = $fv" + assert(lhs ≈ foobarbaz) + assert(rhs ≈ fv) + } + + property("construct/deconstruct filter with fq") = test { + assert(fq"if $fv" ≈ fq"if f(v)") + val fq"if $cond" = fq"if $fv" + assert(cond ≈ fv) + } }
\ No newline at end of file diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala index 8e93422e77..a95016b634 100644 --- a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala +++ b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala @@ -27,4 +27,16 @@ object TypecheckedProps extends QuasiquoteProperties("typechecked") { 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" + val xs = q"val xs = List(1, 2, 3)" + val q"$_; for(..$enums0) yield $body0" = typecheck(q"$xs; for(..$enums) yield $body") + assert(enums0 ≈ enums) + assert(body0 ≈ body) + val q"$_; for(..$enums1) $body1" = typecheck(q"$xs; for(..$enums) $body") + assert(enums1 ≈ enums) + assert(body1 ≈ body) + } }
\ No newline at end of file |