Skip to content

Commit e032488

Browse files
committed
Add more tests to US and UK.
Just to be sure I've got this right, I go from scancodes to Unicode, based on various online tables.
1 parent c7d5933 commit e032488

File tree

2 files changed

+133
-2
lines changed

2 files changed

+133
-2
lines changed

src/layouts/uk105.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,70 @@ impl KeyboardLayout for Uk105Key {
7979
#[cfg(test)]
8080
mod test {
8181
use super::*;
82-
use crate::{HandleControl, Keyboard, ScancodeSet2};
82+
use crate::{EventDecoder, HandleControl, Keyboard, ScancodeSet, ScancodeSet1, ScancodeSet2};
83+
84+
#[test]
85+
fn layout() {
86+
// Codes taken from https://kbdlayout.info/kbduk/overview+scancodes?arrangement=ISO105
87+
let mut s = ScancodeSet1::new();
88+
let mut dec = EventDecoder::new(Uk105Key, HandleControl::Ignore);
89+
let data = [
90+
(0x29, '`'),
91+
(0x02, '1'),
92+
(0x03, '2'),
93+
(0x04, '3'),
94+
(0x05, '4'),
95+
(0x06, '5'),
96+
(0x07, '6'),
97+
(0x08, '7'),
98+
(0x09, '8'),
99+
(0x0a, '9'),
100+
(0x0b, '0'),
101+
(0x0c, '-'),
102+
(0x0d, '='),
103+
(0x0f, '\t'),
104+
(0x10, 'q'),
105+
(0x11, 'w'),
106+
(0x12, 'e'),
107+
(0x13, 'r'),
108+
(0x14, 't'),
109+
(0x15, 'y'),
110+
(0x16, 'u'),
111+
(0x17, 'i'),
112+
(0x18, 'o'),
113+
(0x19, 'p'),
114+
(0x1a, '['),
115+
(0x1b, ']'),
116+
(0x1e, 'a'),
117+
(0x1f, 's'),
118+
(0x20, 'd'),
119+
(0x21, 'f'),
120+
(0x22, 'g'),
121+
(0x23, 'h'),
122+
(0x24, 'j'),
123+
(0x25, 'k'),
124+
(0x26, 'l'),
125+
(0x27, ';'),
126+
(0x28, '\''),
127+
(0x2B, '#'),
128+
(0x1c, '\n'),
129+
(0x56, '\\'),
130+
(0x2c, 'z'),
131+
(0x2d, 'x'),
132+
(0x2e, 'c'),
133+
(0x2f, 'v'),
134+
(0x30, 'b'),
135+
(0x31, 'n'),
136+
(0x32, 'm'),
137+
(0x33, ','),
138+
(0x34, '.'),
139+
(0x35, '/'),
140+
];
141+
for (code, unicode) in data {
142+
let ev = s.advance_state(code).unwrap().unwrap();
143+
assert_eq!(Some(DecodedKey::Unicode(unicode)), dec.process_keyevent(ev));
144+
}
145+
}
83146

84147
#[test]
85148
fn test_hash() {

src/layouts/us104.rs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl KeyboardLayout for Us104Key {
214214
DecodedKey::Unicode(']')
215215
}
216216
}
217-
KeyCode::Oem7 => {
217+
KeyCode::Oem5 => {
218218
if modifiers.is_shifted() {
219219
DecodedKey::Unicode('|')
220220
} else {
@@ -484,3 +484,71 @@ impl KeyboardLayout for Us104Key {
484484
}
485485
}
486486
}
487+
488+
#[cfg(test)]
489+
mod test {
490+
use super::*;
491+
use crate::{EventDecoder, ScancodeSet, ScancodeSet1};
492+
493+
#[test]
494+
fn layout() {
495+
// Codes taken from https://kbdlayout.info/kbdus/overview+scancodes?arrangement=ANSI104
496+
let mut s = ScancodeSet1::new();
497+
let mut dec = EventDecoder::new(Us104Key, HandleControl::Ignore);
498+
let data = [
499+
(0x29, '`'),
500+
(0x02, '1'),
501+
(0x03, '2'),
502+
(0x04, '3'),
503+
(0x05, '4'),
504+
(0x06, '5'),
505+
(0x07, '6'),
506+
(0x08, '7'),
507+
(0x09, '8'),
508+
(0x0a, '9'),
509+
(0x0b, '0'),
510+
(0x0c, '-'),
511+
(0x0d, '='),
512+
(0x0f, '\t'),
513+
(0x10, 'q'),
514+
(0x11, 'w'),
515+
(0x12, 'e'),
516+
(0x13, 'r'),
517+
(0x14, 't'),
518+
(0x15, 'y'),
519+
(0x16, 'u'),
520+
(0x17, 'i'),
521+
(0x18, 'o'),
522+
(0x19, 'p'),
523+
(0x1a, '['),
524+
(0x1b, ']'),
525+
(0x56, '\\'),
526+
(0x1e, 'a'),
527+
(0x1f, 's'),
528+
(0x20, 'd'),
529+
(0x21, 'f'),
530+
(0x22, 'g'),
531+
(0x23, 'h'),
532+
(0x24, 'j'),
533+
(0x25, 'k'),
534+
(0x26, 'l'),
535+
(0x27, ';'),
536+
(0x28, '\''),
537+
(0x1c, '\n'),
538+
(0x2c, 'z'),
539+
(0x2d, 'x'),
540+
(0x2e, 'c'),
541+
(0x2f, 'v'),
542+
(0x30, 'b'),
543+
(0x31, 'n'),
544+
(0x32, 'm'),
545+
(0x33, ','),
546+
(0x34, '.'),
547+
(0x35, '/'),
548+
];
549+
for (code, unicode) in data {
550+
let ev = s.advance_state(code).unwrap().unwrap();
551+
assert_eq!(Some(DecodedKey::Unicode(unicode)), dec.process_keyevent(ev));
552+
}
553+
}
554+
}

0 commit comments

Comments
 (0)