Add diff tests

This commit is contained in:
Andras Schmelczer 2025-04-05 09:45:44 +01:00
parent 0c6d36041c
commit 5bb420e162
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 233 additions and 0 deletions

View file

@ -282,3 +282,57 @@ fn conquer<T>(
));
}
}
#[cfg(test)]
mod tests {
use insta::assert_debug_snapshot;
use super::*;
#[test]
fn test_empty_diff() {
let old: Vec<Token<String>> = vec![];
let new: Vec<Token<String>> = vec![];
let result = diff(&old, &new);
assert_eq!(result.len(), 0);
}
#[test]
fn test_identical_content() {
let content = vec!["a".into(), "b".into(), "c".into()];
let result = diff(&content, &content);
assert_debug_snapshot!(result);
}
#[test]
fn test_insert_only() {
let old: Vec<Token<String>> = vec![];
let new: Vec<Token<String>> = vec!["a".into(), "b".into()];
let result = diff(&old, &new);
assert_debug_snapshot!(result);
}
#[test]
fn test_delete_only() {
let old = vec!["a".into(), "b".into()];
let new: Vec<Token<String>> = vec![];
let result = diff(&old, &new);
assert_debug_snapshot!(result);
}
#[test]
fn test_prefix_and_suffix() {
let old = vec!["a".into(), "b".into(), "c".into(), "d".into()];
let new = vec!["a".into(), "x".into(), "d".into()];
let result = diff(&old, &new);
assert_debug_snapshot!(result);
}
#[test]
fn test_complex_diff() {
let old = vec!["a".into(), "b".into(), "c".into(), "d".into()];
let new = vec!["a".into(), "x".into(), "c".into(), "y".into()];
let result = diff(&old, &new);
assert_debug_snapshot!(result);
}
}

View file

@ -0,0 +1,55 @@
---
source: reconcile/src/diffs/myers.rs
expression: result
snapshot_kind: text
---
[
Equal(
[
Token {
normalised: "a",
original: "a",
},
],
),
Insert(
[
Token {
normalised: "x",
original: "x",
},
],
),
Delete(
[
Token {
normalised: "b",
original: "b",
},
],
),
Equal(
[
Token {
normalised: "c",
original: "c",
},
],
),
Insert(
[
Token {
normalised: "y",
original: "y",
},
],
),
Delete(
[
Token {
normalised: "d",
original: "d",
},
],
),
]

View file

@ -0,0 +1,19 @@
---
source: reconcile/src/diffs/myers.rs
expression: result
snapshot_kind: text
---
[
Delete(
[
Token {
normalised: "a",
original: "a",
},
Token {
normalised: "b",
original: "b",
},
],
),
]

View file

@ -0,0 +1,23 @@
---
source: reconcile/src/diffs/myers.rs
expression: result
snapshot_kind: text
---
[
Equal(
[
Token {
normalised: "a",
original: "a",
},
Token {
normalised: "b",
original: "b",
},
Token {
normalised: "c",
original: "c",
},
],
),
]

View file

@ -0,0 +1,19 @@
---
source: reconcile/src/diffs/myers.rs
expression: result
snapshot_kind: text
---
[
Insert(
[
Token {
normalised: "a",
original: "a",
},
Token {
normalised: "b",
original: "b",
},
],
),
]

View file

@ -0,0 +1,43 @@
---
source: reconcile/src/diffs/myers.rs
expression: result
snapshot_kind: text
---
[
Equal(
[
Token {
normalised: "a",
original: "a",
},
],
),
Delete(
[
Token {
normalised: "b",
original: "b",
},
Token {
normalised: "c",
original: "c",
},
],
),
Insert(
[
Token {
normalised: "x",
original: "x",
},
],
),
Equal(
[
Token {
normalised: "d",
original: "d",
},
],
),
]

View file

@ -0,0 +1,20 @@
parent: Hello!
left: |
Hello there!
How are you?
right: |
Hello there!
Best,
Andras
expected: |
Hello there!
How are you?
Best,
Andras