diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-10-31 11:58:15 +0100 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-11-12 14:04:42 +0100 |
commit | c3e766e0b255f8fc202d027406c7efd76c82b49d (patch) | |
tree | 2e40524ce04c8d7bd17062dd02e0d356bdbc83d2 /test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala | |
parent | c6fe22f5479458a688a819f92f2af43c5867ea81 (diff) | |
download | scala-c3e766e0b255f8fc202d027406c7efd76c82b49d.tar.gz scala-c3e766e0b255f8fc202d027406c7efd76c82b49d.tar.bz2 scala-c3e766e0b255f8fc202d027406c7efd76c82b49d.zip |
make fresh names compare similar in quasiquotes
Otherwise it's annoying that trees that look the same are not equal
due to some fresh name hidden underneath. Due to this one test needs
to be changed to use plain equalsStructure.
Diffstat (limited to 'test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala')
-rw-r--r-- | test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala b/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala index 6d3a993d1f..b2bce124ee 100644 --- a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala +++ b/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala @@ -16,8 +16,30 @@ trait Helpers { Result(Prop.Proof) } + object simplify extends Transformer { + object SimplifiedName { + def unapply[T <: Name](name: T): Option[T] = + name.toString.split("\\$").toSeq match { + case first :+ last if scala.util.Try(last.toInt).isSuccess && first.nonEmpty => + val value = first.mkString("", "$", "$") + Some((if (name.isTermName) TermName(value) else TypeName(value)).asInstanceOf[T]) + case _ => None + } + } + + override def transform(tree: Tree): Tree = tree match { + case Ident(SimplifiedName(name)) => Ident(name) + case ValDef(mods, SimplifiedName(name), tpt, rhs) => ValDef(mods, name, tpt, rhs) + case Bind(SimplifiedName(name), rhs) => Bind(name, rhs) + case _ => + super.transform(tree) + } + + def apply(tree: Tree): Tree = transform(tree) + } + implicit class TestSimilarTree(tree1: Tree) { - def ≈(tree2: Tree) = tree1.equalsStructure(tree2) + def ≈(tree2: Tree) = simplify(tree1).equalsStructure(simplify(tree2)) } implicit class TestSimilarListTree(lst: List[Tree]) { |