2019-11-19 17:01:45 -05:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Aviat\Kilo\Tests\Traits;
|
|
|
|
|
2021-03-17 15:38:52 -04:00
|
|
|
use Aviat\Kilo\
|
|
|
|
{
|
|
|
|
Document,
|
|
|
|
Row};
|
2019-11-19 17:01:45 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class RowTest extends TestCase {
|
2021-03-17 15:38:52 -04:00
|
|
|
protected Document $document;
|
2019-11-19 17:01:45 -05:00
|
|
|
protected Row $row;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->document = Document::new();
|
|
|
|
$this->row = Row::new($this->document, '', 0);
|
2019-11-19 17:01:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSanity(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(0, $this->row->size);
|
|
|
|
$this->assertEquals(0, $this->row->rsize);
|
2019-11-20 15:03:48 -05:00
|
|
|
$this->assertNull($this->row->foo);
|
2019-11-19 17:01:45 -05:00
|
|
|
$this->assertEmpty($this->row->chars);
|
|
|
|
$this->assertEmpty($this->row->render);
|
|
|
|
}
|
2019-11-20 15:03:48 -05:00
|
|
|
|
|
|
|
public function testSetRunsUpdate(): void
|
|
|
|
{
|
|
|
|
$this->row->chars = 'abcde';
|
|
|
|
$this->assertEquals('abcde', $this->row->render);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test__toString(): void
|
|
|
|
{
|
|
|
|
$this->row->chars = 'abcde';
|
|
|
|
$this->assertEquals("abcde\n", (string)$this->row);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test__debugInfo(): void
|
|
|
|
{
|
|
|
|
$actual = $this->row->__debugInfo();
|
|
|
|
$expected = [
|
|
|
|
'size' => 0,
|
|
|
|
'rsize' => 0,
|
|
|
|
'chars' => '',
|
|
|
|
'render' => '',
|
|
|
|
'hl' => [],
|
|
|
|
'hlOpenComment' => FALSE,
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
|
|
|
|
2021-03-17 15:38:52 -04:00
|
|
|
public function testInsert(): void
|
2019-11-20 15:03:48 -05:00
|
|
|
{
|
|
|
|
$this->row->chars = 'abde';
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->row->insert(2, 'c');
|
2019-11-20 15:03:48 -05:00
|
|
|
|
|
|
|
$this->assertEquals('abcde', $this->row->chars);
|
|
|
|
$this->assertEquals('abcde', $this->row->render);
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->assertEquals(true, $this->document->dirty);
|
2019-11-20 15:03:48 -05:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:38:52 -04:00
|
|
|
public function testInsertBadOffset(): void
|
2019-11-20 15:03:48 -05:00
|
|
|
{
|
|
|
|
$this->row->chars = 'ab';
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->row->insert(5, 'c');
|
2019-11-20 15:03:48 -05:00
|
|
|
|
|
|
|
$this->assertEquals('abc', $this->row->chars);
|
|
|
|
$this->assertEquals('abc', $this->row->render);
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->assertEquals(true, $this->document->dirty);
|
2019-11-20 15:03:48 -05:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:38:52 -04:00
|
|
|
public function testDelete(): void
|
2019-11-20 15:03:48 -05:00
|
|
|
{
|
|
|
|
$this->row->chars = 'abcdef';
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->row->delete(5);
|
2019-11-20 15:03:48 -05:00
|
|
|
|
|
|
|
$this->assertEquals('abcde', $this->row->chars);
|
|
|
|
$this->assertEquals('abcde', $this->row->render);
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->assertEquals(true, $this->document->dirty);
|
2019-11-20 15:03:48 -05:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:38:52 -04:00
|
|
|
public function testDeleteBadOffset(): void
|
2019-11-20 15:03:48 -05:00
|
|
|
{
|
|
|
|
$this->row->chars = 'ab';
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->row->delete(5);
|
2019-11-20 15:03:48 -05:00
|
|
|
|
|
|
|
$this->assertEquals('ab', $this->row->chars);
|
2021-03-17 15:38:52 -04:00
|
|
|
$this->assertEquals(false, $this->document->dirty);
|
2019-11-20 15:03:48 -05:00
|
|
|
}
|
2019-11-19 17:01:45 -05:00
|
|
|
}
|