diff options
author | Burak Emir <emir@epfl.ch> | 2007-06-20 10:10:53 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2007-06-20 10:10:53 +0000 |
commit | ff5d9c9afa938429d94330b5325a492205cead5d (patch) | |
tree | 7ff50883f952682c0b0625f171e1339ddc2087b0 /test/files/run | |
parent | d1b12f2a86b2a4b26ba9619fcc62ede00896d647 (diff) | |
download | scala-ff5d9c9afa938429d94330b5325a492205cead5d.tar.gz scala-ff5d9c9afa938429d94330b5325a492205cead5d.tar.bz2 scala-ff5d9c9afa938429d94330b5325a492205cead5d.zip |
test cases for pattern matching
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/patmatnew.scala | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala index 0e7359a2b8..0437598c40 100644 --- a/test/files/run/patmatnew.scala +++ b/test/files/run/patmatnew.scala @@ -23,6 +23,7 @@ object Test extends TestConsoleMain { new TestGuards, new TestStream, new Test903, + new Test1093, new Test1163_Order ) @@ -41,7 +42,20 @@ object Test extends TestConsoleMain { case 1 => 1 case _ => 0 }) - } + assertEquals("s2boxed", 1, (1:Any) match { + case 1 => 1 + case _ => 0 + }) + assertEquals("s3", 1, ("hello") match { + case s:String => 1 + case _ => 0 + }) + val xyz: (int, String, boolean) = (1, "abc", true); + assertEquals("s4", 1, xyz._1 match { + case 1 => 1 + case _ => 0 + }) + } } class Test717 extends TestCase("#717 test path of case classes") { val foo1 = new Foo(1) @@ -97,11 +111,10 @@ object Test extends TestConsoleMain { } } - // also: this one from fannkuch - //def flips(l: List[int]): int = (l: @unchecked) match { - // case 1 :: ls => 0 - // case n :: ls => flips((l take n reverse) ::: (l drop n)) + 1 - //} + def flips(l: List[int]): int = (l: @unchecked) match { + case 1 :: ls => 0 + case n :: ls => flips((l take n reverse) ::: (l drop n)) + 1 + } def runTest() = assertEquals("both", (Var("x"),Var("y")), f) } @@ -142,6 +155,16 @@ 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 = { |