From 9c11bd50ca5e13ab2b39949a64f95a5d613c8991 Mon Sep 17 00:00:00 2001 From: Mathias Pius Date: Thu, 12 Jan 2023 14:14:30 +0100 Subject: [PATCH] Add Result test --- Cargo.toml | 2 +- src/lib.rs | 39 ++++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7ca0f1..10da46e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fallible-option" -version = "0.1.2" +version = "0.1.3" authors = ["Mathias Pius "] description = "Fallible is an Option with inverted Try-semantics." keywords = ["error-handling", "result", "try", "fallible"] diff --git a/src/lib.rs b/src/lib.rs index dfab2ce..8f71a9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -689,29 +689,28 @@ where mod tests { use crate::Fallible::{self, Fail, Success}; - #[test] - fn casting_conversion() { - #[derive(Debug, PartialEq)] - struct InnerError(pub u8); + #[derive(Debug, PartialEq)] + struct InnerError(pub u8); - #[derive(Debug, PartialEq)] - enum OuterError { - Inner(InnerError), - } + #[derive(Debug, PartialEq)] + enum OuterError { + Inner(InnerError), + } - impl From for OuterError { - fn from(value: InnerError) -> Self { - OuterError::Inner(value) - } + impl From for OuterError { + fn from(value: InnerError) -> Self { + OuterError::Inner(value) } + } + #[test] + fn fallible_residual_conversion() { fn inner_error() -> Fallible { Fail(InnerError(1)) } fn outer_error() -> Fallible { inner_error()?; - Success } @@ -720,4 +719,18 @@ mod tests { OuterError::Inner(InnerError(1)) ); } + + #[test] + fn result_residual_conversion() { + fn inner_error() -> Fallible { + Fail(InnerError(1)) + } + + fn outer_error() -> Result<(), OuterError> { + inner_error()?; + Ok(()) + } + + assert_eq!(outer_error(), Err(OuterError::Inner(InnerError(1)))); + } }