Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / protocol / __tests__ / DiffusionSubversionWireProtocolTestCase.php
blobf4309b0e7b343e3cd0b48d27f2357b3f3f43525b
1 <?php
3 final class DiffusionSubversionWireProtocolTestCase
4 extends PhabricatorTestCase {
6 public function testSubversionWireProtocolParser() {
7 $this->assertSameSubversionMessages(
8 '( ) ',
9 array(
10 array(
12 ));
14 $this->assertSameSubversionMessages(
15 '( duck 5:quack 42 ( item1 item2 ) ) ',
16 array(
17 array(
18 array(
19 'type' => 'word',
20 'value' => 'duck',
22 array(
23 'type' => 'string',
24 'value' => 'quack',
26 array(
27 'type' => 'number',
28 'value' => 42,
30 array(
31 'type' => 'list',
32 'value' => array(
33 array(
34 'type' => 'word',
35 'value' => 'item1',
37 array(
38 'type' => 'word',
39 'value' => 'item2',
44 ));
46 $this->assertSameSubversionMessages(
47 '( msg1 ) ( msg2 ) ',
48 array(
49 array(
50 array(
51 'type' => 'word',
52 'value' => 'msg1',
55 array(
56 array(
57 'type' => 'word',
58 'value' => 'msg2',
61 ));
63 // This is testing that multiple spaces are parsed correctly. See T13140
64 // for discussion.
65 $this->assertSameSubversionMessages(
66 '( get-file true false ) ',
67 // ^-- Note extra space!
68 array(
69 array(
70 array(
71 'type' => 'word',
72 'value' => 'get-file',
74 array(
75 'type' => 'word',
76 'value' => 'true',
78 array(
79 'type' => 'word',
80 'value' => 'false',
84 '( get-file true false ) ');
86 $this->assertSameSubversionMessages(
87 '( duck 5:quack moo ) ',
88 array(
89 array(
90 array(
91 'type' => 'word',
92 'value' => 'duck',
94 array(
95 'type' => 'string',
96 'value' => 'quack',
98 array(
99 'type' => 'word',
100 'value' => 'moo',
104 '( duck 5:quack moo ) ');
108 public function testSubversionWireProtocolPartialFrame() {
109 $proto = new DiffusionSubversionWireProtocol();
111 // This is primarily a test that we don't hang when we write() a frame
112 // which straddles a string boundary.
113 $msg1 = $proto->writeData('( duck 5:qu');
114 $msg2 = $proto->writeData('ack ) ');
116 $this->assertEqual(array(), ipull($msg1, 'structure'));
117 $this->assertEqual(
118 array(
119 array(
120 array(
121 'type' => 'word',
122 'value' => 'duck',
124 array(
125 'type' => 'string',
126 'value' => 'quack',
130 ipull($msg2, 'structure'));
133 private function assertSameSubversionMessages(
134 $string,
135 array $structs,
136 $serial_string = null) {
138 $proto = new DiffusionSubversionWireProtocol();
140 // Verify that the wire message parses into the structs.
141 $messages = $proto->writeData($string);
142 $messages = ipull($messages, 'structure');
143 $this->assertEqual($structs, $messages, 'parse<'.$string.'>');
145 // Verify that the structs serialize into the wire message.
146 $serial = array();
147 foreach ($structs as $struct) {
148 $serial[] = $proto->serializeStruct($struct);
150 $serial = implode('', $serial);
152 if ($serial_string === null) {
153 $expect_serial = $string;
154 } else {
155 $expect_serial = $serial_string;
158 $this->assertEqual($expect_serial, $serial, 'serialize<'.$string.'>');