assert_not_contains

Macro assert_not_contains 

Source
macro_rules! assert_not_contains {
    ($container:expr, $containee:expr $(,)?) => { ... };
    ($container:expr, $containee:expr, $($message:tt)+) => { ... };
}
Expand description

Assert an expression (such as a string) does not contain an expression (such as a substring).

Pseudocode:
¬ a.contains(b)

  • If true, return ().

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

§Examples

use assertables::*;
use std::collections::HashSet;

// String contains substring
let a = "alfa";
let b = "zz";
assert_not_contains!(a, b);

// Range contains value
let a = 1..3;
let b = 4;
assert_not_contains!(a, &b);

// Vector contains element
let a = vec![1, 2, 3];
let b = 4;
assert_not_contains!(a, &b);

// HashSet does not contain element.
// Notice the &b because the macro calls HashSet.contains(&self, &value).
let a: HashSet<String> = [String::from("1")].into();
let b: String = String::from("2");
assert_not_contains!(a, &b);

// HashSet does not contain element with automatic borrow optimization.
// Notice the b because the value type &str is already a reference,
// which HashSet.contains knows how to borrow to compare to String.
let a: HashSet<String> = [String::from("1")].into();
let b = "2";
assert_not_contains!(a, b);

// This will panic
let a = "alfa";
let b = "lf";
assert_not_contains!(a, b);
// assertion failed: `assert_not_contains!(container, containee)`
// https://docs.rs/assertables/…/assertables/macro.assert_not_contains.html
//  container label: `a`,
//  container debug: `\"alfa\"`,
//  containee label: `b`,
//  containee debug: `\"lf\"`

§Module macros