Skip to content

Commit

Permalink
feat: added enum variant assert macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko von Leipzig committed May 14, 2021
1 parent 1a2662d commit df7dc4f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
mod conformance;
mod resistance;

#[macro_export]
/// Useful for asserting an enum value matches a specific variant
///
/// Usage:
/// `assert_variant!(value, MyEnum::Variant(..));`
macro_rules! assert_variant {
($value:expr, $pattern:pat) => {{
let value = &$value;

if let $pattern = value {
} else {
panic!(
r#"assertion failed (value doesn't match pattern):
value: `{:?}`,
pattern: `{}`"#,
value,
stringify!($pattern)
)
}
}}; // TODO: Additional patterns for trailing args, like assert and assert_eq
}

0 comments on commit df7dc4f

Please sign in to comment.