blob: 37e2fdaef5842ec16f3924036fa1769479cd5d8a [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
6func! Test_search_stat()
7 new
8 set shortmess-=S
9 call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
10
11 " 1) match at second line
12 call cursor(1, 1)
13 let @/ = 'fo*\(bar\?\)\?'
14 let g:a = execute(':unsilent :norm! n')
15 let stat = '\[2/50\]'
16 let pat = escape(@/, '()*?'). '\s\+'
17 call assert_match(pat .. stat, g:a)
18
19 " 2) Match at last line
20 call cursor(line('$')-2, 1)
21 let g:a = execute(':unsilent :norm! n')
22 let stat = '\[50/50\]'
23 call assert_match(pat .. stat, g:a)
24
25 " 3) No search stat
26 set shortmess+=S
27 call cursor(1, 1)
28 let stat = '\[2/50\]'
29 let g:a = execute(':unsilent :norm! n')
30 call assert_notmatch(pat .. stat, g:a)
31 set shortmess-=S
32
33 " 4) Many matches
34 call cursor(line('$')-2, 1)
35 let @/ = '.'
36 let pat = escape(@/, '()*?'). '\s\+'
37 let g:a = execute(':unsilent :norm! n')
38 let stat = '\[>99/>99\]'
39 call assert_match(pat .. stat, g:a)
40
41 " 5) Many matches
42 call cursor(1, 1)
43 let g:a = execute(':unsilent :norm! n')
44 let stat = '\[2/>99\]'
45 call assert_match(pat .. stat, g:a)
46
47 " 6) right-left
48 if exists("+rightleft")
49 set rl
50 call cursor(1,1)
51 let @/ = 'foobar'
52 let pat = 'raboof/\s\+'
53 let g:a = execute(':unsilent :norm! n')
54 let stat = '\[20/2\]'
55 call assert_match(pat .. stat, g:a)
56 set norl
57 endif
58
59 " 7) right-left bottom
60 if exists("+rightleft")
61 set rl
62 call cursor('$',1)
63 let pat = 'raboof?\s\+'
64 let g:a = execute(':unsilent :norm! N')
65 let stat = '\[20/20\]'
66 call assert_match(pat .. stat, g:a)
67 set norl
68 endif
69
70 " 8) right-left back at top
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/1\]'
77 call assert_match(pat .. stat, g:a)
78 call assert_match('search hit BOTTOM, continuing at TOP', g:a)
79 set norl
80 endif
81
82 " 9) normal, back at top
83 call cursor(1,1)
84 let @/ = 'foobar'
85 let pat = '?foobar\s\+'
86 let g:a = execute(':unsilent :norm! N')
87 let stat = '\[20/20\]'
88 call assert_match(pat .. stat, g:a)
89 call assert_match('search hit TOP, continuing at BOTTOM', g:a)
90
91 " 10) normal, no match
92 call cursor(1,1)
93 let @/ = 'zzzzzz'
94 let g:a = ''
95 try
96 let g:a = execute(':unsilent :norm! n')
97 catch /^Vim\%((\a\+)\)\=:E486/
98 let stat = ''
99 " error message is not redir'ed to g:a, it is empty
100 call assert_true(empty(g:a))
101 catch
102 call assert_false(1)
103 endtry
104
105 " close the window
106 set shortmess+=S
107 bwipe!
108endfunc