Make the change type be generic over any T rather &T (#31)
This makes the interface of this crate more flexible as the utility methods such as `iter_changes` now also work if a container does not contain references.
This commit is contained in:
parent
0b8e237280
commit
a3e10af892
7 changed files with 75 additions and 37 deletions
|
|
@ -159,3 +159,27 @@ pub fn group_diff_ops(mut ops: Vec<DiffOp>, n: usize) -> Vec<Vec<DiffOp>> {
|
|||
|
||||
rv
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_non_string_iter_change() {
|
||||
use crate::ChangeTag;
|
||||
|
||||
let old = vec![1, 2, 3];
|
||||
let new = vec![1, 2, 4];
|
||||
let ops = capture_diff_slices(Algorithm::Myers, &old, &new);
|
||||
let changes: Vec<_> = ops
|
||||
.iter()
|
||||
.flat_map(|x| x.iter_changes(&old, &new))
|
||||
.map(|x| (x.tag(), x.value()))
|
||||
.collect();
|
||||
|
||||
assert_eq!(
|
||||
changes,
|
||||
vec![
|
||||
(ChangeTag::Equal, 1),
|
||||
(ChangeTag::Equal, 2),
|
||||
(ChangeTag::Delete, 3),
|
||||
(ChangeTag::Insert, 4),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue