From 457172dca3f3fea505f2421a99f86976141c7e75 Mon Sep 17 00:00:00 2001 From: Heather Miller Date: Tue, 3 Apr 2012 10:17:33 +0200 Subject: Remedies Try/Either signature disparity for source compat. w/ Akka --- test/files/jvm/scala-concurrent-tck.scala | 80 +++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala index 75e2b92ff6..b3470d275d 100644 --- a/test/files/jvm/scala-concurrent-tck.scala +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -1,6 +1,3 @@ - - - import scala.concurrent.{ Future, Promise, @@ -398,6 +395,80 @@ trait Exceptions extends TestBase { } +trait TryEitherExtractor extends TestBase { + + import scala.util.{Try, Success, Failure} + + def testSuccessMatch(): Unit = once { + done => + val thisIsASuccess = Success(42) + thisIsASuccess match { + case Success(v) => + done() + assert(v == 42) + case Failure(e) => + done() + assert(false) + case other => + done() + assert(false) + } + } + + def testRightMatch(): Unit = once { + done => + val thisIsNotASuccess: Right[Throwable, Int] = Right(43) + thisIsNotASuccess match { + case Success(v) => + done() + assert(v == 43) + case Failure(e) => + done() + assert(false) + case other => + done() + assert(false) + } + } + + def testFailureMatch(): Unit = once { + done => + val thisIsAFailure = Failure(new Exception("I'm an exception")) + thisIsAFailure match { + case Success(v) => + done() + assert(false) + case Failure(e) => + done() + assert(e.getMessage == "I'm an exception") + case other => + done() + assert(false) + } + } + + def testLeftMatch(): Unit = once { + done => + val thisIsNotAFailure: Left[Throwable, Int] = Left(new Exception("I'm an exception")) + thisIsNotAFailure match { + case Success(v) => + done() + assert(false) + case Failure(e) => + done() + assert(e.getMessage == "I'm an exception") + case other => + done() + assert(false) + } + + } + + testSuccessMatch() + testRightMatch() + testFailureMatch() + testLeftMatch() +} object Test extends App @@ -406,8 +477,11 @@ with FutureCombinators with FutureProjections with Promises with Exceptions +with TryEitherExtractor { System.exit(0) } + + -- cgit v1.2.3