From afd6560db4dc6655d9fa70a9aa4dca8aa645da44 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Wed, 5 Feb 2020 15:20:32 -0500 Subject: [PATCH] Add KeyType::CTRL helper method --- src/Enum/KeyType.php | 3 ++- tests/Enum/KeyTypeTest.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/Enum/KeyTypeTest.php 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); + } +}