diff options
author | Paul Phillips <paulp@improving.org> | 2013-08-17 09:58:54 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-08-17 10:58:14 -0700 |
commit | 1cd7a9e840158dab17a3aafc0ce849605706a561 (patch) | |
tree | 3777a5c8bdfe0edcdcd45aa453d28704242a8702 /test/files/run/patmat-behavior-2.scala | |
parent | 8f05647ca53da781b420be0723faf1cdbf14b2ff (diff) | |
download | scala-1cd7a9e840158dab17a3aafc0ce849605706a561.tar.gz scala-1cd7a9e840158dab17a3aafc0ce849605706a561.tar.bz2 scala-1cd7a9e840158dab17a3aafc0ce849605706a561.zip |
New tests for name-based pattern matcher.
Diffstat (limited to 'test/files/run/patmat-behavior-2.scala')
-rw-r--r-- | test/files/run/patmat-behavior-2.scala | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/files/run/patmat-behavior-2.scala b/test/files/run/patmat-behavior-2.scala new file mode 100644 index 0000000000..b31f773772 --- /dev/null +++ b/test/files/run/patmat-behavior-2.scala @@ -0,0 +1,50 @@ +case class Foo(x: Int, ys: Int*) { + // We write our own toString because of SI-7735 + override def toString = (x +: ys).mkString("Foo(", ", ", ")") +} + +object Test { + def f1(x: Any) = x match { + case Foo(x) => true + case _ => false + } + def f2(x: Any) = x match { + case Foo(x, y) => true + case _ => false + } + def f3(x: Any) = x match { + case Foo(x, y, z) => true + case _ => false + } + def f1seq(x: Any) = x match { + case Foo(x, ys @ _*) => true + case _ => false + } + def f2seq(x: Any) = x match { + case Foo(x, y, zs @ _*) => true + case _ => false + } + def f3seq(x: Any) = x match { + case Foo(x, y, z, qs @ _*) => true + case _ => false + } + + val x1 = Foo(1) + val x2 = Foo(1, 2) + val x3 = Foo(1, 2, 3) + + val fs = List[Any => Boolean](f1, f2, f3) + val fseqs = List[Any => Boolean](f1seq, f2seq, f3seq) + val xs = List[Foo](x1, x2, x3) + + def main(args: Array[String]): Unit = { + for ((f, i) <- fs.zipWithIndex) { + xs foreach (x => println(s"f${i+1}($x) == ${f(x)}")) + println("") + } + for ((f, i) <- fseqs.zipWithIndex) { + xs foreach (x => println(s"f${i+1}seq($x) == ${f(x)}")) + println("") + } + } +} |