macro_rules! static_regex {
($name:ident, $pattern:literal $(,)?) => {
static $name: std::sync::LazyLock<regex::Regex> = std::sync::LazyLock::new(|| {
regex::Regex::new($pattern).expect(concat!("invalid static regex pattern: ", $pattern))
});
};
}
pub(crate) use static_regex;
#[cfg(test)]
#[expect(clippy::expect_used, reason = "tests use expect freely")]
mod tests {
static_regex!(WORD_RE, r"\b(\w+)\b");
#[test]
fn macro_compiles_and_matches() {
let cap = WORD_RE.captures("hello").expect("should match a word");
assert_eq!(&cap[1], "hello");
}
}