Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | c7a10b3 | 2019-05-06 21:37:18 +0200 | [diff] [blame] | 6 | source shared.vim |
| 7 | |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 8 | func! Test_search_stat() |
| 9 | new |
| 10 | set shortmess-=S |
Bram Moolenaar | 9ce3fa8 | 2019-05-07 21:29:11 +0200 | [diff] [blame] | 11 | " Append 50 lines with text to search for, "foobar" appears 20 times |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 12 | call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10)) |
| 13 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 14 | " match at second line |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 15 | call cursor(1, 1) |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 16 | let messages_before = execute('messages') |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 22 | " didn't get added to message history |
| 23 | call assert_equal(messages_before, execute('messages')) |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 24 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 25 | " Match at last line |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 31 | " No search stat |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 39 | " Many matches |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | dc6855a | 2019-05-18 19:26:29 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 50 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 51 | " Many matches |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | dc6855a | 2019-05-18 19:26:29 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 60 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 61 | " right-left |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 73 | " right-left bottom |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 84 | " right-left back at top |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 96 | " normal, back at bottom |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | c7a10b3 | 2019-05-06 21:37:18 +0200 | [diff] [blame] | 104 | call assert_match('\[20/20\] W', Screenline(&lines)) |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 105 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 106 | " normal, no match |
Bram Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 120 | " normal, n comes from a mapping |
Bram Moolenaar | 9ce3fa8 | 2019-05-07 21:29:11 +0200 | [diff] [blame] | 121 | " 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 Moolenaar | 984f031 | 2019-05-24 13:11:47 +0200 | [diff] [blame^] | 136 | " normal, but silent |
Bram Moolenaar | 9ce3fa8 | 2019-05-07 21:29:11 +0200 | [diff] [blame] | 137 | 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 Moolenaar | 9dfa313 | 2019-05-04 21:08:40 +0200 | [diff] [blame] | 144 | " close the window |
| 145 | set shortmess+=S |
| 146 | bwipe! |
| 147 | endfunc |