Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/test.patch
Original file line number Diff line number Diff line change
@@ -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