|
1 | 1 | # A part of NonVisual Desktop Access (NVDA) |
2 | 2 | # This file is covered by the GNU General Public License. |
3 | 3 | # See the file COPYING for more details. |
4 | | -# Copyright (C) 2020 NV Access Limited |
| 4 | +# Copyright (C) 2020-2022 NV Access Limited, Cyrille Bougot |
5 | 5 |
|
6 | 6 | """Unit tests for the characterProcessing module. |
7 | 7 | """ |
|
11 | 11 | from characterProcessing import SpeechSymbolProcessor |
12 | 12 | from characterProcessing import SymbolLevel |
13 | 13 | from characterProcessing import processSpeechSymbols as process |
| 14 | +from characterProcessing import processSpeechSymbol |
14 | 15 |
|
15 | 16 |
|
16 | 17 | class TestComplex(unittest.TestCase): |
@@ -128,3 +129,56 @@ def test_engine(self): |
128 | 129 | self.assertEqual(replaced, "Le 03 point 04 point 05 point.") |
129 | 130 | replaced = process("fr_FR", "Le 03/04/05.", SymbolLevel.ALL) |
130 | 131 | self.assertEqual(replaced, "Le 03 barre oblique 04 barre oblique 05 point.") |
| 132 | + |
| 133 | + |
| 134 | +# A character in CLDR file but not in symbol file |
| 135 | +CHAR_IN_CLDR_FILE = '☺' |
| 136 | +CHAR_IN_CLDR_FILE_DESC = 'smiling face' |
| 137 | +# A character in symbol file but not in CLDR file |
| 138 | +CHAR_IN_SYMB_FILE = ' ' |
| 139 | +CHAR_IN_SYMB_FILE_DESC = 'space' |
| 140 | +# A character in both CLDR and symbol file |
| 141 | +CHAR_IN_BOTH_FILES = '.' |
| 142 | +CHAR_IN_BOTH_FILES_DESC = 'dot' |
| 143 | + |
| 144 | + |
| 145 | +class TestUsingCLDR(unittest.TestCase): |
| 146 | + |
| 147 | + def test_processSpeechSymbol_withoutSymbolFile(self): |
| 148 | + """Test processSpeechSymbol with languages that have CLDR file but no symbol file. |
| 149 | + """ |
| 150 | + |
| 151 | + languagesWithoutSymbolFile = [ |
| 152 | + # The real list is: |
| 153 | + # 'af_ZA', 'am', 'as', 'gu', 'id', 'kok', 'ml', 'mni', 'ne', 'te', 'th', 'ur' |
| 154 | + # But 'mni' has only a few symbols in CLDR (and not the smiling face) |
| 155 | + 'af_ZA', 'am', 'as', 'gu', 'id', 'kok', 'ml', 'ne', 'te', 'th', 'ur' |
| 156 | + ] |
| 157 | + for locale in languagesWithoutSymbolFile: |
| 158 | + self.assertNotEqual( |
| 159 | + processSpeechSymbol(locale, CHAR_IN_CLDR_FILE), |
| 160 | + CHAR_IN_CLDR_FILE_DESC, |
| 161 | + msg=f'Test failure for locale={locale} with "{CHAR_IN_CLDR_FILE_DESC}"', |
| 162 | + ) |
| 163 | + self.assertEqual( |
| 164 | + processSpeechSymbol(locale, CHAR_IN_SYMB_FILE), |
| 165 | + CHAR_IN_SYMB_FILE_DESC, |
| 166 | + msg=f'Test failure for locale={locale} with "{CHAR_IN_SYMB_FILE_DESC}"', |
| 167 | + ) |
| 168 | + |
| 169 | + def test_processSpeechSymbol_withSymbolFile(self): |
| 170 | + """Test processSpeechSymbol with languages that have both CLDR and symbol file. |
| 171 | + """ |
| 172 | + |
| 173 | + languagesWithSymbolFileAndCLDR = ['fr_FR'] |
| 174 | + for locale in languagesWithSymbolFileAndCLDR: |
| 175 | + self.assertNotEqual( |
| 176 | + processSpeechSymbol(locale, CHAR_IN_CLDR_FILE), |
| 177 | + CHAR_IN_CLDR_FILE_DESC, |
| 178 | + msg=f'Test failure for locale={locale} with "{CHAR_IN_CLDR_FILE_DESC}"', |
| 179 | + ) |
| 180 | + self.assertNotEqual( |
| 181 | + processSpeechSymbol(locale, CHAR_IN_SYMB_FILE), |
| 182 | + CHAR_IN_SYMB_FILE_DESC, |
| 183 | + msg=f'Test failure for locale={locale} with "{CHAR_IN_SYMB_FILE_DESC}"', |
| 184 | + ) |
0 commit comments