1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00
denoland-deno/test_util/src/assertions.rs
David Sherret e66d3c2c2e
refactor: remove DENO_UNSTABLE_NPM_SYNC_DOWNLOAD and custom sync functionality (#20504)
https://github.com/denoland/deno/pull/20488 enables us to remove this
functionality. This is better because our test suite is now not testing
a separate code path.
2023-09-14 17:51:28 +00:00

94 lines
2.6 KiB
Rust

// Copyright 2018-2023 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");
}
}
}
}