rstest_bdd_patterns/lib.rs
1//! Shared step-pattern parsing utilities for rstest-bdd.
2//!
3//! The crate exposes placeholder parsing helpers reused by both the runtime
4//! and proc-macro crates so they can share validation logic without duplicating
5//! the regex construction code paths.
6
7mod capture;
8mod errors;
9mod hint;
10mod pattern;
11
12pub use capture::extract_captured_values;
13pub use errors::{PatternError, PlaceholderErrorInfo};
14pub use hint::get_type_pattern;
15pub use pattern::build_regex_from_pattern;
16
17/// Build and compile a `Regex` from a step pattern.
18///
19/// # Errors
20/// Returns [`PatternError`] if the pattern translation or regex compilation fails.
21///
22/// # Examples
23/// ```
24/// use rstest_bdd_patterns::compile_regex_from_pattern;
25/// let regex = compile_regex_from_pattern("Given {n:u32}").unwrap();
26/// assert!(regex.is_match("Given 42"));
27/// ```
28pub fn compile_regex_from_pattern(pat: &str) -> Result<regex::Regex, PatternError> {
29 let src = build_regex_from_pattern(pat)?;
30 regex::Regex::new(&src).map_err(PatternError::from)
31}