From c61121a813abaace6e739a6f02e4c85b186f95a1 Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Thu, 22 Mar 2007 03:28:30 +0000 Subject: new pattern matching algo removed "removeoption" changed SUnit and some tests added useful debug msg in typer --- test/files/run/bug789.scala | 1 - test/files/run/patmatnew.scala | 30 +++++++++++++++++++++--------- test/files/run/unapply.scala | 28 ++++++++++++++-------------- 3 files changed, 35 insertions(+), 24 deletions(-) (limited to 'test/files/run') diff --git a/test/files/run/bug789.scala b/test/files/run/bug789.scala index 5a3c8d61e8..8cd4102dcf 100644 --- a/test/files/run/bug789.scala +++ b/test/files/run/bug789.scala @@ -22,7 +22,6 @@ object Test { // don't do this at home case _ => "n.a." } - def main(args:Array[String]): Unit = { // make up some class that has a size class MyNode extends SizeImpl diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala index daa1f9898a..46e980dff0 100644 --- a/test/files/run/patmatnew.scala +++ b/test/files/run/patmatnew.scala @@ -13,20 +13,16 @@ trait Shmeez extends AnyRef with Treez { } } -object Test { - import scala.testing.SUnit._ +import scala.testing.SUnit._ - def main(args:Array[String]): Unit = { - val tr = new TestResult - new TestSuite( +object Test extends TestConsoleMain { + + def suite = new TestSuite( new TestSimpleIntSwitch, new Test717, new TestGuards - ).run(tr) + ) - for(val f <- tr.failures()) - Console println f - } class Foo(j:Int) { case class Bar(i:Int) @@ -130,5 +126,21 @@ object Test { case List(1,2,xs @ _*) => case Nil => } + + def j = (List[Int](), List[Int](1)) match { + case (Nil, _) => 'a' + case (_, Nil) => 'b' + case (h1 :: t1, h2 :: t2) => 'c' + } + + def k (x:AnyRef) = x match { + case null => 1 + case _ => 2 + } + + val FooBar = 42 + def lala() = 42 match { + case FooBar => true + } } diff --git a/test/files/run/unapply.scala b/test/files/run/unapply.scala index fb154cf192..d351468bec 100644 --- a/test/files/run/unapply.scala +++ b/test/files/run/unapply.scala @@ -1,12 +1,12 @@ import scala.testing.SUnit._ -object Test { - def main(args:Array[String]) = { - Foo.run - Mas.run - LisSeqArr.run - StreamFoo.run - } +object Test extends TestConsoleMain { + def suite = new TestSuite( + Foo, + Mas, + LisSeqArr, + StreamFoo + ) } // this class is used for representation @@ -28,7 +28,7 @@ object FaaPrecise { object FaaPreciseSome { def unapply(x: Bar) = Some(x.name) // return type Some[String] } -object Foo extends Assert { +object Foo extends TestCase("Foo") with Assert { def unapply(x: Any): Option[Product2[Int, String]] = x match { case y: Bar => Some(Tuple(y.size, y.name)) case _ => None @@ -48,7 +48,7 @@ object Foo extends Assert { def doMatch5(b:Bar) = (b:Any) match { case FaaPreciseSome(n:String) => n } - def run { + override def runTest { val b = new Bar assertEquals(doMatch1(b),(50,"medium")) assertEquals(doMatch2(b),null) @@ -59,7 +59,7 @@ object Foo extends Assert { } // same, but now object is not top-level -object Mas extends Assert { +object Mas extends TestCase("Mas") with Assert { object Gaz { def unapply(x: Any): Option[Product2[Int, String]] = x match { case y: Baz => Some(Tuple(y.size, y.name)) @@ -70,7 +70,7 @@ object Mas extends Assert { var size: Int = 60 var name: String = "too large" } - def run { + def runTest { val b = new Baz assertEquals(b match { case Gaz(s:Int, n:String) => (s,n) @@ -78,8 +78,8 @@ object Mas extends Assert { } } -object LisSeqArr extends Assert { - def run { +object LisSeqArr extends TestCase("LisSeqArr") with Assert { + def runTest { assertEquals((List(1,2,3): Any) match { case List(x,y,_*) => (x,y)}, (1,2)) assertEquals((List(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}, (1,2)) assertEquals((Array(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}, (1,2)) @@ -96,7 +96,7 @@ object StreamFoo extends TestCase("unapply for Streams") with Assert { case Stream.empty => 0 case Stream.cons(hd, tl) => hd + sum(tl) } - override def run { + override def runTest { val str: Stream[int] = Stream.fromIterator(List(1,2,3).elements) assertEquals(sum(str), 6) } -- cgit v1.2.3