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
Improve diff with "\r\n" and "\n" #100
Comments
Thanks for the report. This looks like an issue in the underlying I think a resolution to this issue would take one of two approaches:
I know that line ending detection is possibly Hard, and would probably require a linear pass over the diffed values. Might not be a big a deal as I initially think though. One benefit of the first approach is that it would be a catch-all to warn about other edge cases such as this, which don't produce good output. We could even make it an error-report style message, like "please open an issue at github.com/... with the following details", but that might actually be annoying to users if seen repetitively during testing. |
For anyone wanting to pick up the first approach (print a warning on no diff), the following diff may be useful:
diff --git a/pretty_assertions/src/printer.rs b/pretty_assertions/src/printer.rs
index af3e3e6..6edba1e 100644
--- a/pretty_assertions/src/printer.rs
+++ b/pretty_assertions/src/printer.rs
@@ -89,7 +89,7 @@ pub(crate) fn write_lines<TWrite: fmt::Write>(
let mut previous_deletion = LatentDeletion::default();
while let Some(change) = changes.next() {
- match (change, changes.peek()) {
+ match (dbg!(change), changes.peek()) {
// If the text is unchanged, just print it plain
(::diff::Result::Both(value, _), _) => {
previous_deletion.flush(f)?;
@@ -594,5 +594,23 @@ Cabbage"#;
check_printer(write_lines, left, right, &expected);
}
+
+ /// Test diffing newlines from different conventions.
+ ///
+ /// See: https://github.com/colin-kiegel/rust-pretty-assertions/issues/100
+ #[test]
+ fn different_newlines() {
+ // The below inputs caused an output with no visible diff
+ let left = "\r\n";
+ let right = "\n";
+ let expected = format!(
+ "
+
+Warning: No diff generated for different values.
+",
+ );
+
+ check_printer(write_lines, left, right, &expected);
+ }
}
} |
I'm gonna try the first approach. |
The output produced by a difference with new lines is not very clear.
To reproduce :
I don't know if that has not been thought or if I am doing something wrong.
The text was updated successfully, but these errors were encountered: