diff --git a/tests/ParserTest.php b/tests/ParserTest.php index efbb8a78..9a61ef92 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -74,6 +74,25 @@ public function testParse(): void $this->assertCount(4, $chunks[0]->lines()); } + public function testParseNewFileMode(): void + { + $content = FileUtils::getFileContent(__DIR__ . '/fixtures/test.patch'); + + $diffs = $this->parser->parse($content); + + foreach ($diffs as $diff) { + foreach ($diff->chunks() as $chunk) { + foreach ($chunk->lines() as $index => $line) { + $content = $line->content(); + + if (str_starts_with($content, 'new file mode')) { + self::fail('Line #' . $index + 1 . ' in chunk ' . $chunk->start() . ' of diff ' . $diff->to() . ' is invalid'); + } + } + } + } + } + public function testParseWithMultipleChunks(): void { $content = FileUtils::getFileContent(__DIR__ . '/fixtures/patch2.txt'); diff --git a/tests/fixtures/test.patch b/tests/fixtures/test.patch new file mode 100644 index 00000000..b13e3787 --- /dev/null +++ b/tests/fixtures/test.patch @@ -0,0 +1,14 @@ +diff --git a/file1.txt b/file1.txt +new file mode 100644 +--- /dev/null ++++ b/file1.txt +@@ -0,0 +1,2 @@ ++Line A ++Line B +diff --git a/file2.txt b/file2.txt +new file mode 100644 +--- /dev/null ++++ b/file2.txt +@@ -0,0 +1,2 @@ ++Line X ++Line Y