diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-11-11 22:12:50 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-11-11 22:12:50 +0100 |
commit | 40da520a74fbb13b0ed1c5acb7ddf5c521fd8acc (patch) | |
tree | f39a3f1882103e78329637408a08dc509012bc1e /src/test/scala/scala/async/TreeInterrogation.scala | |
parent | 23e24fc738e2d4ad967090c375cd356cf45745ce (diff) | |
download | scala-async-40da520a74fbb13b0ed1c5acb7ddf5c521fd8acc.tar.gz scala-async-40da520a74fbb13b0ed1c5acb7ddf5c521fd8acc.tar.bz2 scala-async-40da520a74fbb13b0ed1c5acb7ddf5c521fd8acc.zip |
Add a test to interrogate the expanded tree.
- checks that only one function is synthesized
- checks the set of vars created (TODO minimize these)
- use x$1 rather than x1 for the freshened names for lifted vars.
- make execContext a val, not a var.
Diffstat (limited to 'src/test/scala/scala/async/TreeInterrogation.scala')
-rw-r--r-- | src/test/scala/scala/async/TreeInterrogation.scala | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/scala/scala/async/TreeInterrogation.scala b/src/test/scala/scala/async/TreeInterrogation.scala new file mode 100644 index 0000000..7c277b1 --- /dev/null +++ b/src/test/scala/scala/async/TreeInterrogation.scala @@ -0,0 +1,38 @@ +package scala.async + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import AsyncId._ + +@RunWith(classOf[JUnit4]) +class TreeInterrogation { + @Test + def `a minimal set of vals are lifted to vars`() { + val cm = reflect.runtime.currentMirror + val tb = mkToolbox() + val tree = mkToolbox().parse( + """| import _root_.scala.async.AsyncId._ + | async { + | val x = await(1) + | val y = x * 2 + | val z = await(x * 3) + | z + | }""".stripMargin) + val tree1 = tb.typeCheck(tree) + + // println(cm.universe.showRaw(tree1)) + + import tb.mirror.universe._ + val functions = tree1.collect { + case f: Function => f + } + functions.size mustBe 1 + + val varDefs = tree1.collect { + case ValDef(mods, name, _, _) if mods.hasFlag(Flag.MUTABLE) => name + } + // TODO no need to lift `y` as it is only accessed from a single state. + varDefs.map(_.decoded).toSet mustBe(Set("state$async", "onCompleteHandler$async", "x$1", "z$1", "y$1")) + } +} |