diff options
Diffstat (limited to 'internals/src/macros.rs')
-rw-r--r-- | internals/src/macros.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/internals/src/macros.rs b/internals/src/macros.rs new file mode 100644 index 0000000..ac234d7 --- /dev/null +++ b/internals/src/macros.rs @@ -0,0 +1,61 @@ + +/// it's easy to overlook the `!` in `assert!(!this_is.really_eycatching())` +#[cfg(test)] +macro_rules! assert_not { + //direct forward + `!` + ($($t:tt)*) => (assert!(! $($t)*)); +} + +#[cfg(test)] +macro_rules! assert_ok { + ($val:expr) => ({ + match $val { + Ok( res ) => res, + Err( err ) => panic!( "expected Ok(..) got Err({:?})", err) + } + }); + ($val:expr, $ctx:expr) => ({ + match $val { + Ok( res ) => res, + Err( err ) => panic!( "expected Ok(..) got Err({:?}) [ctx: {:?}]", err, $ctx) + } + }); +} + +#[cfg(test)] +macro_rules! assert_err { + ($val:expr) => ({ + match $val { + Ok( val ) => panic!( "expected Err(..) got Ok({:?})", val), + Err( err ) => err, + } + }); + ($val:expr, $ctx:expr) => ({ + match $val { + Ok( val ) => panic!( "expected Err(..) got Ok({:?}) [ctx: {:?}]", val, $ctx), + Err( err ) => err, + } + }); +} + + + + +// macro_rules! deref0 { +// (+mut $name:ident => $tp:ty) => ( +// deref0!{-mut $name => $tp } +// impl ::std::ops::DerefMut for $name { +// fn deref_mut( &mut self ) -> &mut Self::Target { +// &mut self.0 +// } +// } +// ); +// (-mut $name:ident => $tp:ty) => ( +// impl ::std::ops::Deref for $name { +// type Target = $tp; +// fn deref( &self ) -> &Self::Target { +// &self.0 +// } +// } +// ); +// }
\ No newline at end of file |