Treat NovelLinePart as a change

Previously we'd treat it as unchanged, leading to incorrect text diffs
when words were added on a single side.

Fixes #122
html_output
Wilfred Hughes 2022-02-07 20:35:01 +07:00
parent 908c2509d6
commit ab8e8e4485
3 changed files with 13 additions and 1 deletions

@ -28,6 +28,9 @@ Difftastic will now use a text diff for large files, rather than
trying to use more memory than is available. This threshold is
configurable with `--node-limit` and `DFT_NODE_LIMIT`.
Fixed a bug in the text diff logic where lines weren't shown if they
did not have both word additions and word removals.
### Command Line Interface
Difftastic will now error if either argument does not exist, unless

@ -249,6 +249,15 @@ mod tests {
assert!(!positions[0].kind.is_change());
}
#[test]
fn test_positions_whitespace_is_change() {
// Even though the word exists on both sides, it should still
// be treated as a change. We're doing a line-based diff and
// the lines are different.
let positions = change_positions("foo", " foo");
assert!(positions[0].kind.is_change());
}
#[test]
fn test_no_changes_trailing_newlines() {
let positions = change_positions("foo\n", "foo\n");

@ -562,7 +562,7 @@ impl MatchKind {
pub fn is_change(&self) -> bool {
matches!(
self,
MatchKind::Novel { .. } | MatchKind::NovelWord { .. }
MatchKind::Novel { .. } | MatchKind::NovelWord { .. } | MatchKind::NovelLinePart { .. }
)
}
}