aboutsummaryrefslogtreecommitdiff
path: root/test/dotty
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-03-16 16:58:00 +0100
committerJason Zaugg <jzaugg@gmail.com>2014-03-16 16:58:00 +0100
commitfd1214cfff0bf8a257a85e1ef44047ed6de000a2 (patch)
tree4452681787122e8357844e972e40de3b6f150f04 /test/dotty
parent027abb4de0710b17ba92499f231d0b0d6467831a (diff)
downloaddotty-fd1214cfff0bf8a257a85e1ef44047ed6de000a2.tar.gz
dotty-fd1214cfff0bf8a257a85e1ef44047ed6de000a2.tar.bz2
dotty-fd1214cfff0bf8a257a85e1ef44047ed6de000a2.zip
Test case for TreeInfo#defPath
I'm about to refactor that method in terms of a TreeAccumulator. Note that I've packaged the test case in `dotty.tools.dotc.ast` I believe this is the best approach for organizing unit tests: the import tax is minimized, and use of relative imports is made less fragile by avoiding creating new packages to test code. I'll reorganize the other unit tests like this if others agree.
Diffstat (limited to 'test/dotty')
-rw-r--r--test/dotty/tools/dotc/ast/TreeInfoTest.scala30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/dotty/tools/dotc/ast/TreeInfoTest.scala b/test/dotty/tools/dotc/ast/TreeInfoTest.scala
new file mode 100644
index 000000000..6e02ee813
--- /dev/null
+++ b/test/dotty/tools/dotc/ast/TreeInfoTest.scala
@@ -0,0 +1,30 @@
+package dotty.tools.dotc
+package ast
+
+import org.junit.Test
+import test.DottyTest
+import core.Names._
+import core.Types._
+import core.Symbols._
+import org.junit.Assert._
+
+class TreeInfoTest extends DottyTest {
+
+ import tpd._
+
+ @Test
+ def testDefPath = checkCompile("frontend", "class A { def bar = { val x = { val z = 0; 0} }} ") {
+ (tree, context) =>
+ implicit val ctx = context
+ val xTree = tree.find(tree => tree.symbol.name == termName("x")).get
+ val path = defPath(xTree.symbol, tree)
+ assertEquals(List(
+ ("PackageDef", EMPTY_PACKAGE),
+ ("TypeDef", typeName("A")),
+ ("Template", termName("<local A>")),
+ ("DefDef", termName("bar")),
+ ("Block", NoSymbol.name),
+ ("ValDef", termName("x"))
+ ), path.map(x => (x.productPrefix, x.symbol.name)))
+ }
+}