aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala
blob: 2cecffa4a13b276108064151a406a955c42e48b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Copyright (C) 2012-2013 Typesafe Inc. <http://www.typesafe.com>
 */

package scala.async
package run
package live

import org.junit.Test

import internal.AsyncTestLV
import AsyncTestLV._

class LiveVariablesSpec {

  @Test
  def liveVars1() {
    val f = async { 1 }

    def m1(x: Int): Int =
      async { x + 1 }

    def m2(x: Int): String =
      async { x.toString }

    def m3() = async {
      val a = await(f)          // await$1$1
      // a == 1
      val b = await(m1(a))      // await$2$1
      // b == 2
      assert(AsyncTestLV.log.exists(_ == ("await$1$1" -> 0)))
      val res = await(m2(b))    // await$3$1
      assert(AsyncTestLV.log.exists(_ == ("await$2$1" -> 0)))
      res
    }

    assert(m3() == "2")
  }

}