mirror of
https://github.com/neovim/neovim.git
synced 2025-10-10 03:46:31 +00:00
Merge #8701 from janlazo/vim-8.0.1140
This commit is contained in:
@@ -17,7 +17,6 @@ SCRIPTS_DEFAULT = \
|
||||
test14.out \
|
||||
test24.out \
|
||||
test37.out \
|
||||
test40.out \
|
||||
test42.out \
|
||||
test48.out \
|
||||
test52.out \
|
||||
@@ -102,6 +101,7 @@ NEW_TESTS ?= \
|
||||
test_stat.res \
|
||||
test_startup.res \
|
||||
test_substitute.res \
|
||||
test_swap.res \
|
||||
test_syntax.res \
|
||||
test_system.res \
|
||||
test_tab.res \
|
||||
@@ -114,6 +114,7 @@ NEW_TESTS ?= \
|
||||
test_visual.res \
|
||||
test_winbuf_close.res \
|
||||
test_window_id.res \
|
||||
test_wordcount.res \
|
||||
test_writefile.res \
|
||||
test_alot_latin.res \
|
||||
test_alot_utf8.res \
|
||||
|
@@ -1,63 +0,0 @@
|
||||
Test for "*Cmd" autocommands
|
||||
|
||||
STARTTEST
|
||||
:set wildchar=^E
|
||||
:/^start/,$w! Xxx " write lines below to Xxx
|
||||
:au BufReadCmd XtestA 0r Xxx|$del
|
||||
:e XtestA " will read text of Xxd instead
|
||||
:au BufWriteCmd XtestA call append(line("$"), "write")
|
||||
:w " will append a line to the file
|
||||
:r XtestA " should not read anything
|
||||
: " now we have:
|
||||
: " 1 start of Xxx
|
||||
: " 2 test40
|
||||
: " 3 end of Xxx
|
||||
: " 4 write
|
||||
:au FileReadCmd XtestB '[r Xxx
|
||||
:2r XtestB " will read Xxx below line 2 instead
|
||||
: " 1 start of Xxx
|
||||
: " 2 test40
|
||||
: " 3 start of Xxx
|
||||
: " 4 test40
|
||||
: " 5 end of Xxx
|
||||
: " 6 end of Xxx
|
||||
: " 7 write
|
||||
:au FileWriteCmd XtestC '[,']copy $
|
||||
4GA1
|
||||
:4,5w XtestC " will copy lines 4 and 5 to the end
|
||||
:r XtestC " should not read anything
|
||||
: " 1 start of Xxx
|
||||
: " 2 test40
|
||||
: " 3 start of Xxx
|
||||
: " 4 test401
|
||||
: " 5 end of Xxx
|
||||
: " 6 end of Xxx
|
||||
: " 7 write
|
||||
: " 8 test401
|
||||
: " 9 end of Xxx
|
||||
:au FILEAppendCmd XtestD '[,']w! test.out
|
||||
:w >>XtestD " will write all lines to test.out
|
||||
:$r XtestD " should not read anything
|
||||
:$w >>test.out " append "end of Xxx" to test.out
|
||||
:au BufReadCmd XtestE 0r test.out|$del
|
||||
:sp XtestE " split window with test.out
|
||||
5Goasdf:"
|
||||
:au BufWriteCmd XtestE w! test.out
|
||||
:wall " will write other window to test.out
|
||||
: " 1 start of Xxx
|
||||
: " 2 test40
|
||||
: " 3 start of Xxx
|
||||
: " 4 test401
|
||||
: " 5 end of Xxx
|
||||
: " 6 asdf
|
||||
: " 7 end of Xxx
|
||||
: " 8 write
|
||||
: " 9 test401
|
||||
: " 10 end of Xxx
|
||||
: " 11 end of Xxx
|
||||
:qa!
|
||||
ENDTEST
|
||||
|
||||
start of Xxx
|
||||
test40
|
||||
end of Xxx
|
@@ -1,11 +0,0 @@
|
||||
start of Xxx
|
||||
test40
|
||||
start of Xxx
|
||||
test401
|
||||
end of Xxx
|
||||
asdf
|
||||
end of Xxx
|
||||
write
|
||||
test401
|
||||
end of Xxx
|
||||
end of Xxx
|
@@ -30,6 +30,7 @@ source test_put.vim
|
||||
source test_recover.vim
|
||||
source test_regexp_utf8.vim
|
||||
source test_scroll_opt.vim
|
||||
source test_sort.vim
|
||||
source test_source_utf8.vim
|
||||
source test_sha256.vim
|
||||
source test_statusline.vim
|
||||
|
@@ -1,6 +1,5 @@
|
||||
" Tests for autocommands
|
||||
|
||||
|
||||
func! s:cleanup_buffers() abort
|
||||
for bnr in range(1, bufnr('$'))
|
||||
if bufloaded(bnr) && bufnr('%') != bnr
|
||||
|
@@ -467,3 +467,170 @@ func Test_fold_error()
|
||||
set foldmethod&
|
||||
bw!
|
||||
endfunc
|
||||
|
||||
" Various fold related tests
|
||||
|
||||
" Basic test if a fold can be created, opened, moving to the end and closed
|
||||
func Test_fold_manual()
|
||||
enew!
|
||||
set fdm=manual
|
||||
|
||||
let content = ['1 aa', '2 bb', '3 cc']
|
||||
call append(0, content)
|
||||
call cursor(1, 1)
|
||||
normal zf2j
|
||||
call assert_equal('1 aa', getline(foldclosed('.')))
|
||||
normal zo
|
||||
call assert_equal(-1, foldclosed('.'))
|
||||
normal ]z
|
||||
call assert_equal('3 cc', getline('.'))
|
||||
normal zc
|
||||
call assert_equal('1 aa', getline(foldclosed('.')))
|
||||
|
||||
set fdm&
|
||||
enew!
|
||||
endfunc
|
||||
|
||||
" test folding with markers.
|
||||
func Test_fold_marker()
|
||||
enew!
|
||||
set fdm=marker fdl=1 fdc=3
|
||||
|
||||
let content = ['4 dd {{{', '5 ee {{{ }}}', '6 ff }}}']
|
||||
call append(0, content)
|
||||
call cursor(2, 1)
|
||||
call assert_equal(2, foldlevel('.'))
|
||||
normal [z
|
||||
call assert_equal(1, foldlevel('.'))
|
||||
exe "normal jo{{ \<Esc>r{jj"
|
||||
call assert_equal(1, foldlevel('.'))
|
||||
normal kYpj
|
||||
call assert_equal(0, foldlevel('.'))
|
||||
|
||||
set fdm& fdl& fdc&
|
||||
enew!
|
||||
endfunc
|
||||
|
||||
" test folding with indent
|
||||
func Test_fold_indent()
|
||||
enew!
|
||||
set fdm=indent sw=2
|
||||
|
||||
let content = ['1 aa', '2 bb', '3 cc']
|
||||
call append(0, content)
|
||||
call cursor(2, 1)
|
||||
exe "normal i \<Esc>jI "
|
||||
call assert_equal(2, foldlevel('.'))
|
||||
normal k
|
||||
call assert_equal(1, foldlevel('.'))
|
||||
|
||||
set fdm& sw&
|
||||
enew!
|
||||
endfunc
|
||||
|
||||
" test syntax folding
|
||||
func Test_fold_syntax()
|
||||
if !has('syntax')
|
||||
return
|
||||
endif
|
||||
|
||||
enew!
|
||||
set fdm=syntax fdl=0
|
||||
|
||||
syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3
|
||||
syn region Fd1 start="ee" end="ff" fold contained
|
||||
syn region Fd2 start="gg" end="hh" fold contained
|
||||
syn region Fd3 start="commentstart" end="commentend" fold contained
|
||||
let content = ['3 cc', '4 dd {{{', '5 ee {{{ }}}', '{{{{', '6 ff }}}',
|
||||
\ '6 ff }}}', '7 gg', '8 hh', '9 ii']
|
||||
call append(0, content)
|
||||
normal Gzk
|
||||
call assert_equal('9 ii', getline('.'))
|
||||
normal k
|
||||
call assert_equal('3 cc', getline('.'))
|
||||
exe "normal jAcommentstart \<Esc>Acommentend"
|
||||
set fdl=1
|
||||
normal 3j
|
||||
call assert_equal('7 gg', getline('.'))
|
||||
set fdl=0
|
||||
exe "normal zO\<C-L>j"
|
||||
call assert_equal('8 hh', getline('.'))
|
||||
syn clear Fd1 Fd2 Fd3 Hup
|
||||
|
||||
set fdm& fdl&
|
||||
enew!
|
||||
endfunc
|
||||
|
||||
func Flvl()
|
||||
let l = getline(v:lnum)
|
||||
if l =~ "bb$"
|
||||
return 2
|
||||
elseif l =~ "gg$"
|
||||
return "s1"
|
||||
elseif l =~ "ii$"
|
||||
return ">2"
|
||||
elseif l =~ "kk$"
|
||||
return "0"
|
||||
endif
|
||||
return "="
|
||||
endfun
|
||||
|
||||
" test expression folding
|
||||
func Test_fold_expr()
|
||||
enew!
|
||||
set fdm=expr fde=Flvl()
|
||||
|
||||
let content = ['1 aa',
|
||||
\ '2 bb',
|
||||
\ '3 cc',
|
||||
\ '4 dd {{{commentstart commentend',
|
||||
\ '5 ee {{{ }}}',
|
||||
\ '{{{',
|
||||
\ '6 ff }}}',
|
||||
\ '6 ff }}}',
|
||||
\ ' 7 gg',
|
||||
\ ' 8 hh',
|
||||
\ '9 ii',
|
||||
\ 'a jj',
|
||||
\ 'b kk']
|
||||
call append(0, content)
|
||||
call cursor(1, 1)
|
||||
exe "normal /bb$\<CR>"
|
||||
call assert_equal(2, foldlevel('.'))
|
||||
exe "normal /hh$\<CR>"
|
||||
call assert_equal(1, foldlevel('.'))
|
||||
exe "normal /ii$\<CR>"
|
||||
call assert_equal(2, foldlevel('.'))
|
||||
exe "normal /kk$\<CR>"
|
||||
call assert_equal(0, foldlevel('.'))
|
||||
|
||||
set fdm& fde&
|
||||
enew!
|
||||
endfunc
|
||||
|
||||
" Bug with fdm=indent and moving folds
|
||||
" Moving a fold a few times, messes up the folds below the moved fold.
|
||||
" Fixed by 7.4.700
|
||||
func Test_fold_move()
|
||||
enew!
|
||||
set fdm=indent sw=2 fdl=0
|
||||
|
||||
let content = ['', '', 'Line1', ' Line2', ' Line3',
|
||||
\ 'Line4', ' Line5', ' Line6',
|
||||
\ 'Line7', ' Line8', ' Line9']
|
||||
call append(0, content)
|
||||
normal zM
|
||||
call cursor(4, 1)
|
||||
move 2
|
||||
move 1
|
||||
call assert_equal(7, foldclosed(7))
|
||||
call assert_equal(8, foldclosedend(7))
|
||||
call assert_equal(0, foldlevel(9))
|
||||
call assert_equal(10, foldclosed(10))
|
||||
call assert_equal(11, foldclosedend(10))
|
||||
call assert_equal('+-- 2 lines: Line2', foldtextresult(2))
|
||||
call assert_equal('+-- 2 lines: Line8', foldtextresult(10))
|
||||
|
||||
set fdm& sw& fdl&
|
||||
enew!
|
||||
endfunc
|
||||
|
1184
src/nvim/testdir/test_sort.vim
Normal file
1184
src/nvim/testdir/test_sort.vim
Normal file
File diff suppressed because it is too large
Load Diff
@@ -321,3 +321,183 @@ func Test_sub_cmd_8()
|
||||
enew!
|
||||
set titlestring&
|
||||
endfunc
|
||||
|
||||
" Test for *sub-replace-special* and *sub-replace-expression* on substitute().
|
||||
func Test_sub_replace_1()
|
||||
" Run the tests with 'magic' on
|
||||
set magic
|
||||
set cpo&
|
||||
call assert_equal('AA', substitute('A', 'A', '&&', ''))
|
||||
call assert_equal('&', substitute('B', 'B', '\&', ''))
|
||||
call assert_equal('C123456789987654321', substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', ''))
|
||||
call assert_equal('d', substitute('D', 'D', 'd', ''))
|
||||
call assert_equal('~', substitute('E', 'E', '~', ''))
|
||||
call assert_equal('~', substitute('F', 'F', '\~', ''))
|
||||
call assert_equal('Gg', substitute('G', 'G', '\ugg', ''))
|
||||
call assert_equal('Hh', substitute('H', 'H', '\Uh\Eh', ''))
|
||||
call assert_equal('iI', substitute('I', 'I', '\lII', ''))
|
||||
call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', ''))
|
||||
call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', ''))
|
||||
call assert_equal("l\<C-V>\<C-M>l",
|
||||
\ substitute('lLl', 'L', "\<C-V>\<C-M>", ''))
|
||||
call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', ''))
|
||||
call assert_equal("n\<C-V>\<C-M>n",
|
||||
\ substitute('nNn', 'N', "\\\<C-V>\<C-M>", ''))
|
||||
call assert_equal("o\no", substitute('oOo', 'O', '\n', ''))
|
||||
call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', ''))
|
||||
call assert_equal("q\tq", substitute('qQq', 'Q', '\t', ''))
|
||||
call assert_equal('r\r', substitute('rRr', 'R', '\\', ''))
|
||||
call assert_equal('scs', substitute('sSs', 'S', '\c', ''))
|
||||
call assert_equal("u\nu", substitute('uUu', 'U', "\n", ''))
|
||||
call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", ''))
|
||||
call assert_equal("w\\w", substitute('wWw', 'W', "\\", ''))
|
||||
call assert_equal("x\<C-M>x", substitute('xXx', 'X', "\r", ''))
|
||||
call assert_equal("YyyY", substitute('Y', 'Y', '\L\uyYy\l\EY', ''))
|
||||
call assert_equal("zZZz", substitute('Z', 'Z', '\U\lZzZ\u\Ez', ''))
|
||||
endfunc
|
||||
|
||||
func Test_sub_replace_2()
|
||||
" Run the tests with 'magic' off
|
||||
set nomagic
|
||||
set cpo&
|
||||
call assert_equal('AA', substitute('A', 'A', '&&', ''))
|
||||
call assert_equal('&', substitute('B', 'B', '\&', ''))
|
||||
call assert_equal('C123456789987654321', substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', ''))
|
||||
call assert_equal('d', substitute('D', 'D', 'd', ''))
|
||||
call assert_equal('~', substitute('E', 'E', '~', ''))
|
||||
call assert_equal('~', substitute('F', 'F', '\~', ''))
|
||||
call assert_equal('Gg', substitute('G', 'G', '\ugg', ''))
|
||||
call assert_equal('Hh', substitute('H', 'H', '\Uh\Eh', ''))
|
||||
call assert_equal('iI', substitute('I', 'I', '\lII', ''))
|
||||
call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', ''))
|
||||
call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', ''))
|
||||
call assert_equal("l\<C-V>\<C-M>l",
|
||||
\ substitute('lLl', 'L', "\<C-V>\<C-M>", ''))
|
||||
call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', ''))
|
||||
call assert_equal("n\<C-V>\<C-M>n",
|
||||
\ substitute('nNn', 'N', "\\\<C-V>\<C-M>", ''))
|
||||
call assert_equal("o\no", substitute('oOo', 'O', '\n', ''))
|
||||
call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', ''))
|
||||
call assert_equal("q\tq", substitute('qQq', 'Q', '\t', ''))
|
||||
call assert_equal('r\r', substitute('rRr', 'R', '\\', ''))
|
||||
call assert_equal('scs', substitute('sSs', 'S', '\c', ''))
|
||||
call assert_equal("t\<C-M>t", substitute('tTt', 'T', "\r", ''))
|
||||
call assert_equal("u\nu", substitute('uUu', 'U', "\n", ''))
|
||||
call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", ''))
|
||||
call assert_equal('w\w', substitute('wWw', 'W', "\\", ''))
|
||||
call assert_equal('XxxX', substitute('X', 'X', '\L\uxXx\l\EX', ''))
|
||||
call assert_equal('yYYy', substitute('Y', 'Y', '\U\lYyY\u\Ey', ''))
|
||||
endfunc
|
||||
|
||||
func Test_sub_replace_3()
|
||||
set magic&
|
||||
set cpo&
|
||||
call assert_equal('a\a', substitute('aAa', 'A', '\="\\"', ''))
|
||||
call assert_equal('b\\b', substitute('bBb', 'B', '\="\\\\"', ''))
|
||||
call assert_equal("c\rc", substitute('cCc', 'C', "\\=\"\r\"", ''))
|
||||
call assert_equal("d\\\rd", substitute('dDd', 'D', "\\=\"\\\\\r\"", ''))
|
||||
call assert_equal("e\\\\\re", substitute('eEe', 'E', "\\=\"\\\\\\\\\r\"", ''))
|
||||
call assert_equal('f\rf', substitute('fFf', 'F', '\="\\r"', ''))
|
||||
call assert_equal('j\nj', substitute('jJj', 'J', '\="\\n"', ''))
|
||||
call assert_equal("k\<C-M>k", substitute('kKk', 'K', '\="\r"', ''))
|
||||
call assert_equal("l\nl", substitute('lLl', 'L', '\="\n"', ''))
|
||||
endfunc
|
||||
|
||||
" Test for submatch() on substitute().
|
||||
func Test_sub_replace_4()
|
||||
set magic&
|
||||
set cpo&
|
||||
call assert_equal('a\a', substitute('aAa', 'A',
|
||||
\ '\=substitute(submatch(0), ".", "\\", "")', ''))
|
||||
call assert_equal('b\b', substitute('bBb', 'B',
|
||||
\ '\=substitute(submatch(0), ".", "\\\\", "")', ''))
|
||||
call assert_equal("c\<C-V>\<C-M>c", substitute('cCc', 'C', '\=substitute(submatch(0), ".", "\<C-V>\<C-M>", "")', ''))
|
||||
call assert_equal("d\<C-V>\<C-M>d", substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\\<C-V>\<C-M>", "")', ''))
|
||||
call assert_equal("e\\\<C-V>\<C-M>e", substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-M>", "")', ''))
|
||||
call assert_equal("f\<C-M>f", substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', ''))
|
||||
call assert_equal("j\nj", substitute('jJj', 'J', '\=substitute(submatch(0), ".", "\\n", "")', ''))
|
||||
call assert_equal("k\rk", substitute('kKk', 'K', '\=substitute(submatch(0), ".", "\r", "")', ''))
|
||||
call assert_equal("l\nl", substitute('lLl', 'L', '\=substitute(submatch(0), ".", "\n", "")', ''))
|
||||
endfunc
|
||||
|
||||
func Test_sub_replace_5()
|
||||
set magic&
|
||||
set cpo&
|
||||
call assert_equal('A123456789987654321', substitute('A123456789',
|
||||
\ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
|
||||
\ '\=submatch(0) . submatch(9) . submatch(8) . ' .
|
||||
\ 'submatch(7) . submatch(6) . submatch(5) . ' .
|
||||
\ 'submatch(4) . submatch(3) . submatch(2) . submatch(1)',
|
||||
\ ''))
|
||||
call assert_equal("[['A123456789'], ['9'], ['8'], ['7'], ['6'], " .
|
||||
\ "['5'], ['4'], ['3'], ['2'], ['1']]",
|
||||
\ substitute('A123456789',
|
||||
\ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
|
||||
\ '\=string([submatch(0, 1), submatch(9, 1), ' .
|
||||
\ 'submatch(8, 1), submatch(7, 1), submatch(6, 1), ' .
|
||||
\ 'submatch(5, 1), submatch(4, 1), submatch(3, 1), ' .
|
||||
\ 'submatch(2, 1), submatch(1, 1)])',
|
||||
\ ''))
|
||||
endfunc
|
||||
|
||||
func Test_sub_replace_6()
|
||||
set magic&
|
||||
" set cpo+=/
|
||||
call assert_equal('a', substitute('A', 'A', 'a', ''))
|
||||
call assert_equal('%', substitute('B', 'B', '%', ''))
|
||||
" set cpo-=/
|
||||
call assert_equal('c', substitute('C', 'C', 'c', ''))
|
||||
call assert_equal('%', substitute('D', 'D', '%', ''))
|
||||
endfunc
|
||||
|
||||
func Test_sub_replace_7()
|
||||
set magic&
|
||||
set cpo&
|
||||
call assert_equal('AA', substitute('AA', 'A.', '\=submatch(0)', ''))
|
||||
call assert_equal("B\nB", substitute("B\nB", 'B.', '\=submatch(0)', ''))
|
||||
call assert_equal("['B\n']B", substitute("B\nB", 'B.', '\=string(submatch(0, 1))', ''))
|
||||
call assert_equal('-abab', substitute('-bb', '\zeb', 'a', 'g'))
|
||||
call assert_equal('c-cbcbc', substitute('-bb', '\ze', 'c', 'g'))
|
||||
endfunc
|
||||
|
||||
" Test for *:s%* on :substitute.
|
||||
func Test_sub_replace_8()
|
||||
new
|
||||
set magic&
|
||||
set cpo&
|
||||
$put =',,X'
|
||||
s/\(^\|,\)\ze\(,\|X\)/\1N/g
|
||||
call assert_equal('N,,NX', getline("$"))
|
||||
$put =',,Y'
|
||||
let cmd = ':s/\(^\|,\)\ze\(,\|Y\)/\1N/gc'
|
||||
call feedkeys(cmd . "\<CR>a", "xt")
|
||||
call assert_equal('N,,NY', getline("$"))
|
||||
:$put =',,Z'
|
||||
let cmd = ':s/\(^\|,\)\ze\(,\|Z\)/\1N/gc'
|
||||
call feedkeys(cmd . "\<CR>yy", "xt")
|
||||
call assert_equal('N,,NZ', getline("$"))
|
||||
enew! | close
|
||||
endfunc
|
||||
|
||||
func Test_sub_replace_9()
|
||||
new
|
||||
set magic&
|
||||
set cpo&
|
||||
$put ='xxx'
|
||||
call feedkeys(":s/x/X/gc\<CR>yyq", "xt")
|
||||
call assert_equal('XXx', getline("$"))
|
||||
enew! | close
|
||||
endfunc
|
||||
|
||||
func Test_sub_replace_10()
|
||||
set magic&
|
||||
set cpo&
|
||||
call assert_equal('a1a2a3a', substitute('123', '\zs', 'a', 'g'))
|
||||
call assert_equal('aaa', substitute('123', '\zs.', 'a', 'g'))
|
||||
call assert_equal('1a2a3a', substitute('123', '.\zs', 'a', 'g'))
|
||||
call assert_equal('a1a2a3a', substitute('123', '\ze', 'a', 'g'))
|
||||
call assert_equal('a1a2a3', substitute('123', '\ze.', 'a', 'g'))
|
||||
call assert_equal('aaa', substitute('123', '.\ze', 'a', 'g'))
|
||||
call assert_equal('aa2a3a', substitute('123', '1\|\ze', 'a', 'g'))
|
||||
call assert_equal('1aaa', substitute('123', '1\zs\|[23]', 'a', 'g'))
|
||||
endfunc
|
||||
|
48
src/nvim/testdir/test_swap.vim
Normal file
48
src/nvim/testdir/test_swap.vim
Normal file
@@ -0,0 +1,48 @@
|
||||
" Tests for the swap feature
|
||||
|
||||
" Tests for 'directory' option.
|
||||
func Test_swap_directory()
|
||||
if !has("unix")
|
||||
return
|
||||
endif
|
||||
let content = ['start of testfile',
|
||||
\ 'line 2 Abcdefghij',
|
||||
\ 'line 3 Abcdefghij',
|
||||
\ 'end of testfile']
|
||||
call writefile(content, 'Xtest1')
|
||||
|
||||
" '.', swap file in the same directory as file
|
||||
set dir=.,~
|
||||
|
||||
" Verify that the swap file doesn't exist in the current directory
|
||||
call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1))
|
||||
edit Xtest1
|
||||
let swfname = split(execute("swapname"))[0]
|
||||
call assert_equal([swfname], glob(swfname, 1, 1, 1))
|
||||
|
||||
" './dir', swap file in a directory relative to the file
|
||||
set dir=./Xtest2,.,~
|
||||
|
||||
call mkdir("Xtest2")
|
||||
edit Xtest1
|
||||
call assert_equal([], glob(swfname, 1, 1, 1))
|
||||
let swfname = "Xtest2/Xtest1.swp"
|
||||
call assert_equal(swfname, split(execute("swapname"))[0])
|
||||
call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1))
|
||||
|
||||
" 'dir', swap file in directory relative to the current dir
|
||||
set dir=Xtest.je,~
|
||||
|
||||
call mkdir("Xtest.je")
|
||||
call writefile(content, 'Xtest2/Xtest3')
|
||||
edit Xtest2/Xtest3
|
||||
call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1))
|
||||
let swfname = "Xtest.je/Xtest3.swp"
|
||||
call assert_equal(swfname, split(execute("swapname"))[0])
|
||||
call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1))
|
||||
|
||||
set dir&
|
||||
call delete("Xtest1")
|
||||
call delete("Xtest2", "rf")
|
||||
call delete("Xtest.je", "rf")
|
||||
endfunc
|
@@ -174,4 +174,60 @@ func Test_tag_symbolic()
|
||||
%bwipe!
|
||||
endfunc
|
||||
|
||||
" Tests for tag search with !_TAG_FILE_ENCODING.
|
||||
" Depends on the test83-tags2 and test83-tags3 files.
|
||||
func Test_tag_file_encoding()
|
||||
throw 'skipped: Nvim removed test83-tags2, test83-tags3'
|
||||
if has('vms')
|
||||
return
|
||||
endif
|
||||
|
||||
if !has('iconv') || iconv("\x82\x60", "cp932", "utf-8") != "\uff21"
|
||||
return
|
||||
endif
|
||||
|
||||
let save_enc = &encoding
|
||||
set encoding=utf8
|
||||
|
||||
let content = ['text for tags1', 'abcdefghijklmnopqrs']
|
||||
call writefile(content, 'Xtags1.txt')
|
||||
let content = ['text for tags2', 'ABC']
|
||||
call writefile(content, 'Xtags2.txt')
|
||||
let content = ['text for tags3', 'ABC']
|
||||
call writefile(content, 'Xtags3.txt')
|
||||
let content = ['!_TAG_FILE_ENCODING utf-8 //', 'abcdefghijklmnopqrs Xtags1.txt /abcdefghijklmnopqrs']
|
||||
call writefile(content, 'Xtags1')
|
||||
|
||||
" case1:
|
||||
new
|
||||
set tags=Xtags1
|
||||
tag abcdefghijklmnopqrs
|
||||
call assert_equal('Xtags1.txt', expand('%:t'))
|
||||
call assert_equal('abcdefghijklmnopqrs', getline('.'))
|
||||
close
|
||||
|
||||
" case2:
|
||||
new
|
||||
set tags=test83-tags2
|
||||
tag /.BC
|
||||
call assert_equal('Xtags2.txt', expand('%:t'))
|
||||
call assert_equal('ABC', getline('.'))
|
||||
close
|
||||
|
||||
" case3:
|
||||
new
|
||||
set tags=test83-tags3
|
||||
tag abc50
|
||||
call assert_equal('Xtags3.txt', expand('%:t'))
|
||||
call assert_equal('ABC', getline('.'))
|
||||
close
|
||||
|
||||
set tags&
|
||||
let &encoding = save_enc
|
||||
call delete('Xtags1.txt')
|
||||
call delete('Xtags2.txt')
|
||||
call delete('Xtags3.txt')
|
||||
call delete('Xtags1')
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -1274,6 +1274,26 @@ func Test_user_command_with_bang()
|
||||
delcommand Nieuw
|
||||
endfunc
|
||||
|
||||
" Test for script-local function
|
||||
func <SID>DoLast()
|
||||
call append(line('$'), "last line")
|
||||
endfunc
|
||||
|
||||
func s:DoNothing()
|
||||
call append(line('$'), "nothing line")
|
||||
endfunc
|
||||
|
||||
func Test_script_local_func()
|
||||
set nocp viminfo+=nviminfo
|
||||
new
|
||||
nnoremap <buffer> _x :call <SID>DoNothing()<bar>call <SID>DoLast()<bar>delfunc <SID>DoNothing<bar>delfunc <SID>DoLast<cr>
|
||||
|
||||
normal _x
|
||||
call assert_equal('nothing line', getline(2))
|
||||
call assert_equal('last line', getline(3))
|
||||
enew! | close
|
||||
endfunc
|
||||
|
||||
"-------------------------------------------------------------------------------
|
||||
" Modelines {{{1
|
||||
" vim: ts=8 sw=4 tw=80 fdm=marker
|
||||
|
108
src/nvim/testdir/test_wordcount.vim
Normal file
108
src/nvim/testdir/test_wordcount.vim
Normal file
@@ -0,0 +1,108 @@
|
||||
" Test for wordcount() function
|
||||
|
||||
if !has('multi_byte')
|
||||
finish
|
||||
endif
|
||||
|
||||
func Test_wordcount()
|
||||
let save_enc = &enc
|
||||
set encoding=utf-8
|
||||
set selection=inclusive fileformat=unix fileformats=unix
|
||||
|
||||
new
|
||||
|
||||
" Test 1: empty window
|
||||
call assert_equal({'chars': 0, 'cursor_chars': 0, 'words': 0, 'cursor_words': 0,
|
||||
\ 'bytes': 0, 'cursor_bytes': 0}, wordcount())
|
||||
|
||||
" Test 2: some words, cursor at start
|
||||
call append(1, 'one two three')
|
||||
call cursor([1, 1, 0])
|
||||
call assert_equal({'chars': 15, 'cursor_chars': 1, 'words': 3, 'cursor_words': 0,
|
||||
\ 'bytes': 15, 'cursor_bytes': 1}, wordcount())
|
||||
|
||||
" Test 3: some words, cursor at end
|
||||
%d _
|
||||
call append(1, 'one two three')
|
||||
call cursor([2, 99, 0])
|
||||
call assert_equal({'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3,
|
||||
\ 'bytes': 15, 'cursor_bytes': 14}, wordcount())
|
||||
|
||||
" Test 4: some words, cursor at end, ve=all
|
||||
set ve=all
|
||||
%d _
|
||||
call append(1, 'one two three')
|
||||
call cursor([2, 99, 0])
|
||||
call assert_equal({'chars': 15, 'cursor_chars': 15, 'words': 3, 'cursor_words': 3,
|
||||
\ 'bytes': 15, 'cursor_bytes': 15}, wordcount())
|
||||
set ve=
|
||||
|
||||
" Test 5: several lines with words
|
||||
%d _
|
||||
call append(1, ['one two three', 'one two three', 'one two three'])
|
||||
call cursor([4, 99, 0])
|
||||
call assert_equal({'chars': 43, 'cursor_chars': 42, 'words': 9, 'cursor_words': 9,
|
||||
\ 'bytes': 43, 'cursor_bytes': 42}, wordcount())
|
||||
|
||||
" Test 6: one line with BOM set
|
||||
%d _
|
||||
call append(1, 'one two three')
|
||||
set bomb
|
||||
w! Xtest
|
||||
call cursor([2, 99, 0])
|
||||
call assert_equal({'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3,
|
||||
\ 'bytes': 18, 'cursor_bytes': 14}, wordcount())
|
||||
set nobomb
|
||||
w!
|
||||
call delete('Xtest')
|
||||
|
||||
" Test 7: one line with multibyte words
|
||||
%d _
|
||||
call append(1, ['Äne M¤ne Müh'])
|
||||
call cursor([2, 99, 0])
|
||||
call assert_equal({'chars': 14, 'cursor_chars': 13, 'words': 3, 'cursor_words': 3,
|
||||
\ 'bytes': 17, 'cursor_bytes': 16}, wordcount())
|
||||
|
||||
" Test 8: several lines with multibyte words
|
||||
%d _
|
||||
call append(1, ['Äne M¤ne Müh', 'und raus bist dü!'])
|
||||
call cursor([3, 99, 0])
|
||||
call assert_equal({'chars': 32, 'cursor_chars': 31, 'words': 7, 'cursor_words': 7,
|
||||
\ 'bytes': 36, 'cursor_bytes': 35}, wordcount())
|
||||
|
||||
" Visual map to capture wordcount() in visual mode
|
||||
vnoremap <expr> <F2> execute("let g:visual_stat = wordcount()")
|
||||
|
||||
" Test 9: visual mode, complete buffer
|
||||
let g:visual_stat = {}
|
||||
%d _
|
||||
call append(1, ['Äne M¤ne Müh', 'und raus bist dü!'])
|
||||
" start visual mode and select the complete buffer
|
||||
0
|
||||
exe "normal V2j\<F2>y"
|
||||
call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 32,
|
||||
\ 'visual_words': 7, 'visual_bytes': 36}, g:visual_stat)
|
||||
|
||||
" Test 10: visual mode (empty)
|
||||
%d _
|
||||
call append(1, ['Äne M¤ne Müh', 'und raus bist dü!'])
|
||||
" start visual mode and select the complete buffer
|
||||
0
|
||||
exe "normal v$\<F2>y"
|
||||
call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 1,
|
||||
\ 'visual_words': 0, 'visual_bytes': 1}, g:visual_stat)
|
||||
|
||||
" Test 11: visual mode, single line
|
||||
%d _
|
||||
call append(1, ['Äne M¤ne Müh', 'und raus bist dü!'])
|
||||
" start visual mode and select the complete buffer
|
||||
2
|
||||
exe "normal 0v$\<F2>y"
|
||||
call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 13,
|
||||
\ 'visual_words': 3, 'visual_bytes': 16}, g:visual_stat)
|
||||
|
||||
set selection& fileformat& fileformats&
|
||||
let &enc = save_enc
|
||||
enew!
|
||||
close
|
||||
endfunc
|
Reference in New Issue
Block a user