#![allow(clippy::eq_op)]
#![allow(clippy::op_ref)]
#![allow(clippy::assertions_on_constants)]
#![allow(unused_attributes)]
mod helper_macros;
#[macro_export]
macro_rules! test_all_assertification_styles {
(
#[test]
$(#[$attr:meta])?
fn $test_name:ident () {
$($body:tt)+
}
) => {
::paste::paste! {
#[test]
$(#[$attr])?
fn $test_name () {
$($body)+
}
#[::assert2ify::assert2ify]
#[test]
$(#[$attr])?
fn [< $test_name _with_assertification>] () {
$($body)+
}
#[::assert2ify::assert2ify(check)]
#[test]
$(#[$attr])?
fn [< $test_name _with_checkification>] () {
$($body)+
}
}
};
(
fn $test_name:ident () {
$($body:tt)+
}
) => {compile_error!("The given function must be marked #[test]");};
}
macro_rules! test_should_panic {
($test_name:ident, $body:expr) => {
test_all_assertification_styles! {
#[test]
#[should_panic]
fn $test_name () {
$body;
}
}
};
}
#[derive(Eq, PartialEq, Ord, PartialOrd)]
struct I(i32);
test_all_assertification_styles! {
#[test]
fn assert_pass() {
assert!(1 == 1);
assert_eq!(1, 1);
assert_ne!(1, 2);
assert!(1 == 1, "{}", "math broke");
assert_eq!(1, 1, "{}", "math broke");
assert_ne!(1, 2, "{}", "math broke");
assert!(true && true);
assert!(true == true);
assert_eq!(true, true);
assert_ne!(false, true);
assert!(true && true, "{}", "logic broke");
assert!(true == true, "{}", "logic broke");
assert_eq!(true, true, "{}", "logic broke");
assert_ne!(true, false, "{}", "logic broke");
assert!(matches!(Result::<i32, i32>::Ok(10),Ok(10) ));
assert!(matches!(Result::<i32, i32>::Ok(10),Ok(10)), "{}", "rust broke");
}
}
test_all_assertification_styles! {
#[test]
fn non_sized() {
assert!(b"hello"[..] == b"hello"[..]);
assert_eq!(b"hello"[..] , b"hello"[..]);
}
}
test_should_panic!(panic_assert1, assert!(1 == 2));
test_should_panic!(panic_assert2, assert!(1 == 2, "{}", "math broke"));
test_should_panic!(panic_assert3, assert!(true && false));
test_should_panic!(panic_assert4, assert!(true && false, "{}", "logic broke"));
test_should_panic!(
panic_assert5,
assert!(matches!(Result::<i32, i32>::Err(10), Ok(_)))
);
test_should_panic!(
panic_assert6,
assert!(
matches!(Result::<i32, i32>::Err(10), Ok(_)),
"{}",
"rust broke"
)
);
test_should_panic!(panic_assert7, assert_eq!(true, false, "{}", "logic broke"));
test_should_panic!(panic_assert8, assert_ne!(1, 1, "{}", "math broke"));
test_all_assertification_styles! {
#[test]
fn debug_refs() {
assert_eq!(&1 , &1);
assert_eq!(&&1 , &&1);
assert_eq!(&&&&&&&1 , &&&&&&&1);
assert_ne!(&1 , &2);
assert_ne!(&&1 , &&2);
assert_ne!(&&&&&&&2, &&&&&&&1);
assert!(&1 == &1);
assert!(&&1 == &&1);
assert!(&&&&&&&1 == &&&&&&&1);
assert!(matches!(&10,10));
assert!(matches!(& &10,10));
}
}
test_all_assertification_styles! {
#[test]
fn non_debug_refs() {
assert!(&I(1) == &I(1));
assert!(&&I(1) == &&I(1));
assert!(&&&&&&&I(1) == &&&&&&&I(1));
assert!(matches!(&I(10),I(10)));
assert!(matches!(& &I(10),I(10)));
}
}
test_all_assertification_styles! {
#[test]
fn no_copy() {
let a = String::new();
let b = String::new();
assert!(a == b);
assert!(a == b);
assert_eq!(a,b);
assert_eq!(a,b);
drop(a);
drop(b);
}
}