1" 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 6source shared.vim 7 8func! Test_search_stat() 9 new 10 set shortmess-=S 11 " Append 50 lines with text to search for, "foobar" appears 20 times 12 call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10)) 13 14 " match at second line 15 call cursor(1, 1) 16 let messages_before = execute('messages') 17 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) 22 " didn't get added to message history 23 call assert_equal(messages_before, execute('messages')) 24 25 " Match at last line 26 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 31 " No search stat 32 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 39 " Many matches 40 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) 46 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) 50 51 " Many matches 52 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) 56 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) 60 61 " right-left 62 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 73 " right-left bottom 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/20\]' 80 call assert_match(pat .. stat, g:a) 81 set norl 82 endif 83 84 " right-left back at top 85 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 96 " normal, back at bottom 97 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) 104 call assert_match('\[20/20\] W', Screenline(&lines)) 105 106 " normal, no match 107 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 120 " with count 121 call cursor(1, 1) 122 let @/ = 'fo*\(bar\?\)\?' 123 let g:a = execute(':unsilent :norm! 2n') 124 let stat = '\[3/50\]' 125 let pat = escape(@/, '()*?'). '\s\+' 126 call assert_match(pat .. stat, g:a) 127 let g:a = execute(':unsilent :norm! 2n') 128 let stat = '\[5/50\]' 129 call assert_match(pat .. stat, g:a) 130 131 " with offset 132 call cursor(1, 1) 133 call feedkeys("/fo*\\(bar\\?\\)\\?/+1\<cr>", 'tx') 134 let g:a = execute(':unsilent :norm! n') 135 let stat = '\[5/50\]' 136 let pat = escape(@/ .. '/+1', '()*?'). '\s\+' 137 call assert_match(pat .. stat, g:a) 138 139 " normal, n comes from a mapping 140 " Need to move over more than 64 lines to trigger char_avail(. 141 nnoremap n nzv 142 call cursor(1,1) 143 call append(50, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10)) 144 call setline(2, 'find this') 145 call setline(70, 'find this') 146 let @/ = 'find this' 147 let pat = '/find this\s\+' 148 let g:a = execute(':unsilent :norm n') 149 " g:a will contain several lines 150 let g:b = split(g:a, "\n")[-1] 151 let stat = '\[1/2\]' 152 call assert_match(pat .. stat, g:b) 153 unmap n 154 155 " normal, but silent 156 call cursor(1,1) 157 let @/ = 'find this' 158 let pat = '/find this\s\+' 159 let g:a = execute(':norm! n') 160 let stat = '\[1/2\]' 161 call assert_notmatch(pat .. stat, g:a) 162 163 " close the window 164 set shortmess+=S 165 bwipe! 166endfunc 167