diff src/testdir/test_search.vim @ 20199:a4bd28e2cf1d v8.2.0655

patch 8.2.0655: search code not sufficiently tested Commit: https://github.com/vim/vim/commit/224a5f17c6ec9e98322a4c6792ce4f9bb31a4cce Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 28 20:29:07 2020 +0200 patch 8.2.0655: search code not sufficiently tested Problem: Search code not sufficiently tested. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5999)
author Bram Moolenaar <Bram@vim.org>
date Tue, 28 Apr 2020 20:30:04 +0200
parents 2dd1ac2c48f4
children 116c7bd5e980
line wrap: on
line diff
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -1638,6 +1638,12 @@ func Test_search_smartcase()
   exe "normal /\\a\\_.\\(.*\\)o\<CR>"
   call assert_equal([2, 1], [line('.'), col('.')])
 
+  " Test for using special atoms with 'smartcase'
+  call setline(1, ['', '    Hello\ '])
+  call cursor(1, 1)
+  call feedkeys('/\_.\%(\uello\)\' .. "\<CR>", 'xt')
+  call assert_equal([2, 4], [line('.'), col('.')])
+
   set ignorecase& smartcase&
   close!
 endfunc
@@ -1651,4 +1657,91 @@ func Test_search_past_eof()
   close!
 endfunc
 
+" Test for various search offsets
+func Test_search_offset()
+  " With /e, for a match in the first column of a line, the cursor should be
+  " placed at the end of the previous line.
+  new
+  call setline(1, ['one two', 'three four'])
+  call search('two\_.', 'e')
+  call assert_equal([1, 7], [line('.'), col('.')])
+
+  " with cursor at the beginning of the file, use /s+1
+  call cursor(1, 1)
+  exe "normal /two/s+1\<CR>"
+  call assert_equal([1, 6], [line('.'), col('.')])
+
+  " with cursor at the end of the file, use /e-1
+  call cursor(2, 10)
+  exe "normal ?three?e-1\<CR>"
+  call assert_equal([2, 4], [line('.'), col('.')])
+
+  " line offset - after the last line
+  call cursor(1, 1)
+  exe "normal /three/+1\<CR>"
+  call assert_equal([2, 1], [line('.'), col('.')])
+
+  " line offset - before the first line
+  call cursor(2, 1)
+  exe "normal ?one?-1\<CR>"
+  call assert_equal([1, 1], [line('.'), col('.')])
+
+  " character offset - before the first character in the file
+  call cursor(2, 1)
+  exe "normal ?one?s-1\<CR>"
+  call assert_equal([1, 1], [line('.'), col('.')])
+  call cursor(2, 1)
+  exe "normal ?one?e-3\<CR>"
+  call assert_equal([1, 1], [line('.'), col('.')])
+
+  " character offset - after the last character in the file
+  call cursor(1, 1)
+  exe "normal /four/s+4\<CR>"
+  call assert_equal([2, 10], [line('.'), col('.')])
+  call cursor(1, 1)
+  exe "normal /four/e+1\<CR>"
+  call assert_equal([2, 10], [line('.'), col('.')])
+
+  close!
+endfunc
+
+" Test for searching for matching parenthesis using %
+func Test_search_match_paren()
+  new
+  call setline(1, "abc(def')'ghi'('jk'\\t'lm)no")
+  " searching for a matching parenthesis should skip single quoted characters
+  call cursor(1, 4)
+  normal %
+  call assert_equal([1, 25], [line('.'), col('.')])
+  normal %
+  call assert_equal([1, 4], [line('.'), col('.')])
+  call cursor(1, 5)
+  normal ])
+  call assert_equal([1, 25], [line('.'), col('.')])
+  call cursor(1, 24)
+  normal [(
+  call assert_equal([1, 4], [line('.'), col('.')])
+
+  " matching parenthesis in 'virtualedit' mode with cursor after the eol
+  call setline(1, 'abc(defgh)')
+  set virtualedit=all
+  normal 20|%
+  call assert_equal(4, col('.'))
+  set virtualedit&
+  close!
+endfunc
+
+" Test for searching a pattern and stopping before a specified line
+func Test_search_stopline()
+  new
+  call setline(1, ['', '', '', 'vim'])
+  call assert_equal(0, search('vim', 'n', 3))
+  call assert_equal(4, search('vim', 'n', 4))
+  call setline(1, ['vim', '', '', ''])
+  call cursor(4, 1)
+  call assert_equal(0, search('vim', 'bn', 2))
+  call assert_equal(1, search('vim', 'bn', 1))
+  close!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab