def test_unsafe_wrapped_function_returns_error() -> None: error: Exception = Exception("oops") @safe def unsafe(x: int) -> int: if x > 5: raise error else: return x + 1 result: Result[int, Exception] = unsafe(10) assert Err(error) == result
def test_map_error_err() -> None: m: Result[int, str] = Err("oops") assert Err(4) == m.mapError(len)
def test_err_withdefault() -> None: m: Result[int, str] = Err("oops") assert 0 == m.withDefault(0)
def test_apply_err_to_err() -> None: m: Result[int, str] = Err("oops") f: Result[Callable[[int], int], str] = Err("oops") assert Err("oops") == m.apply(f)
def test_apply_ok_to_err() -> None: m: Result[int, str] = Err("oops") increment: Callable[[int], int] = lambda x: x + 1 assert Err("oops") == m.apply(Result.pure(increment))
def test_bind_err() -> None: m: Result[int, str] = Err("oops") increment: Callable[[int], Result[int, str]] = lambda x: Ok(x + 1) assert Err("oops") == m.bind(increment)
def test_err_to_maybe() -> None: result: Result[int, str] = Err("error") assert Nothing() == result.toMaybe()
def test_from_nothing() -> None: m: Maybe[int] = Nothing() result: Result[int, str] = Result.fromMaybe(m, "error") assert Err("error") == result
def test_nothing_to_result() -> None: assert Err("oops") == Nothing().toResult("oops")
def test_from_err() -> None: assert Nothing() == Maybe.fromResult(Err("oops"))
def test_err_to_optional() -> None: assert None == Err("error").toOptional()
def test_from_optional_none() -> None: assert Err("error") == Result.fromOptional(None, "error")