~ubuntu-branches/ubuntu/vivid/phabricator/vivid-proposed

« back to all changes in this revision

Viewing changes to arcanist/src/repository/parser/__tests__/ArcanistMercurialParserTestCase.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-10-23 20:49:26 UTC
  • mfrom: (0.2.1) (0.1.1)
  • Revision ID: package-import@ubuntu.com-20141023204926-vq80u1op4df44azb
Tags: 0~git20141023-1
Initial release (closes: #703046)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
final class ArcanistMercurialParserTestCase extends ArcanistTestCase {
 
4
 
 
5
  public function testParseAll() {
 
6
    $root = dirname(__FILE__).'/mercurial/';
 
7
    foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
 
8
      $this->parseData(
 
9
        basename($file),
 
10
        Filesystem::readFile($root.'/'.$file));
 
11
    }
 
12
  }
 
13
 
 
14
  private function parseData($name, $data) {
 
15
    switch ($name) {
 
16
      case 'branches-basic.txt':
 
17
        $output = ArcanistMercurialParser::parseMercurialBranches($data);
 
18
        $this->assertEqual(
 
19
          array('default', 'stable'),
 
20
          array_keys($output));
 
21
        $this->assertEqual(
 
22
          array('a21ccf4412d5', 'ec222a29bdf0'),
 
23
          array_values(ipull($output, 'rev')));
 
24
        break;
 
25
      case 'branches-with-spaces.txt':
 
26
        $output = ArcanistMercurialParser::parseMercurialBranches($data);
 
27
        $this->assertEqual(
 
28
          array(
 
29
            'm m m m m 2:ffffffffffff (inactive)',
 
30
            'xxx yyy zzz',
 
31
            'default',
 
32
            "'",
 
33
          ),
 
34
          array_keys($output));
 
35
        $this->assertEqual(
 
36
          array('0b9d8290c4e0', '78963faacfc7', '5db03c5500c6', 'ffffffffffff'),
 
37
          array_values(ipull($output, 'rev')));
 
38
        break;
 
39
      case 'branches-empty.txt':
 
40
        $output = ArcanistMercurialParser::parseMercurialBranches($data);
 
41
        $this->assertEqual(array(), $output);
 
42
        break;
 
43
      case 'log-basic.txt':
 
44
        $output = ArcanistMercurialParser::parseMercurialLog($data);
 
45
        $this->assertEqual(
 
46
          3,
 
47
          count($output));
 
48
        $this->assertEqual(
 
49
          array('a21ccf4412d5', 'a051f8a6a7cc', 'b1f49efeab65'),
 
50
          array_values(ipull($output, 'rev')));
 
51
        break;
 
52
      case 'log-empty.txt':
 
53
        // Empty logs (e.g., "hg parents" for a root revision) should parse
 
54
        // correctly.
 
55
        $output = ArcanistMercurialParser::parseMercurialLog($data);
 
56
        $this->assertEqual(
 
57
          array(),
 
58
          $output);
 
59
        break;
 
60
      case 'status-basic.txt':
 
61
        $output = ArcanistMercurialParser::parseMercurialStatus($data);
 
62
        $this->assertEqual(
 
63
          4,
 
64
          count($output));
 
65
        $this->assertEqual(
 
66
          array('changed', 'added', 'removed', 'untracked'),
 
67
          array_keys($output));
 
68
        break;
 
69
      case 'status-moves.txt':
 
70
        $output = ArcanistMercurialParser::parseMercurialStatusDetails($data);
 
71
        $this->assertEqual(
 
72
          'move_source',
 
73
          $output['moved_file']['from']);
 
74
        $this->assertEqual(
 
75
          null,
 
76
          $output['changed_file']['from']);
 
77
        $this->assertEqual(
 
78
          'copy_source',
 
79
          $output['copied_file']['from']);
 
80
        $this->assertEqual(
 
81
          null,
 
82
          idx($output, 'copy_source'));
 
83
        break;
 
84
      default:
 
85
        throw new Exception("No test information for test data '{$name}'!");
 
86
    }
 
87
  }
 
88
 
 
89
}