diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2022-07-17 11:30:32 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-17 11:30:32 +0800 |
| commit | 53c398d8f44f1796c216402c953512eb57733529 (patch) | |
| tree | a4abcbed4256058b40e4dc1badd2f06c22079abf /src/nvim/testdir/test_search.vim | |
| parent | 9f837a5dcf61e0b27778dd7127036e12d694d92c (diff) | |
| parent | 7c3a87182d471649126c58d999d46abede6f60cd (diff) | |
| download | rneovim-53c398d8f44f1796c216402c953512eb57733529.tar.gz rneovim-53c398d8f44f1796c216402c953512eb57733529.tar.bz2 rneovim-53c398d8f44f1796c216402c953512eb57733529.zip | |
Merge pull request #19402 from zeertzjq/vim-8.2.0655
vim-patch:8.2.{0655,1040}: not enough tests
Diffstat (limited to 'src/nvim/testdir/test_search.vim')
| -rw-r--r-- | src/nvim/testdir/test_search.vim | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 747fb0e384..3d1bbfb726 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1732,6 +1732,34 @@ func Test_invalid_regexp() call assert_fails("call search('\\%#=3ab')", 'E864:') endfunc +" Test for searching with 'smartcase' and 'ignorecase' +func Test_search_smartcase() + new + call setline(1, ['', 'Hello']) + set noignorecase nosmartcase + call assert_fails('exe "normal /\\a\\_.\\(.*\\)O\<CR>"', 'E486:') + + set ignorecase nosmartcase + exe "normal /\\a\\_.\\(.*\\)O\<CR>" + call assert_equal([2, 1], [line('.'), col('.')]) + + call cursor(1, 1) + set ignorecase smartcase + call assert_fails('exe "normal /\\a\\_.\\(.*\\)O\<CR>"', 'E486:') + + 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! +endfun + " Test 'smartcase' with utf-8. func Test_search_smartcase_utf8() new @@ -1751,6 +1779,102 @@ func Test_search_smartcase_utf8() close! endfunc +" Test searching past the end of a file +func Test_search_past_eof() + new + call setline(1, ['Line']) + exe "normal /\\n\\zs\<CR>" + call assert_equal([1, 4], [line('.'), col('.')]) + 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 + func Test_incsearch_highlighting_newline() CheckRunVimInTerminal CheckOption incsearch |