blob: fba8af8c7bd74a5a0c46b272aec4fad14dad0668 [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 Moolenaarc0f88232020-08-16 21:51:49 +0200174" Test for spell file format errors
175func Test_spellfile_format_error()
176 let save_rtp = &rtp
177 call mkdir('Xtest/spell', 'p')
178
179 " empty spell file
180 call writefile([], './Xtest/spell/Xtest.utf-8.spl')
181 set runtimepath=./Xtest
182 set spelllang=Xtest
183 call assert_fails('set spell', 'E757:')
184 set nospell spelllang&
185
186 " invalid file ID
187 call writefile(['vim'], './Xtest/spell/Xtest.utf-8.spl')
188 set runtimepath=./Xtest
189 set spelllang=Xtest
190 call assert_fails('set spell', 'E757:')
191 set nospell spelllang&
192
193 " missing version number
194 call writefile(['VIMspell'], './Xtest/spell/Xtest.utf-8.spl')
195 set runtimepath=./Xtest
196 set spelllang=Xtest
197 call assert_fails('set spell', 'E771:')
198 set nospell spelllang&
199
200 " invalid version number
201 call writefile(['VIMspellz'], './Xtest/spell/Xtest.utf-8.spl')
202 set runtimepath=./Xtest
203 set spelllang=Xtest
204 call assert_fails('set spell', 'E772:')
205 set nospell spelllang&
206
207 " no sections
208 call writefile(0z56494D7370656C6C32, './Xtest/spell/Xtest.utf-8.spl', 'b')
209 set runtimepath=./Xtest
210 set spelllang=Xtest
211 call assert_fails('set spell', 'E758:')
212 set nospell spelllang&
213
214 " missing section length
215 call writefile(['VIMspell200'], './Xtest/spell/Xtest.utf-8.spl')
216 set runtimepath=./Xtest
217 set spelllang=Xtest
218 call assert_fails('set spell', 'E758:')
219 set nospell spelllang&
220
221 " unsupported required section
222 call writefile(['VIMspell2z' .. nr2char(1) .. ' ' .. nr2char(4)],
223 \ './Xtest/spell/Xtest.utf-8.spl')
224 set runtimepath=./Xtest
225 set spelllang=Xtest
226 call assert_fails('set spell', 'E770:')
227 set nospell spelllang&
228
229 " unsupported not-required section
230 call writefile(['VIMspell2z' .. nr2char(0) .. ' ' .. nr2char(4)],
231 \ './Xtest/spell/Xtest.utf-8.spl')
232 set runtimepath=./Xtest
233 set spelllang=Xtest
234 call assert_fails('set spell', 'E758:')
235 set nospell spelllang&
236
237 " SN_REGION: invalid number of region names
238 call writefile(0z56494D7370656C6C320000000000FF,
239 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
240 set runtimepath=./Xtest
241 set spelllang=Xtest
242 call assert_fails('set spell', 'E759:')
243 set nospell spelllang&
244
245 " SN_CHARFLAGS: missing <charflagslen> length
246 call writefile(0z56494D7370656C6C32010000000004,
247 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
248 set runtimepath=./Xtest
249 set spelllang=Xtest
250 call assert_fails('set spell', 'E758:')
251 set nospell spelllang&
252
253 " SN_CHARFLAGS: invalid <charflagslen> length
254 call writefile(0z56494D7370656C6C320100000000010201,
255 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
256 set runtimepath=./Xtest
257 set spelllang=Xtest
258 set spell
259 " FIXME: There are no error messages. How to check for the test result?
260 set nospell spelllang&
261
262 " SN_CHARFLAGS: charflagslen == 0 and folcharslen != 0
263 call writefile(0z56494D7370656C6C3201000000000400000101,
264 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
265 set runtimepath=./Xtest
266 set spelllang=Xtest
267 call assert_fails('set spell', 'E759:')
268 set nospell spelllang&
269
270 " SN_CHARFLAGS: missing <folcharslen> length
271 call writefile(0z56494D7370656C6C3201000000000100,
272 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
273 set runtimepath=./Xtest
274 set spelllang=Xtest
275 call assert_fails('set spell', 'E758:')
276 set nospell spelllang&
277
278 " SN_PREFCOND: invalid prefcondcnt
279 call writefile(0z56494D7370656C6C3203000000000100,
280 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
281 set runtimepath=./Xtest
282 set spelllang=Xtest
283 call assert_fails('set spell', 'E759:')
284 set nospell spelllang&
285
286 " SN_PREFCOND: invalid condlen
287 call writefile(0z56494D7370656C6C320300000000020001,
288 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
289 set runtimepath=./Xtest
290 set spelllang=Xtest
291 call assert_fails('set spell', 'E759:')
292 set nospell spelllang&
293
294 " SN_REP: invalid repcount
295 call writefile(0z56494D7370656C6C3204000000000100,
296 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
297 set runtimepath=./Xtest
298 set spelllang=Xtest
299 call assert_fails('set spell', 'E758:')
300 set nospell spelllang&
301
302 " SN_REP: missing rep
303 call writefile(0z56494D7370656C6C320400000000020004,
304 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
305 set runtimepath=./Xtest
306 set spelllang=Xtest
307 call assert_fails('set spell', 'E758:')
308 set nospell spelllang&
309
310 " SN_REP: zero repfromlen
311 call writefile(0z56494D7370656C6C32040000000003000100,
312 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
313 set runtimepath=./Xtest
314 set spelllang=Xtest
315 call assert_fails('set spell', 'E759:')
316 set nospell spelllang&
317
318 " SN_REP: invalid reptolen
319 call writefile(0z56494D7370656C6C320400000000050001014101,
320 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
321 set runtimepath=./Xtest
322 set spelllang=Xtest
323 " FIXME: There are no error messages. How to check for the test result?
324 set spell
325 set nospell spelllang&
326
327 " SN_REP: zero reptolen
328 call writefile(0z56494D7370656C6C320400000000050001014100,
329 \ './Xtest/spell/Xtest.utf-8.spl', 'b')
330 set runtimepath=./Xtest
331 set spelllang=Xtest
332 call assert_fails('set spell', 'E759:')
333 set nospell spelllang&
334
335 let &rtp = save_rtp
336 call delete('Xtest', 'rf')
337endfunc
338
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200339" vim: shiftwidth=2 sts=2 expandtab