Skip to main content

__result_of_ref

Macro __result_of_ref 

Source
macro_rules! __result_of_ref {
    ($function: expr, $matcher: expr) => { ... };
}
Expand description

Matches a value where the reference to the result of callable applied to the value matches the inner matcher.

The callable will be called twice, so make sure it is pure.

use googletest::prelude::*;
fn should_pass_1() -> googletest::Result<()> {
   verify_that!("hello", result_of_ref!(|s: &str| s.to_uppercase(), eq("HELLO")))?; // Passes
   Ok(())
}

fn should_pass_2() -> googletest::Result<()> {
   verify_that!(100, result_of_ref!(|value| value + 1, eq(&101)))?; // Passes
   Ok(())
}

fn should_fail() -> googletest::Result<()> {
   verify_that!("world", result_of_ref!(|s: &str| s.to_uppercase(), eq("HELLO")))?; // Passes
   Ok(())
}
should_pass_1().unwrap();
should_pass_2().unwrap();
should_fail().unwrap_err();