aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/testdir/test_search_stat.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/testdir/test_search_stat.vim')
-rw-r--r--src/nvim/testdir/test_search_stat.vim98
1 files changed, 87 insertions, 11 deletions
diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim
index fa620b4e00..11c6489ca2 100644
--- a/src/nvim/testdir/test_search_stat.vim
+++ b/src/nvim/testdir/test_search_stat.vim
@@ -1,13 +1,9 @@
" Tests for search_stats, when "S" is not in 'shortmess'
-"
-" This test is fragile, it might not work interactively, but it works when run
-" as test!
-source shared.vim
source screendump.vim
source check.vim
-func! Test_search_stat()
+func Test_search_stat()
new
set shortmess-=S
" Append 50 lines with text to search for, "foobar" appears 20 times
@@ -47,7 +43,7 @@ func! Test_search_stat()
call assert_match(pat .. stat, g:a)
call cursor(line('$'), 1)
let g:a = execute(':unsilent :norm! n')
- let stat = '\[1/>99\] W'
+ let stat = 'W \[1/>99\]'
call assert_match(pat .. stat, g:a)
" Many matches
@@ -57,7 +53,7 @@ func! Test_search_stat()
call assert_match(pat .. stat, g:a)
call cursor(1, 1)
let g:a = execute(':unsilent :norm! N')
- let stat = '\[>99/>99\] W'
+ let stat = 'W \[>99/>99\]'
call assert_match(pat .. stat, g:a)
" right-left
@@ -89,7 +85,7 @@ func! Test_search_stat()
call cursor('$',1)
let pat = 'raboof/\s\+'
let g:a = execute(':unsilent :norm! n')
- let stat = '\[20/1\]'
+ let stat = 'W \[20/1\]'
call assert_match(pat .. stat, g:a)
call assert_match('search hit BOTTOM, continuing at TOP', g:a)
set norl
@@ -100,10 +96,10 @@ func! Test_search_stat()
let @/ = 'foobar'
let pat = '?foobar\s\+'
let g:a = execute(':unsilent :norm! N')
- let stat = '\[20/20\]'
+ let stat = 'W \[20/20\]'
call assert_match(pat .. stat, g:a)
call assert_match('search hit TOP, continuing at BOTTOM', g:a)
- call assert_match('\[20/20\] W', Screenline(&lines))
+ call assert_match('W \[20/20\]', Screenline(&lines))
" normal, no match
call cursor(1,1)
@@ -162,11 +158,91 @@ func! Test_search_stat()
let stat = '\[1/2\]'
call assert_notmatch(pat .. stat, g:a)
- " close the window
+ " 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)
+ " Test that the message is not truncated
+ " it would insert '...' into the output.
+ call assert_match('^\s\+' .. stat, g:b)
+ unmap n
+
+ " Clean up
set shortmess+=S
+ " close the window
bwipe!
endfunc
+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
+
+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
+
func Test_searchcount_in_statusline()
CheckScreendump