From d3f9e668bf196f753bc75658e1ef2b965e9215ba Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Fri, 10 Oct 2025 17:17:33 +0200 Subject: [PATCH] Failing test for 'new file mode' --- tests/ParserTest.php | 19 +++++++++++++++++++ tests/fixtures/test.patch | 14 ++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/fixtures/test.patch 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