Use named snapshots for tests
This commit is contained in:
parent
93ded2e62c
commit
18fff98d22
12 changed files with 271 additions and 201 deletions
|
|
@ -185,26 +185,7 @@ fn test_diff() {
|
|||
|
||||
let mut d = crate::algorithms::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,
|
||||
},
|
||||
Replace {
|
||||
old_index: 3,
|
||||
old_len: 1,
|
||||
new_index: 3,
|
||||
new_len: 1,
|
||||
},
|
||||
Equal {
|
||||
old_index: 4,
|
||||
new_index: 4,
|
||||
len: 1,
|
||||
},
|
||||
]
|
||||
"###);
|
||||
insta::assert_debug_snapshot!(d.into_inner().ops());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -214,32 +195,7 @@ fn test_contiguous() {
|
|||
|
||||
let mut d = crate::algorithms::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,
|
||||
},
|
||||
Replace {
|
||||
old_index: 3,
|
||||
old_len: 2,
|
||||
new_index: 3,
|
||||
new_len: 2,
|
||||
},
|
||||
Equal {
|
||||
old_index: 5,
|
||||
new_index: 5,
|
||||
len: 2,
|
||||
},
|
||||
Replace {
|
||||
old_index: 7,
|
||||
old_len: 1,
|
||||
new_index: 7,
|
||||
new_len: 1,
|
||||
},
|
||||
]
|
||||
"###);
|
||||
insta::assert_debug_snapshot!(d.into_inner().ops());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -249,33 +205,5 @@ fn test_pat() {
|
|||
|
||||
let mut d = crate::algorithms::Capture::new();
|
||||
diff_slices(&mut d, a, b).unwrap();
|
||||
insta::assert_debug_snapshot!(d.ops(), @r###"
|
||||
[
|
||||
Equal {
|
||||
old_index: 0,
|
||||
new_index: 0,
|
||||
len: 2,
|
||||
},
|
||||
Delete {
|
||||
old_index: 2,
|
||||
old_len: 1,
|
||||
new_index: 2,
|
||||
},
|
||||
Equal {
|
||||
old_index: 3,
|
||||
new_index: 2,
|
||||
len: 2,
|
||||
},
|
||||
Insert {
|
||||
old_index: 5,
|
||||
new_index: 4,
|
||||
new_len: 1,
|
||||
},
|
||||
Insert {
|
||||
old_index: 5,
|
||||
new_index: 5,
|
||||
new_len: 1,
|
||||
},
|
||||
]
|
||||
"###);
|
||||
insta::assert_debug_snapshot!(d.ops());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,71 +183,17 @@ fn test_patience() {
|
|||
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###"
|
||||
[
|
||||
Replace {
|
||||
old_index: 0,
|
||||
old_len: 1,
|
||||
new_index: 0,
|
||||
new_len: 1,
|
||||
},
|
||||
Equal {
|
||||
old_index: 1,
|
||||
new_index: 1,
|
||||
len: 3,
|
||||
},
|
||||
Replace {
|
||||
old_index: 4,
|
||||
old_len: 2,
|
||||
new_index: 4,
|
||||
new_len: 2,
|
||||
},
|
||||
Equal {
|
||||
old_index: 6,
|
||||
new_index: 6,
|
||||
len: 2,
|
||||
},
|
||||
Replace {
|
||||
old_index: 8,
|
||||
old_len: 1,
|
||||
new_index: 8,
|
||||
new_len: 1,
|
||||
},
|
||||
Equal {
|
||||
old_index: 9,
|
||||
new_index: 9,
|
||||
len: 1,
|
||||
},
|
||||
Replace {
|
||||
old_index: 10,
|
||||
old_len: 1,
|
||||
new_index: 10,
|
||||
new_len: 1,
|
||||
},
|
||||
]
|
||||
"###);
|
||||
insta::assert_debug_snapshot!(d.into_inner().ops());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_patience_out_of_bounds_bug() {
|
||||
// this used to be a 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,
|
||||
},
|
||||
]
|
||||
"###);
|
||||
insta::assert_debug_snapshot!(d.into_inner().ops());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
source: src/algorithms/myers.rs
|
||||
expression: d.into_inner().ops()
|
||||
---
|
||||
[
|
||||
Equal {
|
||||
old_index: 0,
|
||||
new_index: 0,
|
||||
len: 3,
|
||||
},
|
||||
Replace {
|
||||
old_index: 3,
|
||||
old_len: 2,
|
||||
new_index: 3,
|
||||
new_len: 2,
|
||||
},
|
||||
Equal {
|
||||
old_index: 5,
|
||||
new_index: 5,
|
||||
len: 2,
|
||||
},
|
||||
Replace {
|
||||
old_index: 7,
|
||||
old_len: 1,
|
||||
new_index: 7,
|
||||
new_len: 1,
|
||||
},
|
||||
]
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: src/algorithms/myers.rs
|
||||
expression: d.into_inner().ops()
|
||||
---
|
||||
[
|
||||
Equal {
|
||||
old_index: 0,
|
||||
new_index: 0,
|
||||
len: 3,
|
||||
},
|
||||
Replace {
|
||||
old_index: 3,
|
||||
old_len: 1,
|
||||
new_index: 3,
|
||||
new_len: 1,
|
||||
},
|
||||
Equal {
|
||||
old_index: 4,
|
||||
new_index: 4,
|
||||
len: 1,
|
||||
},
|
||||
]
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: src/algorithms/myers.rs
|
||||
expression: d.ops()
|
||||
---
|
||||
[
|
||||
Equal {
|
||||
old_index: 0,
|
||||
new_index: 0,
|
||||
len: 2,
|
||||
},
|
||||
Delete {
|
||||
old_index: 2,
|
||||
old_len: 1,
|
||||
new_index: 2,
|
||||
},
|
||||
Equal {
|
||||
old_index: 3,
|
||||
new_index: 2,
|
||||
len: 2,
|
||||
},
|
||||
Insert {
|
||||
old_index: 5,
|
||||
new_index: 4,
|
||||
new_len: 1,
|
||||
},
|
||||
Insert {
|
||||
old_index: 5,
|
||||
new_index: 5,
|
||||
new_len: 1,
|
||||
},
|
||||
]
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
source: src/algorithms/patience.rs
|
||||
expression: d.into_inner().ops()
|
||||
---
|
||||
[
|
||||
Replace {
|
||||
old_index: 0,
|
||||
old_len: 1,
|
||||
new_index: 0,
|
||||
new_len: 1,
|
||||
},
|
||||
Equal {
|
||||
old_index: 1,
|
||||
new_index: 1,
|
||||
len: 3,
|
||||
},
|
||||
Replace {
|
||||
old_index: 4,
|
||||
old_len: 2,
|
||||
new_index: 4,
|
||||
new_len: 2,
|
||||
},
|
||||
Equal {
|
||||
old_index: 6,
|
||||
new_index: 6,
|
||||
len: 2,
|
||||
},
|
||||
Replace {
|
||||
old_index: 8,
|
||||
old_len: 1,
|
||||
new_index: 8,
|
||||
new_len: 1,
|
||||
},
|
||||
Equal {
|
||||
old_index: 9,
|
||||
new_index: 9,
|
||||
len: 1,
|
||||
},
|
||||
Replace {
|
||||
old_index: 10,
|
||||
old_len: 1,
|
||||
new_index: 10,
|
||||
new_len: 1,
|
||||
},
|
||||
]
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
source: src/algorithms/patience.rs
|
||||
expression: d.into_inner().ops()
|
||||
---
|
||||
[
|
||||
Equal {
|
||||
old_index: 0,
|
||||
new_index: 0,
|
||||
len: 3,
|
||||
},
|
||||
Delete {
|
||||
old_index: 3,
|
||||
old_len: 1,
|
||||
new_index: 3,
|
||||
},
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue