Skip to content

Commit

Permalink
Merge pull request #97 from cpackham/deleted-file
Browse files Browse the repository at this point in the history
Remove newline from RE_DIFF_GIT_{DELETED,NEW}_FILE
  • Loading branch information
matiasb authored Jun 19, 2022
2 parents bc8a9e9 + a3faffc commit ade972f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
16 changes: 16 additions & 0 deletions tests/samples/git_delete.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/somefile.c b/somefile.c
deleted file mode 100644
index abcdefbbb8..0000000000
--- a/somefile.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/**
- * @file somefile.c
- */
-#include <stdio.h>
-
-int main(int argc, cahr *argv[])
-{
- printf("Hello World\n");
- return 0;
-}
10 changes: 10 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,16 @@ def test_parse_filename_with_spaces(self):
self.assertTrue(res[0].is_added_file)
self.assertEqual(res[0].path, 'has spaces/t.sql')

def test_deleted_file(self):
filename = os.path.join(self.samples_dir, 'samples/git_delete.diff')
with open(filename) as f:
res = PatchSet(f)

self.assertEqual(len(res), 1)
self.assertEqual(res[0].source_file, 'a/somefile.c')
self.assertEqual(res[0].target_file, '/dev/null')
self.assertTrue(res[0].is_removed_file)

def test_diff_lines_linenos(self):
with open(self.sample_file, 'rb') as diff_file:
res = PatchSet(diff_file, encoding='utf-8')
Expand Down
4 changes: 2 additions & 2 deletions unidiff/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
r'^diff --git (?P<source>[^\t\n]+) (?P<target>[^\t\n]+)')

# check diff git new file marker `deleted file mode 100644`
RE_DIFF_GIT_DELETED_FILE = re.compile(r'^deleted file mode \d+\n$')
RE_DIFF_GIT_DELETED_FILE = re.compile(r'^deleted file mode \d+$')

# check diff git new file marker `new file mode 100644`
RE_DIFF_GIT_NEW_FILE = re.compile(r'^new file mode \d+\n$')
RE_DIFF_GIT_NEW_FILE = re.compile(r'^new file mode \d+$')


# @@ (source offset, length) (target offset, length) @@ (section header)
Expand Down

0 comments on commit ade972f

Please sign in to comment.