From 7597288c182071de2a78b445f35f0691ebf332b7 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 19 Jan 2024 06:09:20 +0100 Subject: [PATCH] test_error_messages: add back missing validation Make sure to also look for the error part that occurs after the last format specifier. Still not great because it won't fail if there's unexpected output at the beginning or end of the string. --- src/tests/parse_util.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tests/parse_util.rs b/src/tests/parse_util.rs index eb20e41f8..3b6748f5a 100644 --- a/src/tests/parse_util.rs +++ b/src/tests/parse_util.rs @@ -17,7 +17,7 @@ fn test_error_messages() { // Given a format string, returns a list of non-empty strings separated by format specifiers. The // format specifiers themselves are omitted. fn separate_by_format_specifiers(format: &wstr) -> Vec<&wstr> { - let format_specifier_regex = Regex::new(L!(r"%l?[ds]").as_char_slice()).unwrap(); + let format_specifier_regex = Regex::new(L!(r"%l?[cds]").as_char_slice()).unwrap(); let mut result = vec![]; let mut offset = 0; for mtch in format_specifier_regex.find_iter(format.as_char_slice()) { @@ -25,6 +25,7 @@ fn separate_by_format_specifiers(format: &wstr) -> Vec<&wstr> { result.push(&format[offset..mtch.start()]); offset = mtch.end(); } + result.push(&format[offset..]); result } @@ -33,6 +34,7 @@ fn separate_by_format_specifiers(format: &wstr) -> Vec<&wstr> { // that each of the remaining chunks is found (in order) in the string. fn string_matches_format(s: &wstr, format: &wstr) -> bool { let components = separate_by_format_specifiers(format); + assert!(!components.is_empty()); let mut idx = 0; for component in components { let Some(relpos) = s[idx..].find(component) else {