97 lines
2.1 KiB
PHP
97 lines
2.1 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace Aviat\Kilo\Tests\Traits;
|
|
|
|
use Aviat\Kilo\
|
|
{
|
|
Document,
|
|
Row};
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class RowTest extends TestCase {
|
|
protected Document $document;
|
|
protected Row $row;
|
|
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->document = Document::new();
|
|
$this->row = Row::new($this->document, '', 0);
|
|
}
|
|
|
|
public function testSanity(): void
|
|
{
|
|
$this->assertEquals(0, $this->row->size);
|
|
$this->assertEquals(0, $this->row->rsize);
|
|
$this->assertNull($this->row->foo);
|
|
$this->assertEmpty($this->row->chars);
|
|
$this->assertEmpty($this->row->render);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public function testInsert(): void
|
|
{
|
|
$this->row->chars = 'abde';
|
|
$this->row->insert(2, 'c');
|
|
|
|
$this->assertEquals('abcde', $this->row->chars);
|
|
$this->assertEquals('abcde', $this->row->render);
|
|
$this->assertEquals(true, $this->document->dirty);
|
|
}
|
|
|
|
public function testInsertBadOffset(): void
|
|
{
|
|
$this->row->chars = 'ab';
|
|
$this->row->insert(5, 'c');
|
|
|
|
$this->assertEquals('abc', $this->row->chars);
|
|
$this->assertEquals('abc', $this->row->render);
|
|
$this->assertEquals(true, $this->document->dirty);
|
|
}
|
|
|
|
public function testDelete(): void
|
|
{
|
|
$this->row->chars = 'abcdef';
|
|
$this->row->delete(5);
|
|
|
|
$this->assertEquals('abcde', $this->row->chars);
|
|
$this->assertEquals('abcde', $this->row->render);
|
|
$this->assertEquals(true, $this->document->dirty);
|
|
}
|
|
|
|
public function testDeleteBadOffset(): void
|
|
{
|
|
$this->row->chars = 'ab';
|
|
$this->row->delete(5);
|
|
|
|
$this->assertEquals('ab', $this->row->chars);
|
|
$this->assertEquals(false, $this->document->dirty);
|
|
}
|
|
} |