Something went wrong. Try again.
@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
Something went wrong. Try again.
3.8 kB · 160 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161<?php
final class DiffusionSubversionWireProtocolTestCase extends PhabricatorTestCase {
public function testSubversionWireProtocolParser() { $this->assertSameSubversionMessages( '( ) ', array( array( ), ));
$this->assertSameSubversionMessages( '( duck 5:quack 42 ( item1 item2 ) ) ', array( array( array( 'type' => 'word', 'value' => 'duck', ), array( 'type' => 'string', 'value' => 'quack', ), array( 'type' => 'number', 'value' => 42, ), array( 'type' => 'list', 'value' => array( array( 'type' => 'word', 'value' => 'item1', ), array( 'type' => 'word', 'value' => 'item2', ), ), ), ), ));
$this->assertSameSubversionMessages( '( msg1 ) ( msg2 ) ', array( array( array( 'type' => 'word', 'value' => 'msg1', ), ), array( array( 'type' => 'word', 'value' => 'msg2', ), ), ));
// This is testing that multiple spaces are parsed correctly. See T13140 // for discussion. $this->assertSameSubversionMessages( '( get-file true false ) ', // ^-- Note extra space! array( array( array( 'type' => 'word', 'value' => 'get-file', ), array( 'type' => 'word', 'value' => 'true', ), array( 'type' => 'word', 'value' => 'false', ), ), ), '( get-file true false ) ');
$this->assertSameSubversionMessages( '( duck 5:quack moo ) ', array( array( array( 'type' => 'word', 'value' => 'duck', ), array( 'type' => 'string', 'value' => 'quack', ), array( 'type' => 'word', 'value' => 'moo', ), ), ), '( duck 5:quack moo ) ');
}
public function testSubversionWireProtocolPartialFrame() { $proto = new DiffusionSubversionWireProtocol();
// This is primarily a test that we don't hang when we write() a frame // which straddles a string boundary. $msg1 = $proto->writeData('( duck 5:qu'); $msg2 = $proto->writeData('ack ) ');
$this->assertEqual(array(), ipull($msg1, 'structure')); $this->assertEqual( array( array( array( 'type' => 'word', 'value' => 'duck', ), array( 'type' => 'string', 'value' => 'quack', ), ), ), ipull($msg2, 'structure')); }
private function assertSameSubversionMessages( $string, array $structs, $serial_string = null) {
$proto = new DiffusionSubversionWireProtocol();
// Verify that the wire message parses into the structs. $messages = $proto->writeData($string); $messages = ipull($messages, 'structure'); $this->assertEqual($structs, $messages, 'parse<'.$string.'>');
// Verify that the structs serialize into the wire message. $serial = array(); foreach ($structs as $struct) { $serial[] = $proto->serializeStruct($struct); } $serial = implode('', $serial);
if ($serial_string === null) { $expect_serial = $string; } else { $expect_serial = $serial_string; }
$this->assertEqual($expect_serial, $serial, 'serialize<'.$string.'>'); }}