testing.rs (607B)
1 #[cfg(test)] 2 #[macro_export] 3 macro_rules! assert_parser { 4 ($e:expr $(,)?) => { 5 assert_parser!($e, "parser did not complete") 6 }; 7 ($e:expr, $($arg:tt)+) => { 8 if let ::std::result::Result::Ok((i, r)) = $e { 9 assert!(i.is_empty(), "did not read EOF, remaining `{i}`"); 10 r 11 } else { 12 panic!($($arg)+) 13 } 14 }; 15 } 16 17 #[cfg(test)] 18 #[macro_export] 19 macro_rules! parser_test { 20 ($p:expr, [ $( $i:literal => $e:expr ),* ]) => { 21 $( 22 assert_eq!($crate::assert_parser!($p($i), "failed with `{}`", $i), $e); 23 )* 24 } 25 }