diff options
author | Philipp Haller <hallerp@gmail.com> | 2012-11-27 03:07:11 -0800 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2012-11-27 03:07:11 -0800 |
commit | 653a46dc7244aa06f3282150ca4e9694e14a2948 (patch) | |
tree | a4f4a2b8a6848577bae9f82805ffb61fe9b25e00 /src/test/scala/scala | |
parent | 456fd6e561a52f34040d9af041cc2b74880e5579 (diff) | |
parent | 7c93a9e0e288b55027646016913c7368732d54e4 (diff) | |
download | scala-async-653a46dc7244aa06f3282150ca4e9694e14a2948.tar.gz scala-async-653a46dc7244aa06f3282150ca4e9694e14a2948.tar.bz2 scala-async-653a46dc7244aa06f3282150ca4e9694e14a2948.zip |
Merge pull request #45 from phaller/ticket/33-by-name-2
Ticket/33 by name 2
Diffstat (limited to 'src/test/scala/scala')
-rw-r--r-- | src/test/scala/scala/async/TreeInterrogation.scala | 20 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/anf/AnfTransformSpec.scala | 86 |
2 files changed, 94 insertions, 12 deletions
diff --git a/src/test/scala/scala/async/TreeInterrogation.scala b/src/test/scala/scala/async/TreeInterrogation.scala index ecb1bca..b22faa9 100644 --- a/src/test/scala/scala/async/TreeInterrogation.scala +++ b/src/test/scala/scala/async/TreeInterrogation.scala @@ -70,17 +70,15 @@ object TreeInterrogation extends App { val cm = reflect.runtime.currentMirror val tb = mkToolbox("-cp target/scala-2.10/classes -Xprint:all") val tree = tb.parse( - """ - | import scala.async.Async.{async, await} - | import scala.concurrent.{future, ExecutionContext, Await} - | import ExecutionContext.Implicits._ - | import scala.concurrent.duration._ - | - | try { - | val f = async { throw new Exception("problem") } - | Await.result(f, 1.second) - | } catch { - | case ex: Exception if ex.getMessage == "problem" => // okay + """ 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())) | } | () | """.stripMargin) diff --git a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala index 6dd4db7..529386b 100644 --- a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala +++ b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala @@ -163,7 +163,7 @@ class AnfTransformSpec { val result = AsyncId.async { val x = "" match { case "" if false => AsyncId.await(1) + 1 - case _ => 2 + AsyncId.await(1) + case _ => 2 + AsyncId.await(1) } val y = x "" match { @@ -205,4 +205,88 @@ class AnfTransformSpec { } result mustBe (true) } + + @Test + def byNameExpressionsArentLifted() { + import _root_.scala.async.AsyncId.{async, await} + def foo(ignored: => Any, b: Int) = b + val result = async { + foo(???, await(1)) + } + result mustBe (1) + } + + @Test + def evaluationOrderRespected() { + 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())) + } + result mustBe ((1, 2)) + } + + @Test + def awaitNotAllowedInNonPrimaryParamSection1() { + expectError("implementation restriction: await may only be used in the first parameter list.") { + """ + | import _root_.scala.async.AsyncId.{async, await} + | def foo(primary: Any)(i: Int) = i + | async { + | foo(???)(await(0)) + | } + """.stripMargin + } + } + + @Test + def awaitNotAllowedInNonPrimaryParamSection2() { + expectError("implementation restriction: await may only be used in the first parameter list.") { + """ + | import _root_.scala.async.AsyncId.{async, await} + | def foo[T](primary: Any)(i: Int) = i + | async { + | foo[Int](???)(await(0)) + | } + """.stripMargin + } + } + + @Test + def namedArgumentsRespectEvaluationOrder() { + 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(b = next(), a = await(next())) + } + result mustBe ((2, 1)) + } + + @Test + def namedAndDefaultArgumentsRespectEvaluationOrder() { + import scala.async.AsyncId.{async, await} + var i = 0 + def next() = { + i += 1; + i + } + def foo(a: Int = next(), b: Int = next()) = (a, b) + async { + foo(b = await(next())) + } mustBe ((2, 1)) + i = 0 + async { + foo(a = await(next())) + } mustBe ((1, 2)) + } } |