~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to test/files/run/unapply.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import scala.testing.SUnit._
2
 
 
3
 
object Test extends TestConsoleMain {
4
 
  def suite = new TestSuite(
5
 
    Foo,
6
 
    Mas,
7
 
    LisSeqArr,
8
 
    StreamFoo
9
 
  )
 
1
object Test {
 
2
  def main(args: Array[String]) {
 
3
    Foo.run()
 
4
    Mas.run()
 
5
    LisSeqArr.run()
 
6
    StreamFoo.run()
 
7
    Test1256.run()
 
8
  }
10
9
}
11
10
 
12
11
// this class is used for representation
31
30
object VarFoo {
32
31
  def unapply(a : Int)(implicit b : Int) : Option[Int] = Some(a + b)
33
32
}
34
 
object Foo extends TestCase("Foo") with Assert {
 
33
 
 
34
object Foo {
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)
37
37
    case _ => None
38
38
  }
39
39
  def doMatch1(b:Bar) = b match {
51
51
  def doMatch5(b:Bar) = (b:Any) match {
52
52
    case FaaPreciseSome(n:String) => n
53
53
  }
54
 
  override def runTest {
 
54
  def run() {
55
55
    val b = new Bar
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
64
 
    }, 7)
 
64
    }))
65
65
  }
66
66
}
67
67
 
68
68
// same, but now object is not top-level
69
 
object Mas extends TestCase("Mas") with Assert {
 
69
object Mas {
70
70
  object Gaz {
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)
73
73
      case _ => None
74
74
    }
75
75
  }
77
77
    var size: Int    = 60
78
78
    var name: String = "too large"
79
79
  }
80
 
  def runTest {
 
80
  def run() {
81
81
    val b = new Baz
82
 
    assertEquals(b match {
 
82
    assert((60,"too large") == (b match {
83
83
      case Gaz(s:Int, n:String) => (s,n)
84
 
    }, (60,"too large"))
85
 
  }
86
 
}
87
 
 
88
 
object LisSeqArr extends TestCase("LisSeqArr") with Assert {
89
 
//  def foo[A](x:List[A]) {}
90
 
  def runTest {
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})
95
 
 
96
 
    // just compile, feature request #1196
97
 
//    (List(1,2,3): Any) match { 
98
 
//      case a @ List(x,y,_*) => foo(a)
99
 
//    }
100
 
 
101
 
  }
102
 
}
103
 
 
104
 
 
105
 
object StreamFoo extends TestCase("unapply for Streams") with Assert {
106
 
  //val x:Stream[Int] = Stream.cons(1,x)
107
 
 
 
84
    }))
 
85
  }
 
86
}
 
87
 
 
88
object LisSeqArr {
 
89
  def run() {
 
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)}))
 
92
  }
 
93
}
 
94
 
 
95
object StreamFoo {
108
96
  def sum(stream: Stream[Int]): Int =
109
97
    stream match {
110
98
      case Stream.Empty => 0
111
99
      case Stream.cons(hd, tl) => hd + sum(tl)
112
100
    }
113
 
  override def runTest {
 
101
  def run() {
114
102
    val str: Stream[Int] = List(1,2,3).toStream
115
 
    assertEquals(sum(str), 6)
 
103
    assert(6 == sum(str))
116
104
  }
117
105
}
118
106
 
119
 
object Test1256 extends TestCase("1256") {
 
107
object Test1256 {
120
108
  class Sync {
121
109
    def unapply(scrut: Any): Boolean = false
122
110
  }
123
111
  
124
112
  class Buffer {
125
113
    val Get = new Sync
126
 
    
127
114
    val jp: PartialFunction[Any, Any] = {
128
115
      case Get() =>
129
116
    }
130
117
  }
131
118
  
132
 
  override def runTest { assertFalse((new Buffer).jp.isDefinedAt(42)) }
 
119
  def run() {
 
120
    assert(!(new Buffer).jp.isDefinedAt(42))
 
121
  }
133
122
}