Skip to content

Commit

Permalink
Add Result test
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasPius committed Jan 12, 2023
1 parent 1b87214 commit 9c11bd5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fallible-option"
version = "0.1.2"
version = "0.1.3"
authors = ["Mathias Pius <[email protected]>"]
description = "Fallible is an Option with inverted Try-semantics."
keywords = ["error-handling", "result", "try", "fallible"]
Expand Down
39 changes: 26 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InnerError> for OuterError {
fn from(value: InnerError) -> Self {
OuterError::Inner(value)
}
impl From<InnerError> for OuterError {
fn from(value: InnerError) -> Self {
OuterError::Inner(value)
}
}

#[test]
fn fallible_residual_conversion() {
fn inner_error() -> Fallible<InnerError> {
Fail(InnerError(1))
}

fn outer_error() -> Fallible<OuterError> {
inner_error()?;

Success
}

Expand All @@ -720,4 +719,18 @@ mod tests {
OuterError::Inner(InnerError(1))
);
}

#[test]
fn result_residual_conversion() {
fn inner_error() -> Fallible<InnerError> {
Fail(InnerError(1))
}

fn outer_error() -> Result<(), OuterError> {
inner_error()?;
Ok(())
}

assert_eq!(outer_error(), Err(OuterError::Inner(InnerError(1))));
}
}

0 comments on commit 9c11bd5

Please sign in to comment.