use test_better::prelude::*;
use test_better::test_case;
#[test_case("alice", 30 ; "common case")]
#[test_case("bob", 25 ; "another user")]
fn validates_user(name: &str, age: u32) -> TestResult {
expect!(name.len()).to(gt(0usize))?;
expect!(age).to(gt(0u32))
}
#[test_case(2, 2, 4)]
#[test_case(10, 5, 15 ; "bigger numbers")]
fn addition_works(a: i32, b: i32, sum: i32) -> TestResult {
expect!(a + b).to(eq(sum))
}
#[test_case(; "no parameters at all")]
fn the_truth_holds() -> TestResult {
expect!(true).to(is_true())
}
#[test_case(3 ; "not three")]
#[ignore]
fn expects_three(n: i32) -> TestResult {
expect!(n).to(eq(99))
}
#[test]
fn a_failing_case_names_itself_in_the_context() -> TestResult {
let result = expects_three::not_three();
let error = result.err().or_fail()?;
let rendered = format!("{error}");
expect!(rendered.as_str()).to(contains_str("not three"))?;
expect!(rendered.as_str()).to(contains_str("expects_three(3)"))
}