diff --git a/src/parser.rs b/src/parser.rs index 487f3e2..62f9699 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 +++ tzu \n"; test_parser!(headers(sample2b) -> ( File {path: "lao".into(), meta: None}, diff --git a/tests/.editorconfig b/tests/.editorconfig new file mode 100644 index 0000000..b621cc1 --- /dev/null +++ b/tests/.editorconfig @@ -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 diff --git a/tests/parse_patch.rs b/tests/parse_patch.rs index da25ada..14bcb87 100644 --- a/tests/parse_patch.rs +++ b/tests/parse_patch.rs @@ -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"); +}