|
1 | 1 | from textwrap import dedent |
| 2 | +from typing import Dict |
2 | 3 |
|
3 | 4 | from kalamine import KeyboardLayout |
4 | 5 | from kalamine.generators.xkb import xkb_table |
5 | 6 |
|
6 | 7 | from .util import get_layout_dict |
7 | 8 |
|
8 | 9 |
|
9 | | -def load_layout(filename: str) -> KeyboardLayout: |
10 | | - return KeyboardLayout(get_layout_dict(filename)) |
| 10 | +def load_layout( |
| 11 | + filename: str, extraMapping: Dict[str, Dict[str, str]] |
| 12 | +) -> KeyboardLayout: |
| 13 | + return KeyboardLayout(get_layout_dict(filename, extraMapping)) |
11 | 14 |
|
12 | 15 |
|
13 | 16 | def split(multiline_str: str): |
14 | 17 | return dedent(multiline_str).lstrip().rstrip().splitlines() |
15 | 18 |
|
16 | 19 |
|
17 | 20 | def test_ansi(): |
18 | | - layout = load_layout("ansi") |
| 21 | + layout = load_layout("ansi", {}) |
19 | 22 |
|
20 | 23 | expected = split( |
21 | 24 | """ |
@@ -91,8 +94,6 @@ def test_ansi(): |
91 | 94 |
|
92 | 95 |
|
93 | 96 | def test_intl(): |
94 | | - layout = load_layout("intl") |
95 | | - |
96 | 97 | expected = split( |
97 | 98 | """ |
98 | 99 | // Digits |
@@ -158,17 +159,46 @@ def test_intl(): |
158 | 159 | """ |
159 | 160 | ) |
160 | 161 |
|
161 | | - xkbcomp = xkb_table(layout, xkbcomp=True) |
162 | | - assert len(xkbcomp) == len(expected) |
163 | | - assert xkbcomp == expected |
| 162 | + extraMapping = { |
| 163 | + # NOTE: redefine level |
| 164 | + "ae01": {"shift": "?"}, |
| 165 | + # NOTE: test case variants and ODK alias |
| 166 | + "menu": {"base": "a", "sHiFt": "A", "1dk": "æ", "ODk_shiFt": "Æ"}, |
| 167 | + # NOTE: clone level |
| 168 | + "esc": {"base": "(ae11)"}, |
| 169 | + # NOTE: clone key |
| 170 | + "i172": "(lsgt)", |
| 171 | + } |
| 172 | + |
| 173 | + extraSymbols = [ |
| 174 | + "", |
| 175 | + "// System", |
| 176 | + "key <ESC> {[ minus , VoidSymbol , VoidSymbol , VoidSymbol ]}; // -", |
| 177 | + "key <MENU> {[ a , A , ae , AE ]}; // a A æ Æ", |
| 178 | + "", |
| 179 | + "// Miscellaneous", |
| 180 | + "key <I172> {[ backslash , bar , VoidSymbol , VoidSymbol ]}; // \\ |", |
| 181 | + ] |
| 182 | + |
| 183 | + extraExpected = expected + extraSymbols |
| 184 | + extraExpected[1] = ( |
| 185 | + "key <AE01> {[ 1 , question , VoidSymbol , VoidSymbol ]}; // 1 ?" |
| 186 | + ) |
164 | 187 |
|
165 | | - xkbpatch = xkb_table(layout, xkbcomp=False) |
166 | | - assert len(xkbpatch) == len(expected) |
167 | | - assert xkbpatch == expected |
| 188 | + for mapping, expectedʹ in (({}, expected), (extraMapping, extraExpected)): |
| 189 | + layout = load_layout("intl", mapping) |
| 190 | + |
| 191 | + xkbcomp = xkb_table(layout, xkbcomp=True) |
| 192 | + assert len(xkbcomp) == len(expectedʹ) |
| 193 | + assert xkbcomp == expectedʹ |
| 194 | + |
| 195 | + xkbpatch = xkb_table(layout, xkbcomp=False) |
| 196 | + assert len(xkbpatch) == len(expectedʹ) |
| 197 | + assert xkbpatch == expectedʹ |
168 | 198 |
|
169 | 199 |
|
170 | 200 | def test_prog(): |
171 | | - layout = load_layout("prog") |
| 201 | + layout = load_layout("prog", {}) |
172 | 202 |
|
173 | 203 | expected = split( |
174 | 204 | """ |
|
0 commit comments