summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-09-20 13:32:38 +0200
committerDen Shabalin <den.shabalin@gmail.com>2013-10-14 13:30:49 +0200
commit3a148cd0cd404751095cd1c5aca09ad8923c51ab (patch)
tree2ad3cbc115fe0ca270d476171b41519c483ba201 /test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
parentd7aae49f8ff7ccc6c1a588fc116e8c37fdb9e849 (diff)
downloadscala-3a148cd0cd404751095cd1c5aca09ad8923c51ab.tar.gz
scala-3a148cd0cd404751095cd1c5aca09ad8923c51ab.tar.bz2
scala-3a148cd0cd404751095cd1c5aca09ad8923c51ab.zip
SI-6841 SI-6657 add support for packages into quasiquotes and toolbox
In order to implement this a new parser entry point `parseStatsOrPackages` that augments current parseStats with ability to parse "package name { ... }" syntax.
Diffstat (limited to 'test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala')
-rw-r--r--test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
index ced479aef5..e8ddb4b72a 100644
--- a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala
@@ -13,6 +13,7 @@ object DefinitionConstructionProps
with TraitConstruction
with TypeDefConstruction
with ValDefConstruction
+ with PackageConstruction
trait ClassConstruction { self: QuasiquoteProperties =>
val anyRef = ScalaDot(TypeName("AnyRef"))
@@ -292,4 +293,53 @@ trait MethodConstruction { self: QuasiquoteProperties =>
val a = q"new Foo(a)(b)"
assertEqAst(q"@$a def foo", "@Foo(a)(b) def foo")
}
+}
+
+trait PackageConstruction { self: QuasiquoteProperties =>
+ property("splice select into package name") = test {
+ val name = q"foo.bar"
+ assertEqAst(q"package $name { }", "package foo.bar { }")
+ }
+
+ property("splce name into package name") = test{
+ val name = TermName("bippy")
+ assertEqAst(q"package $name { }", "package bippy { }")
+ }
+
+ property("splice members into package body") = test {
+ val members = q"class C" :: q"object O" :: Nil
+ assertEqAst(q"package foo { ..$members }", "package foo { class C; object O }")
+ }
+
+ property("splice illegal members into package body") = test {
+ val f = q"def f"
+ assertThrows[IllegalArgumentException] { q"package foo { $f }" }
+ val v = q"val v = 0"
+ assertThrows[IllegalArgumentException] { q"package foo { $v }" }
+ val expr = q"x + 1"
+ assertThrows[IllegalArgumentException] { q"package foo { $expr }" }
+ }
+
+ property("splice name into package object") = test {
+ val foo = TermName("foo")
+ assertEqAst(q"package object $foo", "package object foo")
+ }
+
+ property("splice parents into package object") = test {
+ val parents = tq"a" :: tq"b" :: Nil
+ assertEqAst(q"package object foo extends ..$parents",
+ "package object foo extends a with b")
+ }
+
+ property("splice members into package object") = test {
+ val members = q"def foo" :: q"val x = 1" :: Nil
+ assertEqAst(q"package object foo { ..$members }",
+ "package object foo { def foo; val x = 1 }")
+ }
+
+ property("splice early def into package object") = test {
+ val edefs = q"val x = 1" :: q"type I = Int" :: Nil
+ 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