Skip to main content

compose

Macro compose 

Source
macro_rules! compose {
    (|$tc:ident| { $($body:tt)* }) => { ... };
}
Expand description

Create a generator from imperative code that draws from other generators.

This is analogous to Hypothesis’s @composite decorator. The closure receives a TestCase parameter. Use tc.draw() to draw values from other generators within the compose block.

§Example

use hegel::generators as gs;

#[hegel::test]
fn my_test(tc: hegel::TestCase) {
    let value = tc.draw(hegel::compose!(|tc| {
        let x = tc.draw(gs::integers::<i32>().min_value(0).max_value(10));
        let y = tc.draw(gs::integers::<i32>().min_value(x).max_value(100));
        (x, y)
    }));
}