diff --git a/src/Enum/KeyType.php b/src/Enum/KeyType.php index efd042a..235771f 100644 --- a/src/Enum/KeyType.php +++ b/src/Enum/KeyType.php @@ -38,7 +38,8 @@ class KeyType { // a = 0x61 // z = 0x7a - if ($ord >= 0x61 && $ord <= 0x7a) + // So, 0x60 < $ord < 0x7b + if ($ord > 0x60 && $ord < 0x7b) { return chr(ctrl_key($char)); } diff --git a/tests/Enum/KeyTypeTest.php b/tests/Enum/KeyTypeTest.php new file mode 100644 index 0000000..c787548 --- /dev/null +++ b/tests/Enum/KeyTypeTest.php @@ -0,0 +1,35 @@ +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); + } +}