diff options
author | Denys Shabalin <denys.shabalin@typesafe.com> | 2014-02-05 16:07:44 +0100 |
---|---|---|
committer | Denys Shabalin <denys.shabalin@typesafe.com> | 2014-02-07 17:19:36 +0100 |
commit | c73f30922f246a7f2afae8e9e52acce2fdbf4d8d (patch) | |
tree | 281498eb15ea44a276ae69d098891c09ac6c8f5b /test | |
parent | 31c5310da39cab33bf37f555777eaa51cf1de820 (diff) | |
download | scala-c73f30922f246a7f2afae8e9e52acce2fdbf4d8d.tar.gz scala-c73f30922f246a7f2afae8e9e52acce2fdbf4d8d.tar.bz2 scala-c73f30922f246a7f2afae8e9e52acce2fdbf4d8d.zip |
Add support for a more straightforward alternative to import selectors
Diffstat (limited to 'test')
3 files changed, 82 insertions, 14 deletions
diff --git a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala index 798c7adf2e..dcd4f63a4d 100644 --- a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala @@ -8,7 +8,8 @@ object DefinitionConstructionProps with TypeDefConstruction with ValDefConstruction with DefConstruction - with PackageConstruction { + with PackageConstruction + with ImportConstruction { property("SI-6842") = test { val x: Tree = q"val x: Int" assertEqAst(q"def f($x) = 0", "def f(x: Int) = 0") @@ -363,3 +364,30 @@ trait DefConstruction { self: QuasiquoteProperties => assertEqAst(q"def foo(implicit ..$xs) = x1 + x2", "def foo(implicit x1: Int, x2: Long) = x1 + x2") } } + +trait ImportConstruction { self: QuasiquoteProperties => + property("construct wildcard import") = test { + val sel = pq"_" + assert(q"import foo.$sel" ≈ q"import foo._") + } + + property("construct named import") = test { + val sel = pq"bar" + assert(q"import foo.$sel" ≈ q"import foo.bar") + } + + property("construct renaming import") = test { + val sel = pq"bar -> baz" + assert(q"import foo.$sel" ≈ q"import foo.{bar => baz}") + } + + property("construct unimport import") = test { + val sels = pq"poison -> _" :: pq"_" :: Nil + assert(q"import foo.{..$sels}" ≈ q"import foo.{poison => _, _}") + } + + property("construct mixed import") = test { + val sels = pq"a -> b" :: pq"c -> _" :: pq"_" :: Nil + assert(q"import foo.{..$sels}" ≈ q"import foo.{a => b, c => _, _}") + } +} diff --git a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala index 88e00c734b..e2d1757d48 100644 --- a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala @@ -10,6 +10,7 @@ object DefinitionDeconstructionProps with ValVarDeconstruction with DefDeconstruction with PackageDeconstruction + with ImportDeconstruction trait TraitDeconstruction { self: QuasiquoteProperties => property("exhaustive trait matcher") = test { @@ -219,3 +220,55 @@ trait DefDeconstruction { self: QuasiquoteProperties => assert(impl.isEmpty) } } + +trait ImportDeconstruction { self: QuasiquoteProperties => + property("exhaustive import matcher") = test { + def matches(line: String) = { + val q"import $ref.{..$sels}" = parse(line) + } + matches("import foo.bar") + matches("import foo.{bar, baz}") + matches("import foo.{a => b, c => d}") + matches("import foo.{poision => _, _}") + matches("import foo.bar.baz._") + } + + property("extract import binding") = test { + val q"import $_.$sel" = q"import foo.bar" + val pq"bar" = sel + } + + property("extract import wildcard") = test { + val q"import $_.$sel" = q"import foo._" + val pq"_" = sel + } + + property("extract import rename") = test { + val q"import $_.$sel" = q"import foo.{bar => baz}" + val pq"bar -> baz" = sel + val pq"$left -> $right" = sel + val pq"bar" = left + val pq"baz" = right + } + + property("extract import unimport") = test { + val q"import $_.$sel" = q"import foo.{bar => _}" + val pq"bar -> _" = sel + val pq"$left -> $right" = sel + val pq"bar" = left + val pq"_" = right + } + + property("splice names into import selector") = forAll { + (expr: Tree, plain: TermName, oldname: TermName, newname: TermName, discard: TermName) => + + val Import(expr1, List( + ImportSelector(plain11, _, plain12, _), + ImportSelector(oldname1, _, newname1, _), + ImportSelector(discard1, _, wildcard, _))) = + q"import $expr.{$plain, $oldname => $newname, $discard => _}" + + expr1 ≈ expr && plain11 == plain12 && plain12 == plain && + oldname1 == oldname && newname1 == newname && discard1 == discard && wildcard == nme.WILDCARD + } +} diff --git a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala index 145e51ab68..058880a25c 100644 --- a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala @@ -85,19 +85,6 @@ object TermConstructionProps extends QuasiquoteProperties("term construction") { q"$fun[..$types]" ≈ (if (types.nonEmpty) TypeApply(fun, types) else fun) } - property("splice names into import selector") = forAll { - (expr: Tree, plain: Name, oldname: Name, newname: Name, discard: Name) => - - val Import(expr1, List( - ImportSelector(plain11, _, plain12, _), - ImportSelector(oldname1, _, newname1, _), - ImportSelector(discard1, _, wildcard, _))) = - q"import $expr.{$plain, $oldname => $newname, $discard => _}" - - expr1 ≈ expr && plain11 == plain12 && plain12 == plain && - oldname1 == oldname && newname1 == newname && discard1 == discard && wildcard == nme.WILDCARD - } - property("splice trees into while loop") = forAll { (cond: Tree, body: Tree) => val LabelDef(_, List(), If(cond1, Block(List(body1), Apply(_, List())), Literal(Constant(())))) = q"while($cond) $body" body1 ≈ body && cond1 ≈ cond |