blob: ab0b60d07238065082eef7c6fc496dfc7aa586d4 (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*
* Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com>
*/
package scala.async
package run
package toughtype
import language.{reflectiveCalls, postfixOps}
import scala.concurrent._
import scala.concurrent.duration._
import scala.async.Async._
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
object ToughTypeObject {
import ExecutionContext.Implicits.global
class Inner
def m2 = async[(List[_], ToughTypeObject.Inner)] {
val y = await(future[List[_]](Nil))
val z = await(future[Inner](new Inner))
(y, z)
}
}
@RunWith(classOf[JUnit4])
class ToughTypeSpec {
@Test def `propogates tough types`() {
val fut = ToughTypeObject.m2
val res: (List[_], scala.async.run.toughtype.ToughTypeObject.Inner) = Await.result(fut, 2 seconds)
res._1 mustBe (Nil)
}
// TODO 2.10.1
// @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
// }
// TODO 2.10.1
// @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
}
}
|