Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,10 @@ mod tests {
File {path: "tzu".into(), meta: None},
));

// note: the trailing tab after lao is intentional and significant here
// see https://github.com/uniphil/patch-rs/commit/364897dae8599cdb758c00fdc8dacd1645959070
let sample2b = "\
--- lao
--- lao
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can I suggest instead adding a \t into the source so that it's obvious to humans and so we don't risk losing it later?

Suggested change
--- lao
--- lao\t

+++ tzu \n";
test_parser!(headers(sample2b) -> (
File {path: "lao".into(), meta: None},
Expand Down
7 changes: 7 additions & 0 deletions tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Tell editors to allow whitespace violations in source
[parse_patch.rs]
trim_trailing_whitespace = false

# This shouldn't be needed
[*.{diff,patch}]
trim_trailing_whitespace = false
34 changes: 34 additions & 0 deletions tests/parse_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,37 @@ rename to new-path.rs
assert_eq!(patches[0].new.path, "new-path.rs");
assert!(patches[0].hunks.is_empty());
}

#[test]
fn binary_diff_interspersed_with_text_diff() {
let sample = "\
--- before.py
+++ after.py
@@ -1,4 +1,4 @@
-bacon
-eggs
-ham
+python
+eggy
+hamster
guido
Binary files old.bin and new.bin differ
--- before2.py
+++ after2.py
@@ -1,4 +1,4 @@
-bacon
-eggs
-ham
+python
+eggy
+hamster
guido
Binary files old2.bin and new2.bin differ
";
let patches = Patch::from_multiple(sample).unwrap();
assert_eq!(patches.len(), 4);
assert_eq!(patches[0].old.path, "before.py");
assert_eq!(patches[1].old.path, "old.bin");
assert_eq!(patches[2].new.path, "after2.py");
assert_eq!(patches[3].new.path, "new2.bin");
}
Loading