mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Make escape_test an ordinary function
This did not need to be a macro.
This commit is contained in:
parent
7b0f9fd5f8
commit
a99fa201b6
1 changed files with 23 additions and 25 deletions
|
@ -97,45 +97,43 @@ fn test_escape_var() {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! escape_test {
|
||||
($escape_style:expr, $unescape_style:expr) => {
|
||||
setlocale();
|
||||
let seed: u128 = 92348567983274852905629743984572;
|
||||
let mut rng = Pcg64Mcg::new(seed);
|
||||
fn escape_test(escape_style: EscapeStringStyle, unescape_style: UnescapeStringStyle) {
|
||||
setlocale();
|
||||
let seed: u128 = 92348567983274852905629743984572;
|
||||
let mut rng = Pcg64Mcg::new(seed);
|
||||
|
||||
let mut random_string = WString::new();
|
||||
let mut escaped_string;
|
||||
for _ in 0..(ESCAPE_TEST_COUNT as u32) {
|
||||
random_string.clear();
|
||||
let length = rng.gen_range(0..=(2 * ESCAPE_TEST_LENGTH));
|
||||
for _ in 0..length {
|
||||
random_string
|
||||
.push(char::from_u32((rng.next_u32() % ESCAPE_TEST_CHAR as u32) + 1).unwrap());
|
||||
}
|
||||
|
||||
escaped_string = escape_string(&random_string, $escape_style);
|
||||
let Some(unescaped_string) = unescape_string(&escaped_string, $unescape_style) else {
|
||||
let slice = escaped_string.as_char_slice();
|
||||
panic!("Failed to unescape string {slice:?}");
|
||||
};
|
||||
assert_eq!(random_string, unescaped_string, "Escaped and then unescaped string {random_string:?}, but got back a different string {unescaped_string:?}. The intermediate escape looked like {escaped_string:?}.");
|
||||
let mut random_string = WString::new();
|
||||
let mut escaped_string;
|
||||
for _ in 0..(ESCAPE_TEST_COUNT as u32) {
|
||||
random_string.clear();
|
||||
let length = rng.gen_range(0..=(2 * ESCAPE_TEST_LENGTH));
|
||||
for _ in 0..length {
|
||||
random_string
|
||||
.push(char::from_u32((rng.next_u32() % ESCAPE_TEST_CHAR as u32) + 1).unwrap());
|
||||
}
|
||||
};
|
||||
|
||||
escaped_string = escape_string(&random_string, escape_style);
|
||||
let Some(unescaped_string) = unescape_string(&escaped_string, unescape_style) else {
|
||||
let slice = escaped_string.as_char_slice();
|
||||
panic!("Failed to unescape string {slice:?}");
|
||||
};
|
||||
assert_eq!(random_string, unescaped_string, "Escaped and then unescaped string {random_string:?}, but got back a different string {unescaped_string:?}. The intermediate escape looked like {escaped_string:?}.");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_random_script() {
|
||||
escape_test!(EscapeStringStyle::default(), UnescapeStringStyle::default());
|
||||
escape_test(EscapeStringStyle::default(), UnescapeStringStyle::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_random_var() {
|
||||
escape_test!(EscapeStringStyle::Var, UnescapeStringStyle::Var);
|
||||
escape_test(EscapeStringStyle::Var, UnescapeStringStyle::Var);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_random_url() {
|
||||
escape_test!(EscapeStringStyle::Url, UnescapeStringStyle::Url);
|
||||
escape_test(EscapeStringStyle::Url, UnescapeStringStyle::Url);
|
||||
}
|
||||
|
||||
#[widestrs]
|
||||
|
|
Loading…
Reference in a new issue