php-kilo/tests/RowTest.php

94 lines
2.1 KiB
PHP
Raw Normal View History

2019-11-19 17:01:45 -05:00
<?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits;
use Aviat\Kilo\{Editor, Row};
use PHPUnit\Framework\TestCase;
class RowTest extends TestCase {
protected Editor $editor;
protected Row $row;
public function setUp(): void
{
parent::setUp();
$this->editor = Editor::new();
$this->row = Row::new($this->editor, '', 0);
}
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);
}
public function testInsertChar(): void
{
$this->row->chars = 'abde';
$this->row->insertChar(2, 'c');
$this->assertEquals('abcde', $this->row->chars);
$this->assertEquals('abcde', $this->row->render);
2021-03-10 22:55:52 -05:00
$this->assertEquals(true, $this->editor->dirty);
2019-11-20 15:03:48 -05:00
}
public function testInsertCharBadOffset(): void
{
$this->row->chars = 'ab';
$this->row->insertChar(5, 'c');
$this->assertEquals('abc', $this->row->chars);
$this->assertEquals('abc', $this->row->render);
2021-03-10 22:55:52 -05:00
$this->assertEquals(true, $this->editor->dirty);
2019-11-20 15:03:48 -05:00
}
public function testDeleteChar(): void
{
$this->row->chars = 'abcdef';
$this->row->deleteChar(5);
$this->assertEquals('abcde', $this->row->chars);
$this->assertEquals('abcde', $this->row->render);
2021-03-10 22:55:52 -05:00
$this->assertEquals(true, $this->editor->dirty);
2019-11-20 15:03:48 -05:00
}
public function testDeleteCharBadOffset(): void
{
$this->row->chars = 'ab';
$this->row->deleteChar(5);
$this->assertEquals('ab', $this->row->chars);
2021-03-10 22:55:52 -05:00
$this->assertEquals(false, $this->editor->dirty);
2019-11-20 15:03:48 -05:00
}
2019-11-19 17:01:45 -05:00
}