diff options
Diffstat (limited to 'test_util/src/assertions.rs')
-rw-r--r-- | test_util/src/assertions.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test_util/src/assertions.rs b/test_util/src/assertions.rs new file mode 100644 index 000000000..ecee14b1f --- /dev/null +++ b/test_util/src/assertions.rs @@ -0,0 +1,39 @@ +#[macro_export] +macro_rules! assert_ends_with { + ($left:expr, $right:expr $(,)?) => { + match (&$left, &$right) { + (actual, expected) => { + let actual = if expected.len() > actual.len() { + actual + } else { + &actual[actual.len() - expected.len()..] + }; + pretty_assertions::assert_eq!( + actual, + *expected, + "should end with expected." + ); + } + } + }; +} + +#[macro_export] +macro_rules! assert_contains { + ($string:expr, $($test:expr),+ $(,)?) => { + let string = &$string; // This might be a function call or something + if !($(string.contains($test))||+) { + panic!("{:?} does not contain any of {:?}", string, [$($test),+]); + } + } +} + +#[macro_export] +macro_rules! assert_not_contains { + ($string:expr, $($test:expr),+ $(,)?) => { + let string = &$string; // This might be a function call or something + if !($(!string.contains($test))||+) { + panic!("{:?} contained {:?}", string, [$($test),+]); + } + } +} |