2019-05-26 20:26:32 -07:00
|
|
|
" Tests for search_stats, when "S" is not in 'shortmess'
|
|
|
|
|
2020-09-12 16:26:56 -07:00
|
|
|
source screendump.vim
|
|
|
|
source check.vim
|
2019-05-27 00:04:46 -07:00
|
|
|
|
2020-09-29 16:33:01 -07:00
|
|
|
func Test_search_stat()
|
2019-05-26 20:26:32 -07:00
|
|
|
new
|
|
|
|
set shortmess-=S
|
2019-05-27 00:20:40 -07:00
|
|
|
" Append 50 lines with text to search for, "foobar" appears 20 times
|
2019-05-26 20:26:32 -07:00
|
|
|
call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
|
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" match at second line
|
2019-05-26 20:26:32 -07:00
|
|
|
call cursor(1, 1)
|
2019-05-27 00:41:50 -07:00
|
|
|
let messages_before = execute('messages')
|
2019-05-26 20:26:32 -07:00
|
|
|
let @/ = 'fo*\(bar\?\)\?'
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
|
|
|
let stat = '\[2/50\]'
|
|
|
|
let pat = escape(@/, '()*?'). '\s\+'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
2019-05-27 00:41:50 -07:00
|
|
|
" didn't get added to message history
|
|
|
|
call assert_equal(messages_before, execute('messages'))
|
2019-05-26 20:26:32 -07:00
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" Match at last line
|
2019-05-26 20:26:32 -07:00
|
|
|
call cursor(line('$')-2, 1)
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
|
|
|
let stat = '\[50/50\]'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" No search stat
|
2019-05-26 20:26:32 -07:00
|
|
|
set shortmess+=S
|
|
|
|
call cursor(1, 1)
|
|
|
|
let stat = '\[2/50\]'
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
|
|
|
call assert_notmatch(pat .. stat, g:a)
|
|
|
|
set shortmess-=S
|
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" Many matches
|
2019-05-26 20:26:32 -07:00
|
|
|
call cursor(line('$')-2, 1)
|
|
|
|
let @/ = '.'
|
|
|
|
let pat = escape(@/, '()*?'). '\s\+'
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
|
|
|
let stat = '\[>99/>99\]'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
2019-05-27 00:34:03 -07:00
|
|
|
call cursor(line('$'), 1)
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
2020-09-29 16:45:32 -07:00
|
|
|
let stat = 'W \[1/>99\]'
|
2019-05-27 00:34:03 -07:00
|
|
|
call assert_match(pat .. stat, g:a)
|
2019-05-26 20:26:32 -07:00
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" Many matches
|
2019-05-26 20:26:32 -07:00
|
|
|
call cursor(1, 1)
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
|
|
|
let stat = '\[2/>99\]'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
2019-05-27 00:34:03 -07:00
|
|
|
call cursor(1, 1)
|
|
|
|
let g:a = execute(':unsilent :norm! N')
|
2020-09-29 16:45:32 -07:00
|
|
|
let stat = 'W \[>99/>99\]'
|
2019-05-27 00:34:03 -07:00
|
|
|
call assert_match(pat .. stat, g:a)
|
2019-05-26 20:26:32 -07:00
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" right-left
|
2019-05-26 20:26:32 -07:00
|
|
|
if exists("+rightleft")
|
|
|
|
set rl
|
|
|
|
call cursor(1,1)
|
|
|
|
let @/ = 'foobar'
|
|
|
|
let pat = 'raboof/\s\+'
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
|
|
|
let stat = '\[20/2\]'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
|
|
|
set norl
|
|
|
|
endif
|
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" right-left bottom
|
2019-05-26 20:26:32 -07:00
|
|
|
if exists("+rightleft")
|
|
|
|
set rl
|
|
|
|
call cursor('$',1)
|
|
|
|
let pat = 'raboof?\s\+'
|
|
|
|
let g:a = execute(':unsilent :norm! N')
|
|
|
|
let stat = '\[20/20\]'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
|
|
|
set norl
|
|
|
|
endif
|
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" right-left back at top
|
2019-05-26 20:26:32 -07:00
|
|
|
if exists("+rightleft")
|
|
|
|
set rl
|
|
|
|
call cursor('$',1)
|
|
|
|
let pat = 'raboof/\s\+'
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
2020-09-29 16:45:32 -07:00
|
|
|
let stat = 'W \[20/1\]'
|
2019-05-26 20:26:32 -07:00
|
|
|
call assert_match(pat .. stat, g:a)
|
|
|
|
call assert_match('search hit BOTTOM, continuing at TOP', g:a)
|
|
|
|
set norl
|
|
|
|
endif
|
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" normal, back at bottom
|
2019-05-26 20:26:32 -07:00
|
|
|
call cursor(1,1)
|
|
|
|
let @/ = 'foobar'
|
|
|
|
let pat = '?foobar\s\+'
|
|
|
|
let g:a = execute(':unsilent :norm! N')
|
2020-09-29 16:45:32 -07:00
|
|
|
let stat = 'W \[20/20\]'
|
2019-05-26 20:26:32 -07:00
|
|
|
call assert_match(pat .. stat, g:a)
|
|
|
|
call assert_match('search hit TOP, continuing at BOTTOM', g:a)
|
2020-09-29 16:45:32 -07:00
|
|
|
call assert_match('W \[20/20\]', Screenline(&lines))
|
2019-05-26 20:26:32 -07:00
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" normal, no match
|
2019-05-26 20:26:32 -07:00
|
|
|
call cursor(1,1)
|
|
|
|
let @/ = 'zzzzzz'
|
|
|
|
let g:a = ''
|
|
|
|
try
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
|
|
|
catch /^Vim\%((\a\+)\)\=:E486/
|
|
|
|
let stat = ''
|
|
|
|
" error message is not redir'ed to g:a, it is empty
|
|
|
|
call assert_true(empty(g:a))
|
|
|
|
catch
|
|
|
|
call assert_false(1)
|
|
|
|
endtry
|
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" with count
|
|
|
|
call cursor(1, 1)
|
|
|
|
let @/ = 'fo*\(bar\?\)\?'
|
|
|
|
let g:a = execute(':unsilent :norm! 2n')
|
|
|
|
let stat = '\[3/50\]'
|
|
|
|
let pat = escape(@/, '()*?'). '\s\+'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
|
|
|
let g:a = execute(':unsilent :norm! 2n')
|
|
|
|
let stat = '\[5/50\]'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
|
|
|
|
|
|
|
" with offset
|
|
|
|
call cursor(1, 1)
|
|
|
|
call feedkeys("/fo*\\(bar\\?\\)\\?/+1\<cr>", 'tx')
|
|
|
|
let g:a = execute(':unsilent :norm! n')
|
|
|
|
let stat = '\[5/50\]'
|
|
|
|
let pat = escape(@/ .. '/+1', '()*?'). '\s\+'
|
|
|
|
call assert_match(pat .. stat, g:a)
|
|
|
|
|
|
|
|
" normal, n comes from a mapping
|
2019-05-27 00:20:40 -07:00
|
|
|
" Need to move over more than 64 lines to trigger char_avail(.
|
|
|
|
nnoremap n nzv
|
|
|
|
call cursor(1,1)
|
|
|
|
call append(50, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
|
|
|
|
call setline(2, 'find this')
|
|
|
|
call setline(70, 'find this')
|
|
|
|
let @/ = 'find this'
|
|
|
|
let pat = '/find this\s\+'
|
|
|
|
let g:a = execute(':unsilent :norm n')
|
|
|
|
" g:a will contain several lines
|
|
|
|
let g:b = split(g:a, "\n")[-1]
|
|
|
|
let stat = '\[1/2\]'
|
|
|
|
call assert_match(pat .. stat, g:b)
|
|
|
|
unmap n
|
|
|
|
|
2019-05-27 01:08:29 -07:00
|
|
|
" normal, but silent
|
2019-05-27 00:20:40 -07:00
|
|
|
call cursor(1,1)
|
|
|
|
let @/ = 'find this'
|
|
|
|
let pat = '/find this\s\+'
|
|
|
|
let g:a = execute(':norm! n')
|
|
|
|
let stat = '\[1/2\]'
|
|
|
|
call assert_notmatch(pat .. stat, g:a)
|
|
|
|
|
2020-09-29 16:26:35 -07:00
|
|
|
" normal, n comes from a silent mapping
|
|
|
|
" First test a normal mapping, then a silent mapping
|
|
|
|
call cursor(1,1)
|
|
|
|
nnoremap n n
|
|
|
|
let @/ = 'find this'
|
|
|
|
let pat = '/find this\s\+'
|
|
|
|
let g:a = execute(':unsilent :norm n')
|
|
|
|
let g:b = split(g:a, "\n")[-1]
|
|
|
|
let stat = '\[1/2\]'
|
|
|
|
call assert_match(pat .. stat, g:b)
|
|
|
|
nnoremap <silent> n n
|
|
|
|
call cursor(1,1)
|
|
|
|
let g:a = execute(':unsilent :norm n')
|
|
|
|
let g:b = split(g:a, "\n")[-1]
|
|
|
|
let stat = '\[1/2\]'
|
|
|
|
call assert_notmatch(pat .. stat, g:b)
|
|
|
|
call assert_match(stat, g:b)
|
2020-09-29 16:33:01 -07:00
|
|
|
" Test that the message is not truncated
|
|
|
|
" it would insert '...' into the output.
|
|
|
|
call assert_match('^\s\+' .. stat, g:b)
|
2020-09-29 16:26:35 -07:00
|
|
|
unmap n
|
|
|
|
|
|
|
|
" Clean up
|
2019-05-26 20:26:32 -07:00
|
|
|
set shortmess+=S
|
2020-09-29 16:26:35 -07:00
|
|
|
" close the window
|
2019-05-26 20:26:32 -07:00
|
|
|
bwipe!
|
|
|
|
endfunc
|
2020-09-12 16:26:56 -07:00
|
|
|
|
2020-09-29 16:53:00 -07:00
|
|
|
func Test_search_stat_foldopen()
|
|
|
|
CheckScreendump
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
set shortmess-=S
|
|
|
|
setl foldenable foldmethod=indent foldopen-=search
|
|
|
|
call append(0, ['if', "\tfoo", "\tfoo", 'endif'])
|
|
|
|
let @/ = 'foo'
|
|
|
|
call cursor(1,1)
|
|
|
|
norm n
|
|
|
|
END
|
|
|
|
call writefile(lines, 'Xsearchstat1')
|
|
|
|
|
|
|
|
let buf = RunVimInTerminal('-S Xsearchstat1', #{rows: 10})
|
|
|
|
call TermWait(buf)
|
|
|
|
call VerifyScreenDump(buf, 'Test_searchstat_3', {})
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "n")
|
|
|
|
call TermWait(buf)
|
|
|
|
call VerifyScreenDump(buf, 'Test_searchstat_3', {})
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "n")
|
|
|
|
call TermWait(buf)
|
|
|
|
call VerifyScreenDump(buf, 'Test_searchstat_3', {})
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
call delete('Xsearchstat1')
|
|
|
|
endfunc
|
|
|
|
|
2020-09-29 16:33:01 -07:00
|
|
|
func! Test_search_stat_screendump()
|
|
|
|
CheckScreendump
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
set shortmess-=S
|
|
|
|
" Append 50 lines with text to search for, "foobar" appears 20 times
|
|
|
|
call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 20))
|
|
|
|
call setline(2, 'find this')
|
|
|
|
call setline(70, 'find this')
|
|
|
|
nnoremap n n
|
|
|
|
let @/ = 'find this'
|
|
|
|
call cursor(1,1)
|
|
|
|
norm n
|
|
|
|
END
|
|
|
|
call writefile(lines, 'Xsearchstat')
|
|
|
|
let buf = RunVimInTerminal('-S Xsearchstat', #{rows: 10})
|
|
|
|
call term_wait(buf)
|
|
|
|
call VerifyScreenDump(buf, 'Test_searchstat_1', {})
|
|
|
|
|
|
|
|
call term_sendkeys(buf, ":nnoremap <silent> n n\<cr>")
|
|
|
|
call term_sendkeys(buf, "gg0n")
|
|
|
|
call term_wait(buf)
|
|
|
|
call VerifyScreenDump(buf, 'Test_searchstat_2', {})
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
call delete('Xsearchstat')
|
|
|
|
endfunc
|
|
|
|
|
2020-09-12 16:26:56 -07:00
|
|
|
func Test_searchcount_in_statusline()
|
|
|
|
CheckScreendump
|
|
|
|
|
|
|
|
let lines =<< trim END
|
|
|
|
set shortmess-=S
|
|
|
|
call append(0, 'this is something')
|
|
|
|
function TestSearchCount() abort
|
|
|
|
let search_count = searchcount()
|
|
|
|
if !empty(search_count)
|
|
|
|
return '[' . search_count.current . '/' . search_count.total . ']'
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
set hlsearch
|
|
|
|
set laststatus=2 statusline+=%{TestSearchCount()}
|
|
|
|
END
|
|
|
|
call writefile(lines, 'Xsearchstatusline')
|
|
|
|
let buf = RunVimInTerminal('-S Xsearchstatusline', #{rows: 10})
|
|
|
|
call TermWait(buf)
|
|
|
|
call term_sendkeys(buf, "/something")
|
|
|
|
call VerifyScreenDump(buf, 'Test_searchstat_4', {})
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "\<Esc>")
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
call delete('Xsearchstatusline')
|
|
|
|
endfunc
|