1<?php 2 3final class PhutilRopeTestCase extends PhutilTestCase { 4 5 public function testRopeOperations() { 6 $rope = new PhutilRope(); 7 $rope->append('aaa'); 8 $rope->append('bbb'); 9 10 $this->assertEqual(6, $rope->getByteLength()); 11 $this->assertEqual('aaabbb', $rope->getAsString()); 12 13 $rope->removeBytesFromHead(2); 14 15 $this->assertEqual(4, $rope->getByteLength()); 16 $this->assertEqual('abbb', $rope->getAsString()); 17 18 $rope->removeBytesFromHead(4); 19 20 $this->assertEqual(0, $rope->getByteLength()); 21 $this->assertEqual('', $rope->getAsString()); 22 } 23 24 public function testMoreRopeOperations() { 25 $rope = new PhutilRope(); 26 $rope->append('aaa'); 27 $rope->append('bbb'); 28 $rope->append('ccc'); 29 $rope->append('rrrrddddddddd'); 30 $rope->removeBytesFromHead(4); 31 32 $string = $rope->getAsString(); 33 $this->assertEqual('bbcccrrrrddddddddd', $string); 34 $this->assertEqual(strlen($string), $rope->getByteLength()); 35 36 $rope = new PhutilRope(); 37 $rope->append('aaa'); 38 $rope->append('bbb'); 39 $rope->removeBytesFromHead(6); 40 41 $string = $rope->getAsString(); 42 $this->assertEqual('', $string); 43 $this->assertEqual(0, $rope->getByteLength()); 44 45 46 $rope = new PhutilRope(); 47 $rope->append('a'); 48 $rope->append('b'); 49 $rope->append('c'); 50 $rope->removeBytesFromHead(1024); 51 52 $string = $rope->getAsString(); 53 $this->assertEqual('', $string); 54 $this->assertEqual(0, $rope->getByteLength()); 55 } 56} 57