checkito/lib.rs
1#![doc = include_str!("../README.md")]
2
3pub mod all;
4pub mod any;
5pub mod array;
6pub mod boxed;
7pub mod cardinality;
8pub mod check;
9pub mod collect;
10pub mod convert;
11pub mod dampen;
12pub mod filter;
13pub mod filter_map;
14pub mod flatten;
15pub mod generate;
16pub mod keep;
17pub mod lazy;
18pub mod map;
19mod prelude;
20pub mod primitive;
21pub mod prove;
22#[cfg(feature = "regex")]
23pub mod regex;
24#[doc(hidden)]
25pub mod run;
26pub mod same;
27pub mod sample;
28pub mod shrink;
29pub mod size;
30pub mod standard;
31pub mod state;
32pub mod unify;
33mod utility;
34
35pub use check::Check;
36/// Turns a function into a property test.
37///
38/// It takes a list of generators as input, which are used to produce random
39/// arguments for the function it's attached to.
40///
41/// The function can return `()`, `bool`, or `Result` to indicate whether the
42/// property holds. Any `panic` within the function is also treated as a test
43/// failure.
44///
45/// # Arguments
46///
47/// - **Generators**: The first arguments to the macro are a comma-separated
48/// list of generators. The values produced by these generators will be passed
49/// as arguments to the test function. You can use `_` to infer the default
50/// generator for a type.
51/// - `verbose`: A boolean (`true` or `false`) to enable or disable verbose
52/// output, which shows every generation and shrink step. Defaults to `false`.
53/// - `color`: A boolean (`true` or `false`) to enable or disable colored
54/// output. Defaults to `true`.
55/// - `debug`: A boolean (`true` or `false`) that controls the output format. If
56/// `true`, the full `Debug` representation of test results is printed. If
57/// `false`, a more minimal output is used. Defaults to `true`.
58///
59/// # Examples
60///
61/// A simple test with a range generator:
62/// ```
63/// # use checkito::check;
64/// #[check(0..100)]
65/// fn is_less_than_100(x: i32) {
66/// assert!(x < 100);
67/// }
68/// ```
69///
70/// Using multiple generators and inferring a type:
71/// ```
72/// # use checkito::check;
73/// #[check(.., 0.0..1.0, _)]
74/// fn complex_test(x: i32, y: f64, z: bool) {
75/// // ...
76/// }
77/// ```
78///
79/// Disabling color and enabling verbose output:
80/// ```
81/// # use checkito::check;
82/// #[check(0..10, color = false, verbose = true)]
83/// #[should_panic]
84/// fn failing_test(x: i32) {
85/// assert!(x > 5);
86/// }
87/// ```
88#[cfg(feature = "check")]
89pub use checkito_macro::check;
90/// Creates a generator from a compile-time constant value.
91///
92/// This macro is useful for embedding constant values directly into generators.
93/// This is mainly relevant for static cardinality estimates. When possible, the
94/// expression inside the macro is converted to a generator with constant
95/// parameters.
96#[cfg(feature = "constant")]
97pub use checkito_macro::constant;
98/// Creates a generator from a regular expression, validated at compile time.
99///
100/// This macro takes a string literal representing a regular expression and
101/// produces a generator that yields strings matching that pattern. The regex is
102/// parsed and validated at compile time, so any errors in the pattern will
103/// result in a compilation failure.
104///
105/// # Examples
106///
107/// ```
108/// # use checkito::{check, regex};
109/// #[check(regex!("[a-zA-Z0-9]{1,10}"))]
110/// fn has_alphanumeric_content(s: String) {
111/// assert!(s.chars().all(|c| c.is_alphanumeric()));
112/// assert!(s.len() >= 1 && s.len() <= 10);
113/// }
114/// ```
115#[cfg(feature = "regex")]
116pub use checkito_macro::regex;
117pub use generate::{FullGenerate, Generate};
118pub use prelude::*;
119pub use prove::Prove;
120pub use sample::Sample;
121pub use shrink::Shrink;
122
123const GENERATES: usize = 1 << 10;
124const SHRINKS: usize = 1 << 20;
125const SAMPLES: usize = 1 << 7;
126const COLLECTS: usize = 1 << 10;
127const RETRIES: usize = 1 << 8;
128#[cfg(feature = "regex")]
129const REPEATS: u32 = 1 << 6;