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 {
check!(name.len()).satisfies(gt(0usize))?;
check!(age).satisfies(gt(0u32))
}
#[test_case(2, 2, 4)]
#[test_case(10, 5, 15 ; "bigger numbers")]
fn addition_works(a: i32, b: i32, sum: i32) -> TestResult {
check!(a + b).satisfies(eq(sum))
}
#[test_case(; "no parameters at all")]
fn the_truth_holds() -> TestResult {
check!(true).satisfies(is_true())
}
#[test_case(3 ; "not three")]
#[ignore]
fn expects_three(n: i32) -> TestResult {
check!(n).satisfies(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}");
check!(rendered.as_str()).satisfies(contains_str("not three"))?;
check!(rendered.as_str()).satisfies(contains_str("expects_three(3)"))
}