Mercurial > vim
comparison src/testdir/test_spell.vim @ 18970:0413239d2b96 v8.2.0046
patch 8.2.0046: tests for spell suggestions are slow
Commit: https://github.com/vim/vim/commit/767340574b5a0c697e650b3bbc3a4af10e51cb89
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 26 14:30:15 2019 +0100
patch 8.2.0046: tests for spell suggestions are slow
Problem: Tests for spell suggestions are slow.
Solution: Use shorter words. Test with latin1 and utf-8 to cover more code.
(Dominique Pelle, closes #5399)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 26 Dec 2019 14:45:06 +0100 |
parents | 305a7a8d9d4b |
children | da98d2ed8dc5 |
comparison
equal
deleted
inserted
replaced
18969:23d5acda7107 | 18970:0413239d2b96 |
---|---|
130 | 130 |
131 " Test spellsuggest({word} [, {max} [, {capital}]]) | 131 " Test spellsuggest({word} [, {max} [, {capital}]]) |
132 func Test_spellsuggest() | 132 func Test_spellsuggest() |
133 " No suggestions when spell checking is not enabled. | 133 " No suggestions when spell checking is not enabled. |
134 set nospell | 134 set nospell |
135 call assert_equal([], spellsuggest('mercurry')) | 135 call assert_equal([], spellsuggest('marrch')) |
136 | 136 |
137 set spell | 137 set spell |
138 | 138 |
139 " With 1 argument. | 139 " With 1 argument. |
140 call assert_equal(['mercury', 'Mercury'], spellsuggest('mercurry')[0:1]) | 140 call assert_equal(['march', 'March'], spellsuggest('marrch')[0:1]) |
141 | 141 |
142 " With 2 arguments. | 142 " With 2 arguments. |
143 call assert_equal(['mercury', 'Mercury'], spellsuggest('mercurry', 2)) | 143 call assert_equal(['march', 'March'], spellsuggest('marrch', 2)) |
144 | 144 |
145 " With 3 arguments. | 145 " With 3 arguments. |
146 call assert_equal(['mercury'], spellsuggest('mercurry', 1, 0)) | 146 call assert_equal(['march'], spellsuggest('marrch', 1, 0)) |
147 call assert_equal(['Mercury'], spellsuggest('mercurry', 1, 1)) | 147 call assert_equal(['March'], spellsuggest('marrch', 1, 1)) |
148 | 148 |
149 " Test with digits and hyphen. | 149 " Test with digits and hyphen. |
150 call assert_equal('Carbon-14', spellsuggest('Carbon-15')[0]) | 150 call assert_equal('Carbon-14', spellsuggest('Carbon-15')[0]) |
151 | 151 |
152 " Comment taken from spellsuggest.c explains the following test cases: | 152 " Comment taken from spellsuggest.c explains the following test cases: |
153 " | 153 " |
154 " If there are more UPPER than lower case letters suggest an | 154 " If there are more UPPER than lower case letters suggest an |
155 " ALLCAP word. Otherwise, if the first letter is UPPER then | 155 " ALLCAP word. Otherwise, if the first letter is UPPER then |
156 " suggest ONECAP. Exception: "ALl" most likely should be "All", | 156 " suggest ONECAP. Exception: "ALl" most likely should be "All", |
157 " require three upper case letters. | 157 " require three upper case letters. |
158 call assert_equal(['MACARONI', 'macaroni'], spellsuggest('maCARONI', 2)) | 158 call assert_equal(['THIRD', 'third'], spellsuggest('thIRD', 2)) |
159 call assert_equal(['macaroni', 'MACARONI'], spellsuggest('maCAroni', 2)) | 159 call assert_equal(['third', 'THIRD'], spellsuggest('tHIrd', 2)) |
160 call assert_equal(['Macaroni'], spellsuggest('MACAroni', 1)) | 160 call assert_equal(['Third'], spellsuggest('THird', 1)) |
161 call assert_equal(['All'], spellsuggest('ALl', 1)) | 161 call assert_equal(['All'], spellsuggest('ALl', 1)) |
162 | 162 |
163 set spell& | 163 set spell& |
164 endfunc | 164 endfunc |
165 | 165 |
166 " Test 'spellsuggest' option with methods fast, best and double. | 166 " Test 'spellsuggest' option with methods fast, best and double. |
167 func Test_spellsuggest_option_methods() | 167 func Test_spellsuggest_option_methods() |
168 set spell | 168 set spell |
169 | 169 |
170 set spellsuggest=fast | 170 for e in ['latin1', 'utf-8'] |
171 call assert_equal(['Keyword', 'Keyboard'], spellsuggest('Keybord', 2)) | 171 exe 'set encoding=' .. e |
172 | 172 |
173 " With best or double option, "Keyboard" should become the top suggestion | 173 set spellsuggest=fast |
174 " because of better phonetic matching. | 174 call assert_equal(['Stick', 'Stitch'], spellsuggest('Stich', 2), e) |
175 set spellsuggest=best | 175 |
176 call assert_equal(['Keyboard', 'Keyword'], spellsuggest('Keybord', 2)) | 176 " With best or double option, "Stitch" should become the top suggestion |
177 | 177 " because of better phonetic matching. |
178 set spellsuggest=double | 178 set spellsuggest=best |
179 call assert_equal(['Keyboard', 'Keyword'], spellsuggest('Keybord', 2)) | 179 call assert_equal(['Stitch', 'Stick'], spellsuggest('Stich', 2), e) |
180 | 180 |
181 set spell& spellsuggest& | 181 set spellsuggest=double |
182 call assert_equal(['Stitch', 'Stick'], spellsuggest('Stich', 2), e) | |
183 endfor | |
184 | |
185 set spell& spellsuggest& encoding& | |
182 endfunc | 186 endfunc |
183 | 187 |
184 " Test 'spellsuggest' option with value file:{filename} | 188 " Test 'spellsuggest' option with value file:{filename} |
185 func Test_spellsuggest_option_file() | 189 func Test_spellsuggest_option_file() |
186 set spell spellsuggest=file:Xspellsuggest | 190 set spell spellsuggest=file:Xspellsuggest |
218 new | 222 new |
219 | 223 |
220 " We limited the number of suggestions to 2, so selecting | 224 " We limited the number of suggestions to 2, so selecting |
221 " the 1st and 2nd suggestion should correct the word, but | 225 " the 1st and 2nd suggestion should correct the word, but |
222 " selecting a 3rd suggestion should do nothing. | 226 " selecting a 3rd suggestion should do nothing. |
223 call setline(1, 'Keybord') | 227 call setline(1, 'A baord') |
224 norm 1z= | 228 norm $1z= |
225 call assert_equal('Keyboard', getline(1)) | 229 call assert_equal('A board', getline(1)) |
226 | 230 |
227 call setline(1, 'Keybord') | 231 call setline(1, 'A baord') |
228 norm 2z= | 232 norm $2z= |
229 call assert_equal('Keyword', getline(1)) | 233 call assert_equal('A bard', getline(1)) |
230 | 234 |
231 call setline(1, 'Keybord') | 235 call setline(1, 'A baord') |
232 norm 3z= | 236 norm $3z= |
233 call assert_equal('Keybord', getline(1)) | 237 call assert_equal('A baord', getline(1)) |
234 | 238 |
235 let a = execute('norm z=') | 239 let a = execute('norm $z=') |
236 call assert_equal( | 240 call assert_equal( |
237 \ "\n" | 241 \ "\n" |
238 \ .. "Change \"Keybord\" to:\n" | 242 \ .. "Change \"baord\" to:\n" |
239 \ .. " 1 \"Keyboard\"\n" | 243 \ .. " 1 \"board\"\n" |
240 \ .. " 2 \"Keyword\"\n" | 244 \ .. " 2 \"bard\"\n" |
241 \ .. "Type number and <Enter> or click with mouse (empty cancels): ", a) | 245 \ .. "Type number and <Enter> or click with mouse (empty cancels): ", a) |
242 | 246 |
243 set spell spellsuggest=0 | 247 set spell spellsuggest=0 |
244 call assert_equal("\nSorry, no suggestions", execute('norm z=')) | 248 call assert_equal("\nSorry, no suggestions", execute('norm $z=')) |
245 | 249 |
246 " Unlike z=, function spellsuggest(...) should not be affected by the | 250 " Unlike z=, function spellsuggest(...) should not be affected by the |
247 " max number of suggestions (2) set by the 'spellsuggest' option. | 251 " max number of suggestions (2) set by the 'spellsuggest' option. |
248 call assert_equal(['Keyboard', 'Keyword', 'Keyboards'], spellsuggest('Keybord', 3)) | 252 call assert_equal(['board', 'bard', 'broad'], spellsuggest('baord', 3)) |
249 | 253 |
250 set spellsuggest& spell& | 254 set spellsuggest& spell& |
251 bwipe! | 255 bwipe! |
252 endfunc | 256 endfunc |
253 | 257 |
256 " A silly 'spellsuggest' function which makes suggestions all uppercase | 260 " A silly 'spellsuggest' function which makes suggestions all uppercase |
257 " and makes the score of each suggestion the length of the suggested word. | 261 " and makes the score of each suggestion the length of the suggested word. |
258 " So shorter suggestions are preferred. | 262 " So shorter suggestions are preferred. |
259 func MySuggest() | 263 func MySuggest() |
260 let spellsuggest_save = &spellsuggest | 264 let spellsuggest_save = &spellsuggest |
261 set spellsuggest=best | 265 set spellsuggest=3,best |
262 let result = map(spellsuggest(v:val, 3), "[toupper(v:val), len(v:val)]") | 266 let result = map(spellsuggest(v:val, 3), "[toupper(v:val), len(v:val)]") |
263 let &spellsuggest = spellsuggest_save | 267 let &spellsuggest = spellsuggest_save |
264 return result | 268 return result |
265 endfunc | 269 endfunc |
266 | 270 |
267 set spell spellsuggest=3,expr:MySuggest() | 271 set spell spellsuggest=expr:MySuggest() |
268 call assert_equal(['KEYWORD', 'KEYBOARD', 'KEYBOARDS'], spellsuggest('Keybord', 3)) | 272 call assert_equal(['BARD', 'BOARD', 'BROAD'], spellsuggest('baord', 3)) |
269 call assert_equal(['KEYWORD', 'KEYBOARD', 'KEYBOARDS'], spellsuggest('Keybord', 3)) | |
270 | 273 |
271 new | 274 new |
272 call setline(1, 'Keybord') | 275 call setline(1, 'baord') |
273 let a = execute('norm z=') | 276 let a = execute('norm z=') |
274 call assert_equal( | 277 call assert_equal( |
275 \ "\n" | 278 \ "\n" |
276 \ .. "Change \"Keybord\" to:\n" | 279 \ .. "Change \"baord\" to:\n" |
277 \ .. " 1 \"KEYWORD\"\n" | 280 \ .. " 1 \"BARD\"\n" |
278 \ .. " 2 \"KEYBOARD\"\n" | 281 \ .. " 2 \"BOARD\"\n" |
279 \ .. " 3 \"KEYBOARDS\"\n" | 282 \ .. " 3 \"BROAD\"\n" |
280 \ .. "Type number and <Enter> or click with mouse (empty cancels): ", a) | 283 \ .. "Type number and <Enter> or click with mouse (empty cancels): ", a) |
281 | 284 |
282 " With verbose, z= should show the score i.e. word length with | 285 " With verbose, z= should show the score i.e. word length with |
283 " our SpellSuggest() function. | 286 " our SpellSuggest() function. |
284 set verbose=1 | 287 set verbose=1 |
285 let a = execute('norm z=') | 288 let a = execute('norm z=') |
286 call assert_equal( | 289 call assert_equal( |
287 \ "\n" | 290 \ "\n" |
288 \ .. "Change \"Keybord\" to:\n" | 291 \ .. "Change \"baord\" to:\n" |
289 \ .. " 1 \"KEYWORD\" (7 - 0)\n" | 292 \ .. " 1 \"BARD\" (4 - 0)\n" |
290 \ .. " 2 \"KEYBOARD\" (8 - 0)\n" | 293 \ .. " 2 \"BOARD\" (5 - 0)\n" |
291 \ .. " 3 \"KEYBOARDS\" (9 - 0)\n" | 294 \ .. " 3 \"BROAD\" (5 - 0)\n" |
292 \ .. "Type number and <Enter> or click with mouse (empty cancels): ", a) | 295 \ .. "Type number and <Enter> or click with mouse (empty cancels): ", a) |
293 | 296 |
294 set spell& spellsuggest& verbose& | 297 set spell& spellsuggest& verbose& |
295 bwipe! | 298 bwipe! |
296 endfunc | 299 endfunc |