summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-09-02 15:51:56 +0200
committerDen Shabalin <den.shabalin@gmail.com>2013-09-05 14:39:12 +0200
commit901cdc1855e8e80957b18add4991736b9f458d77 (patch)
treeb6ac94c657f262d3a4e398e36b07d042ba4fbfa1 /test
parentf9d5e3d4e8cca61ee75072ab13c2935061a1850e (diff)
downloadscala-901cdc1855e8e80957b18add4991736b9f458d77.tar.gz
scala-901cdc1855e8e80957b18add4991736b9f458d77.tar.bz2
scala-901cdc1855e8e80957b18add4991736b9f458d77.zip
refine block and applied/typeapplied splicing/matching semantics
1. blocks now match single term-level expressions to account for automatic block elimination. E.g. val q"{ ..$stats }" = q"foo" will match into stats = List(q"foo"). This is useful to uniformly deal with blocks on term level. 2. blocks in quasiquotes collapse into single expressions 3. Applied and TypeApplied now have constructors too which helps to unify matching and extraction in quasiquote reifier 4. TypeApplied now matches AppliedTypeTree too 5. Add Syntactic prefix to Applied and TypeApplied
Diffstat (limited to 'test')
-rw-r--r--test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala2
-rw-r--r--test/files/scalacheck/quasiquotes/PatternConstructionProps.scala2
-rw-r--r--test/files/scalacheck/quasiquotes/TermConstructionProps.scala8
-rw-r--r--test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala5
4 files changed, 12 insertions, 5 deletions
diff --git a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
index 5d657b931b..dc3fc60f8c 100644
--- a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
@@ -118,7 +118,7 @@ trait TypeDefConstruction { self: QuasiquoteProperties =>
property("splice into applied type tree") = forAll { (T1: TypeName, T2: TypeName, args: List[Tree]) =>
q"type $T1 = $T2[..$args]" ≈
TypeDef(Modifiers(), T1, List(),
- AppliedTypeTree(Ident(T2), args))
+ if(args.nonEmpty) AppliedTypeTree(Ident(T2), args) else Ident(T2))
}
}
diff --git a/test/files/scalacheck/quasiquotes/PatternConstructionProps.scala b/test/files/scalacheck/quasiquotes/PatternConstructionProps.scala
index aee50c9c5f..504cb2a77d 100644
--- a/test/files/scalacheck/quasiquotes/PatternConstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/PatternConstructionProps.scala
@@ -32,6 +32,6 @@ object PatternConstructionProps extends QuasiquoteProperties("pattern constructi
}
property("splice into casedef") = forAll { (pat: Tree, cond: Tree, body: Tree) =>
- cq"$pat if $cond => $body" ≈ CaseDef(pat, cond, Block(List(), body))
+ cq"$pat if $cond => $body" ≈ CaseDef(pat, cond, body)
}
} \ No newline at end of file
diff --git a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
index 5a765f7911..599dfd442a 100644
--- a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
@@ -88,7 +88,7 @@ object TermConstructionProps extends QuasiquoteProperties("term construction") {
}
property("splice trees into type apply") = forAll { (fun: TreeIsTerm, types: List[Tree]) =>
- q"$fun[..$types]" ≈ TypeApply(fun, types)
+ q"$fun[..$types]" ≈ (if (types.nonEmpty) TypeApply(fun, types) else fun)
}
property("splice names into import selector") = forAll {
@@ -122,8 +122,10 @@ object TermConstructionProps extends QuasiquoteProperties("term construction") {
def blockInvariant(quote: Tree, trees: List[Tree]) =
quote ≈ (trees match {
- case Nil => Block(Nil, q"()")
- case _ => Block(trees.init, trees.last)
+ case Nil => q"()"
+ case _ :+ last if !last.isTerm => Block(trees, q"()")
+ case head :: Nil => head
+ case init :+ last => Block(init, last)
})
property("splice list of trees into block (1)") = forAll { (trees: List[Tree]) =>
diff --git a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala
index 132baeb977..6087bbdb74 100644
--- a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala
@@ -62,4 +62,9 @@ object TermDeconstructionProps extends QuasiquoteProperties("term deconstruction
val q"$x match { case ..$cases }" = q"x match { case 1 => case 2 => }"
x ≈ q"x" && cases ≈ List(cq"1 =>", cq"2 =>")
}
+
+ property("deconstruct block") = test {
+ val q"{ ..$xs }" = q"{ x1; x2; x3 }"
+ assert(xs ≈ List(q"x1", q"x2", q"x3"))
+ }
} \ No newline at end of file