diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-06-21 15:25:07 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-21 15:25:07 -0400 |
commit | 3455f16079c2ca676e092d2123b8895e68e1a3ee (patch) | |
tree | cccbca198d8f4e375b6e90b6415acffad532589a /test_util/src/assertions.rs | |
parent | 7ad0d092281c040c5c5be4ba0415f3e7551201de (diff) |
chore(test_util): add new string assertion macros (#14928)
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),+]); + } + } +} |