Skip to content

Pretty print unified diff with 5 line before/after window#10

Merged
ahl merged 2 commits into
masterfrom
print-diff-only
Mar 26, 2022
Merged

Pretty print unified diff with 5 line before/after window#10
ahl merged 2 commits into
masterfrom
print-diff-only

Conversation

@david-crespo

@david-crespo david-crespo commented Mar 18, 2022

Copy link
Copy Markdown
Contributor

Closes #9

Tried and failed to make it work with difference and pretty_assertions. Found success with Similar. Very clean.

This is already a net improvement as-is, but some possible improvements:

  • use color
  • increase window size to 10 or something
  • tests could assert what gets printed to stdout instead of only checking for the panic

one line difference

Screen Shot 2022-03-18 at 4 37 22 PM

all lines difference

Screen Shot 2022-03-18 at 4 37 33 PM

Comment thread src/lib.rs Outdated
Changeset::new(expected.as_ref(), actual.as_ref(), "\n");
println!("{}", changeset);
let diff =
unified_diff(Algorithm::Myers, &expected, &actual, 5, None);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Myers is the default algorithm in git, so that seems fine. 5 is the number of lines before and after. None could be replaced with a header representing the two file names, not sure if we care.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there's only one file and it should be clear from context so agreed that it's not useful to add a header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't print the whole file when there's a diff

2 participants