Add test case for #96
This commit is contained in:
parent
3a50dfa69d
commit
c39888e01b
@ -33,7 +33,7 @@ public inline fun <V, E> binding(crossinline block: BindingScope<E>.() -> V): Re
|
|||||||
return with(BindingScopeImpl<E>()) {
|
return with(BindingScopeImpl<E>()) {
|
||||||
try {
|
try {
|
||||||
Ok(block())
|
Ok(block())
|
||||||
} catch (ex: BindException) {
|
} catch (_: BindException) {
|
||||||
result!!
|
result!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,4 +78,24 @@ class BindingTest {
|
|||||||
actual = result,
|
actual = result,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun runCatchingInsideBindingDoesNotSwallow() {
|
||||||
|
fun squareNumber(): Result<Int, BindingError> = throw RuntimeException()
|
||||||
|
|
||||||
|
val squaredNumbers = binding<List<Int>, BindingError> {
|
||||||
|
val result: Result<List<Int>, Throwable> = runCatching {
|
||||||
|
(0..<10).map { number ->
|
||||||
|
squareNumber().bind()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.mapError { BindingError }.bind()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
expected = Err(BindingError),
|
||||||
|
actual = squaredNumbers,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user