Changeset View
Changeset View
Standalone View
Standalone View
src/parser/__tests__/ArcanistDiffParserTestCase.php
| Show First 20 Lines • Show All 577 Lines • ▼ Show 20 Lines | EOTEXT | ||||
| break; | break; | ||||
| case 'git-format-patch.gitdiff': | case 'git-format-patch.gitdiff': | ||||
| $this->assertEqual(2, count($changes)); | $this->assertEqual(2, count($changes)); | ||||
| $change = array_shift($changes); | $change = array_shift($changes); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| ArcanistDiffChangeType::TYPE_MESSAGE, | ArcanistDiffChangeType::TYPE_MESSAGE, | ||||
| $change->getType()); | $change->getType()); | ||||
| $this->assertEqual("WIP", $change->getMetadata('message')); | $this->assertEqual('WIP', $change->getMetadata('message')); | ||||
| $change = array_shift($changes); | $change = array_shift($changes); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| ArcanistDiffChangeType::TYPE_CHANGE, | ArcanistDiffChangeType::TYPE_CHANGE, | ||||
| $change->getType()); | $change->getType()); | ||||
| break; | break; | ||||
| default: | default: | ||||
| throw new Exception("No test block for diff file {$diff_file}."); | throw new Exception("No test block for diff file {$diff_file}."); | ||||
| Show All 20 Lines | foreach ($tests as $input => $expect) { | ||||
| $expect, | $expect, | ||||
| ArcanistDiffParser::stripGitPathPrefix($input), | ArcanistDiffParser::stripGitPathPrefix($input), | ||||
| "Strip git prefix from '{$input}'."); | "Strip git prefix from '{$input}'."); | ||||
| } | } | ||||
| } | } | ||||
| public function testGitPathSplitting() { | public function testGitPathSplitting() { | ||||
| static $tests = array( | static $tests = array( | ||||
| "a/old.c b/new.c" => array('old.c', 'new.c'), | 'a/old.c b/new.c' => array('old.c', 'new.c'), | ||||
| "a/old.c b/new.c\n" => array('old.c', 'new.c'), | "a/old.c b/new.c\n" => array('old.c', 'new.c'), | ||||
| "a/old.c b/new.c\r\n" => array('old.c', 'new.c'), | "a/old.c b/new.c\r\n" => array('old.c', 'new.c'), | ||||
| "old.c new.c" => array('old.c', 'new.c'), | 'old.c new.c' => array('old.c', 'new.c'), | ||||
| "1/old.c 2/new.c" => array('old.c', 'new.c'), | '1/old.c 2/new.c' => array('old.c', 'new.c'), | ||||
| '"a/\\"quotes1\\"" "b/\\"quotes2\\""' => array( | '"a/\\"quotes1\\"" "b/\\"quotes2\\""' => array( | ||||
| '"quotes1"', | '"quotes1"', | ||||
| '"quotes2"', | '"quotes2"', | ||||
| ), | ), | ||||
| '"a/\\"quotes and spaces1\\"" "b/\\"quotes and spaces2\\""' => array( | '"a/\\"quotes and spaces1\\"" "b/\\"quotes and spaces2\\""' => array( | ||||
| '"quotes and spaces1"', | '"quotes and spaces1"', | ||||
| '"quotes and spaces2"', | '"quotes and spaces2"', | ||||
| ), | ), | ||||
| '"a/\\342\\230\\2031" "b/\\342\\230\\2032"' => array( | '"a/\\342\\230\\2031" "b/\\342\\230\\2032"' => array( | ||||
| "\xE2\x98\x831", | "\xE2\x98\x831", | ||||
| "\xE2\x98\x832", | "\xE2\x98\x832", | ||||
| ), | ), | ||||
| "a/Core Data/old.c b/Core Data/new.c" => array( | 'a/Core Data/old.c b/Core Data/new.c' => array( | ||||
| 'Core Data/old.c', | 'Core Data/old.c', | ||||
| 'Core Data/new.c', | 'Core Data/new.c', | ||||
| ), | ), | ||||
| "some file with spaces.c some file with spaces.c" => array( | 'some file with spaces.c some file with spaces.c' => array( | ||||
| 'some file with spaces.c', | 'some file with spaces.c', | ||||
| 'some file with spaces.c', | 'some file with spaces.c', | ||||
| ), | ), | ||||
| ); | ); | ||||
| foreach ($tests as $input => $expect) { | foreach ($tests as $input => $expect) { | ||||
| $result = ArcanistDiffParser::splitGitDiffPaths($input); | $result = ArcanistDiffParser::splitGitDiffPaths($input); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $expect, | $expect, | ||||
| $result, | $result, | ||||
| "Split: {$input}"); | "Split: {$input}"); | ||||
| } | } | ||||
| static $ambiguous = array( | static $ambiguous = array( | ||||
| "old file with spaces.c new file with spaces.c", | 'old file with spaces.c new file with spaces.c', | ||||
| ); | ); | ||||
| foreach ($ambiguous as $input) { | foreach ($ambiguous as $input) { | ||||
| $caught = null; | $caught = null; | ||||
| try { | try { | ||||
| ArcanistDiffParser::splitGitDiffPaths($input); | ArcanistDiffParser::splitGitDiffPaths($input); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $caught = $ex; | $caught = $ex; | ||||
| } | } | ||||
| $this->assertTrue( | $this->assertTrue( | ||||
| ($caught instanceof Exception), | ($caught instanceof Exception), | ||||
| "Ambiguous: {$input}"); | "Ambiguous: {$input}"); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||