#![cfg(test)]
use assert_rs::*;
#[test]
fn is_some() -> impl Assertion {
assert_that!(Some("hi")).is_some()
}
#[test]
fn isnt_some() -> impl Assertion {
assert_that!(i8::MIN.checked_abs()).is_some().should_fail()
}
#[test]
fn is_none() -> impl Assertion {
assert_that!(3_u8.checked_div(0)).is_none()
}
#[test]
fn isnt_none() -> impl Assertion {
assert_that!(Some(42)).is_none().should_fail()
}
#[test]
fn is_ok() -> impl Assertion {
assert_that!(str::from_utf8(&[100])).is_ok()
}
#[test]
#[allow(invalid_from_utf8, reason = "yes i know")]
fn isnt_ok() -> impl Assertion {
assert_that!(str::from_utf8(&[200])).is_ok().should_fail()
}
#[test]
#[allow(invalid_from_utf8, reason = "yes i know")]
fn is_err() -> impl Assertion {
assert_that!(str::from_utf8(&[200])).is_err()
}
#[test]
fn isnt_err() -> impl Assertion {
assert_that!(str::from_utf8(&[100])).is_err().should_fail()
}
#[test]
fn is_some_and() -> impl Assertion {
assert_that!(8_u8.checked_div(4)).is_some_and(|a| a.copied().is_equal_to(2))
}
#[test]
fn isnt_some_and() -> impl Assertion {
assert_that!(8_u8.checked_div(0))
.is_some_and(|a| a.copied().is_equal_to(2))
.should_fail()
}
#[test]
fn is_some_and_false() -> impl Assertion {
assert_that!(8_u8.checked_div(4))
.is_some_and(|a| a.copied().is_equal_to(83))
.should_fail()
}
#[test]
fn is_none_or() -> impl Assertion {
assert_that!(8_u8.checked_div(0)).is_none_or(|a| a.copied().is_equal_to(2))
}
#[test]
fn isnt_none_or_true() -> impl Assertion {
assert_that!(8_u8.checked_div(4)).is_none_or(|a| a.copied().is_equal_to(2))
}
#[test]
fn is_none_or_false() -> impl Assertion {
assert_that!(8_u8.checked_div(4))
.is_none_or(|a| a.copied().is_equal_to(83))
.should_fail()
}
#[test]
fn is_ok_and() -> impl Assertion {
assert_that!(Ok::<u8, &str>(1 + 2)).is_ok_and(|o| o.copied().is_equal_to(3))
}
#[test]
fn isnt_ok_and() -> impl Assertion {
assert_that!(Err::<u8, &str>("oh no"))
.is_ok_and(|o| o.copied().is_equal_to(3))
.should_fail()
}
#[test]
fn is_ok_and_false() -> impl Assertion {
assert_that!(Ok::<u8, &str>(3 + 4))
.is_ok_and(|o| o.copied().is_equal_to(5))
.should_fail()
}
#[test]
fn isnt_ok_and_false() -> impl Assertion {
assert_that!(Err::<u8, &str>("and the wheel spins and lands on France!"))
.is_ok_and(|o| o.copied().is_equal_to(5))
.should_fail()
}
#[test]
fn is_err_and() -> impl Assertion {
assert_that!(Err::<u8, &str>("signed for: nut kick."))
.is_err_and(|o| o.copied().map(str::len).is_equal_to(21))
}
#[test]
fn isnt_err_and() -> impl Assertion {
assert_that!(Ok::<u8, &str>(42))
.is_err_and(|o| {
o.copied()
.is_equal_to("somewhere sunrise begins another day")
})
.should_fail()
}
#[test]
fn is_err_and_false() -> impl Assertion {
assert_that!(Err::<u8, &str>("horrible suffering"))
.is_err_and(|o| o.copied().is_equal_to("eat fruit"))
.should_fail()
}
#[test]
fn isnt_err_and_false() -> impl Assertion {
assert_that!(Ok::<u8, &str>(250))
.is_err_and(|o| {
o.copied()
.is_equal_to("chip pan fires have gone right out of fashion, haven't they?")
})
.should_fail()
}