expect_not_empty

Macro expect_not_empty 

Source
macro_rules! expect_not_empty {
    ( $a:expr ) => { ... };
}
Expand description

Expects that the given container (e.g., Vec) contains at least one element or given string has non-zero length; otherwise returns early.

ยงExamples


fn passing_test() -> Result<()> {
    expect_not_empty!(vec![1]);
    Ok(())
}

fn failing_test() -> Result<()> {
    let empty: Vec<i32> = vec![];
    expect_not_empty!(empty);  // returns early
    Ok(())  // won't be reached
}