|
7 | 7 | from django.test import SimpleTestCase |
8 | 8 |
|
9 | 9 | from weblate.checks.chars import ( |
| 10 | + AcceleratorKeyCheck, |
10 | 11 | BeginNewlineCheck, |
11 | 12 | BeginSpaceCheck, |
12 | 13 | DoubleSpaceCheck, |
|
32 | 33 | from weblate.trans.tests.factories import make_check, make_unit |
33 | 34 |
|
34 | 35 |
|
| 36 | +class AcceleratorKeyCheckTest(CheckTestCase): |
| 37 | + check = AcceleratorKeyCheck() |
| 38 | + |
| 39 | + def setUp(self) -> None: |
| 40 | + super().setUp() |
| 41 | + self.test_good_matching = ("&File", "&File", "accelerators") |
| 42 | + self.test_good_none = ("File", "File", "accelerators") |
| 43 | + self.test_good_flag = ("&File", "File", "") |
| 44 | + self.test_failure_1 = ("&File", "File", "accelerators") |
| 45 | + self.test_failure_2 = ("File", "&File", "accelerators") |
| 46 | + self.test_failure_3 = ("&File", "&File &Edit", "accelerators") |
| 47 | + |
| 48 | + def test_underscore_accelerator(self) -> None: |
| 49 | + self.do_test(False, ("_File", "_File", "accelerators")) |
| 50 | + self.do_test(True, ("_File", "File", "accelerators")) |
| 51 | + self.do_test(True, ("File", "_File", "accelerators")) |
| 52 | + |
| 53 | + def test_literal_ampersand(self) -> None: |
| 54 | + # A balanced, literal ampersand is not treated as an accelerator key. |
| 55 | + self.do_test(False, ("Walter & Sons", "Walter & Sons", "accelerators")) |
| 56 | + |
| 57 | + def test_multiple_accelerators(self) -> None: |
| 58 | + # More than one accelerator in the target is reported even if counts match. |
| 59 | + self.do_test(True, ("&File &Edit", "&File &Edit", "accelerators")) |
| 60 | + # A mismatched marker type (& vs _) is reported. |
| 61 | + self.do_test(True, ("&File", "_File", "accelerators")) |
| 62 | + |
| 63 | + |
35 | 64 | class BeginNewlineCheckTest(CheckTestCase): |
36 | 65 | check = BeginNewlineCheck() |
37 | 66 |
|
|
0 commit comments