forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SI-6455 util.Try supports withFilter
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package scala.util | ||
|
||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
import org.junit.Test | ||
import org.junit.Assert._ | ||
|
||
/* Test Try's withFilter method, which was added along with the -Xfuture fix for SI-6455 */ | ||
@RunWith(classOf[JUnit4]) | ||
class TryTest { | ||
@Test | ||
def withFilterFail(): Unit = { | ||
val fail = for (x <- util.Try(1) if x > 1) yield x | ||
assert(fail.isFailure) | ||
} | ||
|
||
@Test | ||
def withFilterSuccess(): Unit = { | ||
val success1 = for (x <- util.Try(1) if x >= 1) yield x | ||
assertEquals(success1, util.Success(1)) | ||
} | ||
|
||
@Test | ||
def withFilterFlatMap(): Unit = { | ||
val successFlatMap = for (x <- util.Try(1) if x >= 1; y <- util.Try(2) if x < y) yield x | ||
assertEquals(successFlatMap, util.Success(1)) | ||
} | ||
|
||
@Test | ||
def withFilterForeach(): Unit = { | ||
var ok = false | ||
for (x <- util.Try(1) if x == 1) ok = x == 1 | ||
assert(ok) | ||
} | ||
} |