52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
"""Key/character translation tables."""
|
|
|
|
import pytest
|
|
|
|
from mcqemu.keymap import char_to_keys, parse_chord, resolve_key
|
|
|
|
|
|
def test_aliases():
|
|
assert resolve_key("enter") == "ret"
|
|
assert resolve_key("Escape") == "esc"
|
|
assert resolve_key("space") == "spc"
|
|
assert resolve_key("win") == "meta_l"
|
|
|
|
|
|
def test_plain_qcodes_pass_through():
|
|
for key in ("ret", "f11", "a", "9", "ctrl", "grave_accent"):
|
|
assert resolve_key(key) == key
|
|
|
|
|
|
def test_unknown_key_raises():
|
|
with pytest.raises(ValueError, match="Unknown key"):
|
|
resolve_key("hyperspace")
|
|
|
|
|
|
def test_chords():
|
|
assert parse_chord("ctrl-alt-f2") == ["ctrl", "alt", "f2"]
|
|
assert parse_chord("ctrl-c") == ["ctrl", "c"]
|
|
assert parse_chord("-") == ["minus"]
|
|
|
|
|
|
def test_char_lowercase():
|
|
assert char_to_keys("a") == ("a", False)
|
|
assert char_to_keys("5") == ("5", False)
|
|
|
|
|
|
def test_char_shifted():
|
|
assert char_to_keys("A") == ("a", True)
|
|
assert char_to_keys("!") == ("1", True)
|
|
assert char_to_keys("_") == ("minus", True)
|
|
assert char_to_keys('"') == ("apostrophe", True)
|
|
|
|
|
|
def test_char_specials():
|
|
assert char_to_keys(" ") == ("spc", False)
|
|
assert char_to_keys("\n") == ("ret", False)
|
|
assert char_to_keys("/") == ("slash", False)
|
|
|
|
|
|
def test_untypeable_char_raises():
|
|
with pytest.raises(ValueError, match="Cannot type"):
|
|
char_to_keys("é")
|