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());
|
let mut d = crate::algorithms::Replace::new(crate::algorithms::Capture::new());
|
||||||
diff_slices(&mut d, a, b).unwrap();
|
diff_slices(&mut d, a, b).unwrap();
|
||||||
insta::assert_debug_snapshot!(d.into_inner().ops(), @r###"
|
insta::assert_debug_snapshot!(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,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -214,32 +195,7 @@ fn test_contiguous() {
|
||||||
|
|
||||||
let mut d = crate::algorithms::Replace::new(crate::algorithms::Capture::new());
|
let mut d = crate::algorithms::Replace::new(crate::algorithms::Capture::new());
|
||||||
diff_slices(&mut d, a, b).unwrap();
|
diff_slices(&mut d, a, b).unwrap();
|
||||||
insta::assert_debug_snapshot!(d.into_inner().ops(), @r###"
|
insta::assert_debug_snapshot!(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,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -249,33 +205,5 @@ fn test_pat() {
|
||||||
|
|
||||||
let mut d = crate::algorithms::Capture::new();
|
let mut d = crate::algorithms::Capture::new();
|
||||||
diff_slices(&mut d, a, b).unwrap();
|
diff_slices(&mut d, a, b).unwrap();
|
||||||
insta::assert_debug_snapshot!(d.ops(), @r###"
|
insta::assert_debug_snapshot!(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,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,71 +183,17 @@ fn test_patience() {
|
||||||
let mut d = Replace::new(crate::algorithms::Capture::new());
|
let mut d = Replace::new(crate::algorithms::Capture::new());
|
||||||
diff_slices(&mut d, a, b).unwrap();
|
diff_slices(&mut d, a, b).unwrap();
|
||||||
|
|
||||||
insta::assert_debug_snapshot!(d.into_inner().ops(), @r###"
|
insta::assert_debug_snapshot!(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,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_patience_out_of_bounds_bug() {
|
fn test_patience_out_of_bounds_bug() {
|
||||||
|
// this used to be a bug
|
||||||
let a: &[usize] = &[1, 2, 3, 4];
|
let a: &[usize] = &[1, 2, 3, 4];
|
||||||
let b: &[usize] = &[1, 2, 3];
|
let b: &[usize] = &[1, 2, 3];
|
||||||
|
|
||||||
let mut d = Replace::new(crate::algorithms::Capture::new());
|
let mut d = Replace::new(crate::algorithms::Capture::new());
|
||||||
diff_slices(&mut d, a, b).unwrap();
|
diff_slices(&mut d, a, b).unwrap();
|
||||||
|
|
||||||
insta::assert_debug_snapshot!(d.into_inner().ops(), @r###"
|
insta::assert_debug_snapshot!(d.into_inner().ops());
|
||||||
[
|
|
||||||
Equal {
|
|
||||||
old_index: 0,
|
|
||||||
new_index: 0,
|
|
||||||
len: 3,
|
|
||||||
},
|
|
||||||
Delete {
|
|
||||||
old_index: 3,
|
|
||||||
old_len: 1,
|
|
||||||
new_index: 3,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
},
|
||||||
|
]
|
||||||
22
src/snapshots/similar__text__captured_ops.snap
Normal file
22
src/snapshots/similar__text__captured_ops.snap
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
---
|
||||||
|
source: src/text.rs
|
||||||
|
expression: "&diff.ops()"
|
||||||
|
---
|
||||||
|
[
|
||||||
|
Equal {
|
||||||
|
old_index: 0,
|
||||||
|
new_index: 0,
|
||||||
|
len: 1,
|
||||||
|
},
|
||||||
|
Replace {
|
||||||
|
old_index: 1,
|
||||||
|
old_len: 1,
|
||||||
|
new_index: 1,
|
||||||
|
new_len: 1,
|
||||||
|
},
|
||||||
|
Equal {
|
||||||
|
old_index: 2,
|
||||||
|
new_index: 2,
|
||||||
|
len: 1,
|
||||||
|
},
|
||||||
|
]
|
||||||
39
src/snapshots/similar__text__char_diff.snap
Normal file
39
src/snapshots/similar__text__char_diff.snap
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
---
|
||||||
|
source: src/text.rs
|
||||||
|
expression: diff.ops()
|
||||||
|
---
|
||||||
|
[
|
||||||
|
Equal {
|
||||||
|
old_index: 0,
|
||||||
|
new_index: 0,
|
||||||
|
len: 1,
|
||||||
|
},
|
||||||
|
Replace {
|
||||||
|
old_index: 1,
|
||||||
|
old_len: 1,
|
||||||
|
new_index: 1,
|
||||||
|
new_len: 1,
|
||||||
|
},
|
||||||
|
Equal {
|
||||||
|
old_index: 2,
|
||||||
|
new_index: 2,
|
||||||
|
len: 5,
|
||||||
|
},
|
||||||
|
Replace {
|
||||||
|
old_index: 7,
|
||||||
|
old_len: 2,
|
||||||
|
new_index: 7,
|
||||||
|
new_len: 1,
|
||||||
|
},
|
||||||
|
Equal {
|
||||||
|
old_index: 9,
|
||||||
|
new_index: 8,
|
||||||
|
len: 1,
|
||||||
|
},
|
||||||
|
Replace {
|
||||||
|
old_index: 10,
|
||||||
|
old_len: 1,
|
||||||
|
new_index: 9,
|
||||||
|
new_len: 1,
|
||||||
|
},
|
||||||
|
]
|
||||||
42
src/snapshots/similar__text__line_ops.snap
Normal file
42
src/snapshots/similar__text__line_ops.snap
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
---
|
||||||
|
source: src/text.rs
|
||||||
|
expression: "&changes"
|
||||||
|
---
|
||||||
|
[
|
||||||
|
Change {
|
||||||
|
tag: Equal,
|
||||||
|
old_index: Some(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
new_index: Some(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
value: "Hello World\n",
|
||||||
|
},
|
||||||
|
Change {
|
||||||
|
tag: Delete,
|
||||||
|
old_index: Some(
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
new_index: None,
|
||||||
|
value: "some stuff here\n",
|
||||||
|
},
|
||||||
|
Change {
|
||||||
|
tag: Insert,
|
||||||
|
old_index: None,
|
||||||
|
new_index: Some(
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
value: "some amazing stuff here\n",
|
||||||
|
},
|
||||||
|
Change {
|
||||||
|
tag: Equal,
|
||||||
|
old_index: Some(
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
new_index: Some(
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
value: "some more stuff here\n",
|
||||||
|
},
|
||||||
|
]
|
||||||
11
src/snapshots/similar__text__unified_diff.snap
Normal file
11
src/snapshots/similar__text__unified_diff.snap
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
source: src/text.rs
|
||||||
|
expression: "&diff.unified_diff(3, Some((\"old\", \"new\")))"
|
||||||
|
---
|
||||||
|
--- old
|
||||||
|
+++ new
|
||||||
|
@@ -0 +2 @@
|
||||||
|
Hello World
|
||||||
|
-some stuff here
|
||||||
|
+some amazing stuff here
|
||||||
|
some more stuff here
|
||||||
78
src/text.rs
78
src/text.rs
|
|
@ -605,26 +605,7 @@ fn test_captured_ops() {
|
||||||
"Hello World\nsome stuff here\nsome more stuff here\n",
|
"Hello World\nsome stuff here\nsome more stuff here\n",
|
||||||
"Hello World\nsome amazing stuff here\nsome more stuff here\n",
|
"Hello World\nsome amazing stuff here\nsome more stuff here\n",
|
||||||
);
|
);
|
||||||
insta::assert_debug_snapshot!(&diff.ops(), @r###"
|
insta::assert_debug_snapshot!(&diff.ops());
|
||||||
[
|
|
||||||
Equal {
|
|
||||||
old_index: 0,
|
|
||||||
new_index: 0,
|
|
||||||
len: 1,
|
|
||||||
},
|
|
||||||
Replace {
|
|
||||||
old_index: 1,
|
|
||||||
old_len: 1,
|
|
||||||
new_index: 1,
|
|
||||||
new_len: 1,
|
|
||||||
},
|
|
||||||
Equal {
|
|
||||||
old_index: 2,
|
|
||||||
new_index: 2,
|
|
||||||
len: 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -634,15 +615,7 @@ fn test_unified_diff() {
|
||||||
"Hello World\nsome amazing stuff here\nsome more stuff here\n",
|
"Hello World\nsome amazing stuff here\nsome more stuff here\n",
|
||||||
);
|
);
|
||||||
assert_eq!(diff.newline_terminated(), true);
|
assert_eq!(diff.newline_terminated(), true);
|
||||||
insta::assert_snapshot!(&diff.unified_diff(3, Some(("old", "new"))), @r###"
|
insta::assert_snapshot!(&diff.unified_diff(3, Some(("old", "new"))));
|
||||||
--- old
|
|
||||||
+++ new
|
|
||||||
@@ -0 +2 @@
|
|
||||||
Hello World
|
|
||||||
-some stuff here
|
|
||||||
+some amazing stuff here
|
|
||||||
some more stuff here
|
|
||||||
"###);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -657,44 +630,11 @@ fn test_line_ops() {
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|op| diff.iter_changes(op))
|
.flat_map(|op| diff.iter_changes(op))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
insta::assert_debug_snapshot!(&changes, @r###"
|
insta::assert_debug_snapshot!(&changes);
|
||||||
[
|
}
|
||||||
Change {
|
|
||||||
tag: Equal,
|
#[test]
|
||||||
old_index: Some(
|
fn test_char_diff() {
|
||||||
0,
|
let diff = TextDiff::from_chars("Hello World", "Hallo Welt");
|
||||||
),
|
insta::assert_debug_snapshot!(diff.ops());
|
||||||
new_index: Some(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
value: "Hello World\n",
|
|
||||||
},
|
|
||||||
Change {
|
|
||||||
tag: Delete,
|
|
||||||
old_index: Some(
|
|
||||||
1,
|
|
||||||
),
|
|
||||||
new_index: None,
|
|
||||||
value: "some stuff here\n",
|
|
||||||
},
|
|
||||||
Change {
|
|
||||||
tag: Insert,
|
|
||||||
old_index: None,
|
|
||||||
new_index: Some(
|
|
||||||
1,
|
|
||||||
),
|
|
||||||
value: "some amazing stuff here\n",
|
|
||||||
},
|
|
||||||
Change {
|
|
||||||
tag: Equal,
|
|
||||||
old_index: Some(
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
new_index: Some(
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
value: "some more stuff here\n",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue