summaryrefslogtreecommitdiff
path: root/test/files/scalacheck
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-01-29 01:55:46 -0800
committerJason Zaugg <jzaugg@gmail.com>2014-01-29 01:55:46 -0800
commit4506acba688e80a4f778e495a74e7a50f83c4e1b (patch)
treeb05a731dde14ce49f344260ceef2023cd973e646 /test/files/scalacheck
parent057adc70346414c10273f58fcd44114bf0672933 (diff)
parent8e9862473abd03bded2d3afa60c777099f7872c5 (diff)
downloadscala-4506acba688e80a4f778e495a74e7a50f83c4e1b.tar.gz
scala-4506acba688e80a4f778e495a74e7a50f83c4e1b.tar.bz2
scala-4506acba688e80a4f778e495a74e7a50f83c4e1b.zip
Merge pull request #3374 from densh/si/6844-8076
SI-6844 SI-8076 improve handling of function parameters in quasiquotes
Diffstat (limited to 'test/files/scalacheck')
-rw-r--r--test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala15
-rw-r--r--test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala31
2 files changed, 44 insertions, 2 deletions
diff --git a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
index 2af656c7c9..3166eb7a99 100644
--- a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
@@ -7,6 +7,7 @@ object DefinitionConstructionProps
with TraitConstruction
with TypeDefConstruction
with ValDefConstruction
+ with DefConstruction
with PackageConstruction {
property("SI-6842") = test {
val x: Tree = q"val x: Int"
@@ -349,4 +350,16 @@ trait PackageConstruction { self: QuasiquoteProperties =>
assertEqAst(q"package object foo extends { ..$edefs } with Any",
"package object foo extends { val x = 1; type I = Int } with Any")
}
-} \ No newline at end of file
+}
+
+trait DefConstruction { self: QuasiquoteProperties =>
+ property("construct implicit args (1)") = test {
+ val x = q"val x: Int"
+ assertEqAst(q"def foo(implicit $x) = x", "def foo(implicit x: Int) = x")
+ }
+
+ property("construct implicit args (2)") = test {
+ val xs = q"val x1: Int" :: q"val x2: Long" :: Nil
+ assertEqAst(q"def foo(implicit ..$xs) = x1 + x2", "def foo(implicit x1: Int, x2: Long) = x1 + x2")
+ }
+}
diff --git a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala
index 94465930ed..209fe9bbeb 100644
--- a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala
@@ -8,6 +8,7 @@ object DefinitionDeconstructionProps
with ObjectDeconstruction
with ModsDeconstruction
with ValVarDeconstruction
+ with DefDeconstruction
with PackageDeconstruction
trait TraitDeconstruction { self: QuasiquoteProperties =>
@@ -179,4 +180,32 @@ trait PackageDeconstruction { self: QuasiquoteProperties =>
matches("package object foo extends { val early = 1 } with daddy")
assertThrows[MatchError] { matches("object foo") }
}
-} \ No newline at end of file
+}
+
+trait DefDeconstruction { self: QuasiquoteProperties =>
+ property("exhaustive def matcher") = test {
+ def matches(line: String) = {
+ val t = parse(line)
+ val q"$mods0 def $name0[..$targs0](...$argss0): $restpe0 = $body0" = t
+ val q"$mods1 def $name1[..$targs1](...$argss1)(implicit ..$impl1): $restpe1 = $body1" = t
+ }
+ matches("def foo = foo")
+ matches("implicit def foo: Int = 2")
+ matches("def foo[T](x: T): T = x")
+ matches("def foo[A: B] = implicitly[B[A]]")
+ matches("private def foo = 0")
+ matches("def foo[A <% B] = null")
+ matches("def foo(one: One)(two: Two) = (one, two)")
+ matches("def foo[T](args: T*) = args.toList")
+ }
+
+ property("extract implicit arg list (1)") = test {
+ val q"def foo(...$argss)(implicit ..$impl)" = q"def foo(x: Int)(implicit y: Int)"
+ assert(impl ≈ List(q"${Modifiers(IMPLICIT | PARAM)} val y: Int"))
+ }
+
+ property("extract implicit arg list (2)") = test {
+ val q"def foo(...$argss)(implicit ..$impl)" = q"def foo(x: Int)"
+ assert(impl.isEmpty)
+ }
+}