macro_rules! assert_bag_superbag {
    ($a:expr, $b:expr $(,)?) => { ... };
    ($a:expr, $b:expr, $($arg:tt)+) => { ... };
}
Expand description

Assert a bag is a superbag of another.

  • If true, return ().

  • Otherwise, call panic! in order to print the values of the expressions with their debug representations.

Examples

let a = [1, 1, 1];
let b = [1, 1];
assert_bag_superbag!(&a, &b);
//-> ()

let result = panic::catch_unwind(|| {
let a = [1, 1];
let b = [2, 2];
assert_bag_superbag!(&a, &b);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_bag_superbag!(left_bag, right_bag)`\n",
    "  left_bag label: `&a`,\n",
    "  left_bag debug: `[1, 1]`,\n",
    " right_bag label: `&b`,\n",
    " right_bag debug: `[2, 2]`,\n",
    "            left: `{1: 2}`,\n",
    "           right: `{2: 2}`"
);
 
let result = panic::catch_unwind(|| {
let a = [1, 1];
let b = [1, 1, 1];
assert_bag_superbag!(&a, &b);
//-> panic!
});
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
    "assertion failed: `assert_bag_superbag!(left_bag, right_bag)`\n",
    "  left_bag label: `&a`,\n",
    "  left_bag debug: `[1, 1]`,\n",
    " right_bag label: `&b`,\n",
    " right_bag debug: `[1, 1, 1]`,\n",
    "            left: `{1: 2}`,\n",
    "           right: `{1: 3}`"
);
assert_eq!(actual, expect);

This implementation uses [BTreeMap] to count items and sort them.