aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala')
-rw-r--r--src/test/scala/scala/async/TestUtils.scala9
-rw-r--r--src/test/scala/scala/async/TreeInterrogation.scala38
2 files changed, 44 insertions, 3 deletions
diff --git a/src/test/scala/scala/async/TestUtils.scala b/src/test/scala/scala/async/TestUtils.scala
index 0920659..bac22a3 100644
--- a/src/test/scala/scala/async/TestUtils.scala
+++ b/src/test/scala/scala/async/TestUtils.scala
@@ -40,11 +40,14 @@ trait TestUtils {
}
def eval(code: String, compileOptions: String = ""): Any = {
+ val tb = mkToolbox(compileOptions)
+ tb.eval(tb.parse(code))
+ }
+
+ def mkToolbox(compileOptions: String = "") = {
val m = scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
- val tb = m.mkToolBox(options = compileOptions)
- val result = tb.eval(tb.parse(code))
- result
+ m.mkToolBox(options = compileOptions)
}
def expectError(errorSnippet: String, compileOptions: String = "")(code: String) {
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"))
+ }
+}