Changeset View
Changeset View
Standalone View
Standalone View
src/parser/__tests__/ArcanistDiffParserTestCase.php
| Show First 20 Lines • Show All 596 Lines • ▼ Show 20 Lines | EOTEXT | ||||
| break; | break; | ||||
| case 'git-remove-spaces.gitdiff': | case 'git-remove-spaces.gitdiff': | ||||
| $this->assertEqual(1, count($changes)); | $this->assertEqual(1, count($changes)); | ||||
| $change = array_shift($changes); | $change = array_shift($changes); | ||||
| $this->assertEqual('file with spaces.txt', $change->getOldPath()); | $this->assertEqual('file with spaces.txt', $change->getOldPath()); | ||||
| break; | break; | ||||
| default: | default: | ||||
| throw new Exception("No test block for diff file {$diff_file}."); | throw new Exception(pht('No test block for diff file %s.', $diff_file)); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| public function testGitPrefixStripping() { | public function testGitPrefixStripping() { | ||||
| static $tests = array( | static $tests = array( | ||||
| 'a/file.c' => 'file.c', | 'a/file.c' => 'file.c', | ||||
| 'b/file.c' => 'file.c', | 'b/file.c' => 'file.c', | ||||
| 'i/file.c' => 'file.c', | 'i/file.c' => 'file.c', | ||||
| 'c/file.c' => 'file.c', | 'c/file.c' => 'file.c', | ||||
| 'w/file.c' => 'file.c', | 'w/file.c' => 'file.c', | ||||
| 'o/file.c' => 'file.c', | 'o/file.c' => 'file.c', | ||||
| '1/file.c' => 'file.c', | '1/file.c' => 'file.c', | ||||
| '2/file.c' => 'file.c', | '2/file.c' => 'file.c', | ||||
| 'src/file.c' => 'src/file.c', | 'src/file.c' => 'src/file.c', | ||||
| 'file.c' => 'file.c', | 'file.c' => 'file.c', | ||||
| ); | ); | ||||
| foreach ($tests as $input => $expect) { | foreach ($tests as $input => $expect) { | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $expect, | $expect, | ||||
| ArcanistDiffParser::stripGitPathPrefix($input), | ArcanistDiffParser::stripGitPathPrefix($input), | ||||
| "Strip git prefix from '{$input}'."); | pht("Strip git prefix from '%s'.", $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'), | ||||
| Show All 21 Lines | static $tests = array( | ||||
| ), | ), | ||||
| ); | ); | ||||
| 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}"); | pht('Split: %s', $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}"); | pht('Ambiguous: %s', $input)); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||