diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/scala/async/TreeInterrogation.scala | 20 | ||||
-rw-r--r-- | src/test/scala/scala/async/neg/NakedAwait.scala | 10 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/toughtype/ToughType.scala | 31 |
3 files changed, 50 insertions, 11 deletions
diff --git a/src/test/scala/scala/async/TreeInterrogation.scala b/src/test/scala/scala/async/TreeInterrogation.scala index b22faa9..93cfdf5 100644 --- a/src/test/scala/scala/async/TreeInterrogation.scala +++ b/src/test/scala/scala/async/TreeInterrogation.scala @@ -62,23 +62,21 @@ object TreeInterrogation extends App { val levels = Seq("trace", "debug") def setAll(value: Boolean) = levels.foreach(set(_, value)) - setAll(true) - try t finally setAll(false) + setAll(value = true) + try t finally setAll(value = false) } withDebug { val cm = reflect.runtime.currentMirror - val tb = mkToolbox("-cp target/scala-2.10/classes -Xprint:all") + val tb = mkToolbox("-cp target/scala-2.10/classes -Xprint:flatten") val tree = tb.parse( """ import scala.async.AsyncId.{async, await} - | def foo(a: Int, b: Int) = (a, b) - | val result = async { - | var i = 0 - | def next() = { - | i += 1; - | i - | } - | foo(next(), await(next())) + | async { + | await(1) + | val neg1 = -1 + | val a = await(1) + | val f = { case x => ({case x => neg1 * x}: PartialFunction[Int, Int])(x + a) }: PartialFunction[Int, Int] + | await(f(2)) | } | () | """.stripMargin) diff --git a/src/test/scala/scala/async/neg/NakedAwait.scala b/src/test/scala/scala/async/neg/NakedAwait.scala index ecc84f9..9974a07 100644 --- a/src/test/scala/scala/async/neg/NakedAwait.scala +++ b/src/test/scala/scala/async/neg/NakedAwait.scala @@ -93,6 +93,16 @@ class NakedAwait { } @Test + def nestedPatMatFunction() { + expectError("await must not be used under a nested class.") { // TODO more specific error message + """ + | import _root_.scala.async.AsyncId._ + | async { { case x => { await(false) } } : PartialFunction[Any, Any] } + """.stripMargin + } + } + + @Test def tryBody() { expectError("await must not be used under a try/catch.") { """ diff --git a/src/test/scala/scala/async/run/toughtype/ToughType.scala b/src/test/scala/scala/async/run/toughtype/ToughType.scala index 9cfc1ca..83f5a2d 100644 --- a/src/test/scala/scala/async/run/toughtype/ToughType.scala +++ b/src/test/scala/scala/async/run/toughtype/ToughType.scala @@ -36,4 +36,35 @@ class ToughTypeSpec { val res: (List[_], scala.async.run.toughtype.ToughTypeObject.Inner) = Await.result(fut, 2 seconds) res._1 mustBe (Nil) } + + @Test def patternMatchingPartialFunction() { + import AsyncId.{await, async} + async { + await(1) + val a = await(1) + val f = { case x => x + a }: PartialFunction[Int, Int] + await(f(2)) + } mustBe 3 + } + + @Test def patternMatchingPartialFunctionNested() { + import AsyncId.{await, async} + async { + await(1) + val neg1 = -1 + val a = await(1) + val f = { case x => ({case x => neg1 * x}: PartialFunction[Int, Int])(x + a) }: PartialFunction[Int, Int] + await(f(2)) + } mustBe -3 + } + + @Test def patternMatchingFunction() { + import AsyncId.{await, async} + async { + await(1) + val a = await(1) + val f = { case x => x + a }: Function[Int, Int] + await(f(2)) + } mustBe 3 + } } |