summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2015-04-13 22:08:06 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2015-04-13 22:08:06 -0700
commit56d79460dc3e9dbec054c1459122f5b87989f4e3 (patch)
treea7150045728ed004252841e3ce4c553f48112bf1 /test
parent696ba40e13e8fc18b404aab908147b135691b9f7 (diff)
parentf10dcc76dff4aa9146cd1ec4052fe136f597a260 (diff)
downloadscala-56d79460dc3e9dbec054c1459122f5b87989f4e3.tar.gz
scala-56d79460dc3e9dbec054c1459122f5b87989f4e3.tar.bz2
scala-56d79460dc3e9dbec054c1459122f5b87989f4e3.zip
Merge pull request #4436 from adriaanm/rebase-4082
SI-8336: add `fold` & `toEither` to `util.Try`
Diffstat (limited to 'test')
-rw-r--r--test/files/jvm/try-type-tests.scala43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/files/jvm/try-type-tests.scala b/test/files/jvm/try-type-tests.scala
index 962afbd30f..b3926020f0 100644
--- a/test/files/jvm/try-type-tests.scala
+++ b/test/files/jvm/try-type-tests.scala
@@ -118,6 +118,44 @@ trait TryStandard {
assert(f.transform(succ, fail).get == 0)
}
+ def testSuccessEither(): Unit = {
+ val t = Success(1)
+ assert(t.toEither.isRight)
+ }
+
+ def testFailureEither(): Unit = {
+ val t = Failure(new Exception("foo"))
+ assert(t.toEither.isLeft)
+ }
+
+ def testFoldSuccess(): Unit = {
+ val t = Success(1)
+ val res = t.fold("Throws " + _, "Returns " + _)
+ assert(res == "Returns 1")
+ }
+
+ def testFoldFailure(): Unit = {
+ val t = Failure(new Exception("foo"))
+ val res = t.fold("Throws " + _, "Returns " + _)
+ assert(res == "Throws java.lang.Exception: foo")
+ }
+
+ def testFoldSuccessFailure(): Unit = {
+ val t = Success(1)
+ val res = t.fold("Throws " + _, _ => throw new Exception("foo"))
+ assert(res == "Throws java.lang.Exception: foo")
+ }
+
+ def testFoldFailureFailure(): Unit = {
+ val t = Failure(new Exception("foo"))
+ val res = try {
+ t.fold(_ => throw new Exception("bar"), "Returns " + _)
+ } catch {
+ case e: Throwable => "Throws " + e
+ }
+ assert(res == "Throws java.lang.Exception: bar")
+ }
+
testForeachSuccess()
testForeachFailure()
testFlatMapSuccess()
@@ -136,6 +174,11 @@ trait TryStandard {
testFailedFailure()
testSuccessTransform()
testFailureTransform()
+ testSuccessEither()
+ testFailureEither()
+ testFoldSuccess()
+ testFoldFailure()
+ testFoldSuccessFailure()
}
object Test