@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 160 lines 3.8 kB view raw
1<?php 2 3final class DiffusionSubversionWireProtocolTestCase 4 extends PhabricatorTestCase { 5 6 public function testSubversionWireProtocolParser() { 7 $this->assertSameSubversionMessages( 8 '( ) ', 9 array( 10 array( 11 ), 12 )); 13 14 $this->assertSameSubversionMessages( 15 '( duck 5:quack 42 ( item1 item2 ) ) ', 16 array( 17 array( 18 array( 19 'type' => 'word', 20 'value' => 'duck', 21 ), 22 array( 23 'type' => 'string', 24 'value' => 'quack', 25 ), 26 array( 27 'type' => 'number', 28 'value' => 42, 29 ), 30 array( 31 'type' => 'list', 32 'value' => array( 33 array( 34 'type' => 'word', 35 'value' => 'item1', 36 ), 37 array( 38 'type' => 'word', 39 'value' => 'item2', 40 ), 41 ), 42 ), 43 ), 44 )); 45 46 $this->assertSameSubversionMessages( 47 '( msg1 ) ( msg2 ) ', 48 array( 49 array( 50 array( 51 'type' => 'word', 52 'value' => 'msg1', 53 ), 54 ), 55 array( 56 array( 57 'type' => 'word', 58 'value' => 'msg2', 59 ), 60 ), 61 )); 62 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', 73 ), 74 array( 75 'type' => 'word', 76 'value' => 'true', 77 ), 78 array( 79 'type' => 'word', 80 'value' => 'false', 81 ), 82 ), 83 ), 84 '( get-file true false ) '); 85 86 $this->assertSameSubversionMessages( 87 '( duck 5:quack moo ) ', 88 array( 89 array( 90 array( 91 'type' => 'word', 92 'value' => 'duck', 93 ), 94 array( 95 'type' => 'string', 96 'value' => 'quack', 97 ), 98 array( 99 'type' => 'word', 100 'value' => 'moo', 101 ), 102 ), 103 ), 104 '( duck 5:quack moo ) '); 105 106 } 107 108 public function testSubversionWireProtocolPartialFrame() { 109 $proto = new DiffusionSubversionWireProtocol(); 110 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 ) '); 115 116 $this->assertEqual(array(), ipull($msg1, 'structure')); 117 $this->assertEqual( 118 array( 119 array( 120 array( 121 'type' => 'word', 122 'value' => 'duck', 123 ), 124 array( 125 'type' => 'string', 126 'value' => 'quack', 127 ), 128 ), 129 ), 130 ipull($msg2, 'structure')); 131 } 132 133 private function assertSameSubversionMessages( 134 $string, 135 array $structs, 136 $serial_string = null) { 137 138 $proto = new DiffusionSubversionWireProtocol(); 139 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.'>'); 144 145 // Verify that the structs serialize into the wire message. 146 $serial = array(); 147 foreach ($structs as $struct) { 148 $serial[] = $proto->serializeStruct($struct); 149 } 150 $serial = implode('', $serial); 151 152 if ($serial_string === null) { 153 $expect_serial = $string; 154 } else { 155 $expect_serial = $serial_string; 156 } 157 158 $this->assertEqual($expect_serial, $serial, 'serialize<'.$string.'>'); 159 } 160}