diff options
| author | Asher Gomez <ashersaupingomez@gmail.com> | 2024-02-20 00:34:24 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-19 06:34:24 -0700 |
| commit | 2b279ad630651e973d5a31586f58809f005bc925 (patch) | |
| tree | 3e3cbeb4126643c75381dd5422e8603a7488bb8a /tests/util/server/src/assertions.rs | |
| parent | eb542bc185c6c4ce1847417a2dfdf04862cd86db (diff) | |
chore: move `test_util` to `tests/util/server` (#22444)
As discussed with @mmastrac.
---------
Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
Diffstat (limited to 'tests/util/server/src/assertions.rs')
| -rw-r--r-- | tests/util/server/src/assertions.rs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/util/server/src/assertions.rs b/tests/util/server/src/assertions.rs new file mode 100644 index 000000000..b9aba9354 --- /dev/null +++ b/tests/util/server/src/assertions.rs @@ -0,0 +1,94 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use crate::colors; + +#[macro_export] +macro_rules! assert_starts_with { + ($string:expr, $($test:expr),+) => { + let string = $string; // This might be a function call or something + if !($(string.starts_with($test))||+) { + panic!("{:?} does not start with {:?}", string, [$($test),+]); + } + } +} + +#[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),+]); + } + } +} + +#[track_caller] +pub fn assert_wildcard_match(actual: &str, expected: &str) { + if !expected.contains("[WILDCARD]") && !expected.contains("[UNORDERED_START]") + { + pretty_assertions::assert_eq!(actual, expected); + } else { + match crate::wildcard_match_detailed(expected, actual) { + crate::WildcardMatchResult::Success => { + // ignore + } + crate::WildcardMatchResult::Fail(debug_output) => { + println!( + "{}{}{}", + colors::bold("-- "), + colors::bold_red("OUTPUT"), + colors::bold(" START --"), + ); + println!("{}", actual); + println!("{}", colors::bold("-- OUTPUT END --")); + println!( + "{}{}{}", + colors::bold("-- "), + colors::bold_green("EXPECTED"), + colors::bold(" START --"), + ); + println!("{}", expected); + println!("{}", colors::bold("-- EXPECTED END --")); + println!( + "{}{}{}", + colors::bold("-- "), + colors::bold_blue("DEBUG"), + colors::bold(" START --"), + ); + println!("{debug_output}"); + println!("{}", colors::bold("-- DEBUG END --")); + panic!("pattern match failed"); + } + } + } +} |
