Skip to content

Commit 05882be

Browse files
committed
Add test case for file rename with non-100% similarity
1 parent b6e8b32 commit 05882be

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/parse_patch.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use chrono::DateTime;
2-
use gitpatch::{File, FileMetadata, ParseError, Patch};
2+
use gitpatch::{File, FileMetadata, Line, ParseError, Patch};
33

44
use pretty_assertions::assert_eq;
55

@@ -368,3 +368,34 @@ Binary files old.bin and new.bin differ
368368
assert_eq!(patches[0].old.path, "before.py");
369369
assert_eq!(patches[1].old.path, "old.bin");
370370
}
371+
372+
#[test]
373+
fn parses_file_renames_with_some_diff() {
374+
let sample = "\
375+
diff --git a/src/ast.rs b/src/ast-2.rs
376+
similarity index 99%
377+
rename from src/ast.rs
378+
rename to src/ast-2.rs
379+
index d923f10..b47f160 100644
380+
--- a/src/ast.rs
381+
+++ b/src/ast-2.rs
382+
@@ -4,6 +4,7 @@ use std::fmt;
383+
use chrono::{DateTime, FixedOffset};
384+
385+
use crate::parser::{parse_multiple_patches, parse_single_patch, ParseError};
386+
+use new_crate;
387+
388+
/// A complete patch summarizing the differences between two files
389+
#[derive(Debug, Clone, Eq, PartialEq)]
390+
";
391+
392+
let patches = Patch::from_multiple(sample).unwrap();
393+
assert_eq!(patches.len(), 1);
394+
assert_eq!(patches[0].old.path, "a/src/ast.rs");
395+
assert_eq!(patches[0].new.path, "b/src/ast-2.rs");
396+
397+
assert!(patches[0].hunks[0]
398+
.lines
399+
.iter()
400+
.any(|line| matches!(line, Line::Add("use new_crate;"))));
401+
}

0 commit comments

Comments
 (0)