Add KeyType::CTRL helper method
Some checks failed
timw4mail/php-kilo/master There was a failure building this commit
Some checks failed
timw4mail/php-kilo/master There was a failure building this commit
This commit is contained in:
parent
366945bda1
commit
afd6560db4
@ -38,7 +38,8 @@ class KeyType {
|
|||||||
|
|
||||||
// a = 0x61
|
// a = 0x61
|
||||||
// z = 0x7a
|
// z = 0x7a
|
||||||
if ($ord >= 0x61 && $ord <= 0x7a)
|
// So, 0x60 < $ord < 0x7b
|
||||||
|
if ($ord > 0x60 && $ord < 0x7b)
|
||||||
{
|
{
|
||||||
return chr(ctrl_key($char));
|
return chr(ctrl_key($char));
|
||||||
}
|
}
|
||||||
|
35
tests/Enum/KeyTypeTest.php
Normal file
35
tests/Enum/KeyTypeTest.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Aviat\Kilo\Tests\Enum;
|
||||||
|
|
||||||
|
use Aviat\Kilo\Enum\KeyType;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class KeyTypeTest extends TestCase {
|
||||||
|
public function testSanityCheck(): void
|
||||||
|
{
|
||||||
|
for ($i = 1; $i < 27; $i++)
|
||||||
|
{
|
||||||
|
$char = chr(0x60 + $i);
|
||||||
|
$ord = $i;
|
||||||
|
$expected = chr($ord);
|
||||||
|
|
||||||
|
$actual = KeyType::CTRL($char);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual, "CTRL + '{$char}' should return chr($ord)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNullOnInvalidChar(): void
|
||||||
|
{
|
||||||
|
$this->assertNull(KeyType::CTRL("\t"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSameOutputOnUpperOrLower(): void
|
||||||
|
{
|
||||||
|
$lower = KeyType::CTRL('v');
|
||||||
|
$upper = KeyType::CTRL('V');
|
||||||
|
|
||||||
|
$this->assertEquals($lower, $upper);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user