robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
20.4 KiB666 linesraw
1" Tests for search_stats, when "S" is not in 'shortmess'
2
3source check.vim
4source screendump.vim
5
6func Test_search_stat()
7  new
8  set shortmess-=S
9  " Append 50 lines with text to search for, "foobar" appears 20 times
10  call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
11
12  call cursor(1, 1)
13
14  " searchcount() returns an empty dictionary when previous pattern was not set
15  call assert_equal({}, searchcount(#{pattern: ''}))
16  " but setting @/ should also work (even 'n' nor 'N' was executed)
17  " recompute the count when the last position is different.
18  call assert_equal(
19    \ #{current: 1, exact_match: 1, total: 40, incomplete: 0, maxcount: 99},
20    \ searchcount(#{pattern: 'foo'}))
21  call assert_equal(
22    \ #{current: 0, exact_match: 0, total: 10, incomplete: 0, maxcount: 99},
23    \ searchcount(#{pattern: 'fooooobar'}))
24  call assert_equal(
25    \ #{current: 0, exact_match: 0, total: 10, incomplete: 0, maxcount: 99},
26    \ searchcount(#{pattern: 'fooooobar', pos: [2, 1, 0]}))
27  call assert_equal(
28    \ #{current: 1, exact_match: 1, total: 10, incomplete: 0, maxcount: 99},
29    \ searchcount(#{pattern: 'fooooobar', pos: [3, 1, 0]}))
30  " on last char of match
31  call assert_equal(
32    \ #{current: 1, exact_match: 1, total: 10, incomplete: 0, maxcount: 99},
33    \ searchcount(#{pattern: 'fooooobar', pos: [3, 9, 0]}))
34  " on char after match
35  call assert_equal(
36    \ #{current: 1, exact_match: 0, total: 10, incomplete: 0, maxcount: 99},
37    \ searchcount(#{pattern: 'fooooobar', pos: [3, 10, 0]}))
38  call assert_equal(
39    \ #{current: 1, exact_match: 0, total: 10, incomplete: 0, maxcount: 99},
40    \ searchcount(#{pattern: 'fooooobar', pos: [4, 1, 0]}))
41  call assert_equal(
42    \ #{current: 1, exact_match: 0, total: 2, incomplete: 2, maxcount: 1},
43    \ searchcount(#{pattern: 'fooooobar', pos: [4, 1, 0], maxcount: 1}))
44  call assert_equal(
45    \ #{current: 0, exact_match: 0, total: 2, incomplete: 2, maxcount: 1},
46    \ searchcount(#{pattern: 'fooooobar', maxcount: 1}))
47
48  " match at second line
49  let messages_before = execute('messages')
50  let @/ = 'fo*\(bar\?\)\?'
51  let g:a = execute(':unsilent :norm! n')
52  let stat = '\[2/50\]'
53  let pat = escape(@/, '()*?'). '\s\+'
54  call assert_match(pat .. stat, g:a)
55  call assert_equal(
56    \ #{current: 2, exact_match: 1, total: 50, incomplete: 0, maxcount: 99},
57    \ searchcount(#{recompute: 0}))
58  " didn't get added to message history
59  call assert_equal(messages_before, execute('messages'))
60
61  " Match at last line
62  call cursor(line('$')-2, 1)
63  let g:a = execute(':unsilent :norm! n')
64  let stat = '\[50/50\]'
65  call assert_match(pat .. stat, g:a)
66  call assert_equal(
67    \ #{current: 50, exact_match: 1, total: 50, incomplete: 0, maxcount: 99},
68    \ searchcount(#{recompute: 0}))
69
70  " No search stat
71  set shortmess+=S
72  call cursor(1, 1)
73  let stat = '\[2/50\]'
74  let g:a = execute(':unsilent :norm! n')
75  call assert_notmatch(pat .. stat, g:a)
76  " n does not update search stat
77  call assert_equal(
78    \ #{current: 50, exact_match: 1, total: 50, incomplete: 0, maxcount: 99},
79    \ searchcount(#{recompute: 0}))
80  call assert_equal(
81    \ #{current: 2, exact_match: 1, total: 50, incomplete: 0, maxcount: 99},
82    \ searchcount(#{recompute: v:true}))
83  set shortmess-=S
84
85  " Many matches
86  call cursor(line('$')-2, 1)
87  let @/ = '.'
88  let pat = escape(@/, '()*?'). '\s\+'
89  let g:a = execute(':unsilent :norm! n')
90  let stat = '\[>99/>99\]'
91  call assert_match(pat .. stat, g:a)
92  call assert_equal(
93    \ #{current: 100, exact_match: 0, total: 100, incomplete: 2, maxcount: 99},
94    \ searchcount(#{recompute: 0}))
95  call assert_equal(
96    \ #{current: 272, exact_match: 1, total: 280, incomplete: 0, maxcount: 0},
97    \ searchcount(#{recompute: v:true, maxcount: 0, timeout: 200}))
98  call assert_equal(
99    \ #{current: 1, exact_match: 1, total: 280, incomplete: 0, maxcount: 0},
100    \ searchcount(#{recompute: 1, maxcount: 0, pos: [1, 1, 0], timeout: 200}))
101  call cursor(line('$'), 1)
102  let g:a = execute(':unsilent :norm! n')
103  let stat = 'W \[1/>99\]'
104  call assert_match(pat .. stat, g:a)
105  call assert_equal(
106    \ #{current: 1, exact_match: 1, total: 100, incomplete: 2, maxcount: 99},
107    \ searchcount(#{recompute: 0}))
108  call assert_equal(
109    \ #{current: 1, exact_match: 1, total: 280, incomplete: 0, maxcount: 0},
110    \ searchcount(#{recompute: 1, maxcount: 0, timeout: 200}))
111  call assert_equal(
112    \ #{current: 271, exact_match: 1, total: 280, incomplete: 0, maxcount: 0},
113    \ searchcount(#{recompute: 1, maxcount: 0, pos: [line('$')-2, 1, 0], timeout: 200}))
114
115  " Many matches
116  call cursor(1, 1)
117  let g:a = execute(':unsilent :norm! n')
118  let stat = '\[2/>99\]'
119  call assert_match(pat .. stat, g:a)
120  call cursor(1, 1)
121  let g:a = execute(':unsilent :norm! N')
122  let stat = 'W \[>99/>99\]'
123  call assert_match(pat .. stat, g:a)
124
125  " right-left
126  if exists("+rightleft")
127    set rl
128    call cursor(1,1)
129    let @/ = 'foobar'
130    let pat = 'raboof/\s\+'
131    let g:a = execute(':unsilent :norm! n')
132    let stat = '\[20/2\]'
133    call assert_match(pat .. stat, g:a)
134    set norl
135  endif
136
137  " right-left bottom
138  if exists("+rightleft")
139    set rl
140    call cursor('$',1)
141    let pat = 'raboof?\s\+'
142    let g:a = execute(':unsilent :norm! N')
143    let stat = '\[20/20\]'
144    call assert_match(pat .. stat, g:a)
145    set norl
146  endif
147
148  " right-left back at top
149  if exists("+rightleft")
150    set rl
151    call cursor('$',1)
152    let pat = 'raboof/\s\+'
153    let g:a = execute(':unsilent :norm! n')
154    let stat = 'W \[20/1\]'
155    call assert_match(pat .. stat, g:a)
156    set norl
157  endif
158
159  " normal, back at bottom
160  call cursor(1,1)
161  let @/ = 'foobar'
162  let pat = '?foobar\s\+'
163  let g:a = execute(':unsilent :norm! N')
164  let stat = 'W \[20/20\]'
165  call assert_match(pat .. stat, g:a)
166  call assert_match('W \[20/20\]', Screenline(&lines))
167
168  " normal, no match
169  call cursor(1,1)
170  let @/ = 'zzzzzz'
171  let g:a = ''
172  try
173    let g:a = execute(':unsilent :norm! n')
174  catch /^Vim\%((\a\+)\)\=:E486/
175    let stat = ''
176    " error message is not redir'ed to g:a, it is empty
177    call assert_true(empty(g:a))
178  catch
179    call assert_false(1)
180  endtry
181
182  " with count
183  call cursor(1, 1)
184  let @/ = 'fo*\(bar\?\)\?'
185  let g:a = execute(':unsilent :norm! 2n')
186  let stat = '\[3/50\]'
187  let pat = escape(@/, '()*?'). '\s\+'
188  call assert_match(pat .. stat, g:a)
189  let g:a = execute(':unsilent :norm! 2n')
190  let stat = '\[5/50\]'
191  call assert_match(pat .. stat, g:a)
192
193  " with offset
194  call cursor(1, 1)
195  call feedkeys("/fo*\\(bar\\?\\)\\?/+1\<cr>", 'tx')
196  let g:a = execute(':unsilent :norm! n')
197  let stat = '\[5/50\]'
198  let pat = escape(@/ .. '/+1', '()*?'). '\s\+'
199  call assert_match(pat .. stat, g:a)
200
201  " with semicolon, with/without trailing slash
202  call cursor(1, 1)
203  call feedkeys("/fooo/;/foobar/\<cr>", 'tx')
204  call assert_match('^/foobar\s*\[2/20\]', Screenline(&lines))
205  call feedkeys("/fooo/;/foobar\<cr>", 'tx')
206  call assert_match('^/foobar\s*\[4/20\]', Screenline(&lines))
207
208  " normal, n comes from a mapping
209  "     Need to move over more than 64 lines to trigger char_avail(.
210  nnoremap n nzv
211  call cursor(1,1)
212  call append(50, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
213  call setline(2, 'find this')
214  call setline(70, 'find this')
215  let @/ = 'find this'
216  let pat = '/find this\s\+'
217  let g:a = execute(':unsilent :norm n')
218  " g:a will contain several lines
219  let g:b = split(g:a, "\n")[-1]
220  let stat = '\[1/2\]'
221  call assert_match(pat .. stat, g:b)
222  unmap n
223
224  " normal, but silent
225  call cursor(1,1)
226  let @/ = 'find this'
227  let pat = '/find this\s\+'
228  let g:a = execute(':norm! n')
229  let stat = '\[1/2\]'
230  call assert_notmatch(pat .. stat, g:a)
231
232  " normal, n comes from a silent mapping
233  " First test a normal mapping, then a silent mapping
234  call cursor(1,1)
235  nnoremap n n
236  let @/ = 'find this'
237  let pat = '/find this\s\+'
238  let g:a = execute(':unsilent :norm n')
239  let g:b = split(g:a, "\n")[-1]
240  let stat = '\[1/2\]'
241  call assert_match(pat .. stat, g:b)
242  nnoremap <silent> n n
243  call cursor(1,1)
244  let g:a = execute(':unsilent :norm n')
245  let g:b = split(g:a, "\n")[-1]
246  let stat = '\[1/2\]'
247  call assert_notmatch(pat .. stat, g:b)
248  call assert_match(stat, g:b)
249  " Test that the message is not truncated
250  " it would insert '...' into the output.
251  call assert_match('^\s\+' .. stat, g:b)
252  unmap n
253
254  " Time out
255  %delete _
256  call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 100000))
257  call cursor(1, 1)
258  call assert_equal(1, searchcount(#{pattern: 'foo', maxcount: 0, timeout: 1}).incomplete)
259
260  " Clean up
261  set shortmess+=S
262  " close the window
263  bwipe!
264endfunc
265
266func Test_searchcount_fails()
267  call assert_fails('echo searchcount("boo!")', 'E1206:')
268  call assert_fails('echo searchcount({"timeout" : []})', 'E745:')
269  call assert_fails('echo searchcount({"maxcount" : []})', 'E745:')
270  call assert_fails('echo searchcount({"pattern" : []})', 'E730:')
271  call assert_fails('echo searchcount({"pos" : 1})', 'E475:')
272  call assert_fails('echo searchcount({"pos" : [1]})', 'E475:')
273  call assert_fails('echo searchcount({"pos" : [[], 2, 3]})', 'E745:')
274  call assert_fails('echo searchcount({"pos" : [1, [], 3]})', 'E745:')
275  call assert_fails('echo searchcount({"pos" : [1, 2, []]})', 'E745:')
276endfunc
277
278func Test_search_stat_narrow_screen()
279  " This used to crash Vim
280  let save_columns = &columns
281  try
282    let after =<< trim [CODE]
283      set laststatus=2
284      set columns=16
285      set shortmess-=S showcmd
286      call setline(1, 'abc')
287      call feedkeys("/abc\<CR>:quit!\<CR>")
288      autocmd VimLeavePre * call writefile(["done"], "Xdone")
289    [CODE]
290
291    if !RunVim([], after, '--clean')
292      return
293    endif
294    call assert_equal("done", readfile("Xdone")[0])
295    call delete('Xdone')
296  finally
297    let &columns = save_columns
298  endtry
299endfunc
300
301func Test_searchcount_in_statusline()
302  CheckScreendump
303
304  let lines =<< trim END
305    set shortmess-=S
306    call append(0, 'this is something')
307    function TestSearchCount() abort
308      let search_count = searchcount()
309      if !empty(search_count)
310	return '[' . search_count.current . '/' . search_count.total . ']'
311      else
312	return ''
313      endif
314    endfunction
315    set hlsearch
316    set laststatus=2 statusline+=%{TestSearchCount()}
317  END
318  call writefile(lines, 'Xsearchstatusline', 'D')
319  let buf = RunVimInTerminal('-S Xsearchstatusline', #{rows: 10})
320  call TermWait(buf)
321  call term_sendkeys(buf, "/something")
322  call VerifyScreenDump(buf, 'Test_searchstat_4', {})
323
324  call term_sendkeys(buf, "\<Esc>")
325  call StopVimInTerminal(buf)
326endfunc
327
328func Test_search_stat_foldopen()
329  CheckScreendump
330
331  let lines =<< trim END
332    set shortmess-=S
333    setl foldenable foldmethod=indent foldopen-=search
334    call append(0, ['if', "\tfoo", "\tfoo", 'endif'])
335    let @/ = 'foo'
336    call cursor(1,1)
337    norm n
338  END
339  call writefile(lines, 'Xsearchstat1', 'D')
340
341  let buf = RunVimInTerminal('-S Xsearchstat1', #{rows: 10})
342  call VerifyScreenDump(buf, 'Test_searchfoldopen_1', {})
343
344  call term_sendkeys(buf, "n")
345  call VerifyScreenDump(buf, 'Test_searchfoldopen_2', {})
346
347  call term_sendkeys(buf, "n")
348  call VerifyScreenDump(buf, 'Test_searchfoldopen_2', {})
349
350  call StopVimInTerminal(buf)
351endfunc
352
353func! Test_search_stat_screendump()
354  CheckScreendump
355
356  let lines =<< trim END
357    set shortmess-=S
358    " Append 50 lines with text to search for, "foobar" appears 20 times
359    call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 20))
360    call setline(2, 'find this')
361    call setline(70, 'find this')
362    nnoremap n n
363    let @/ = 'find this'
364    call cursor(1,1)
365    norm n
366  END
367  call writefile(lines, 'Xsearchstat', 'D')
368  let buf = RunVimInTerminal('-S Xsearchstat', #{rows: 10})
369  call VerifyScreenDump(buf, 'Test_searchstat_1', {})
370
371  call term_sendkeys(buf, ":nnoremap <silent> n n\<cr>")
372  call term_sendkeys(buf, "gg0n")
373  call VerifyScreenDump(buf, 'Test_searchstat_2', {})
374
375  call StopVimInTerminal(buf)
376endfunc
377
378func Test_search_stat_then_gd()
379  CheckScreendump
380
381  let lines =<< trim END
382    call setline(1, ['int cat;', 'int dog;', 'cat = dog;'])
383    set shortmess-=S
384    set hlsearch
385  END
386  call writefile(lines, 'Xsearchstatgd', 'D')
387
388  let buf = RunVimInTerminal('-S Xsearchstatgd', #{rows: 10})
389  call term_sendkeys(buf, "/dog\<CR>")
390  call VerifyScreenDump(buf, 'Test_searchstatgd_1', {})
391
392  call term_sendkeys(buf, "G0gD")
393  call VerifyScreenDump(buf, 'Test_searchstatgd_2', {})
394
395  call StopVimInTerminal(buf)
396endfunc
397
398func Test_search_stat_and_incsearch()
399  CheckScreendump
400
401  let lines =<< trim END
402    call setline(1, ['abc--c', '--------abc', '--abc'])
403    set hlsearch
404    set incsearch
405    set bg=dark
406    set showtabline=2
407
408    function MyTabLine()
409    try
410      let a=searchcount(#{recompute: 1, maxcount: -1})
411      return a.current .. '/' .. a.total
412    catch
413      return ''
414    endtry
415    endfunction
416
417    set tabline=%!MyTabLine()
418  END
419  call writefile(lines, 'Xsearchstat_inc', 'D')
420
421  let buf = RunVimInTerminal('-S Xsearchstat_inc', #{rows: 10})
422  call TermWait(buf, 100)
423  call term_sendkeys(buf, "/abc")
424  call TermWait(buf)
425  " The first 3 chars on line 2 should have highlighting, but the following not
426  " So assert the attr value of those 4 chars
427  call WaitForAssert({-> assert_true(
428    \ term_scrape(buf, 2)[0].attr == term_scrape(buf, 2)[1].attr &&
429    \ term_scrape(buf, 2)[1].attr == term_scrape(buf, 2)[2].attr &&
430    \ term_scrape(buf, 2)[2].attr != term_scrape(buf, 2)[3].attr)}, 1000)
431  call VerifyScreenDump(buf, 'Test_searchstat_inc_1', {})
432
433  call term_sendkeys(buf, "\<c-g>")
434  call WaitForAssert({-> assert_match('^3', term_getline(buf, 1))}, 1000)
435  call VerifyScreenDump(buf, 'Test_searchstat_inc_2', {})
436
437  call term_sendkeys(buf, "\<c-g>")
438  call WaitForAssert({-> assert_match('^1', term_getline(buf, 1))}, 1000)
439  call VerifyScreenDump(buf, 'Test_searchstat_inc_3', {})
440
441  call term_sendkeys(buf, "\<esc>:qa\<cr>")
442  call TermWait(buf)
443
444  call StopVimInTerminal(buf)
445endfunc
446
447func Test_search_stat_backwards()
448  CheckScreendump
449
450  let lines =<< trim END
451    set shm-=S
452    call setline(1, ['test', ''])
453  END
454  call writefile(lines, 'Xsearchstat_back', 'D')
455
456  let buf = RunVimInTerminal('-S Xsearchstat_back', #{rows: 10})
457  call term_sendkeys(buf, "*")
458  call TermWait(buf)
459  call VerifyScreenDump(buf, 'Test_searchstat_back_1', {})
460
461  call term_sendkeys(buf, "N")
462  call TermWait(buf)
463  call VerifyScreenDump(buf, 'Test_searchstat_back_2', {})
464
465  call term_sendkeys(buf, ":set shm+=S\<cr>N")
466  call TermWait(buf)
467  " shows "Search Hit Bottom.."
468  call VerifyScreenDump(buf, 'Test_searchstat_back_3', {})
469
470  call term_sendkeys(buf, "\<esc>:qa\<cr>")
471  call TermWait(buf)
472
473  call StopVimInTerminal(buf)
474endfunc
475
476func Test_search_stat_smartcase_ignorecase()
477  CheckRunVimInTerminal
478
479  let lines =<< trim END
480    set shm-=S ignorecase smartcase
481    call setline(1, [' MainmainmainmmmainmAin', ''])
482  END
483  call writefile(lines, 'Xsearchstat_ignorecase', '5')
484
485  let buf = RunVimInTerminal('-S Xsearchstat_ignorecase', #{rows: 10})
486  call term_sendkeys(buf, "/main\<cr>nnnn")
487  call WaitForAssert({-> assert_match('\[5\/5\]', term_getline(buf, 10))}, 1000)
488
489  call term_sendkeys(buf, "/mAin\<cr>")
490  call WaitForAssert({-> assert_match('\[1\/1\]', term_getline(buf, 10))}, 1000)
491
492  call StopVimInTerminal(buf)
493endfunc
494
495func Test_search_stat_option_values()
496  call assert_fails(':set maxsearchcount=0', 'E487:')
497  call assert_fails(':set maxsearchcount=10000', 'E474:')
498  set maxsearchcount=9999
499  call assert_equal(9999, &msc)
500  set maxsearchcount=1
501  call assert_equal(1, &msc)
502  set maxsearchcount=999
503  call assert_equal(999, &msc)
504  set maxsearchcount&vim
505endfunc
506
507func Test_search_stat_option()
508  " Asan causes wrong results, because the search times out
509  CheckNotAsan
510  " s390x is too slow, search times out
511  CheckNotS390
512  " Mark the test as flaky as the search may still occasionally time out
513  let g:test_is_flaky = 1
514
515  enew
516  set shortmess-=S
517  set maxsearchcount=999
518  " Append 1000 lines with text to search for, "foobar" appears 20 times
519  call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 1000))
520
521  call cursor(1, 1)
522  call assert_equal(
523    \ #{exact_match: 1, current: 1, incomplete: 2, maxcount: 999, total: 1000},
524    \ searchcount(#{pattern: 'fooooobar', pos: [3, 1, 0]}))
525  " on last char of match
526  call assert_equal(
527    \ #{exact_match: 1, current: 1, incomplete: 2, maxcount: 999, total: 1000},
528    \ searchcount(#{pattern: 'fooooobar', pos: [3, 9, 0]}))
529  " on char after match
530  call assert_equal(
531    \ #{exact_match: 0, current: 1, incomplete: 2, maxcount: 999, total: 1000},
532    \ searchcount(#{pattern: 'fooooobar', pos: [3, 10, 0]}))
533
534  " match at second line
535  let messages_before = execute('messages')
536  let @/ = 'fo*\(bar\?\)\?'
537  let g:a = execute(':unsilent :norm! n')
538  let stat = '\[2/>999\]'
539  let pat = escape(@/, '()*?'). '\s\+'
540  call assert_match(pat .. stat, g:a)
541  call assert_equal(
542    \ #{exact_match: 1, current: 2, incomplete: 2, maxcount: 999, total: 1000},
543    \ searchcount(#{recompute: 0}))
544  " didn't get added to message history
545  call assert_equal(messages_before, execute('messages'))
546
547  " If the test is being retried due to flakiness, extend the searchcount()
548  " timeout, too
549  let timeout = 500 * get(g:, 'run_nr', 1)
550
551  " Many matches
552  call cursor(line('$')-2, 1)
553  let @/ = '.'
554  let pat = escape(@/, '()*?'). '\s\+'
555  let g:a = execute(':unsilent :norm! n')
556  let stat = '\[>999/>999\]'
557  call assert_match(pat .. stat, g:a)
558  call assert_equal(
559    \ #{exact_match: 0, current: 1000, incomplete: 2, maxcount: 999, total: 1000},
560    \ searchcount(#{recompute: 0}))
561  call assert_equal(
562    \ #{exact_match: 1, current: 27992, incomplete: 0, maxcount:0, total: 28000},
563    \ searchcount(#{recompute: v:true, maxcount: 0, timeout: timeout}))
564  call assert_equal(
565    \ #{exact_match: 1, current: 1, incomplete: 0, maxcount: 0, total: 28000},
566    \ searchcount(#{recompute: 1, maxcount: 0, pos: [1, 1, 0], timeout: timeout}))
567  call cursor(line('$'), 1)
568  let g:a = execute(':unsilent :norm! n')
569  let stat = 'W \[1/>999\]'
570  call assert_match(pat .. stat, g:a)
571  call assert_equal(
572    \ #{current: 1, exact_match: 1, total: 1000, incomplete: 2, maxcount: 999},
573    \ searchcount(#{recompute: 0}))
574  call assert_equal(
575    \ #{current: 1, exact_match: 1, total: 28000, incomplete: 0, maxcount: 0},
576    \ searchcount(#{recompute: 1, maxcount: 0, timeout: timeout}))
577  call assert_equal(
578    \ #{current: 27991, exact_match: 1, total: 28000, incomplete: 0, maxcount: 0},
579    \ searchcount(#{recompute: 1, maxcount: 0, pos: [line('$')-2, 1, 0], timeout: timeout}))
580
581  " Many matches
582  call cursor(1, 1)
583  let g:a = execute(':unsilent :norm! n')
584  let stat = '\[2/>999\]'
585  call assert_match(pat .. stat, g:a)
586  call cursor(1, 1)
587  let g:a = execute(':unsilent :norm! N')
588  let stat = '\[>999/>999\]'
589  call assert_match(pat .. stat, g:a)
590  set maxsearchcount=500
591  call cursor(1, 1)
592  let g:a = execute(':unsilent :norm! n')
593  let stat = '\[2/>500\]'
594  call assert_match(pat .. stat, g:a)
595  call cursor(1, 1)
596  let g:a = execute(':unsilent :norm! N')
597  let stat = '\[>500/>500\]'
598  call assert_match(pat .. stat, g:a)
599  set maxsearchcount=20
600  call cursor(1, 1)
601  let g:a = execute(':unsilent :norm! n')
602  let stat = '\[2/>20\]'
603  call assert_match(pat .. stat, g:a)
604  call cursor(1, 1)
605  let g:a = execute(':unsilent :norm! N')
606  let stat = '\[>20/>20\]'
607  call assert_match(pat .. stat, g:a)
608  set maxsearchcount=999
609
610  " right-left
611  if exists("+rightleft")
612    set rl
613    call cursor(1,1)
614    let @/ = 'foobar'
615    let pat = 'raboof/\s\+'
616    let g:a = execute(':unsilent :norm! n')
617    let stat = '\[>999/2\]'
618    call assert_match(pat .. stat, g:a)
619
620    " right-left bottom
621    call cursor('$',1)
622    let pat = 'raboof?\s\+'
623    let g:a = execute(':unsilent :norm! N')
624    let stat = '\[>999/>999\]'
625    call assert_match(pat .. stat, g:a)
626
627    " right-left back at top
628    call cursor('$',1)
629    let pat = 'raboof/\s\+'
630    let g:a = execute(':unsilent :norm! n')
631    let stat = 'W \[>999/1\]'
632    call assert_match(pat .. stat, g:a)
633    set norl
634  endif
635
636  " normal, back at bottom
637  call cursor(1,1)
638  let @/ = 'foobar'
639  let pat = '?foobar\s\+'
640  let g:a = execute(':unsilent :norm! N')
641  let stat = 'W \[>999/>999\]'
642  call assert_match(pat .. stat, g:a)
643  call assert_match('W \[>999/>999\]', Screenline(&lines))
644
645  " normal, no match
646  call cursor(1,1)
647  let @/ = 'zzzzzz'
648  let g:a = ''
649  try
650    let g:a = execute(':unsilent :norm! n')
651  catch /^Vim\%((\a\+)\)\=:E486/
652    let stat = ''
653    " error message is not redir'ed to g:a, it is empty
654    call assert_true(empty(g:a))
655  catch
656    call assert_false(1)
657  endtry
658
659  " Clean up
660  set shortmess+=S
661  set maxsearchcount&vim
662  " close the window
663  bwipe!
664endfunc
665
666" vim: shiftwidth=2 sts=2 expandtab