blob: ad46b2d0592ab25313fb190e4b8ca45e177e0698 [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
Bram Moolenaar9ce3fa82019-05-07 21:29:11 +020011 " Append 50 lines with text to search for, "foobar" appears 20 times
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020012 call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
13
Bram Moolenaar984f0312019-05-24 13:11:47 +020014 " match at second line
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020015 call cursor(1, 1)
Bram Moolenaar984f0312019-05-24 13:11:47 +020016 let messages_before = execute('messages')
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020017 let @/ = 'fo*\(bar\?\)\?'
18 let g:a = execute(':unsilent :norm! n')
19 let stat = '\[2/50\]'
20 let pat = escape(@/, '()*?'). '\s\+'
21 call assert_match(pat .. stat, g:a)
Bram Moolenaar984f0312019-05-24 13:11:47 +020022 " didn't get added to message history
23 call assert_equal(messages_before, execute('messages'))
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020024
Bram Moolenaar984f0312019-05-24 13:11:47 +020025 " Match at last line
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020026 call cursor(line('$')-2, 1)
27 let g:a = execute(':unsilent :norm! n')
28 let stat = '\[50/50\]'
29 call assert_match(pat .. stat, g:a)
30
Bram Moolenaar984f0312019-05-24 13:11:47 +020031 " No search stat
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020032 set shortmess+=S
33 call cursor(1, 1)
34 let stat = '\[2/50\]'
35 let g:a = execute(':unsilent :norm! n')
36 call assert_notmatch(pat .. stat, g:a)
37 set shortmess-=S
38
Bram Moolenaar984f0312019-05-24 13:11:47 +020039 " Many matches
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020040 call cursor(line('$')-2, 1)
41 let @/ = '.'
42 let pat = escape(@/, '()*?'). '\s\+'
43 let g:a = execute(':unsilent :norm! n')
44 let stat = '\[>99/>99\]'
45 call assert_match(pat .. stat, g:a)
Bram Moolenaardc6855a2019-05-18 19:26:29 +020046 call cursor(line('$'), 1)
47 let g:a = execute(':unsilent :norm! n')
48 let stat = '\[1/>99\] W'
49 call assert_match(pat .. stat, g:a)
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020050
Bram Moolenaar984f0312019-05-24 13:11:47 +020051 " Many matches
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020052 call cursor(1, 1)
53 let g:a = execute(':unsilent :norm! n')
54 let stat = '\[2/>99\]'
55 call assert_match(pat .. stat, g:a)
Bram Moolenaardc6855a2019-05-18 19:26:29 +020056 call cursor(1, 1)
57 let g:a = execute(':unsilent :norm! N')
58 let stat = '\[>99/>99\] W'
59 call assert_match(pat .. stat, g:a)
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020060
Bram Moolenaar984f0312019-05-24 13:11:47 +020061 " right-left
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020062 if exists("+rightleft")
63 set rl
64 call cursor(1,1)
65 let @/ = 'foobar'
66 let pat = 'raboof/\s\+'
67 let g:a = execute(':unsilent :norm! n')
68 let stat = '\[20/2\]'
69 call assert_match(pat .. stat, g:a)
70 set norl
71 endif
72
Bram Moolenaar984f0312019-05-24 13:11:47 +020073 " right-left bottom
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020074 if exists("+rightleft")
75 set rl
76 call cursor('$',1)
77 let pat = 'raboof?\s\+'
78 let g:a = execute(':unsilent :norm! N')
79 let stat = '\[20/20\]'
80 call assert_match(pat .. stat, g:a)
81 set norl
82 endif
83
Bram Moolenaar984f0312019-05-24 13:11:47 +020084 " right-left back at top
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020085 if exists("+rightleft")
86 set rl
87 call cursor('$',1)
88 let pat = 'raboof/\s\+'
89 let g:a = execute(':unsilent :norm! n')
90 let stat = '\[20/1\]'
91 call assert_match(pat .. stat, g:a)
92 call assert_match('search hit BOTTOM, continuing at TOP', g:a)
93 set norl
94 endif
95
Bram Moolenaar984f0312019-05-24 13:11:47 +020096 " normal, back at bottom
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020097 call cursor(1,1)
98 let @/ = 'foobar'
99 let pat = '?foobar\s\+'
100 let g:a = execute(':unsilent :norm! N')
101 let stat = '\[20/20\]'
102 call assert_match(pat .. stat, g:a)
103 call assert_match('search hit TOP, continuing at BOTTOM', g:a)
Bram Moolenaarc7a10b32019-05-06 21:37:18 +0200104 call assert_match('\[20/20\] W', Screenline(&lines))
Bram Moolenaar9dfa3132019-05-04 21:08:40 +0200105
Bram Moolenaar984f0312019-05-24 13:11:47 +0200106 " normal, no match
Bram Moolenaar9dfa3132019-05-04 21:08:40 +0200107 call cursor(1,1)
108 let @/ = 'zzzzzz'
109 let g:a = ''
110 try
111 let g:a = execute(':unsilent :norm! n')
112 catch /^Vim\%((\a\+)\)\=:E486/
113 let stat = ''
114 " error message is not redir'ed to g:a, it is empty
115 call assert_true(empty(g:a))
116 catch
117 call assert_false(1)
118 endtry
119
Bram Moolenaar984f0312019-05-24 13:11:47 +0200120 " normal, n comes from a mapping
Bram Moolenaar9ce3fa82019-05-07 21:29:11 +0200121 " Need to move over more than 64 lines to trigger char_avail(.
122 nnoremap n nzv
123 call cursor(1,1)
124 call append(50, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
125 call setline(2, 'find this')
126 call setline(70, 'find this')
127 let @/ = 'find this'
128 let pat = '/find this\s\+'
129 let g:a = execute(':unsilent :norm n')
130 " g:a will contain several lines
131 let g:b = split(g:a, "\n")[-1]
132 let stat = '\[1/2\]'
133 call assert_match(pat .. stat, g:b)
134 unmap n
135
Bram Moolenaar984f0312019-05-24 13:11:47 +0200136 " normal, but silent
Bram Moolenaar9ce3fa82019-05-07 21:29:11 +0200137 call cursor(1,1)
138 let @/ = 'find this'
139 let pat = '/find this\s\+'
140 let g:a = execute(':norm! n')
141 let stat = '\[1/2\]'
142 call assert_notmatch(pat .. stat, g:a)
143
Bram Moolenaar9dfa3132019-05-04 21:08:40 +0200144 " close the window
145 set shortmess+=S
146 bwipe!
147endfunc