Skip to content

Commit 8d8916d

Browse files
committed
Add getOrThrow(moreInfo: => String) to Option in test-util
Closes #179
1 parent aa8c238 commit 8d8916d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

test-util/shared/src/main/scala/japgolly/microlibs/testutil/TestUtilImplicits.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ trait TestUtilImplicits {
88

99
implicit def toTestUtilEitherExt[A, B](x: Either[A, B])(implicit l: Line): EitherExt[A, B] =
1010
new EitherExt(x)
11+
12+
implicit def toTestUtilOptionExt[A](x: Option[A])(implicit l: Line): OptionExt[A] =
13+
new OptionExt(x)
1114
}
1215

1316
object TestUtilImplicits {
@@ -26,4 +29,9 @@ object TestUtilImplicits {
2629
def getLeftOrThrow(moreInfo: => String): A =
2730
self.fold(identity, e => fail(s"${moreInfo.replaceFirst("\\.?$", ".")} Expected Left(_), found Right($e)"))
2831
}
32+
33+
implicit class OptionExt[A](private val self: Option[A])(implicit l: Line) {
34+
def getOrThrow(moreInfo: => String): A =
35+
self.getOrElse(fail(s"${moreInfo.replaceFirst("\\.?$", ".")} Expected Some(_), found None"))
36+
}
2937
}

0 commit comments

Comments
 (0)