blob: 57dad81b8162a1f3ddd9b6b917dbe8f6e57904ea [file] [log] [blame]
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02001" Tests for search_stats, when "S" is not in 'shortmess'
2"
3" This test is fragile, it might not work interactively, but it works when run
4" as test!
5
Bram Moolenaarc7a10b32019-05-06 21:37:18 +02006source shared.vim
7
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02008func! Test_search_stat()
9 new
10 set shortmess-=S
11 call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
12
13 " 1) match at second line
14 call cursor(1, 1)
15 let @/ = 'fo*\(bar\?\)\?'
16 let g:a = execute(':unsilent :norm! n')
17 let stat = '\[2/50\]'
18 let pat = escape(@/, '()*?'). '\s\+'
19 call assert_match(pat .. stat, g:a)
20
21 " 2) Match at last line
22 call cursor(line('$')-2, 1)
23 let g:a = execute(':unsilent :norm! n')
24 let stat = '\[50/50\]'
25 call assert_match(pat .. stat, g:a)
26
27 " 3) No search stat
28 set shortmess+=S
29 call cursor(1, 1)
30 let stat = '\[2/50\]'
31 let g:a = execute(':unsilent :norm! n')
32 call assert_notmatch(pat .. stat, g:a)
33 set shortmess-=S
34
35 " 4) Many matches
36 call cursor(line('$')-2, 1)
37 let @/ = '.'
38 let pat = escape(@/, '()*?'). '\s\+'
39 let g:a = execute(':unsilent :norm! n')
40 let stat = '\[>99/>99\]'
41 call assert_match(pat .. stat, g:a)
42
43 " 5) Many matches
44 call cursor(1, 1)
45 let g:a = execute(':unsilent :norm! n')
46 let stat = '\[2/>99\]'
47 call assert_match(pat .. stat, g:a)
48
49 " 6) right-left
50 if exists("+rightleft")
51 set rl
52 call cursor(1,1)
53 let @/ = 'foobar'
54 let pat = 'raboof/\s\+'
55 let g:a = execute(':unsilent :norm! n')
56 let stat = '\[20/2\]'
57 call assert_match(pat .. stat, g:a)
58 set norl
59 endif
60
61 " 7) right-left bottom
62 if exists("+rightleft")
63 set rl
64 call cursor('$',1)
65 let pat = 'raboof?\s\+'
66 let g:a = execute(':unsilent :norm! N')
67 let stat = '\[20/20\]'
68 call assert_match(pat .. stat, g:a)
69 set norl
70 endif
71
72 " 8) right-left back at top
73 if exists("+rightleft")
74 set rl
75 call cursor('$',1)
76 let pat = 'raboof/\s\+'
77 let g:a = execute(':unsilent :norm! n')
78 let stat = '\[20/1\]'
79 call assert_match(pat .. stat, g:a)
80 call assert_match('search hit BOTTOM, continuing at TOP', g:a)
81 set norl
82 endif
83
Bram Moolenaarc7a10b32019-05-06 21:37:18 +020084 " 9) normal, back at bottom
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020085 call cursor(1,1)
86 let @/ = 'foobar'
87 let pat = '?foobar\s\+'
88 let g:a = execute(':unsilent :norm! N')
89 let stat = '\[20/20\]'
90 call assert_match(pat .. stat, g:a)
91 call assert_match('search hit TOP, continuing at BOTTOM', g:a)
Bram Moolenaarc7a10b32019-05-06 21:37:18 +020092 call assert_match('\[20/20\] W', Screenline(&lines))
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020093
94 " 10) normal, no match
95 call cursor(1,1)
96 let @/ = 'zzzzzz'
97 let g:a = ''
98 try
99 let g:a = execute(':unsilent :norm! n')
100 catch /^Vim\%((\a\+)\)\=:E486/
101 let stat = ''
102 " error message is not redir'ed to g:a, it is empty
103 call assert_true(empty(g:a))
104 catch
105 call assert_false(1)
106 endtry
107
108 " close the window
109 set shortmess+=S
110 bwipe!
111endfunc