blob: 107cd54a0e022633d2eee3cdd5eed7a5980bf5c2 [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)
43
44 " 5) Many matches
45 call cursor(1, 1)
46 let g:a = execute(':unsilent :norm! n')
47 let stat = '\[2/>99\]'
48 call assert_match(pat .. stat, g:a)
49
50 " 6) right-left
51 if exists("+rightleft")
52 set rl
53 call cursor(1,1)
54 let @/ = 'foobar'
55 let pat = 'raboof/\s\+'
56 let g:a = execute(':unsilent :norm! n')
57 let stat = '\[20/2\]'
58 call assert_match(pat .. stat, g:a)
59 set norl
60 endif
61
62 " 7) right-left bottom
63 if exists("+rightleft")
64 set rl
65 call cursor('$',1)
66 let pat = 'raboof?\s\+'
67 let g:a = execute(':unsilent :norm! N')
68 let stat = '\[20/20\]'
69 call assert_match(pat .. stat, g:a)
70 set norl
71 endif
72
73 " 8) right-left back at top
74 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/1\]'
80 call assert_match(pat .. stat, g:a)
81 call assert_match('search hit BOTTOM, continuing at TOP', g:a)
82 set norl
83 endif
84
Bram Moolenaarc7a10b32019-05-06 21:37:18 +020085 " 9) normal, back at bottom
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020086 call cursor(1,1)
87 let @/ = 'foobar'
88 let pat = '?foobar\s\+'
89 let g:a = execute(':unsilent :norm! N')
90 let stat = '\[20/20\]'
91 call assert_match(pat .. stat, g:a)
92 call assert_match('search hit TOP, continuing at BOTTOM', g:a)
Bram Moolenaarc7a10b32019-05-06 21:37:18 +020093 call assert_match('\[20/20\] W', Screenline(&lines))
Bram Moolenaar9dfa3132019-05-04 21:08:40 +020094
95 " 10) normal, no match
96 call cursor(1,1)
97 let @/ = 'zzzzzz'
98 let g:a = ''
99 try
100 let g:a = execute(':unsilent :norm! n')
101 catch /^Vim\%((\a\+)\)\=:E486/
102 let stat = ''
103 " error message is not redir'ed to g:a, it is empty
104 call assert_true(empty(g:a))
105 catch
106 call assert_false(1)
107 endtry
108
Bram Moolenaar9ce3fa82019-05-07 21:29:11 +0200109 " 11) normal, n comes from a mapping
110 " Need to move over more than 64 lines to trigger char_avail(.
111 nnoremap n nzv
112 call cursor(1,1)
113 call append(50, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
114 call setline(2, 'find this')
115 call setline(70, 'find this')
116 let @/ = 'find this'
117 let pat = '/find this\s\+'
118 let g:a = execute(':unsilent :norm n')
119 " g:a will contain several lines
120 let g:b = split(g:a, "\n")[-1]
121 let stat = '\[1/2\]'
122 call assert_match(pat .. stat, g:b)
123 unmap n
124
125 " 11) normal, but silent
126 call cursor(1,1)
127 let @/ = 'find this'
128 let pat = '/find this\s\+'
129 let g:a = execute(':norm! n')
130 let stat = '\[1/2\]'
131 call assert_notmatch(pat .. stat, g:a)
132
Bram Moolenaar9dfa3132019-05-04 21:08:40 +0200133 " close the window
134 set shortmess+=S
135 bwipe!
136endfunc