Skip to content

Commit

Permalink
feat: add assert_matches macro
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Sep 14, 2023
1 parent 79fc777 commit 2b8d905
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,46 @@ pub use miden_hir_type::{FunctionType, Type, TypeRepr};

pub type Felt = winter_math::fields::f64::BaseElement;

macro_rules! assert_matches {
($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
match $left {
$( $pattern )|+ $( if $guard )? => {}
ref left_val => {
panic!(r#"
assertion failed: `(left matches right)`
left: `{:?}`,
right: `{}`"#, left_val, stringify!($($pattern)|+ $(if $guard)?));
}
}
};

($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $msg:literal $(,)?) => {
match $left {
$( $pattern )|+ $( if $guard )? => {}
ref left_val => {
panic!(concat!(r#"
assertion failed: `(left matches right)`
left: `{:?}`,
right: `{}`
"#, $msg), left_val, stringify!($($pattern)|+ $(if $guard)?));
}
}
};

($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $msg:literal, $($arg:tt)+) => {
match $left {
$( $pattern )|+ $( if $guard )? => {}
ref left_val => {
panic!(concat!(r#"
assertion failed: `(left matches right)`
left: `{:?}`,
right: `{}`
"#, $msg), left_val, stringify!($($pattern)|+ $(if $guard)?), $($arg)+);
}
}
}
}

mod asm;
mod block;
mod builder;
Expand Down

0 comments on commit 2b8d905

Please sign in to comment.