32
31
def unapply(a : Int)(implicit b : Int) : Option[Int] = Some(a + b)
34
object Foo extends TestCase("Foo") with Assert {
35
35
def unapply(x: Any): Option[Product2[Int, String]] = x match {
36
case y: Bar => Some(Tuple(y.size, y.name))
36
case y: Bar => Some(y.size, y.name)
39
39
def doMatch1(b:Bar) = b match {
51
51
def doMatch5(b:Bar) = (b:Any) match {
52
52
case FaaPreciseSome(n:String) => n
54
override def runTest {
56
assertEquals(doMatch1(b),(50,"medium"))
57
assertEquals(doMatch2(b),null)
58
assertEquals(doMatch3(b),"medium")
59
assertEquals(doMatch4(b),"medium")
60
assertEquals(doMatch5(b),"medium")
56
assert(doMatch1(b) == (50,"medium"))
57
assert(doMatch2(b) == null)
58
assert(doMatch3(b) == "medium")
59
assert(doMatch4(b) == "medium")
60
assert(doMatch5(b) == "medium")
61
61
implicit val bc: Int = 3
62
assertEquals(4 match {
62
assert(7 == (4 match {
63
63
case VarFoo(x) => x
68
68
// same, but now object is not top-level
69
object Mas extends TestCase("Mas") with Assert {
71
71
def unapply(x: Any): Option[Product2[Int, String]] = x match {
72
case y: Baz => Some(Tuple(y.size, y.name))
72
case y: Baz => Some(y.size, y.name)
78
78
var name: String = "too large"
82
assertEquals(b match {
82
assert((60,"too large") == (b match {
83
83
case Gaz(s:Int, n:String) => (s,n)
88
object LisSeqArr extends TestCase("LisSeqArr") with Assert {
89
// def foo[A](x:List[A]) {}
91
assertEquals((List(1,2,3): Any) match { case List(x,y,_*) => (x,y)}, (1,2))
92
assertEquals((List(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}, (1,2))
93
//assertEquals((Array(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}, (1,2))
94
//assertEquals((Array(1,2,3): Any) match { case Array(x,y,_*) => {x,y}}, {1,2})
96
// just compile, feature request #1196
97
// (List(1,2,3): Any) match {
98
// case a @ List(x,y,_*) => foo(a)
105
object StreamFoo extends TestCase("unapply for Streams") with Assert {
106
//val x:Stream[Int] = Stream.cons(1,x)
90
assert((1,2) == ((List(1,2,3): Any) match { case List(x,y,_*) => (x,y)}))
91
assert((1,2) == ((List(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}))
108
96
def sum(stream: Stream[Int]): Int =
110
98
case Stream.Empty => 0
111
99
case Stream.cons(hd, tl) => hd + sum(tl)
113
override def runTest {
114
102
val str: Stream[Int] = List(1,2,3).toStream
115
assertEquals(sum(str), 6)
103
assert(6 == sum(str))
119
object Test1256 extends TestCase("1256") {
121
109
def unapply(scrut: Any): Boolean = false
125
113
val Get = new Sync
127
114
val jp: PartialFunction[Any, Any] = {
132
override def runTest { assertFalse((new Buffer).jp.isDefinedAt(42)) }
120
assert(!(new Buffer).jp.isDefinedAt(42))