diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-23 04:54:11 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-23 04:54:11 -0700 |
commit | a456f4648a82e22b9fa66f05835c01173c16c7c8 (patch) | |
tree | f418e9b8d4985ae26f9d663f2d7b05c3147dea17 /test | |
parent | c96f135f32ffc79bc4bd7ece92aa2f18f2efe99e (diff) | |
parent | c8a9329ff9b2a6ea99eef7234c9f84c0bfe0166b (diff) | |
download | scala-a456f4648a82e22b9fa66f05835c01173c16c7c8.tar.gz scala-a456f4648a82e22b9fa66f05835c01173c16c7c8.tar.bz2 scala-a456f4648a82e22b9fa66f05835c01173c16c7c8.zip |
Merge pull request #2962 from densh/topic/syntactic-assign
Quasiquotes: add syntactic extractor for assignment-like trees
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/macro-quasiquotes.check | 2 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/TermConstructionProps.scala | 24 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala | 20 |
3 files changed, 45 insertions, 1 deletions
diff --git a/test/files/neg/macro-quasiquotes.check b/test/files/neg/macro-quasiquotes.check index a2d48723b5..96ef75dd32 100644 --- a/test/files/neg/macro-quasiquotes.check +++ b/test/files/neg/macro-quasiquotes.check @@ -1,6 +1,6 @@ Macros_1.scala:14: error: macro implementation has wrong shape: required: (x: Impls.this.c.Expr[Int]): Impls.this.c.Expr[Any] - found : (x: Impls.this.c.universe.Block): Impls.this.c.universe.Apply + found : (x: Impls.this.c.universe.Block): Impls.this.c.universe.Tree type mismatch for parameter x: Impls.this.c.Expr[Int] does not conform to Impls.this.c.universe.Block def m3(x: Int) = macro Impls.impl3 ^ diff --git a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala index c6cca85c81..753ad1aa59 100644 --- a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala @@ -167,4 +167,28 @@ object TermConstructionProps extends QuasiquoteProperties("term construction") { val x = q"val x: Int = 1" assertThrows[IllegalArgumentException] { q"($x) => x" } } + + property("assign variable") = test { + val v = q"v" + val value = q"foo" + assertEqAst(q"$v = $value", "v = foo") + } + + property("assign update 1") = test { + val v = q"v" + val args = q"1" :: q"2" :: Nil + val value = q"foo" + assertEqAst(q"$v(..$args) = $value", "v(1, 2) = foo") + } + + property("assign update 2") = test { + val a = q"v(0)" + val value = q"foo" + assertEqAst(q"$a = $value", "v(0) = foo") + } + + property("assign or named arg") = test { + val assignx = q"x = 1" + assertEqAst(q"f($assignx)", "f(x = 1)") + } } diff --git a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala index 45c7ee4bb7..22d4b1ce4f 100644 --- a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala @@ -91,4 +91,24 @@ object TermDeconstructionProps extends QuasiquoteProperties("term deconstruction matches("new { val early = 1} with Parent[Int] { body }") matches("new Foo { selfie => }") } + + property("exhaustive assign pattern") = test { + def matches(tree: Tree) { val q"$rhs = $lhs" = tree } + matches(parse("left = right")) + matches(parse("arr(1) = 2")) + matches(AssignOrNamedArg(EmptyTree, EmptyTree)) + } + + property("deconstruct update 1") = test { + val q"$obj(..$args) = $value" = q"foo(bar) = baz" + assert(obj ≈ q"foo") + assert(args ≈ List(q"bar")) + assert(value ≈ q"baz") + } + + property("deconstruct update 2") = test { + val q"$left = $value" = q"foo(bar) = baz" + assert(left ≈ q"foo(bar)") + assert(value ≈ q"baz") + } } |