Skip to content

Commit e86891c

Browse files
uniphilwhitty
authored andcommitted
restore trailing tab for parser test_headers
also add one more test for binary differing
1 parent 5a3b88d commit e86891c

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/parser.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,10 @@ mod tests {
501501
File {path: "tzu".into(), meta: None},
502502
));
503503

504+
// note: the trailing tab after lao is intentional and significant here
505+
// see https://github.com/uniphil/patch-rs/commit/364897dae8599cdb758c00fdc8dacd1645959070
504506
let sample2b = "\
505-
--- lao
507+
--- lao
506508
+++ tzu \n";
507509
test_parser!(headers(sample2b) -> (
508510
File {path: "lao".into(), meta: None},

tests/.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Tell editors to allow whitespace violations in source
2+
[parse_patch.rs]
3+
trim_trailing_whitespace = false
4+
5+
# This shouldn't be needed
6+
[*.{diff,patch}]
7+
trim_trailing_whitespace = false

tests/parse_patch.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,37 @@ rename to new-path.rs
416416
assert_eq!(patches[0].new.path, "new-path.rs");
417417
assert!(patches[0].hunks.is_empty());
418418
}
419+
420+
#[test]
421+
fn binary_diff_interspersed_with_text_diff() {
422+
let sample = "\
423+
--- before.py
424+
+++ after.py
425+
@@ -1,4 +1,4 @@
426+
-bacon
427+
-eggs
428+
-ham
429+
+python
430+
+eggy
431+
+hamster
432+
guido
433+
Binary files old.bin and new.bin differ
434+
--- before2.py
435+
+++ after2.py
436+
@@ -1,4 +1,4 @@
437+
-bacon
438+
-eggs
439+
-ham
440+
+python
441+
+eggy
442+
+hamster
443+
guido
444+
Binary files old2.bin and new2.bin differ
445+
";
446+
let patches = Patch::from_multiple(sample).unwrap();
447+
assert_eq!(patches.len(), 4);
448+
assert_eq!(patches[0].old.path, "before.py");
449+
assert_eq!(patches[1].old.path, "old.bin");
450+
assert_eq!(patches[2].new.path, "after2.py");
451+
assert_eq!(patches[3].new.path, "new2.bin");
452+
}

0 commit comments

Comments
 (0)