Macro assertables::assert_gt

source ·
macro_rules! assert_gt {
    ($a:expr, $b:expr $(,)?) => { ... };
    ($a:expr, $b:expr, $($message:tt)+) => { ... };
}
Expand description

Assert a value is greater than an expression.

  • If true, return ().

  • Otherwise, call panic! with a message and the values of the expressions with their debug representations.

§Examples

// Return Ok
let a = 2;
let b = 1;
assert_gt!(a, b);
//-> ()

let a = 1;
let b = 2;
// Panic with error message
let result = panic::catch_unwind(|| {
assert_gt!(a, b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_gt!(a, b)`\n",
    " a label: `a`,\n",
    " a debug: `1`,\n",
    " b label: `b`,\n",
    " b debug: `2`,\n",
    "       a: `1`,\n",
    "       b: `2`"
);
assert_eq!(actual, expect);

// Panic with error message
let result = panic::catch_unwind(|| {
assert_gt!(a, b, "message");
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = "message";
assert_eq!(actual, expect);

§Module macros