diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/scala/async/TreeInterrogation.scala | 37 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/ifelse0/WhileSpec.scala | 40 |
2 files changed, 46 insertions, 31 deletions
diff --git a/src/test/scala/scala/async/TreeInterrogation.scala b/src/test/scala/scala/async/TreeInterrogation.scala index c8fe2d6..b42726b 100644 --- a/src/test/scala/scala/async/TreeInterrogation.scala +++ b/src/test/scala/scala/async/TreeInterrogation.scala @@ -66,43 +66,18 @@ object TreeInterrogation extends App { withDebug { val cm = reflect.runtime.currentMirror val tb = mkToolbox("-cp ${toolboxClasspath} -Xprint:typer -uniqid") - import scala.async.internal.AsyncTestLV._ + import scala.async.internal.AsyncId._ val tree = tb.parse( """ - | import scala.async.internal.AsyncTestLV._ - | import scala.async.internal.AsyncTestLV - | - | case class MCell[T](var v: T) - | val f = async { MCell(1) } - | - | def m1(x: MCell[Int], y: Int): Int = - | async { x.v + y } - | case class Cell[T](v: T) - | + | import scala.async.internal.AsyncId._ | async { - | // state #1 - | val a: MCell[Int] = await(f) // await$13$1 - | // state #2 - | var y = MCell(0) - | - | while (a.v < 10) { - | // state #4 - | a.v = a.v + 1 - | y = MCell(await(a).v + 1) // await$14$1 - | // state #7 + | var b = true + | while(await(b)) { + | b = false | } - | - | // state #3 - | assert(AsyncTestLV.log.exists(entry => entry._1 == "await$14$1")) - | - | val b = await(m1(a, y.v)) // await$15$1 - | // state #8 - | assert(AsyncTestLV.log.exists(_ == ("a$1" -> MCell(10)))) - | assert(AsyncTestLV.log.exists(_ == ("y$1" -> MCell(11)))) - | b + | await(b) | } | - | | """.stripMargin) println(tree) val tree1 = tb.typeCheck(tree.duplicate) diff --git a/src/test/scala/scala/async/run/ifelse0/WhileSpec.scala b/src/test/scala/scala/async/run/ifelse0/WhileSpec.scala index 4b3c2aa..76e6b1e 100644 --- a/src/test/scala/scala/async/run/ifelse0/WhileSpec.scala +++ b/src/test/scala/scala/async/run/ifelse0/WhileSpec.scala @@ -76,4 +76,44 @@ class WhileSpec { } result mustBe () } + + @Test def doWhile() { + import AsyncId._ + val result = async { + var b = 0 + var x = "" + await(do { + x += "1" + x += await("2") + x += "3" + b += await(1) + } while (b < 2)) + await(x) + } + result mustBe "123123" + } + + @Test def whileAwaitCondition() { + import AsyncId._ + val result = async { + var b = true + while(await(b)) { + b = false + } + await(b) + } + result mustBe false + } + + @Test def doWhileAwaitCondition() { + import AsyncId._ + val result = async { + var b = true + do { + b = false + } while(await(b)) + b + } + result mustBe false + } } |