diff src/testdir/test_search_stat.vim @ 20697:1260b27535b5 v8.2.0902

patch 8.2.0902: using searchcount() in 'statusline' causes an error Commit: https://github.com/vim/vim/commit/442a85369f3eb9834dbab42add45f7c4106700f4 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 4 20:56:09 2020 +0200 patch 8.2.0902: using searchcount() in 'statusline' causes an error Problem: Using searchcount() in 'statusline' causes an error. Solution: Avoid saving/restoring the search patten recursively. (closes #6194)
author Bram Moolenaar <Bram@vim.org>
date Thu, 04 Jun 2020 21:00:03 +0200
parents 4c66962d322b
children ce36225c9bed
line wrap: on
line diff
--- a/src/testdir/test_search_stat.vim
+++ b/src/testdir/test_search_stat.vim
@@ -263,6 +263,34 @@ func Test_searchcount_fails()
   call assert_fails('echo searchcount("boo!")', 'E715:')
 endfunc
 
+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
+
 func Test_search_stat_foldopen()
   CheckScreendump