From 8af1dfade7e0fafcbe7adb4dbea14d734d9b8dea Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Sat, 1 Sep 2007 06:51:58 +0000 Subject: fixed ticket #2 (patch from tags/R_2_6_0-RC2), ... fixed ticket #2 (patch from tags/R_2_6_0-RC2), reorganized test cases --- test/files/run/patmatnew.scala | 143 ++++++++++++++++++++++++++++++++++------- 1 file changed, 119 insertions(+), 24 deletions(-) (limited to 'test/files/run/patmatnew.scala') diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala index fdb01c9aec..09b12f710c 100644 --- a/test/files/run/patmatnew.scala +++ b/test/files/run/patmatnew.scala @@ -33,11 +33,16 @@ object Test extends TestConsoleMain { TestEqualsPatternOpt, new TestStream, new Test903, - new Test1093, new Test1163_Order, new TestUnbox, + Bug457, + Bug508, + Bug789, + Bug995, + Bug1093, + Bug1094, ClassDefInGuard, - Bug457 + Ticket_2 ) class Foo(j:Int) { @@ -225,16 +230,6 @@ object Test extends TestConsoleMain { Some(p.father) } - class Test1093 extends TestCase("bug1093") { - override def runTest { - val x = Some(3) match { - case Some(1 | 2) => 1 - case Some(3) => 2 - } - assertEquals("ok", 2, x) - } - } - class Test903 extends TestCase("bug903") { override def runTest = { @@ -451,24 +446,18 @@ object Test extends TestConsoleMain { } } - + // bug#457 object Bug457 extends TestCase("Bug457") { - def method1() = { - val x = "Hello, world"; - val y = 100; - + val x = "Hello, world"; val y = 100; y match { case _: Int if (x match { case t => t.trim().length() > 0 }) => false; case _ => true; - } - } + }} def method2(): scala.Boolean = { - val x: String = "Hello, world"; - val y: scala.Int = 100; - { + val x: String = "Hello, world"; val y: scala.Int = 100; { var temp1: scala.Int = y; var result: scala.Boolean = false; if ( @@ -483,16 +472,122 @@ object Test extends TestConsoleMain { result else throw new MatchError("crazybox.scala, line 9") - } - } + }} override def runTest { method1(); method2(); } + } + + // bug#508 + + object Bug508 extends TestCase("aladdin #508") { + case class Operator(x: Int); + val EQ = new Operator(2); + + def analyze(x: Pair[Operator, Int]) = x match { + case Pair(EQ, 0) => "0" + case Pair(EQ, 1) => "1" + case Pair(EQ, 2) => "2" + } + override def runTest { + val x = Pair(EQ, 0); + assertEquals("0", analyze(x)); // should print "0" + val y = Pair(EQ, 1); + assertEquals("1", analyze(y)); // should print "1" + val z = Pair(EQ, 2); + assertEquals("2", analyze(z)); // should print "2" + } + } + + // bug#789 + + object Bug789 extends TestCase("aladdin #789") { // don't do this at home + + trait Impl + + trait SizeImpl extends Impl { def size = 42 } + + trait ColorImpl extends Impl { def color = "red" } + + type Both = SizeImpl with ColorImpl + + def info(x:Impl) = x match { + case x:Both => "size "+x.size+" color "+x.color // you wish + case x:SizeImpl => "!size "+x.size + case x:ColorImpl => "color "+x.color + case _ => "n.a." + } + def info2(x:Impl) = x match { + case x:SizeImpl with ColorImpl => "size "+x.size+" color "+x.color // you wish + case x:SizeImpl => "!size "+x.size + case x:ColorImpl => "color "+x.color + case _ => "n.a." + } + + override def runTest { + // make up some class that has a size + class MyNode extends SizeImpl + assertEquals("!size 42", info(new MyNode)) + assertEquals("!size 42", info2(new MyNode)) + } } + // bug#995 + + object Bug995 extends TestCase("aladdin #995") { + def foo(v: Any): String = v match { + case s: Seq[_] => "Seq" // see hack in object Seq.unapplySeq + //case a: AnyRef if runtime.ScalaRunTime.isArray(a) => "Array" + case _ => v.toString + } + override def runTest { assertEquals("Seq", foo(Array(0))) } + } + + // bug#1093 (contribution #460) + + object Bug1093 extends TestCase("aladdin #1093") { + override def runTest {assertTrue(Some(3) match { + case Some(1 | 2) => false + case Some(3) => true + })} + } + + // bug#1094 (contribution #461) + + object Bug1094 extends TestCase("aladdin #1094") { + def foo(ps: String*) = "Foo" + case class X(p: String, ps: String*) + def bar = + X("a", "b") match { + case X(p, ps @ _*) => foo(ps : _*) + } + override def runTest { assertEquals("Foo", bar) } + } + + // #2 + + class Outer_2 { + case class Foo(x: int, y: int) { + override def equals(other: Any) = other match { + case Outer_2.this.Foo(`x`, `y`) => true + case _ => false + } + } + } + + object Ticket_2 extends TestCase("#2") { override def runTest { + val o1 = new Outer_2; val o2 = new Outer_2; val x: Any = o1.Foo(1, 2); val y: Any = o2.Foo(1, 2) + assertFalse("equals test returns true (but should not)", x equals y) + assertTrue("match enters wrong case", x match { + case o2.Foo(x, y) => false; + case o1.Foo(x, y) => true + case _ => false + }) + }} } + -- cgit v1.2.3