80 lines
2.4 KiB
Rust
80 lines
2.4 KiB
Rust
|
|
//! Integration coverage for the shared printable-character HID contract.
|
||
|
|
//!
|
||
|
|
//! Scope: verify the shared character-to-HID table from the top-level testing
|
||
|
|
//! module so both client and server rely on the same canonical assertions.
|
||
|
|
//! Targets: `common/src/hid.rs`.
|
||
|
|
//! Why: this mapping is a cross-crate contract and should live in one obvious
|
||
|
|
//! place instead of being duplicated by package-local test suites.
|
||
|
|
|
||
|
|
use lesavka_common::hid::char_to_usage;
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn char_to_usage_covers_letters_digits_symbols_and_whitespace() {
|
||
|
|
for (offset, ch) in ('a'..='z').enumerate() {
|
||
|
|
assert_eq!(char_to_usage(ch), Some((0x04 + offset as u8, 0x00)));
|
||
|
|
}
|
||
|
|
|
||
|
|
for (offset, ch) in ('A'..='Z').enumerate() {
|
||
|
|
assert_eq!(char_to_usage(ch), Some((0x04 + offset as u8, 0x02)));
|
||
|
|
}
|
||
|
|
|
||
|
|
for (offset, ch) in ('1'..='9').enumerate() {
|
||
|
|
assert_eq!(char_to_usage(ch), Some((0x1E + offset as u8, 0x00)));
|
||
|
|
}
|
||
|
|
assert_eq!(char_to_usage('0'), Some((0x27, 0x00)));
|
||
|
|
|
||
|
|
let cases = [
|
||
|
|
('!', (0x1E, 0x02)),
|
||
|
|
('@', (0x1F, 0x02)),
|
||
|
|
('#', (0x20, 0x02)),
|
||
|
|
('$', (0x21, 0x02)),
|
||
|
|
('%', (0x22, 0x02)),
|
||
|
|
('^', (0x23, 0x02)),
|
||
|
|
('&', (0x24, 0x02)),
|
||
|
|
('*', (0x25, 0x02)),
|
||
|
|
('(', (0x26, 0x02)),
|
||
|
|
(')', (0x27, 0x02)),
|
||
|
|
('-', (0x2D, 0x00)),
|
||
|
|
('_', (0x2D, 0x02)),
|
||
|
|
('=', (0x2E, 0x00)),
|
||
|
|
('+', (0x2E, 0x02)),
|
||
|
|
('[', (0x2F, 0x00)),
|
||
|
|
('{', (0x2F, 0x02)),
|
||
|
|
(']', (0x30, 0x00)),
|
||
|
|
('}', (0x30, 0x02)),
|
||
|
|
('\\', (0x31, 0x00)),
|
||
|
|
('|', (0x31, 0x02)),
|
||
|
|
(';', (0x33, 0x00)),
|
||
|
|
(':', (0x33, 0x02)),
|
||
|
|
('\'', (0x34, 0x00)),
|
||
|
|
('"', (0x34, 0x02)),
|
||
|
|
('`', (0x35, 0x00)),
|
||
|
|
('~', (0x35, 0x02)),
|
||
|
|
(',', (0x36, 0x00)),
|
||
|
|
('<', (0x36, 0x02)),
|
||
|
|
('.', (0x37, 0x00)),
|
||
|
|
('>', (0x37, 0x02)),
|
||
|
|
('/', (0x38, 0x00)),
|
||
|
|
('?', (0x38, 0x02)),
|
||
|
|
(' ', (0x2C, 0x00)),
|
||
|
|
('\n', (0x28, 0x00)),
|
||
|
|
('\r', (0x28, 0x00)),
|
||
|
|
('\t', (0x2B, 0x00)),
|
||
|
|
];
|
||
|
|
|
||
|
|
for (ch, expected) in cases {
|
||
|
|
assert_eq!(
|
||
|
|
char_to_usage(ch),
|
||
|
|
Some(expected),
|
||
|
|
"unexpected mapping for {ch:?}"
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn char_to_usage_rejects_characters_outside_the_ascii_contract() {
|
||
|
|
for ch in ['é', '🙂', '\u{2603}'] {
|
||
|
|
assert_eq!(char_to_usage(ch), None, "unexpected support for {ch:?}");
|
||
|
|
}
|
||
|
|
}
|