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

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

Merged
merged 2 commits into from
Mar 26, 2022

Conversation

david-crespo
Copy link
Contributor

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

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

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
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
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