php-kilo/tests/RowTest.php

99 lines
2.1 KiB
PHP
Raw Normal View History

2019-11-19 17:01:45 -05:00
<?php declare(strict_types=1);
2021-04-14 13:24:13 -04:00
namespace Aviat\Kilo\Tests;
2019-11-19 17:01:45 -05:00
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();
2021-04-14 13:24:13 -04:00
$this->document->insertRow(0, '');
$this->row = $this->document->rows[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
{
2021-04-14 13:24:13 -04:00
$this->row->setChars('abcde');
2021-04-14 14:40:35 -04:00
$this->assertNotEmpty($this->row->chars);
$this->assertEquals('abcde', $this->row->render);
2019-11-20 15:03:48 -05:00
}
public function test__toString(): void
{
2021-04-14 13:24:13 -04:00
$this->row->setChars('abcde');
2019-11-20 15:03:48 -05:00
$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
{
2021-04-14 13:24:13 -04:00
$this->row->setChars('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
{
2021-04-14 13:24:13 -04:00
$this->row->setChars('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
{
2021-04-14 13:24:13 -04:00
$this->row->setChars('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
{
2021-04-14 13:24:13 -04:00
$this->row->setChars('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);
}
2019-11-19 17:01:45 -05:00
}