diff --git a/CHANGELOG.md b/CHANGELOG.md index 138bd83..b9fe103 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to similar are documented here. +## 0.2.0 + +* Fixed a bug in the patience algorithm causing it not not work. + ## 0.1.0 * Initial release. diff --git a/README.md b/README.md index 82b1b0c..42bd5d5 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,12 @@ [![Documentation](https://docs.rs/similar/badge.svg)](https://docs.rs/similar) Similar is a dependency free crate for Rust that implements different diffing -algorithms and high level interfaces for it. +algorithms and high level interfaces for it. It is based on the [pijul](https://pijul.org/) +implementation of the Myer's and Patience algorithms and inherits some ideas +from there. -It provides both low level implementations of Myer's and the Patience diff -algorithm as well as high level text diffing utilities (such as the ability -to generate unified diffs). +It's intended to be replacement for the popular but unmaintained +[difference] crate. ```rust use similar::algorithms::Algorithm; diff --git a/src/algorithms/patience.rs b/src/algorithms/patience.rs index 0cbbd52..29b1535 100644 --- a/src/algorithms/patience.rs +++ b/src/algorithms/patience.rs @@ -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, + }, + ] + "###); +}