-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f6a711
commit 31afc4b
Showing
7 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mod is_none; | ||
mod is_some; | ||
|
||
pub use is_some::SomeAsserter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::{implementation, BasicAsserter}; | ||
use std::fmt::Debug; | ||
|
||
impl<SomeValue> BasicAsserter<Option<SomeValue>> | ||
where | ||
SomeValue: Debug, | ||
{ | ||
/// Asserts that the [Option] is [None]. | ||
/// | ||
/// # Examples | ||
/// ``` | ||
/// # use smoothy::assert_that; | ||
/// # | ||
/// let option: Option<String> = None; | ||
/// | ||
/// assert_that(option).is_none(); | ||
/// ``` | ||
/// | ||
/// # Panics | ||
/// When the [Option] is [Some] | ||
pub fn is_none(self) { | ||
implementation::assert(self.value.is_none(), "Option is None", &self.value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::{implementation, BasicAsserter}; | ||
use std::fmt::Debug; | ||
|
||
impl<SomeValue> BasicAsserter<Option<SomeValue>> | ||
where | ||
SomeValue: Debug, | ||
{ | ||
/// Asserts that the [Option] is [Some]. | ||
/// | ||
/// Allows the usage of chained assertions on an option-type (see [`SomeAsserter`]). | ||
/// | ||
/// # Examples | ||
/// ``` | ||
/// # use smoothy::assert_that; | ||
/// # | ||
/// let option: Option<String> = Some(String::new()); | ||
/// | ||
/// assert_that(option).is_some(); | ||
/// ``` | ||
/// | ||
/// # Panics | ||
/// When the [Option] is [None] | ||
pub fn is_some(self) -> SomeAsserter<SomeValue> { | ||
implementation::assert(self.value.is_some(), "Option is Some", &self.value); | ||
|
||
#[allow(clippy::unwrap_used)] | ||
let value = self.value.unwrap(); | ||
|
||
SomeAsserter { value } | ||
} | ||
} | ||
|
||
/// Enables various assertions on [Some]-values | ||
pub struct SomeAsserter<SomeValue> { | ||
value: SomeValue, | ||
} | ||
|
||
impl<SomeValue> SomeAsserter<SomeValue> { | ||
/// Prepares the [Some] value for further assertions. | ||
/// | ||
/// # Examples | ||
/// ``` | ||
/// # use smoothy::{assert_that, BasicAsserter}; | ||
/// # | ||
/// let option: Option<String> = Some(String::from("Hello World!")); | ||
/// | ||
/// let asserter = assert_that(option).is_some().and_value(); | ||
/// // further assertions | ||
/// asserter.equals("Hello World!"); | ||
/// ``` | ||
pub fn and_value(self) -> BasicAsserter<SomeValue> { | ||
BasicAsserter { value: self.value } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use smoothy::*; | ||
|
||
mod assert_option { | ||
use super::*; | ||
|
||
#[test] | ||
fn succeeds() { | ||
let option: Option<()> = None; | ||
|
||
assert_that(option).is_none(); | ||
} | ||
|
||
#[test] | ||
#[should_panic = "assertion failed: `(Option is None)`"] | ||
fn fails() { | ||
let option: Option<()> = Some(()); | ||
|
||
assert_that(option).is_none(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use smoothy::*; | ||
|
||
mod assert_option { | ||
use super::*; | ||
|
||
#[test] | ||
fn succeeds() { | ||
let option: Option<String> = Some(String::new()); | ||
|
||
assert_that(option).is_some(); | ||
} | ||
|
||
#[test] | ||
#[should_panic = "assertion failed: `(Option is Some)`"] | ||
fn fails() { | ||
let option: Option<()> = None; | ||
|
||
assert_that(option).is_some(); | ||
} | ||
} | ||
|
||
mod assert_some { | ||
use super::*; | ||
|
||
#[test] | ||
fn transforms_to_basic_asserter() { | ||
let option: Option<String> = Some(String::new()); | ||
|
||
let asserter: BasicAsserter<String> = assert_that(option).is_some().and_value(); | ||
asserter.equals(""); | ||
} | ||
} |