From a99fa201b618a22c4bff5549ec4b5d61358638b5 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 8 Jul 2023 11:19:44 -0700 Subject: [PATCH] Make escape_test an ordinary function This did not need to be a macro. --- fish-rust/src/tests/string_escape.rs | 48 +++++++++++++--------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/fish-rust/src/tests/string_escape.rs b/fish-rust/src/tests/string_escape.rs index aaf6eec26..d5a34cfc8 100644 --- a/fish-rust/src/tests/string_escape.rs +++ b/fish-rust/src/tests/string_escape.rs @@ -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]