File: test_steno.py

package info (click to toggle)
plover 4.0.0~dev10-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,644 kB
  • sloc: python: 17,030; sh: 664; ansic: 25; makefile: 19
file content (68 lines) | stat: -rw-r--r-- 1,782 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (c) 2013 Hesky Fisher
# See LICENSE.txt for details.

"""Unit tests for steno.py."""

from plover.steno import normalize_steno, Stroke

from plover_build_utils.testing import parametrize


NORMALIZE_TESTS = (
    # TODO: More cases
    lambda: ('S', 'S'),
    lambda: ('S-', 'S'),
    lambda: ('-S', '-S'),
    lambda: ('ES', 'ES'),
    lambda: ('-ES', 'ES'),
    lambda: ('TW-EPBL', 'TWEPBL'),
    lambda: ('TWEPBL', 'TWEPBL'),
    lambda: ('19', '1-9'),
    lambda: ('14', '14'),
    lambda: ('146', '14-6'),
    lambda: ('67', '-67'),
    lambda: ('6', '-6'),
    lambda: ('9', '-9'),
    lambda: ('5', '5'),
    lambda: ('0', '0'),
    lambda: ('456', '456'),
    lambda: ('46', '4-6'),
    lambda: ('4*6', '4*6'),
    lambda: ('456', '456'),
    lambda: ('S46', 'S4-6'),
    # Number key.
    lambda: ('#S', '#S'),
    lambda: ('#A', '#A'),
    lambda: ('#0', '0'),
    lambda: ('#6', '-6'),
    # Implicit hyphens.
    lambda: ('SA-', 'SA'),
    lambda: ('SA-R', 'SAR'),
    lambda: ('-O', 'O'),
    lambda: ('S*-R', 'S*R'),
    lambda: ('S-*R', 'S*R'),
)

@parametrize(NORMALIZE_TESTS)
def test_normalize_steno(steno, strokes):
    result = '/'.join(normalize_steno(steno))
    msg = 'normalize_steno(%r)=%r != %r' % (
        steno, result, strokes,
    )
    assert result == strokes, msg


STROKE_TESTS = (
    lambda: (['S-'], ['S-'], 'S'),
    lambda: (['S-', 'T-'], ['S-', 'T-'], 'ST'),
    lambda: (['T-', 'S-'], ['S-', 'T-'], 'ST'),
    lambda: (['-P', '-P'], ['-P'], '-P'),
    lambda: (['-P', 'X-'], ['X-', '-P'], 'X-P'),
    lambda: (['#', 'S-', '-T'], ['1-', '-9'], '1-9'),
)

@parametrize(STROKE_TESTS)
def test_stroke(keys, steno_keys, rtfcre):
    stroke = Stroke(keys)
    assert stroke.steno_keys == steno_keys
    assert stroke.rtfcre == rtfcre