summaryrefslogtreecommitdiff
path: root/test/files/jvm/try-type-tests.scala
diff options
context:
space:
mode:
authorHeather Miller <heather.miller@epfl.ch>2012-08-04 21:55:35 +0200
committerHeather Miller <heather.miller@epfl.ch>2012-08-04 21:55:35 +0200
commit3cb0e784a05db7d0b542cec9bf4c5fbf3772a6cf (patch)
tree36c1a6040e0f0aa6e64c0eef6fb55bea61bf4141 /test/files/jvm/try-type-tests.scala
parentab63cca87f68d80aff0ff6cd83ecd85b9e1d0c7a (diff)
downloadscala-3cb0e784a05db7d0b542cec9bf4c5fbf3772a6cf.tar.gz
scala-3cb0e784a05db7d0b542cec9bf4c5fbf3772a6cf.tar.bz2
scala-3cb0e784a05db7d0b542cec9bf4c5fbf3772a6cf.zip
Basing Futures on Try instead of Either
Diffstat (limited to 'test/files/jvm/try-type-tests.scala')
-rw-r--r--test/files/jvm/try-type-tests.scala128
1 files changed, 3 insertions, 125 deletions
diff --git a/test/files/jvm/try-type-tests.scala b/test/files/jvm/try-type-tests.scala
index eecbb0ae57..9dece8d6d8 100644
--- a/test/files/jvm/try-type-tests.scala
+++ b/test/files/jvm/try-type-tests.scala
@@ -59,12 +59,12 @@ trait TryStandard {
def testRescueSuccess(): Unit = {
val t = Success(1)
- t.rescue{ case x => assert(false); Try() }
+ t.recoverWith{ case x => assert(false); Try() }
}
def testRescueFailure(): Unit = {
val t = Failure(new Exception("foo"))
- val n = t.rescue{ case x => Try(1) }
+ val n = t.recoverWith{ case x => Try(1) }
assert(n.get == 1)
}
@@ -121,130 +121,8 @@ trait TryStandard {
testFailedFailure()
}
-// tests that implicit conversions from Try to Either behave as expected
-trait TryImplicitConversionTry2Either {
-
- def testTry2RightMap(): Unit = {
- val t = Success(1)
- val n = t.right.map(x => x * 100)
- assert(n == Right(100))
- }
-
- def testTry2LeftMap(): Unit = {
- val e = new Exception("foo")
- val t = Failure(e)
- val n = t.left.map(x => x)
- assert(n == Left(e))
- }
-
- def testTry2FoldSuccess(): Unit = {
- val t = Success(1)
- val n = t.fold(x => assert(false), y => y * 200)
- assert(n == 200)
- }
-
- def testTry2FoldFailure(): Unit = {
- val e = new Exception("foo")
- val t = Failure(e)
- val n = t.fold(x => x, y => assert(false))
- assert(n == e)
- }
-
- def testTry2SwapSuccess(): Unit = {
- val t = Success(1)
- val n = t.swap
- assert(n == Left(1))
- }
-
- def testTry2SwapFailure(): Unit = {
- val e = new Exception("foo")
- val t = Failure(e)
- val n = t.swap
- assert(n == Right(e))
- }
-
- // def testTry2MergeSucccess(): Unit = {
- // val t: Try[Int] = Success(1)
- // val n = (t: Either[Any, Any]).t.merge // connecting two implicit conversions
- // assert(n == 1)
- // }
-
- // def testTry2MergeFailure(): Unit = {
- // val e = new Exception("foo")
- // val t = Failure(e)
- // val n = (t: Either[Any, Any]).merge // connecting two implicit conversions
- // assert(n == e)
- // }
-
- testTry2RightMap()
- testTry2LeftMap()
- testTry2FoldSuccess()
- testTry2FoldFailure()
- testTry2SwapSuccess()
- testTry2SwapFailure()
- // testTry2MergeSucccess()
- // testTry2MergeFailure()
-}
-
-// tests that implicit conversions from Either to Try behave as expected
-trait TryImplicitConversionEither2Try {
-
- def testRight2FilterSuccessTrue(): Unit = {
- def expectsTry[U <% Try[Int]](rght: U): Try[Int] = {
- val n = rght.filter(x => x > 0) // this should be converted to a Try
- n
- }
- val r = Right(1)
- val n = expectsTry(r)
- assert(n == Success(1))
- }
-
- def testRight2FilterSuccessFalse(): Unit = {
- def expectsTry[U <% Try[Int]](rght: U): Try[Int] = {
- val n = rght.filter(x => x < 0) // this should be converted to a Try
- n
- }
- val r = Right(1)
- val n = expectsTry(r)
- n match {
- case Failure(e: NoSuchElementException) => assert(true)
- case _ => assert(false)
- }
- }
-
- def testLeft2FilterFailure(): Unit = {
- def expectsTry[U <% Try[Int]](rght: U): Try[Int] = {
- val n = rght.filter(x => x > 0) // this should be converted to a Try
- n
- }
- val r = Left(new Exception("foo"))
- val n = expectsTry(r)
- n match {
- case Failure(e: Exception) => assert(true)
- case _ => assert(false)
- }
- }
-
- def testRight2GetSuccess(): Unit = {
- def expectsTry[U <% Try[Int]](rght: U): Int = {
- val n = rght.get // this should be converted to a Try
- n
- }
- val r = Right(1)
- val n = expectsTry(r)
- assert(n == 1)
- }
-
- testRight2FilterSuccessTrue()
- testRight2FilterSuccessFalse()
- testLeft2FilterFailure()
- testRight2GetSuccess()
-}
-
object Test
extends App
-with TryStandard
-with TryImplicitConversionTry2Either
-with TryImplicitConversionEither2Try {
+with TryStandard {
System.exit(0)
} \ No newline at end of file