diff --git a/tests/test_serializer_xkb.py b/tests/test_serializer_xkb.py index 45319db..febf4f5 100644 --- a/tests/test_serializer_xkb.py +++ b/tests/test_serializer_xkb.py @@ -1,4 +1,5 @@ from textwrap import dedent +from typing import Dict from kalamine import KeyboardLayout from kalamine.generators.xkb import xkb_table @@ -6,8 +7,10 @@ from .util import get_layout_dict -def load_layout(filename: str) -> KeyboardLayout: - return KeyboardLayout(get_layout_dict(filename)) +def load_layout( + filename: str, extraMapping: Dict[str, Dict[str, str]] +) -> KeyboardLayout: + return KeyboardLayout(get_layout_dict(filename, extraMapping)) def split(multiline_str: str): @@ -15,7 +18,7 @@ def split(multiline_str: str): def test_ansi(): - layout = load_layout("ansi") + layout = load_layout("ansi", {}) expected = split( """ @@ -91,8 +94,6 @@ def test_ansi(): def test_intl(): - layout = load_layout("intl") - expected = split( """ // Digits @@ -158,17 +159,46 @@ def test_intl(): """ ) - xkbcomp = xkb_table(layout, xkbcomp=True) - assert len(xkbcomp) == len(expected) - assert xkbcomp == expected + extraMapping = { + # NOTE: redefine level + "ae01": {"shift": "?"}, + # NOTE: test case variants and ODK alias + "menu": {"base": "a", "sHiFt": "A", "1dk": "æ", "ODk_shiFt": "Æ"}, + # NOTE: clone level + "esc": {"base": "(ae11)"}, + # NOTE: clone key + "i172": "(lsgt)", + } + + extraSymbols = [ + "", + "// System", + "key {[ minus , VoidSymbol , VoidSymbol , VoidSymbol ]}; // -", + "key {[ a , A , ae , AE ]}; // a A æ Æ", + "", + "// Miscellaneous", + "key {[ backslash , bar , VoidSymbol , VoidSymbol ]}; // \\ |", + ] + + extraExpected = expected + extraSymbols + extraExpected[1] = ( + "key {[ 1 , question , VoidSymbol , VoidSymbol ]}; // 1 ?" + ) - xkbpatch = xkb_table(layout, xkbcomp=False) - assert len(xkbpatch) == len(expected) - assert xkbpatch == expected + for mapping, expectedʹ in (({}, expected), (extraMapping, extraExpected)): + layout = load_layout("intl", mapping) + + xkbcomp = xkb_table(layout, xkbcomp=True) + assert len(xkbcomp) == len(expectedʹ) + assert xkbcomp == expectedʹ + + xkbpatch = xkb_table(layout, xkbcomp=False) + assert len(xkbpatch) == len(expectedʹ) + assert xkbpatch == expectedʹ def test_prog(): - layout = load_layout("prog") + layout = load_layout("prog", {}) expected = split( """ diff --git a/tests/util.py b/tests/util.py index c4b35f2..45a8d0b 100644 --- a/tests/util.py +++ b/tests/util.py @@ -1,14 +1,19 @@ """Some util functions for tests.""" from pathlib import Path -from typing import Dict +from typing import Dict, Optional import tomli -def get_layout_dict(filename: str) -> Dict: +def get_layout_dict( + filename: str, extraMapping: Optional[Dict[str, Dict[str, str]]] = None +) -> Dict: """Return the layout directory path.""" file_path = Path(__file__).parent.parent / f"layouts/{filename}.toml" with file_path.open(mode="rb") as file: - return tomli.load(file) + layout = tomli.load(file) + if extraMapping: + layout.update({"mapping": extraMapping}) + return layout