Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text diff of large chunks to not emit last blank line #731

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sample_files/compare.expected
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sample_files/bad_combine_1.rs sample_files/bad_combine_2.rs
f5051bf7d2b8afa3a677388cbd458891 -

sample_files/big_text_hunk_1.txt sample_files/big_text_hunk_2.txt
fd0c8912c094097f82c6b29ae66fb912 -
fc26d41a5ff771670e04033b177973d2 -

sample_files/change_outer_1.el sample_files/change_outer_2.el
2b9334a4cc72da63bba28eff958f0038 -
Expand Down
3 changes: 3 additions & 0 deletions src/line_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ pub(crate) fn change_positions(lhs_src: &str, rhs_src: &str) -> Vec<MatchedPos>
// individual words.
if lhs_words.len() > MAX_WORDS_IN_LINE || rhs_words.len() > MAX_WORDS_IN_LINE {
for lhs_pos in lhs_lp.from_region(lhs_offset, lhs_offset + lhs_part.len()) {
if lhs_pos.start_col == lhs_pos.end_col {
continue; // Omit last blank line
}
mps.push(MatchedPos {
kind: MatchKind::NovelWord {
highlight: TokenKind::Atom(AtomKind::Normal),
Expand Down
40 changes: 40 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,46 @@ fn inline() {
cmd.assert().success();
}

#[test]
fn inline_big_text_hunk() {
let mut cmd = get_base_command();

cmd.arg("--display=inline")
.arg("sample_files/big_text_hunk_1.txt")
.arg("sample_files/big_text_hunk_2.txt");
cmd.assert().success();
}

#[test]
fn side_by_side_big_text_hunk() {
let mut cmd = get_base_command();

cmd.arg("--display=side-by-side")
.arg("sample_files/big_text_hunk_1.txt")
.arg("sample_files/big_text_hunk_2.txt");
cmd.assert().success();
}

#[test]
fn inline_many_newlines() {
let mut cmd = get_base_command();

cmd.arg("--display=inline")
.arg("sample_files/many_newlines_1.txt")
.arg("sample_files/many_newlines_2.txt");
cmd.assert().success();
}

#[test]
fn side_by_side_many_newlines() {
let mut cmd = get_base_command();

cmd.arg("--display=side-by-side")
.arg("sample_files/many_newlines_1.txt")
.arg("sample_files/many_newlines_2.txt");
cmd.assert().success();
}

#[test]
fn binary_changed() {
let mut cmd = get_base_command();
Expand Down
Loading