warpdotdev/warp, scoped to crates/fuzzy_match, at 714c51f1e2: the project's own tests caught 32 of 37 planted faults, 5 got through, and corral proved 3 of those missing tests by writing a test and running it.
#[cfg(test)]
mod corral_tests_2 {
use super::super::*;
#[test]
fn test_wildcard_star_single_char_match_and_bounds() {
let text = "prefix_a12b";
let pattern = "a?*b";
let result = match_wildcard_pattern(text, pattern);
assert!(result.is_some());
let match_result = result.unwrap();
let char_count = text.chars().count();
assert!(!match_result.matched_indices.is_empty());
for &idx in &match_result.matched_indices {
assert!(
idx < char_count,
"matched index {} is outside character bounds (count: {})",
idx,
char_count
);
}
assert_eq!(match_result.matched_indices, vec![7, 8, 9, 10]);
}
#[test]
fn test_wildcard_star_single_char_in_path_within_bounds() {
let text = "path/file_12a.rs";
let pattern = "file_?*a.rs";
let result = match_wildcard_pattern(text, pattern);
assert!(result.is_some());
let match_result = result.unwrap();
let char_count = text.chars().count();
assert!(!match_result.matched_indices.is_empty());
for &idx in &match_result.matched_indices {
assert!(
idx < char_count,
"matched index {} is outside character bounds (count: {})",
idx,
char_count
);
}
}
#[test]
fn test_glob_match_chars_star_matches_one_character() {
let text_chars: Vec<char> = "a12b".chars().collect();
let pattern_chars: Vec<char> = "a?*b".chars().collect();
assert!(is_glob_match_chars(&text_chars, &pattern_chars));
}
#[test]
fn test_glob_match_star_no_match() {
assert!(!is_glob_match("abc", "*d*"));
assert!(!is_glob_match("test", "*x*y*"));
assert!(!is_glob_match("button.rs", "*/ui/*.rs"));
}
#[test]
fn test_wildcard_pattern_multiple_stars_no_match() {
assert!(match_wildcard_pattern("abc", "*d*").is_none());
assert!(match_wildcard_pattern("button.rs", "*component*button*").is_none());
assert!(match_wildcard_pattern("hello/world", "src/*foo*").is_none());
}
#[test]
fn test_wildcard_case_insensitive_indices_strictly_within_bounds() {
let text = "\u{0130}"; // 'İ' expands from 1 char to 2 chars in lowercase ("i\u{0307}")
let pattern = "??";
let result = match_wildcard_pattern_case_insensitive(text, pattern).expect("pattern should match");
assert_eq!(result.matched_indices, vec![0]);
for &idx in &result.matched_indices {
assert!(
idx < text.chars().count(),
"Matched index {} is not strictly within bounds for text length {}",
idx,
text.chars().count()
);
}
}
}
A proven fault was caught by a test corral wrote and ran; an unproven one was not, so it may be a missing test or a fault no test can see.
s2/m3 · line 555 proven
- if is_glob_match_chars_recursive(text, pattern, i + 1, pattern_idx + 1) {
+ if is_glob_match_chars_recursive(text, pattern, i + 2, pattern_idx + 1) {s3/m5 · line 601 proven
- false + true
s5/m1 · line 663 proven
- .retain(|&idx| idx < text.chars().count()); + .retain(|&idx| idx <= text.chars().count());
s0/m7 · line 475 unproven
- (start_char_idx..start_char_idx + prefix_char_count).collect(); + (start_char_idx..start_char_idx + prefix_char_count + text.chars().count()).collect();
s0/m2 · line 477 unproven
- (start_char_idx..start_char_idx + prefix_char_count).collect(); + (start_char_idx..=text.chars().count()).collect();