blob: 322d137e2ec698867e2ea57f4760f88bedda0d53 [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
14 " 1) match at second line
15 call cursor(1, 1)
16 let @/ = 'fo*\(bar\?\)\?'
17 let g:a = execute(':unsilent :norm! n')
18 let stat = '\[2/50\]'
19 let pat = escape(@/, '()*?'). '\s\+'
20 call assert_match(pat .. stat, g:a)
21
22 " 2) Match at last line
23 call cursor(line('$')-2, 1)
24 let g:a = execute(':unsilent :norm! n')
25 let stat = '\[50/50\]'
26 call assert_match(pat .. stat, g:a)
27
28 " 3) No search stat
29 set shortmess+=S
30 call cursor(1, 1)
31 let stat = '\[2/50\]'
32 let g:a = execute(':unsilent :norm! n')
33 call assert_notmatch(pat .. stat, g:a)
34 set shortmess-=S
35
36 " 4) Many matches
37 call cursor(line('$')-2, 1)
38 let @/ = '.'
39 let pat = escape(@/, '()*?'). '\s\+'
40 let g:a = execute(':unsilent :norm! n')
41 let stat = '\[>99/>99\]'
42 call assert_match(pat .. stat, g:a)
Bram Moolenaardc6855a2019-05-18 19:26:29 +020043 call cursor(line('$'), 1)
44 let g:a = execute(':unsilent :norm! n')
45 let stat = '\[1/>99\] W'
46 call assert_match(pat .. stat, g:a)
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020047
48 " 5) Many matches
49 call cursor(1, 1)
50 let g:a = execute(':unsilent :norm! n')
51 let stat = '\[2/>99\]'
52 call assert_match(pat .. stat, g:a)
Bram Moolenaardc6855a2019-05-18 19:26:29 +020053 call cursor(1, 1)
54 let g:a = execute(':unsilent :norm! N')
55 let stat = '\[>99/>99\] W'
56 call assert_match(pat .. stat, g:a)
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020057
58 " 6) right-left
59 if exists("+rightleft")
60 set rl
61 call cursor(1,1)
62 let @/ = 'foobar'
63 let pat = 'raboof/\s\+'
64 let g:a = execute(':unsilent :norm! n')
65 let stat = '\[20/2\]'
66 call assert_match(pat .. stat, g:a)
67 set norl
68 endif
69
70 " 7) right-left bottom
71 if exists("+rightleft")
72 set rl
73 call cursor('$',1)
74 let pat = 'raboof?\s\+'
75 let g:a = execute(':unsilent :norm! N')
76 let stat = '\[20/20\]'
77 call assert_match(pat .. stat, g:a)
78 set norl
79 endif
80
81 " 8) right-left back at top
82 if exists("+rightleft")
83 set rl
84 call cursor('$',1)
85 let pat = 'raboof/\s\+'
86 let g:a = execute(':unsilent :norm! n')
87 let stat = '\[20/1\]'
88 call assert_match(pat .. stat, g:a)
89 call assert_match('search hit BOTTOM, continuing at TOP', g:a)
90 set norl
91 endif
92
Bram Moolenaarc7a10b32019-05-06 21:37:18 +020093 " 9) normal, back at bottom
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020094 call cursor(1,1)
95 let @/ = 'foobar'
96 let pat = '?foobar\s\+'
97 let g:a = execute(':unsilent :norm! N')
98 let stat = '\[20/20\]'
99 call assert_match(pat .. stat, g:a)
100 call assert_match('search hit TOP, continuing at BOTTOM', g:a)
Bram Moolenaarc7a10b32019-05-06 21:37:18 +0200101 call assert_match('\[20/20\] W', Screenline(&lines))
Bram Moolenaar9dfa3132019-05-04 21:08:40 +0200102
103 " 10) normal, no match
104 call cursor(1,1)
105 let @/ = 'zzzzzz'
106 let g:a = ''
107 try
108 let g:a = execute(':unsilent :norm! n')
109 catch /^Vim\%((\a\+)\)\=:E486/
110 let stat = ''
111 " error message is not redir'ed to g:a, it is empty
112 call assert_true(empty(g:a))
113 catch
114 call assert_false(1)
115 endtry
116
Bram Moolenaar9ce3fa82019-05-07 21:29:11 +0200117 " 11) normal, n comes from a mapping
118 " Need to move over more than 64 lines to trigger char_avail(.
119 nnoremap n nzv
120 call cursor(1,1)
121 call append(50, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
122 call setline(2, 'find this')
123 call setline(70, 'find this')
124 let @/ = 'find this'
125 let pat = '/find this\s\+'
126 let g:a = execute(':unsilent :norm n')
127 " g:a will contain several lines
128 let g:b = split(g:a, "\n")[-1]
129 let stat = '\[1/2\]'
130 call assert_match(pat .. stat, g:b)
131 unmap n
132
133 " 11) normal, but silent
134 call cursor(1,1)
135 let @/ = 'find this'
136 let pat = '/find this\s\+'
137 let g:a = execute(':norm! n')
138 let stat = '\[1/2\]'
139 call assert_notmatch(pat .. stat, g:a)
140
Bram Moolenaar9dfa3132019-05-04 21:08:40 +0200141 " close the window
142 set shortmess+=S
143 bwipe!
144endfunc