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/scalacheck/quasiquotes/ForProps.scala | |
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/scalacheck/quasiquotes/ForProps.scala')
-rw-r--r-- | test/files/scalacheck/quasiquotes/ForProps.scala | 38 |
1 files changed, 35 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 |