php-kilo/tests/Enum/KeyCodeTest.php

39 lines
809 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;
use Aviat\Kilo\Enum\KeyCode;
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);
2020-02-05 16:32:17 -05:00
$actual = KeyCode::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
{
2020-02-05 16:32:17 -05:00
$this->assertNull(KeyCode::CTRL("\t"));
2020-02-05 15:20:32 -05:00
}
public function testSameOutputOnUpperOrLower(): void
{
2020-02-05 16:32:17 -05:00
$lower = KeyCode::CTRL('v');
$upper = KeyCode::CTRL('V');
2020-02-05 15:20:32 -05:00
$this->assertEquals($lower, $upper);
}
}