diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/jvm/unittest_io.scala | 22 | ||||
-rw-r--r-- | test/files/jvm/unittest_xml.scala | 2 | ||||
-rw-r--r-- | test/files/jvm/xml01.scala | 2 | ||||
-rw-r--r-- | test/files/neg/patmatexhaust.check | 32 | ||||
-rw-r--r-- | test/files/neg/patmatexhaust.scala | 8 | ||||
-rw-r--r-- | test/files/pos/patterns.scala | 9 | ||||
-rw-r--r-- | test/files/run/bug789.scala | 1 | ||||
-rw-r--r-- | test/files/run/patmatnew.scala | 30 | ||||
-rw-r--r-- | test/files/run/unapply.scala | 28 |
9 files changed, 81 insertions, 53 deletions
diff --git a/test/files/jvm/unittest_io.scala b/test/files/jvm/unittest_io.scala index 59b82ff57e..f4f2e08c7c 100644 --- a/test/files/jvm/unittest_io.scala +++ b/test/files/jvm/unittest_io.scala @@ -1,7 +1,11 @@ -object Test { +import scala.testing.SUnit._ +import scala.io.Source - import scala.testing.SUnit._ - import scala.io.Source +object Test extends TestConsoleMain { + + def suite = new TestSuite( + new ReadlinesTest + ) class ReadlinesTest extends TestCase("scala.io.Source method getLines") { @@ -11,20 +15,10 @@ it is split on several lines. isn't it? """) - assertEquals("wrong number of lines",src.getLines.toList.length,5) // five new lines in there + def runTest() = assertEquals("wrong number of lines",src.getLines.toList.length,5) // five new lines in there //for(val line <- src.getLines) { // Console.print(line) //} } - def main(args:Array[String]) = { - val ts = new TestSuite( - new ReadlinesTest - ) - val tr = new TestResult() - ts.run(tr) - for(val failure <- tr.failures) { - Console.println(failure) - } - } } diff --git a/test/files/jvm/unittest_xml.scala b/test/files/jvm/unittest_xml.scala index 312b69d529..6fdacbbf75 100644 --- a/test/files/jvm/unittest_xml.scala +++ b/test/files/jvm/unittest_xml.scala @@ -64,6 +64,7 @@ object Test { } class UtilityTest extends TestCase("scala.xml.Utility") with Assert { + def runTest() = { val x = <foo> <toomuchws/> </foo> @@ -92,6 +93,7 @@ object Test { assertEquals("pretty print sorted attrib:"+pp.format(q), "<a a=\"2\" g=\"3\" j=\"2\" oo=\"2\"></a>", pp.format(q)) } + } def main(args:Array[String]) = { val ts = new TestSuite( diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala index 8c99cfd358..7de6211e29 100644 --- a/test/files/jvm/xml01.scala +++ b/test/files/jvm/xml01.scala @@ -209,6 +209,8 @@ object Test { //Console.println("char '"+c+"' \u015e"); assertTrue(c == '\u015e'); } + // buraq: if the following test fails with 'character x not allowed', it is + // related to the mutable variable in a closures in MarkupParser.parsecharref { val isr = scala.io.Source.fromString(xmlAttrValueNorm); val pxmlB = scala.xml.parsing.ConstructingParser.fromSource(isr,false); diff --git a/test/files/neg/patmatexhaust.check b/test/files/neg/patmatexhaust.check index 19e79b2928..719f98b8d3 100644 --- a/test/files/neg/patmatexhaust.check +++ b/test/files/neg/patmatexhaust.check @@ -1,23 +1,27 @@ -patmatexhaust.scala:8: warning: does not cover case {object Baz} +patmatexhaust.scala:7: warning: match is not exhaustive! +missing combination Baz + def ma1(x:Foo) = x match { ^ -patmatexhaust.scala:12: warning: does not cover case {class Bar} +patmatexhaust.scala:11: warning: match is not exhaustive! +missing combination Bar + def ma2(x:Foo) = x match { ^ -patmatexhaust.scala:24: warning: does not cover case {class Kult} - case (Kult(_), Qult()) => // Kult missing - ^ -patmatexhaust.scala:26: warning: does not cover case {class Qult} - case (Qult(), Kult(_)) => // Qult missing - ^ -patmatexhaust.scala:44: warning: does not cover cases {object Gu,class Gp} +patmatexhaust.scala:23: warning: match is not exhaustive! +missing combination Kult Kult +missing combination Qult Qult + + def ma3(x:Mult) = (x,x) match { // not exhaustive + ^ +patmatexhaust.scala:49: warning: match is not exhaustive! +missing combination Gu +missing combination Gp + def ma4(x:Deep) = x match { // missing cases: Gu, Gp ^ -patmatexhaust.scala:51: warning: does not cover case {class Gp} - case Ga => - ^ -patmatexhaust.scala:65: error: unreachable code +patmatexhaust.scala:70: error: unreachable code case 1 => ^ -6 warnings found +four warnings found one error found diff --git a/test/files/neg/patmatexhaust.scala b/test/files/neg/patmatexhaust.scala index 204bf2f170..b2d0b8ddd2 100644 --- a/test/files/neg/patmatexhaust.scala +++ b/test/files/neg/patmatexhaust.scala @@ -1,5 +1,4 @@ class TestSealedExhaustive { // compile only - sealed class Foo case class Bar(x:Int) extends Foo @@ -20,6 +19,7 @@ class TestSealedExhaustive { // compile only def ma33(x:Kult) = x match { // exhaustive case Kult(_) => // exhaustive } + def ma3(x:Mult) = (x,x) match { // not exhaustive case (Kult(_), Qult()) => // Kult missing //case Pair(Kult(_), Kult(_)) => @@ -27,6 +27,11 @@ class TestSealedExhaustive { // compile only //case Pair(Qult(), Qult()) => } + def ma3u(x:Mult) = ((x,x) : @unchecked) match { // not exhaustive, but not checked! + case (Kult(_), Qult()) => + case (Qult(), Kult(_)) => + } + sealed class Deep case object Ga extends Deep @@ -64,4 +69,5 @@ class TestSealedExhaustive { // compile only case 1 => case 1 => } + } diff --git a/test/files/pos/patterns.scala b/test/files/pos/patterns.scala index 85d8a1b7da..547d692d87 100644 --- a/test/files/pos/patterns.scala +++ b/test/files/pos/patterns.scala @@ -27,3 +27,12 @@ object test { case None => println("nothing") } } + +// if bodies are duplicated, then we would get an error like "double definition" + +trait John[A,B] { + def filter(x:Any) = x match { + case (x::xs, _) => "ga" + case _ => {x:String => "foobar"} + } +} 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) } |