Macro expecting::expect_contains

source ·
macro_rules! expect_contains {
    ( $container:expr, $element_or_substr:expr ) => { ... };
}
Expand description

Expects that the given container (e.g., Vec) contains the element or given string contains the substring; otherwise returns early.

§Examples


fn passing_test() -> Result<()> {
    let v: Vec<i32> = vec![42, 1337];
    expect_contains!(v, 42);
    Ok(())
}

fn passing_test_for_string() -> Result<()> {
    let superstring = "angelheaded hipsters";
    expect_contains!(superstring, "hip");
    Ok(())
}

fn failing_test() -> Result<()> {
    let v: Vec<i32> = vec![42, 1337];
    expect_contains!(v, 13);  // returns early
    Ok(())  // won't be reached
}