blob: 6913d407169d52be1529838a1b10c338415225e2 [file] [log] [blame]
Bram Moolenaar08cc3742019-08-11 22:51:14 +02001" Test for commands that operate on the spellfile.
2
3source shared.vim
4source check.vim
5
6CheckFeature spell
7CheckFeature syntax
8
9func Test_spell_normal()
10 new
11 call append(0, ['1 good', '2 goood', '3 goood'])
12 set spell spellfile=./Xspellfile.add spelllang=en
13 let oldlang=v:lang
14 lang C
15
16 " Test for zg
17 1
18 norm! ]s
19 call assert_equal('2 goood', getline('.'))
20 norm! zg
21 1
22 let a=execute('unsilent :norm! ]s')
23 call assert_equal('1 good', getline('.'))
24 call assert_equal('search hit BOTTOM, continuing at TOP', a[1:])
25 let cnt=readfile('./Xspellfile.add')
26 call assert_equal('goood', cnt[0])
27
28 " Test for zw
29 2
30 norm! $zw
31 1
32 norm! ]s
33 call assert_equal('2 goood', getline('.'))
34 let cnt=readfile('./Xspellfile.add')
35 call assert_equal('#oood', cnt[0])
36 call assert_equal('goood/!', cnt[1])
37
38 " Test for :spellrare
39 spellrare rare
40 let cnt=readfile('./Xspellfile.add')
41 call assert_equal(['#oood', 'goood/!', 'rare/?'], cnt)
42
43 " Make sure :spellundo works for rare words.
44 spellundo rare
45 let cnt=readfile('./Xspellfile.add')
46 call assert_equal(['#oood', 'goood/!', '#are/?'], cnt)
47
48 " Test for zg in visual mode
49 let a=execute('unsilent :norm! V$zg')
50 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
51 1
52 norm! ]s
53 call assert_equal('3 goood', getline('.'))
54 let cnt=readfile('./Xspellfile.add')
55 call assert_equal('2 goood', cnt[3])
56 " Remove "2 good" from spellfile
57 2
58 let a=execute('unsilent norm! V$zw')
59 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
60 let cnt=readfile('./Xspellfile.add')
61 call assert_equal('2 goood/!', cnt[4])
62
63 " Test for zG
64 let a=execute('unsilent norm! V$zG')
65 call assert_match("Word '2 goood' added to .*", a)
66 let fname=matchstr(a, 'to\s\+\zs\f\+$')
67 let cnt=readfile(fname)
68 call assert_equal('2 goood', cnt[0])
69
70 " Test for zW
71 let a=execute('unsilent norm! V$zW')
72 call assert_match("Word '2 goood' added to .*", a)
73 let cnt=readfile(fname)
74 call assert_equal('# goood', cnt[0])
75 call assert_equal('2 goood/!', cnt[1])
76
77 " Test for zuW
78 let a=execute('unsilent norm! V$zuW')
79 call assert_match("Word '2 goood' removed from .*", a)
80 let cnt=readfile(fname)
81 call assert_equal('# goood', cnt[0])
82 call assert_equal('# goood/!', cnt[1])
83
84 " Test for zuG
85 let a=execute('unsilent norm! $zG')
86 call assert_match("Word 'goood' added to .*", a)
87 let cnt=readfile(fname)
88 call assert_equal('# goood', cnt[0])
89 call assert_equal('# goood/!', cnt[1])
90 call assert_equal('goood', cnt[2])
91 let a=execute('unsilent norm! $zuG')
92 let cnt=readfile(fname)
93 call assert_match("Word 'goood' removed from .*", a)
94 call assert_equal('# goood', cnt[0])
95 call assert_equal('# goood/!', cnt[1])
96 call assert_equal('#oood', cnt[2])
97 " word not found in wordlist
98 let a=execute('unsilent norm! V$zuG')
99 let cnt=readfile(fname)
100 call assert_match("", a)
101 call assert_equal('# goood', cnt[0])
102 call assert_equal('# goood/!', cnt[1])
103 call assert_equal('#oood', cnt[2])
104
105 " Test for zug
106 call delete('./Xspellfile.add')
107 2
108 let a=execute('unsilent norm! $zg')
109 let cnt=readfile('./Xspellfile.add')
110 call assert_equal('goood', cnt[0])
111 let a=execute('unsilent norm! $zug')
112 call assert_match("Word 'goood' removed from \./Xspellfile.add", a)
113 let cnt=readfile('./Xspellfile.add')
114 call assert_equal('#oood', cnt[0])
115 " word not in wordlist
116 let a=execute('unsilent norm! V$zug')
117 call assert_match('', a)
118 let cnt=readfile('./Xspellfile.add')
119 call assert_equal('#oood', cnt[0])
120
121 " Test for zuw
122 call delete('./Xspellfile.add')
123 2
124 let a=execute('unsilent norm! Vzw')
125 let cnt=readfile('./Xspellfile.add')
126 call assert_equal('2 goood/!', cnt[0])
127 let a=execute('unsilent norm! Vzuw')
128 call assert_match("Word '2 goood' removed from \./Xspellfile.add", a)
129 let cnt=readfile('./Xspellfile.add')
130 call assert_equal('# goood/!', cnt[0])
131 " word not in wordlist
132 let a=execute('unsilent norm! $zug')
133 call assert_match('', a)
134 let cnt=readfile('./Xspellfile.add')
135 call assert_equal('# goood/!', cnt[0])
136
137 " add second entry to spellfile setting
138 set spellfile=./Xspellfile.add,./Xspellfile2.add
139 call delete('./Xspellfile.add')
140 2
141 let a=execute('unsilent norm! $2zg')
142 let cnt=readfile('./Xspellfile2.add')
143 call assert_match("Word 'goood' added to ./Xspellfile2.add", a)
144 call assert_equal('goood', cnt[0])
145
146 " Test for :spellgood!
147 let temp = execute(':spe!0/0')
148 call assert_match('Invalid region', temp)
149 let spellfile = matchstr(temp, 'Invalid region nr in \zs.*\ze line \d: 0')
150 call assert_equal(['# goood', '# goood/!', '#oood', '0/0'], readfile(spellfile))
151
152 " Test for :spellrare!
153 :spellrare! raare
154 call assert_equal(['# goood', '# goood/!', '#oood', '0/0', 'raare/?'], readfile(spellfile))
155 call delete(spellfile)
156
157 " clean up
158 exe "lang" oldlang
159 call delete("./Xspellfile.add")
160 call delete("./Xspellfile2.add")
161 call delete("./Xspellfile.add.spl")
162 call delete("./Xspellfile2.add.spl")
163
164 " zux -> no-op
165 2
166 norm! $zux
167 call assert_equal([], glob('Xspellfile.add',0,1))
168 call assert_equal([], glob('Xspellfile2.add',0,1))
169
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200170 set spellfile= spell& spelllang&
Bram Moolenaar08cc3742019-08-11 22:51:14 +0200171 bw!
172endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200173
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200174" Spell file content test. Write 'content' to the spell file prefixed by the
175" spell file header and then enable spell checking. If 'emsg' is not empty,
176" then check for error.
177func Spellfile_Test(content, emsg)
178 let splfile = './Xtest/spell/Xtest.utf-8.spl'
179 " Add the spell file header and version (VIMspell2)
180 let v = 0z56494D7370656C6C32 + a:content
181 call writefile(v, splfile, 'b')
182 set runtimepath=./Xtest
183 set spelllang=Xtest
184 if a:emsg != ''
185 call assert_fails('set spell', a:emsg)
186 else
187 " FIXME: With some invalid spellfile contents, there are no error
188 " messages. So don't know how to check for the test result.
189 set spell
190 endif
191 set nospell spelllang& rtp&
192endfunc
193
194" Test for spell file format errors.
195" The spell file format is described in spellfile.c
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200196func Test_spellfile_format_error()
197 let save_rtp = &rtp
198 call mkdir('Xtest/spell', 'p')
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200199 let splfile = './Xtest/spell/Xtest.utf-8.spl'
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200200
201 " empty spell file
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200202 call writefile([], splfile)
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200203 set runtimepath=./Xtest
204 set spelllang=Xtest
205 call assert_fails('set spell', 'E757:')
206 set nospell spelllang&
207
208 " invalid file ID
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200209 call writefile(0z56494D, splfile, 'b')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200210 set runtimepath=./Xtest
211 set spelllang=Xtest
212 call assert_fails('set spell', 'E757:')
213 set nospell spelllang&
214
215 " missing version number
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200216 call writefile(0z56494D7370656C6C, splfile, 'b')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200217 set runtimepath=./Xtest
218 set spelllang=Xtest
219 call assert_fails('set spell', 'E771:')
220 set nospell spelllang&
221
222 " invalid version number
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200223 call writefile(0z56494D7370656C6C7A, splfile, 'b')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200224 set runtimepath=./Xtest
225 set spelllang=Xtest
226 call assert_fails('set spell', 'E772:')
227 set nospell spelllang&
228
229 " no sections
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200230 call Spellfile_Test(0z, 'E758:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200231
232 " missing section length
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200233 call Spellfile_Test(0z00, 'E758:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200234
235 " unsupported required section
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200236 call Spellfile_Test(0z7A0100000004, 'E770:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200237
238 " unsupported not-required section
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200239 call Spellfile_Test(0z7A0000000004, 'E758:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200240
241 " SN_REGION: invalid number of region names
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200242 call Spellfile_Test(0z0000000000FF, 'E759:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200243
244 " SN_CHARFLAGS: missing <charflagslen> length
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200245 call Spellfile_Test(0z010000000004, 'E758:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200246
247 " SN_CHARFLAGS: invalid <charflagslen> length
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200248 call Spellfile_Test(0z0100000000010201, '')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200249
250 " SN_CHARFLAGS: charflagslen == 0 and folcharslen != 0
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200251 call Spellfile_Test(0z01000000000400000101, 'E759:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200252
253 " SN_CHARFLAGS: missing <folcharslen> length
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200254 call Spellfile_Test(0z01000000000100, 'E758:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200255
256 " SN_PREFCOND: invalid prefcondcnt
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200257 call Spellfile_Test(0z03000000000100, 'E759:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200258
259 " SN_PREFCOND: invalid condlen
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200260 call Spellfile_Test(0z0300000000020001, 'E759:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200261
262 " SN_REP: invalid repcount
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200263 call Spellfile_Test(0z04000000000100, 'E758:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200264
265 " SN_REP: missing rep
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200266 call Spellfile_Test(0z0400000000020004, 'E758:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200267
268 " SN_REP: zero repfromlen
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200269 call Spellfile_Test(0z040000000003000100, 'E759:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200270
271 " SN_REP: invalid reptolen
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200272 call Spellfile_Test(0z0400000000050001014101, '')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200273
274 " SN_REP: zero reptolen
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200275 call Spellfile_Test(0z0400000000050001014100, 'E759:')
276
277 " SN_SAL: missing salcount
278 call Spellfile_Test(0z05000000000102, 'E758:')
279
280 " SN_SAL: missing salfromlen
281 call Spellfile_Test(0z050000000003080001, 'E758:')
282
283 " SN_SAL: missing saltolen
284 call Spellfile_Test(0z0500000000050400010161, 'E758:')
285
286 " SN_WORDS: non-NUL terminated word
287 call Spellfile_Test(0z0D000000000376696D, 'E758:')
288
289 " SN_WORDS: very long word
290 let v = eval('0z0D000000012C' .. repeat('41', 300))
291 call Spellfile_Test(v, 'E759:')
292
293 " SN_SOFO: missing sofofromlen
294 call Spellfile_Test(0z06000000000100, 'E758:')
295
296 " SN_SOFO: missing sofotolen
297 call Spellfile_Test(0z06000000000400016100, 'E758:')
298
299 " SN_SOFO: missing sofoto
300 call Spellfile_Test(0z0600000000050001610000, 'E759:')
301
302 " SN_COMPOUND: compmax is less than 2
303 call Spellfile_Test(0z08000000000101, 'E759:')
304
305 " SN_COMPOUND: missing compsylmax and other options
306 call Spellfile_Test(0z0800000000020401, 'E759:')
307
308 " SN_COMPOUND: missing compoptions
309 call Spellfile_Test(0z080000000005040101, 'E758:')
310
311 " SN_INFO: missing info
312 call Spellfile_Test(0z0F0000000005040101, '')
313
314 " SN_MIDWORD: missing midword
315 call Spellfile_Test(0z0200000000040102, '')
316
317 " SN_MAP: missing midword
318 call Spellfile_Test(0z0700000000040102, '')
319
320 " SN_SYLLABLE: missing SYLLABLE item
321 call Spellfile_Test(0z0900000000040102, '')
322
323 " SN_SYLLABLE: More than SY_MAXLEN size
324 let v = eval('0z090000000022612F' .. repeat('62', 32))
325 call Spellfile_Test(v, '')
326
327 " LWORDTREE: missing
328 call Spellfile_Test(0zFF, 'E758:')
329
330 " LWORDTREE: missing tree node
331 call Spellfile_Test(0zFF00000004, 'E758:')
332
333 " LWORDTREE: missing tree node value
334 call Spellfile_Test(0zFF0000000402, 'E758:')
335
336 " KWORDTREE: missing tree node
337 call Spellfile_Test(0zFF0000000000000004, 'E758:')
338
339 " PREFIXTREE: missing tree node
340 call Spellfile_Test(0zFF000000000000000000000004, 'E758:')
341
342 let &rtp = save_rtp
343 call delete('Xtest', 'rf')
344endfunc
345
346" Test for format errors in suggest file
347func Test_sugfile_format_error()
348 let save_rtp = &rtp
349 call mkdir('Xtest/spell', 'p')
350 let splfile = './Xtest/spell/Xtest.utf-8.spl'
351 let sugfile = './Xtest/spell/Xtest.utf-8.sug'
352
353 " create an empty spell file with a suggest timestamp
354 call writefile(0z56494D7370656C6C320B00000000080000000000000044FF000000000000000000000000, splfile, 'b')
355
356 " 'encoding' is set before each test to clear the previously loaded suggest
357 " file from memory.
358
359 " empty suggest file
360 set encoding=utf-8
361 call writefile([], sugfile)
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200362 set runtimepath=./Xtest
363 set spelllang=Xtest
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200364 set spell
365 call assert_fails("let s = spellsuggest('abc')", 'E778:')
366 set nospell spelllang&
367
368 " zero suggest version
369 set encoding=utf-8
370 call writefile(0z56494D73756700, sugfile)
371 set runtimepath=./Xtest
372 set spelllang=Xtest
373 set spell
374 call assert_fails("let s = spellsuggest('abc')", 'E779:')
375 set nospell spelllang&
376
377 " unsupported suggest version
378 set encoding=utf-8
379 call writefile(0z56494D7375671F, sugfile)
380 set runtimepath=./Xtest
381 set spelllang=Xtest
382 set spell
383 call assert_fails("let s = spellsuggest('abc')", 'E780:')
384 set nospell spelllang&
385
386 " missing suggest timestamp
387 set encoding=utf-8
388 call writefile(0z56494D73756701, sugfile)
389 set runtimepath=./Xtest
390 set spelllang=Xtest
391 set spell
392 call assert_fails("let s = spellsuggest('abc')", 'E781:')
393 set nospell spelllang&
394
395 " incorrect suggest timestamp
396 set encoding=utf-8
397 call writefile(0z56494D7375670100000000000000FF, sugfile)
398 set runtimepath=./Xtest
399 set spelllang=Xtest
400 set spell
401 call assert_fails("let s = spellsuggest('abc')", 'E781:')
402 set nospell spelllang&
403
404 " missing suggest wordtree
405 set encoding=utf-8
406 call writefile(0z56494D737567010000000000000044, sugfile)
407 set runtimepath=./Xtest
408 set spelllang=Xtest
409 set spell
410 call assert_fails("let s = spellsuggest('abc')", 'E782:')
Bram Moolenaarc0f88232020-08-16 21:51:49 +0200411 set nospell spelllang&
412
413 let &rtp = save_rtp
414 call delete('Xtest', 'rf')
415endfunc
416
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200417" Test for using :mkspell to create a spell file from a list of words
418func Test_wordlist_dic()
419 " duplicate encoding
420 let lines =<< trim [END]
421 # This is an example word list
422
423 /encoding=latin1
424 /encoding=latin1
425 example
426 [END]
427 call writefile(lines, 'Xwordlist.dic')
428 let output = execute('mkspell Xwordlist.spl Xwordlist.dic')
429 call assert_match('Duplicate /encoding= line ignored in Xwordlist.dic line 4: /encoding=latin1', output)
430
431 " multiple encoding for a word
432 let lines =<< trim [END]
433 example
434 /encoding=latin1
435 example
436 [END]
437 call writefile(lines, 'Xwordlist.dic')
438 let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
439 call assert_match('/encoding= line after word ignored in Xwordlist.dic line 2: /encoding=latin1', output)
440
441 " unsupported encoding for a word
442 let lines =<< trim [END]
443 /encoding=Xtest
444 example
445 [END]
446 call writefile(lines, 'Xwordlist.dic')
447 let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
448 call assert_match('Conversion in Xwordlist.dic not supported: from Xtest to utf-8', output)
449
450 " duplicate region
451 let lines =<< trim [END]
452 /regions=usca
453 /regions=usca
454 example
455 [END]
456 call writefile(lines, 'Xwordlist.dic')
457 let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
458 call assert_match('Duplicate /regions= line ignored in Xwordlist.dic line 2: regions=usca', output)
459
460 " maximum regions
461 let lines =<< trim [END]
462 /regions=uscauscauscauscausca
463 example
464 [END]
465 call writefile(lines, 'Xwordlist.dic')
466 let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
467 call assert_match('Too many regions in Xwordlist.dic line 1: uscauscauscauscausca', output)
468
469 " unsupported '/' value
470 let lines =<< trim [END]
471 /test=abc
472 example
473 [END]
474 call writefile(lines, 'Xwordlist.dic')
475 let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
476 call assert_match('/ line ignored in Xwordlist.dic line 1: /test=abc', output)
477
478 " unsupported flag
479 let lines =<< trim [END]
480 example/+
481 [END]
482 call writefile(lines, 'Xwordlist.dic')
483 let output = execute('mkspell! Xwordlist.spl Xwordlist.dic')
484 call assert_match('Unrecognized flags in Xwordlist.dic line 1: +', output)
485
486 " non-ascii word
487 call writefile(["ʀʀ"], 'Xwordlist.dic')
488 let output = execute('mkspell! -ascii Xwordlist.spl Xwordlist.dic')
489 call assert_match('Ignored 1 words with non-ASCII characters', output)
490
491 call delete('Xwordlist.spl')
492 call delete('Xwordlist.dic')
493endfunc
494
495" Test for the :mkspell command
496func Test_mkspell()
497 call assert_fails('mkspell Xtest_us.spl', 'E751:')
498 call assert_fails('mkspell a b c d e f g h i j k', 'E754:')
499
500 call writefile([], 'Xtest.spl')
501 call writefile([], 'Xtest.dic')
502 call assert_fails('mkspell Xtest.spl Xtest.dic', 'E13:')
503 call delete('Xtest.spl')
504 call delete('Xtest.dic')
505
506 call mkdir('Xtest.spl')
507 call assert_fails('mkspell! Xtest.spl Xtest.dic', 'E17:')
508 call delete('Xtest.spl', 'rf')
509
510 call assert_fails('mkspell en en_US abc_xyz', 'E755:')
511endfunc
512
Bram Moolenaarc8ec5fe2020-08-24 20:28:56 +0200513" Tests for :mkspell with a .dic and .aff file
514func Test_aff_file_format_error()
515 " No word count in .dic file
516 call writefile([], 'Xtest.dic')
517 call writefile([], 'Xtest.aff')
518 call assert_fails('mkspell! Xtest.spl Xtest', 'E760:')
519
520 " Invalid encoding in .aff file
521 call writefile(['1', 'work'], 'Xtest.dic')
522 call writefile(['# comment', 'SET Xinvalidencoding'], 'Xtest.aff')
523 let output = execute('mkspell! Xtest.spl Xtest')
524 call assert_match('Conversion in Xtest.aff not supported: from xinvalidencoding', output)
525
526 " Invalid flag in .aff file
527 call writefile(['1', 'work'], 'Xtest.dic')
528 call writefile(['FLAG xxx'], 'Xtest.aff')
529 let output = execute('mkspell! Xtest.spl Xtest')
530 call assert_match('Invalid value for FLAG in Xtest.aff line 1: xxx', output)
531
532 " set FLAGS after using flag for an affix
533 call writefile(['1', 'work'], 'Xtest.dic')
534 call writefile(['SFX L Y 1', 'SFX L 0 re [^x]', 'FLAG long'], 'Xtest.aff')
535 let output = execute('mkspell! Xtest.spl Xtest')
536 call assert_match('FLAG after using flags in Xtest.aff line 3: long', output)
537
538 " INFO in affix file
539 let save_encoding = &encoding
540 call mkdir('Xrtp/spell', 'p')
541 call writefile(['1', 'work'], 'Xrtp/spell/Xtest.dic')
542 call writefile(['NAME klingon', 'VERSION 1.4', 'AUTHOR Spock'],
543 \ 'Xrtp/spell/Xtest.aff')
544 silent mkspell! Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest
545 let save_rtp = &rtp
546 set runtimepath=./Xrtp
547 set spelllang=Xtest
548 set spell
549 let output = split(execute('spellinfo'), "\n")
550 call assert_equal("NAME klingon", output[1])
551 call assert_equal("VERSION 1.4", output[2])
552 call assert_equal("AUTHOR Spock", output[3])
553 let &rtp = save_rtp
554 call delete('Xrtp', 'rf')
555 set spell& spelllang& spellfile&
556 %bw!
557 " 'encoding' must be set again to clear the spell file in memory
558 let &encoding = save_encoding
559
560 " COMPOUNDFORBIDFLAG flag after PFX in an affix file
561 call writefile(['1', 'work'], 'Xtest.dic')
562 call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDFLAG c', 'COMPOUNDFORBIDFLAG x'],
563 \ 'Xtest.aff')
564 let output = execute('mkspell! Xtest.spl Xtest')
565 call assert_match('Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in Xtest.aff line 4', output)
566
567 " COMPOUNDPERMITFLAG flag after PFX in an affix file
568 call writefile(['1', 'work'], 'Xtest.dic')
569 call writefile(['PFX L Y 1', 'PFX L 0 re x', 'COMPOUNDPERMITFLAG c'],
570 \ 'Xtest.aff')
571 let output = execute('mkspell! Xtest.spl Xtest')
572 call assert_match('Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in Xtest.aff line 3', output)
573
574 " Wrong COMPOUNDRULES flag value in an affix file
575 call writefile(['1', 'work'], 'Xtest.dic')
576 call writefile(['COMPOUNDRULES a'], 'Xtest.aff')
577 let output = execute('mkspell! Xtest.spl Xtest')
578 call assert_match('Wrong COMPOUNDRULES value in Xtest.aff line 1: a', output)
579
580 " Wrong COMPOUNDWORDMAX flag value in an affix file
581 call writefile(['1', 'work'], 'Xtest.dic')
582 call writefile(['COMPOUNDWORDMAX 0'], 'Xtest.aff')
583 let output = execute('mkspell! Xtest.spl Xtest')
584 call assert_match('Wrong COMPOUNDWORDMAX value in Xtest.aff line 1: 0', output)
585
586 " Wrong COMPOUNDMIN flag value in an affix file
587 call writefile(['1', 'work'], 'Xtest.dic')
588 call writefile(['COMPOUNDMIN 0'], 'Xtest.aff')
589 let output = execute('mkspell! Xtest.spl Xtest')
590 call assert_match('Wrong COMPOUNDMIN value in Xtest.aff line 1: 0', output)
591
592 " Wrong COMPOUNDSYLMAX flag value in an affix file
593 call writefile(['1', 'work'], 'Xtest.dic')
594 call writefile(['COMPOUNDSYLMAX 0'], 'Xtest.aff')
595 let output = execute('mkspell! Xtest.spl Xtest')
596 call assert_match('Wrong COMPOUNDSYLMAX value in Xtest.aff line 1: 0', output)
597
598 " Wrong CHECKCOMPOUNDPATTERN flag value in an affix file
599 call writefile(['1', 'work'], 'Xtest.dic')
600 call writefile(['CHECKCOMPOUNDPATTERN 0'], 'Xtest.aff')
601 let output = execute('mkspell! Xtest.spl Xtest')
602 call assert_match('Wrong CHECKCOMPOUNDPATTERN value in Xtest.aff line 1: 0', output)
603
604 " Duplicate affix entry in an affix file
605 call writefile(['1', 'work'], 'Xtest.dic')
606 call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L Y 1', 'PFX L 0 re x'],
607 \ 'Xtest.aff')
608 let output = execute('mkspell! Xtest.spl Xtest')
609 call assert_match('Duplicate affix in Xtest.aff line 3: L', output)
610
611 " Duplicate affix entry in an affix file
612 call writefile(['1', 'work'], 'Xtest.dic')
613 call writefile(['PFX L Y 1', 'PFX L Y 1'], 'Xtest.aff')
614 let output = execute('mkspell! Xtest.spl Xtest')
615 call assert_match('Unrecognized or duplicate item in Xtest.aff line 2: PFX', output)
616
617 " Different combining flags in an affix file
618 call writefile(['1', 'work'], 'Xtest.dic')
619 call writefile(['PFX L Y 1', 'PFX L 0 re x', 'PFX L N 1'], 'Xtest.aff')
620 let output = execute('mkspell! Xtest.spl Xtest')
621 call assert_match('Different combining flag in continued affix block in Xtest.aff line 3', output)
622
623 " Try to reuse a affix used for BAD flag
624 call writefile(['1', 'work'], 'Xtest.dic')
625 call writefile(['BAD x', 'PFX x Y 1', 'PFX x 0 re x'], 'Xtest.aff')
626 let output = execute('mkspell! Xtest.spl Xtest')
627 call assert_match('Affix also used for BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST in Xtest.aff line 2: x', output)
628
629 " Trailing characters in an affix entry
630 call writefile(['1', 'work'], 'Xtest.dic')
631 call writefile(['PFX L Y 1 Test', 'PFX L 0 re x'], 'Xtest.aff')
632 let output = execute('mkspell! Xtest.spl Xtest')
633 call assert_match('Trailing text in Xtest.aff line 1: Test', output)
634
635 " Trailing characters in an affix entry
636 call writefile(['1', 'work'], 'Xtest.dic')
637 call writefile(['PFX L Y 1', 'PFX L 0 re x Test'], 'Xtest.aff')
638 let output = execute('mkspell! Xtest.spl Xtest')
639 call assert_match('Trailing text in Xtest.aff line 2: Test', output)
640
641 " Incorrect combine flag in an affix entry
642 call writefile(['1', 'work'], 'Xtest.dic')
643 call writefile(['PFX L X 1', 'PFX L 0 re x'], 'Xtest.aff')
644 let output = execute('mkspell! Xtest.spl Xtest')
645 call assert_match('Expected Y or N in Xtest.aff line 1: X', output)
646
647 " Invalid count for REP item
648 call writefile(['1', 'work'], 'Xtest.dic')
649 call writefile(['REP a'], 'Xtest.aff')
650 let output = execute('mkspell! Xtest.spl Xtest')
651 call assert_match('Expected REP(SAL) count in Xtest.aff line 1', output)
652
653 " Trailing characters in REP item
654 call writefile(['1', 'work'], 'Xtest.dic')
655 call writefile(['REP 1', 'REP f ph test'], 'Xtest.aff')
656 let output = execute('mkspell! Xtest.spl Xtest')
657 call assert_match('Trailing text in Xtest.aff line 2: test', output)
658
659 " Invalid count for MAP item
660 call writefile(['1', 'work'], 'Xtest.dic')
661 call writefile(['MAP a'], 'Xtest.aff')
662 let output = execute('mkspell! Xtest.spl Xtest')
663 call assert_match('Expected MAP count in Xtest.aff line 1', output)
664
665 " Duplicate character in a MAP item
666 call writefile(['1', 'work'], 'Xtest.dic')
667 call writefile(['MAP 2', 'MAP xx', 'MAP yy'], 'Xtest.aff')
668 let output = execute('mkspell! Xtest.spl Xtest')
669 call assert_match('Duplicate character in MAP in Xtest.aff line 2', output)
670
671 " Use COMPOUNDSYLMAX without SYLLABLE
672 call writefile(['1', 'work'], 'Xtest.dic')
673 call writefile(['COMPOUNDSYLMAX 2'], 'Xtest.aff')
674 let output = execute('mkspell! Xtest.spl Xtest')
675 call assert_match('COMPOUNDSYLMAX used without SYLLABLE', output)
676
677 " Missing SOFOTO
678 call writefile(['1', 'work'], 'Xtest.dic')
679 call writefile(['SOFOFROM abcdef'], 'Xtest.aff')
680 let output = execute('mkspell! Xtest.spl Xtest')
681 call assert_match('Missing SOFOTO line in Xtest.aff', output)
682
683 " FIXME: The following test causes a heap overflow with the ASAN build
684 " " Both SAL and SOFOFROM/SOFOTO items
685 " call writefile(['1', 'work'], 'Xtest.dic')
686 " call writefile(['SOFOFROM abcd', 'SOFOTO ABCD', 'SAL CIA X'], 'Xtest.aff')
687 " let output = execute('mkspell! Xtest.spl Xtest')
688 " call assert_match('Both SAL and SOFO lines in Xtest.aff', output)
689
690 " use an alphabet flag when FLAG is num
691 call writefile(['1', 'work'], 'Xtest.dic')
692 call writefile(['FLAG num', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff')
693 let output = execute('mkspell! Xtest.spl Xtest')
694 call assert_match('Flag is not a number in Xtest.aff line 2: L', output)
695
696 " use number and alphabet flag when FLAG is num
697 call writefile(['1', 'work'], 'Xtest.dic')
698 call writefile(['FLAG num', 'SFX 4f Y 1', 'SFX 4f 0 re [^x]'], 'Xtest.aff')
699 let output = execute('mkspell! Xtest.spl Xtest')
700 call assert_match('Affix name too long in Xtest.aff line 2: 4f', output)
701
702 " use a single character flag when FLAG is long
703 call writefile(['1', 'work'], 'Xtest.dic')
704 call writefile(['FLAG long', 'SFX L Y 1', 'SFX L 0 re [^x]'], 'Xtest.aff')
705 let output = execute('mkspell! Xtest.spl Xtest')
706 call assert_match('Illegal flag in Xtest.aff line 2: L', output)
707
708 call delete('Xtest.dic')
709 call delete('Xtest.aff')
710 call delete('Xtest.spl')
711 call delete('Xtest.sug')
712endfunc
713
Bram Moolenaarfc2a47f2020-08-20 15:41:55 +0200714func Test_spell_add_word()
715 set spellfile=
716 call assert_fails('spellgood abc', 'E764:')
717
718 set spellfile=Xtest.utf-8.add
719 call assert_fails('2spellgood abc', 'E765:')
720
721 edit Xtest.utf-8.add
722 call setline(1, 'sample')
723 call assert_fails('spellgood abc', 'E139:')
724 set spellfile&
725 %bw!
726endfunc
727
Bram Moolenaarc8ec5fe2020-08-24 20:28:56 +0200728" When 'spellfile' is not set, adding a new good word will automatically set
729" the 'spellfile'
730func Test_init_spellfile()
731 let save_rtp = &rtp
732 let save_encoding = &encoding
733 call mkdir('Xrtp/spell', 'p')
734 call writefile(['vim'], 'Xrtp/spell/Xtest.dic')
735 silent mkspell Xrtp/spell/Xtest.utf-8.spl Xrtp/spell/Xtest.dic
736 set runtimepath=./Xrtp
737 set spelllang=Xtest
738 set spell
739 silent spellgood abc
740 call assert_equal('./Xrtp/spell/Xtest.utf-8.add', &spellfile)
741 call assert_equal(['abc'], readfile('Xrtp/spell/Xtest.utf-8.add'))
742 call assert_true(filereadable('Xrtp/spell/Xtest.utf-8.spl'))
743 set spell& spelllang& spellfile&
744 call delete('Xrtp', 'rf')
745 let &encoding = save_encoding
746 let &rtp = save_rtp
747 %bw!
748endfunc
749
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200750" vim: shiftwidth=2 sts=2 expandtab