From a588e2ef21f18df156895aba0086b6a931d67a16 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Tue, 25 Feb 2025 16:52:17 +0100 Subject: [PATCH] add(test): input testing of `Key.isAscii` --- src/input.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/input.zig b/src/input.zig index cd420d4..fe3c271 100644 --- a/src/input.zig +++ b/src/input.zig @@ -88,6 +88,24 @@ pub const Key = packed struct { (this.cp >= 32 and this.cp <= 126 or // ascii printable characters (except for input.Delete) this.cp >= 128 and this.cp <= 255); // extended ascii codes } + + test "isAscii with ascii character" { + try std.testing.expectEqual(true, isAscii(.{ .cp = 'c' })); + try std.testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .ctrl = true } })); + try std.testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .alt = true } })); + try std.testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .alt = true, .ctrl = true } })); + } + + test "isAscii with non-ascii character" { + try std.testing.expectEqual(false, isAscii(.{ .cp = Escape })); + try std.testing.expectEqual(false, isAscii(.{ .cp = Enter })); + try std.testing.expectEqual(false, isAscii(.{ .cp = Enter, .mod = .{ .alt = true } })); + } + + test "isAscii with excluded input.Delete" { + try std.testing.expectEqual(false, isAscii(.{ .cp = Delete })); + try std.testing.expectEqual(false, isAscii(.{ .cp = Delete, .mod = .{ .alt = false, .ctrl = false } })); + } }; // codepoints for keys