php-kilo/tests/Enum/KeyCodeTest.php

39 lines
824 B
PHP
Raw Normal View History

2020-02-05 15:20:32 -05:00
<?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Enum;
2020-02-05 16:32:17 -05:00
use function Aviat\Kilo\ctrl_key;
2021-04-09 13:52:01 -04:00
use Aviat\Kilo\Enum\RawKeyCode;
2020-02-05 15:20:32 -05:00
use PHPUnit\Framework\TestCase;
2020-02-05 16:32:17 -05:00
class KeyCodeTest extends TestCase {
2020-02-05 15:20:32 -05:00
public function testSanityCheck(): void
{
for ($i = 1; $i < 27; $i++)
{
$char = chr(0x60 + $i);
$ord = $i;
$expected = chr($ord);
2021-04-09 13:52:01 -04:00
$actual = RawKeyCode::CTRL($char);
2020-02-05 15:20:32 -05:00
2020-12-04 11:18:21 -05:00
$this->assertEquals(ctrl_key($char), $ord, 'chr(ctrl_key) !== CTRL');
2020-02-05 16:32:17 -05:00
$this->assertEquals($expected, $actual, "CTRL+'{$char}' should return chr($ord)");
2020-02-05 15:20:32 -05:00
}
}
public function testNullOnInvalidChar(): void
{
2021-04-09 13:52:01 -04:00
$this->assertNull(RawKeyCode::CTRL("\t"));
2020-02-05 15:20:32 -05:00
}
public function testSameOutputOnUpperOrLower(): void
{
2021-04-09 13:52:01 -04:00
$lower = RawKeyCode::CTRL('v');
$upper = RawKeyCode::CTRL('V');
2020-02-05 15:20:32 -05:00
$this->assertEquals($lower, $upper);
}
}