|
1 | 1 | use chrono::DateTime;
|
2 |
| -use gitpatch::{File, FileMetadata, ParseError, Patch}; |
| 2 | +use gitpatch::{File, FileMetadata, Line, ParseError, Patch}; |
3 | 3 |
|
4 | 4 | use pretty_assertions::assert_eq;
|
5 | 5 |
|
@@ -368,3 +368,34 @@ Binary files old.bin and new.bin differ
|
368 | 368 | assert_eq!(patches[0].old.path, "before.py");
|
369 | 369 | assert_eq!(patches[1].old.path, "old.bin");
|
370 | 370 | }
|
| 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