Fix bug in patience

This commit is contained in:
Armin Ronacher 2021-01-24 03:01:40 +01:00
parent 89729de117
commit 5dca6ae665
3 changed files with 34 additions and 5 deletions

View file

@ -30,7 +30,7 @@ where
D: DiffHook,
{
let old_indexes = unique(old, old_range.start, old_range.end);
let new_indexes = unique(new, old_range.start, old_range.end);
let new_indexes = unique(new, new_range.start, new_range.end);
let mut d = Replace::new(Patience {
d,
@ -227,3 +227,27 @@ fn test_patience() {
]
"###);
}
#[test]
fn test_patience_out_of_bounds_bug() {
let a: &[usize] = &[1, 2, 3, 4];
let b: &[usize] = &[1, 2, 3];
let mut d = Replace::new(crate::algorithms::Capture::new());
diff_slices(&mut d, a, b).unwrap();
insta::assert_debug_snapshot!(d.into_inner().ops(), @r###"
[
Equal {
old_index: 0,
new_index: 0,
len: 3,
},
Delete {
old_index: 3,
old_len: 1,
new_index: 3,
},
]
"###);
}