summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/lift-and-unlift.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/files/run/lift-and-unlift.scala b/test/files/run/lift-and-unlift.scala
new file mode 100644
index 0000000000..859ec02f99
--- /dev/null
+++ b/test/files/run/lift-and-unlift.scala
@@ -0,0 +1,25 @@
+object Test {
+ def evens1(x: Int) = if (x % 2 == 0) Some(x) else None
+ def evens2: PartialFunction[Int, Int] = {
+ case x if x % 2 == 0 => x
+ }
+
+ def main(args: Array[String]): Unit = {
+ val f1 = evens1 _
+ val f2 = evens2.lift
+
+ assert(1 to 10 forall (x => f1(x) == f2(x)))
+
+ val f3 = f1.unlift
+ val f4 = f2.unlift
+
+ assert(1 to 10 forall { x =>
+ if (!f3.isDefinedAt(x)) !f4.isDefinedAt(x)
+ else f3(x) == f4(x)
+ })
+
+ assert(f1 eq f3.lift)
+ // Hmm, why is this not true:
+ // assert(f2 eq f4.lift)
+ }
+}