aboutsummaryrefslogtreecommitdiff
path: root/tests/run/lift-and-unlift.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2015-09-14 17:07:23 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-09-14 17:07:23 +0200
commit12053fa4d55497fc4df06afd67ba3762019969c3 (patch)
tree0cbab1dee0784793d2ab09124a0103412e813072 /tests/run/lift-and-unlift.scala
parent91f992c8af3e61a76bd862ad43b9abef9a6c3403 (diff)
downloaddotty-12053fa4d55497fc4df06afd67ba3762019969c3.tar.gz
dotty-12053fa4d55497fc4df06afd67ba3762019969c3.tar.bz2
dotty-12053fa4d55497fc4df06afd67ba3762019969c3.zip
Enable more tests that pass
Diffstat (limited to 'tests/run/lift-and-unlift.scala')
-rw-r--r--tests/run/lift-and-unlift.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/run/lift-and-unlift.scala b/tests/run/lift-and-unlift.scala
new file mode 100644
index 000000000..9cd85666e
--- /dev/null
+++ b/tests/run/lift-and-unlift.scala
@@ -0,0 +1,27 @@
+import Function.unlift
+
+object Test {
+ def evens1(x: Int) = if (x % 2 == 0) Some(x) else None
+ val 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 = unlift(f1)
+ val f4 = unlift(f2)
+
+ assert(1 to 10 forall { x =>
+ if (!f3.isDefinedAt(x)) !f4.isDefinedAt(x)
+ else f3(x) == f4(x)
+ })
+
+ assert(f1 eq f3.lift)
+ assert(f4 eq unlift(f2))
+ assert(f4 eq evens2)
+ }
+}