diff options
Diffstat (limited to 'src/nvim/testdir/test_functions.vim')
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 94 |
1 files changed, 62 insertions, 32 deletions
diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index ed080afee6..a0e9f780c6 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -56,6 +56,7 @@ func Test_empty() endif call assert_equal(0, empty(function('Test_empty'))) + call assert_equal(0, empty(function('Test_empty', [0]))) endfunc func Test_len() @@ -294,7 +295,7 @@ func Test_resolve_unix() call delete('Xlink') silent !ln -s -f Xlink2/ Xlink1 - call assert_equal('Xlink2', resolve('Xlink1')) + call assert_equal('Xlink2', 'Xlink1'->resolve()) call assert_equal('Xlink2/', resolve('Xlink1/')) call delete('Xlink1') @@ -359,10 +360,10 @@ endfunc func Test_pathshorten() call assert_equal('', pathshorten('')) call assert_equal('foo', pathshorten('foo')) - call assert_equal('/foo', pathshorten('/foo')) + call assert_equal('/foo', '/foo'->pathshorten()) call assert_equal('f/', pathshorten('foo/')) call assert_equal('f/bar', pathshorten('foo/bar')) - call assert_equal('f/b/foobar', pathshorten('foo/bar/foobar')) + call assert_equal('f/b/foobar', 'foo/bar/foobar'->pathshorten()) call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar')) call assert_equal('.f/bar', pathshorten('.foo/bar')) call assert_equal('~f/bar', pathshorten('~foo/bar')) @@ -657,8 +658,8 @@ func Test_mode() exe "normal gRabc\<C-X>\<C-L>\<F2>\<Esc>u" call assert_equal('R-Rvc', g:current_modes) - call assert_equal('n', mode(0)) - call assert_equal('n', mode(1)) + call assert_equal('n', 0->mode()) + call assert_equal('n', 1->mode()) " i_CTRL-O exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>" @@ -822,7 +823,7 @@ endfunc func Test_match_func() call assert_equal(4, match('testing', 'ing')) - call assert_equal(4, match('testing', 'ing', 2)) + call assert_equal(4, 'testing'->match('ing', 2)) call assert_equal(-1, match('testing', 'ing', 5)) call assert_equal(-1, match('testing', 'ing', 8)) call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing')) @@ -831,7 +832,7 @@ endfunc func Test_matchend() call assert_equal(7, matchend('testing', 'ing')) - call assert_equal(7, matchend('testing', 'ing', 2)) + call assert_equal(7, 'testing'->matchend('ing', 2)) call assert_equal(-1, matchend('testing', 'ing', 5)) call assert_equal(-1, matchend('testing', 'ing', 8)) call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing')) @@ -840,13 +841,13 @@ endfunc func Test_matchlist() call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')) - call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2)) + call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], 'acd'->matchlist('\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2)) call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4)) endfunc func Test_matchstr() call assert_equal('ing', matchstr('testing', 'ing')) - call assert_equal('ing', matchstr('testing', 'ing', 2)) + call assert_equal('ing', 'testing'->matchstr('ing', 2)) call assert_equal('', matchstr('testing', 'ing', 5)) call assert_equal('', matchstr('testing', 'ing', 8)) call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing')) @@ -855,7 +856,7 @@ endfunc func Test_matchstrpos() call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing')) - call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2)) + call assert_equal(['ing', 4, 7], 'testing'->matchstrpos('ing', 2)) call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5)) call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8)) call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing')) @@ -876,21 +877,21 @@ Test call assert_equal(0, nextnonblank(-1)) call assert_equal(0, nextnonblank(0)) call assert_equal(1, nextnonblank(1)) - call assert_equal(4, nextnonblank(2)) + call assert_equal(4, 2->nextnonblank()) call assert_equal(4, nextnonblank(3)) call assert_equal(4, nextnonblank(4)) call assert_equal(6, nextnonblank(5)) call assert_equal(6, nextnonblank(6)) call assert_equal(7, nextnonblank(7)) - call assert_equal(0, nextnonblank(8)) + call assert_equal(0, 8->nextnonblank()) call assert_equal(0, prevnonblank(-1)) call assert_equal(0, prevnonblank(0)) - call assert_equal(1, prevnonblank(1)) + call assert_equal(1, 1->prevnonblank()) call assert_equal(1, prevnonblank(2)) call assert_equal(1, prevnonblank(3)) call assert_equal(4, prevnonblank(4)) - call assert_equal(4, prevnonblank(5)) + call assert_equal(4, 5->prevnonblank()) call assert_equal(6, prevnonblank(6)) call assert_equal(7, prevnonblank(7)) call assert_equal(0, prevnonblank(8)) @@ -912,7 +913,7 @@ func Test_byte2line_line2byte() call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], \ map(range(-1, 8), 'v:val->byte2line()')) call assert_equal([-1, -1, 1, 3, 6, 8, -1], - \ map(range(-1, 5), 'line2byte(v:val)')) + \ map(range(-1, 5), 'v:val->line2byte()')) set fileformat=dos call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1], @@ -1007,6 +1008,7 @@ func Test_count() call assert_equal(1, count(l, 'a', 0, 1)) call assert_equal(2, count(l, 'a', 1, 1)) call assert_fails('call count(l, "a", 0, 10)', 'E684:') + call assert_fails('call count(l, "a", [])', 'E745:') let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'} call assert_equal(2, count(d, 'a')) @@ -1034,6 +1036,8 @@ func Test_count() call assert_equal(2, count("foo", "O", 1)) call assert_equal(2, count("fooooo", "oo")) call assert_equal(0, count("foo", "")) + + call assert_fails('call count(0, 0)', 'E712:') endfunc func Test_changenr() @@ -1061,7 +1065,7 @@ func Test_filewritable() call assert_equal(0, filewritable('Xfilewritable')) call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----')) - call assert_equal(1, filewritable('Xfilewritable')) + call assert_equal(1, 'Xfilewritable'->filewritable()) call assert_equal(0, filewritable('doesnotexist')) @@ -1072,12 +1076,12 @@ endfunc func Test_Executable() if has('win32') call assert_equal(1, executable('notepad')) - call assert_equal(1, executable('notepad.exe')) + call assert_equal(1, 'notepad.exe'->executable()) call assert_equal(0, executable('notepad.exe.exe')) call assert_equal(0, executable('shell32.dll')) call assert_equal(0, executable('win.ini')) elseif has('unix') - call assert_equal(1, executable('cat')) + call assert_equal(1, 'cat'->executable()) call assert_equal(0, executable('nodogshere')) " get "cat" path and remove the leading / @@ -1086,8 +1090,7 @@ func Test_Executable() " check that the relative path works in / lcd / call assert_equal(1, executable(catcmd)) - " let result = catcmd->exepath() - let result = exepath(catcmd) + let result = catcmd->exepath() " when using chroot looking for sbin/cat can return bin/cat, that is OK if catcmd =~ '\<sbin\>' && result =~ '\<bin\>' call assert_equal('/' .. substitute(catcmd, '\<sbin\>', 'bin', ''), result) @@ -1132,7 +1135,7 @@ endfunc func Test_hlexists() call assert_equal(0, hlexists('does_not_exist')) - " call assert_equal(0, hlexists('Number')) + " call assert_equal(0, 'Number'->hlexists()) call assert_equal(0, highlight_exists('does_not_exist')) " call assert_equal(0, highlight_exists('Number')) syntax on @@ -1165,7 +1168,7 @@ endfunc func Test_inputlist() call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx') call assert_equal(1, c) - call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>2\<cr>", 'tx') + call feedkeys(":let c = ['Select color:', '1. red', '2. green', '3. blue']->inputlist()\<cr>2\<cr>", 'tx') call assert_equal(2, c) call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx') call assert_equal(3, c) @@ -1297,7 +1300,7 @@ func Test_trim() call assert_fails('call trim(" vim ", " ", -1)', 'E475:') call assert_fails('call trim(" vim ", " ", 3)', 'E475:') - let chars = join(map(range(1, 0x20) + [0xa0], {n -> nr2char(n)}), '') + let chars = join(map(range(1, 0x20) + [0xa0], {n -> n->nr2char()}), '') call assert_equal("x", trim(chars . "x" . chars)) endfunc @@ -1311,7 +1314,7 @@ func Test_func_range_with_edit() " is invalid in that buffer. call writefile(['just one line'], 'Xfuncrange2') new - call setline(1, range(10)) + call setline(1, 10->range()) write Xfuncrange1 call assert_fails('5,8call EditAnotherFile()', 'E16:') @@ -1324,7 +1327,7 @@ func Test_func_exists_on_reload() call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists') call assert_equal(0, exists('*ExistingFunction')) source Xfuncexists - call assert_equal(1, exists('*ExistingFunction')) + call assert_equal(1, '*ExistingFunction'->exists()) " Redefining a function when reloading a script is OK. source Xfuncexists call assert_equal(1, exists('*ExistingFunction')) @@ -1355,7 +1358,7 @@ func Test_func_sandbox() sandbox let F = {-> 'hello'} call assert_equal('hello', F()) - sandbox let F = {-> execute("normal ix\<Esc>")} + sandbox let F = {-> "normal ix\<Esc>"->execute()} call assert_fails('call F()', 'E48:') unlet F @@ -1418,7 +1421,7 @@ func Test_reg_executing_and_recording() let g:regs = [] func TestFunc() abort let g:regs += [reg_executing()] - let g:typed = input('?') + let g:typed = '?'->input() let g:regs += [reg_executing()] endfunc call feedkeys("@qy\<CR>", 'xt') @@ -1434,6 +1437,25 @@ func Test_reg_executing_and_recording() unlet s:reg_stat endfunc +func Test_inputsecret() + map W :call TestFunc()<CR> + let @q = "W" + let g:typed1 = '' + let g:typed2 = '' + let g:regs = [] + func TestFunc() abort + let g:typed1 = '?'->inputsecret() + let g:typed2 = inputsecret('password: ') + endfunc + call feedkeys("@qsomething\<CR>else\<CR>", 'xt') + call assert_equal("something", g:typed1) + call assert_equal("else", g:typed2) + delfunc TestFunc + unmap W + unlet g:typed1 + unlet g:typed2 +endfunc + func Test_getchar() call feedkeys('a', '') call assert_equal(char2nr('a'), getchar()) @@ -1491,17 +1513,17 @@ func Test_libcall_libcallnr() endif if has('win32') - call assert_equal($USERPROFILE, libcall(libc, 'getenv', 'USERPROFILE')) + call assert_equal($USERPROFILE, 'USERPROFILE'->libcall(libc, 'getenv')) else - call assert_equal($HOME, libcall(libc, 'getenv', 'HOME')) + call assert_equal($HOME, 'HOME'->libcall(libc, 'getenv')) endif " If function returns NULL, libcall() should return an empty string. call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT')) " Test libcallnr() with string and integer argument. - call assert_equal(4, libcallnr(libc, 'strlen', 'abcd')) - call assert_equal(char2nr('A'), libcallnr(libc, 'toupper', char2nr('a'))) + call assert_equal(4, 'abcd'->libcallnr(libc, 'strlen')) + call assert_equal(char2nr('A'), char2nr('a')->libcallnr(libc, 'toupper')) call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:') call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:') @@ -1564,7 +1586,7 @@ func Test_readdir() call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files)) " Only results containing "f" - let files = readdir('Xdir', { x -> stridx(x, 'f') !=- 1 }) + let files = 'Xdir'->readdir({ x -> stridx(x, 'f') !=- 1 }) call assert_equal(['foo.txt'], sort(files)) " Only .txt files @@ -1597,6 +1619,14 @@ func Test_call() call assert_fails("call call('Mylen', [], 0)", 'E715:') endfunc +func Test_char2nr() + call assert_equal(12354, char2nr('あ', 1)) +endfunc + +func Test_eventhandler() + call assert_equal(0, eventhandler()) +endfunc + " Test for the eval() function func Test_eval() call assert_fails("call eval('5 a')", 'E488:') |