php-kilo/tests/RowTest.php
Timothy Warren a50c22c0e0
All checks were successful
timw4mail/php-kilo/pipeline/head This commit looks good
Fix more tests
2021-04-14 14:40:35 -04:00

99 lines
2.1 KiB
PHP

<?php declare(strict_types=1);
namespace Aviat\Kilo\Tests;
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->document->insertRow(0, '');
$this->row = $this->document->rows[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->setChars('abcde');
$this->assertNotEmpty($this->row->chars);
$this->assertEquals('abcde', $this->row->render);
}
public function test__toString(): void
{
$this->row->setChars('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->setChars('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->setChars('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->setChars('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->setChars('ab');
$this->row->delete(5);
$this->assertEquals('ab', $this->row->chars);
}
}