#![no_std]
#![no_implicit_prelude]
#[macro_export]
macro_rules! operator_assertion_macros {
(
$(#![$shared_attr:meta])*
in $(::$module:ident)+;
use $assert:path;
$(#[$attr_simple:meta])* simple = $name_simple:ident;
$(#[$attr_expr:meta])* expr = $name_expr:ident;
) => {
$(#[$shared_attr])*
$(#[$attr_expr])*
macro_rules! $name_expr {
($left:expr, $op:tt, $right:expr) => {
match ($left, $right) {
(left, right) => {
$assert!(
left $op right,
"{left_expr} {op} {right_expr} ⇒ {left_value:?} {op} {right_value:?} ⇒ false",
op = stringify!($op),
left_expr = stringify!($left),
right_expr = stringify!($right),
left_value = left,
right_value = right,
)
}
}
};
}
$(#[$shared_attr])*
$(#[$attr_simple])*
macro_rules! $name_simple {
($left:ident $op:tt $right:ident) => {
$(::$module)+::$name_expr!($left, $op, $right)
};
($left:ident $op:tt $right:literal) => {
$(::$module)+::$name_expr!($left, $op, $right)
};
($left:literal $op:tt $right:ident) => {
$(::$module)+::$name_expr!($left, $op, $right)
};
($left:literal $op:tt $right:literal) => {
$(::$module)+::$name_expr!($left, $op, $right)
};
}
};
}
#[macro_export]
macro_rules! function_assertion_macro {
(
$(#![$shared_attr:meta])*
use $assert:path;
$(#[$attr:meta])* $name:ident;
) => {
$(#[$shared_attr])*
$(#[$attr])*
macro_rules! $name {
($function:ident($left:expr, $right:expr)) => {
match ($left, $right) {
(left, right) => {
$assert!(
$function($left, $right),
"{func}({left_expr}, {right_expr}) ⇒ {func}({left_value:?}, {right_value:?}) ⇒ false",
func = stringify!($function),
left_expr = stringify!($left),
right_expr = stringify!($right),
left_value = left,
right_value = right,
)
}
}
};
(not $function:ident($left:expr, $right:expr)) => {
match ($left, $right) {
(left, right) => {
$assert!(
!$function($left, $right),
"{func}({left_expr}, {right_expr}) ⇒ {func}({left_value}, {right_value}) ⇒ true",
func = stringify!($function),
left_expr = stringify!($left),
right_expr = stringify!($right),
left_value = left,
right_value = right,
)
}
}
};
}
};
}
operator_assertion_macros! {
#![macro_export]
in ::assert_cmp;
use ::core::assert;
simple = assert_op;
expr = assert_op_expr;
}
operator_assertion_macros! {
#![macro_export]
in ::assert_cmp;
use ::core::debug_assert;
simple = debug_assert_op;
expr = debug_assert_op_expr;
}
function_assertion_macro! {
#![macro_export]
use ::core::assert;
assert_fn;
}
function_assertion_macro! {
#![macro_export]
use ::core::debug_assert;
debug_assert_fn;
}