aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/autocmd.c16
-rw-r--r--src/nvim/autocmd.c3
-rw-r--r--src/nvim/eval/typval.c21
-rw-r--r--src/nvim/getchar.c7
-rw-r--r--src/nvim/main.c4
-rw-r--r--src/nvim/os/pty_process_win.c2
-rw-r--r--src/nvim/testdir/test_alot.vim39
-rw-r--r--src/nvim/testdir/test_delete.vim114
-rw-r--r--src/nvim/testdir/test_file_perm.vim30
-rw-r--r--src/nvim/testdir/test_mapping.vim30
-rw-r--r--src/nvim/testdir/test_searchpos.vim30
-rw-r--r--src/nvim/testdir/test_set.vim29
-rw-r--r--src/nvim/testdir/test_sort.vim1
13 files changed, 254 insertions, 72 deletions
diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c
index ad0e78cb50..0ad7b320d0 100644
--- a/src/nvim/api/autocmd.c
+++ b/src/nvim/api/autocmd.c
@@ -1,3 +1,6 @@
+// This is an open source non-commercial project. Dear PVS-Studio, please check
+// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+
#include <stdbool.h>
#include <stdio.h>
@@ -128,10 +131,8 @@ Array nvim_get_autocmds(Dict(get_autocmds) *opts, Error *err)
continue;
}
- for (AutoPat *ap = au_get_autopat_for_event(event);
- ap != NULL;
- ap = ap->next) {
- if (ap == NULL || ap->cmds == NULL) {
+ for (AutoPat *ap = au_get_autopat_for_event(event); ap != NULL; ap = ap->next) {
+ if (ap->cmds == NULL) {
continue;
}
@@ -423,13 +424,6 @@ Integer nvim_create_autocmd(uint64_t channel_id, Object event, Dict(create_autoc
ADD(patterns, STRING_OBJ(cstr_to_string((char *)pattern_buflocal)));
}
- if (aucmd.type == CALLABLE_NONE) {
- api_set_error(err,
- kErrorTypeValidation,
- "'command' or 'callback' is required");
- goto cleanup;
- }
-
if (opts->desc.type != kObjectTypeNil) {
if (opts->desc.type == kObjectTypeString) {
desc = opts->desc.data.string.data;
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 66222f6a6a..e7e1d5fd1b 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -887,7 +887,6 @@ int do_autocmd_event(event_T event, char_u *pat, bool once, int nested, char_u *
while (patlen) {
// detect special <buffer[=X]> buffer-local patterns
is_buflocal = aupat_is_buflocal(pat, patlen);
- buflocal_nr = 0;
if (is_buflocal) {
buflocal_nr = aupat_get_buflocal_nr(pat, patlen);
@@ -2474,7 +2473,7 @@ bool aucmd_exec_is_deleted(AucmdExecutable acc)
case CALLABLE_EX:
return acc.callable.cmd == NULL;
case CALLABLE_CB:
- return callback_is_freed(acc.callable.cb);
+ return acc.callable.cb.type == kCallbackNone;
case CALLABLE_NONE:
return true;
}
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 44b003d106..d492c67877 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1155,27 +1155,6 @@ void callback_free(Callback *callback)
callback->data.funcref = NULL;
}
-/// Check if callback is freed
-bool callback_is_freed(Callback callback)
-{
- switch (callback.type) {
- case kCallbackFuncref:
- return false;
- break;
- case kCallbackPartial:
- return false;
- break;
- case kCallbackLua:
- return callback.data.luaref == LUA_NOREF;
- break;
- case kCallbackNone:
- return true;
- break;
- }
-
- return true;
-}
-
/// Copy a callback into a typval_T.
void callback_put(Callback *cb, typval_T *tv)
FUNC_ATTR_NONNULL_ALL
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 85a5c176bb..8426cdb98c 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -1712,11 +1712,10 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
int local_State = get_real_state();
bool is_plug_map = false;
- // Check if typehead starts with a <Plug> mapping.
- // In that case we will ignore nore flag on it.
+ // If typehead starts with <Plug> then remap, even for a "noremap" mapping.
if (typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL
- && typebuf.tb_buf[typebuf.tb_off+1] == KS_EXTRA
- && typebuf.tb_buf[typebuf.tb_off+2] == KE_PLUG) {
+ && typebuf.tb_buf[typebuf.tb_off + 1] == KS_EXTRA
+ && typebuf.tb_buf[typebuf.tb_off + 2] == KE_PLUG) {
is_plug_map = true;
}
diff --git a/src/nvim/main.c b/src/nvim/main.c
index b02ebbe030..d0b3a435c3 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -357,7 +357,7 @@ int main(int argc, char **argv)
// Execute --cmd arguments.
exe_pre_commands(&params);
- if (!vimrc_none) {
+ if (!vimrc_none || params.clean) {
// Sources ftplugin.vim and indent.vim. We do this *before* the user startup scripts to ensure
// ftplugins run before FileType autocommands defined in the init file (which allows those
// autocommands to overwrite settings from ftplugins).
@@ -368,7 +368,7 @@ int main(int argc, char **argv)
source_startup_scripts(&params);
// If using the runtime (-u is not NONE), enable syntax & filetype plugins.
- if (!vimrc_none) {
+ if (!vimrc_none || params.clean) {
// Sources filetype.lua and filetype.vim unless the user explicitly disabled it with :filetype
// off.
filetype_maybe_enable();
diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c
index f78f3e66f5..99231968a2 100644
--- a/src/nvim/os/pty_process_win.c
+++ b/src/nvim/os/pty_process_win.c
@@ -281,7 +281,7 @@ static void wait_eof_timer_cb(uv_timer_t *wait_eof_timer)
PtyProcess *ptyproc = wait_eof_timer->data;
Process *proc = (Process *)ptyproc;
- if (proc->out.closed || !uv_is_readable(proc->out.uvstream)) {
+ if (proc->out.closed || proc->out.did_eof || !uv_is_readable(proc->out.uvstream)) {
uv_timer_stop(&ptyproc->wait_eof_timer);
pty_process_finish2(ptyproc);
}
diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim
index 5a3d1d56bb..bb744f7b41 100644
--- a/src/nvim/testdir/test_alot.vim
+++ b/src/nvim/testdir/test_alot.vim
@@ -3,56 +3,33 @@
source test_backup.vim
source test_behave.vim
-source test_cd.vim
-source test_changedtick.vim
source test_compiler.vim
-source test_cursor_func.vim
-source test_cursorline.vim
source test_ex_equal.vim
source test_ex_undo.vim
source test_ex_z.vim
source test_ex_mode.vim
-source test_execute_func.vim
+source test_expand.vim
source test_expand_func.vim
source test_feedkeys.vim
-source test_filter_cmd.vim
-source test_filter_map.vim
-source test_findfile.vim
-source test_float_func.vim
-source test_functions.vim
+source test_file_perm.vim
+source test_fnamemodify.vim
source test_ga.vim
+source test_glob2regpat.vim
source test_global.vim
-source test_goto.vim
-source test_join.vim
source test_jumps.vim
-source test_fileformat.vim
-source test_filetype.vim
-source test_filetype_lua.vim
-source test_lambda.vim
+source test_lispwords.vim
source test_menu.vim
-source test_messages.vim
-source test_modeline.vim
source test_move.vim
-source test_partial.vim
-source test_popup.vim
source test_put.vim
-source test_rename.vim
+source test_reltime.vim
source test_scroll_opt.vim
+source test_searchpos.vim
+source test_set.vim
source test_shift.vim
-" Test fails on windows CI when using the MSVC compiler.
-" source test_sort.vim
source test_sha256.vim
-source test_suspend.vim
-source test_syn_attr.vim
source test_tabline.vim
-source test_tabpage.vim
source test_tagcase.vim
source test_tagfunc.vim
-source test_tagjump.vim
-source test_taglist.vim
-source test_true_false.vim
source test_unlet.vim
source test_version.vim
-source test_virtualedit.vim
-source test_window_cmd.vim
source test_wnext.vim
diff --git a/src/nvim/testdir/test_delete.vim b/src/nvim/testdir/test_delete.vim
new file mode 100644
index 0000000000..b23a3bd025
--- /dev/null
+++ b/src/nvim/testdir/test_delete.vim
@@ -0,0 +1,114 @@
+" Test for delete().
+
+func Test_file_delete()
+ split Xfile
+ call setline(1, ['a', 'b'])
+ wq
+ call assert_equal(['a', 'b'], readfile('Xfile'))
+ call assert_equal(0, delete('Xfile'))
+ call assert_fails('call readfile("Xfile")', 'E484:')
+ call assert_equal(-1, delete('Xfile'))
+ bwipe Xfile
+endfunc
+
+func Test_dir_delete()
+ call mkdir('Xdir1')
+ call assert_true(isdirectory('Xdir1'))
+ call assert_equal(0, delete('Xdir1', 'd'))
+ call assert_false(isdirectory('Xdir1'))
+ call assert_equal(-1, delete('Xdir1', 'd'))
+endfunc
+
+func Test_recursive_delete()
+ call mkdir('Xdir1')
+ call mkdir('Xdir1/subdir')
+ call mkdir('Xdir1/empty')
+ split Xdir1/Xfile
+ call setline(1, ['a', 'b'])
+ w
+ w Xdir1/subdir/Xfile
+ close
+ call assert_true(isdirectory('Xdir1'))
+ call assert_equal(['a', 'b'], readfile('Xdir1/Xfile'))
+ call assert_true(isdirectory('Xdir1/subdir'))
+ call assert_equal(['a', 'b'], readfile('Xdir1/subdir/Xfile'))
+ call assert_true('Xdir1/empty'->isdirectory())
+ call assert_equal(0, delete('Xdir1', 'rf'))
+ call assert_false(isdirectory('Xdir1'))
+ call assert_equal(-1, delete('Xdir1', 'd'))
+ bwipe Xdir1/Xfile
+ bwipe Xdir1/subdir/Xfile
+endfunc
+
+func Test_symlink_delete()
+ if !has('unix')
+ return
+ endif
+ split Xfile
+ call setline(1, ['a', 'b'])
+ wq
+ silent !ln -s Xfile Xlink
+ " Delete the link, not the file
+ call assert_equal(0, delete('Xlink'))
+ call assert_equal(-1, delete('Xlink'))
+ call assert_equal(0, delete('Xfile'))
+ bwipe Xfile
+endfunc
+
+func Test_symlink_dir_delete()
+ if !has('unix')
+ return
+ endif
+ call mkdir('Xdir1')
+ silent !ln -s Xdir1 Xlink
+ call assert_true(isdirectory('Xdir1'))
+ call assert_true(isdirectory('Xlink'))
+ " Delete the link, not the directory
+ call assert_equal(0, delete('Xlink'))
+ call assert_equal(-1, delete('Xlink'))
+ call assert_equal(0, delete('Xdir1', 'd'))
+endfunc
+
+func Test_symlink_recursive_delete()
+ if !has('unix')
+ return
+ endif
+ call mkdir('Xdir3')
+ call mkdir('Xdir3/subdir')
+ call mkdir('Xdir4')
+ split Xdir3/Xfile
+ call setline(1, ['a', 'b'])
+ w
+ w Xdir3/subdir/Xfile
+ w Xdir4/Xfile
+ close
+ silent !ln -s ../Xdir4 Xdir3/Xlink
+
+ call assert_true(isdirectory('Xdir3'))
+ call assert_equal(['a', 'b'], readfile('Xdir3/Xfile'))
+ call assert_true(isdirectory('Xdir3/subdir'))
+ call assert_equal(['a', 'b'], readfile('Xdir3/subdir/Xfile'))
+ call assert_true(isdirectory('Xdir4'))
+ call assert_true(isdirectory('Xdir3/Xlink'))
+ call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
+
+ call assert_equal(0, delete('Xdir3', 'rf'))
+ call assert_false(isdirectory('Xdir3'))
+ call assert_equal(-1, delete('Xdir3', 'd'))
+ " symlink is deleted, not the directory it points to
+ call assert_true(isdirectory('Xdir4'))
+ call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
+ call assert_equal(0, delete('Xdir4/Xfile'))
+ call assert_equal(0, delete('Xdir4', 'd'))
+
+ bwipe Xdir3/Xfile
+ bwipe Xdir3/subdir/Xfile
+ bwipe Xdir4/Xfile
+endfunc
+
+func Test_delete_errors()
+ call assert_fails('call delete('''')', 'E474:')
+ call assert_fails('call delete(''foo'', 0)', 'E15:')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_file_perm.vim b/src/nvim/testdir/test_file_perm.vim
new file mode 100644
index 0000000000..1cb09e8647
--- /dev/null
+++ b/src/nvim/testdir/test_file_perm.vim
@@ -0,0 +1,30 @@
+" Test getting and setting file permissions.
+
+func Test_file_perm()
+ call assert_equal('', getfperm('Xtest'))
+ call assert_equal(0, 'Xtest'->setfperm('r--------'))
+
+ call writefile(['one'], 'Xtest')
+ call assert_true(len('Xtest'->getfperm()) == 9)
+
+ call assert_equal(1, setfperm('Xtest', 'rwx------'))
+ if has('win32')
+ call assert_equal('rw-rw-rw-', getfperm('Xtest'))
+ else
+ call assert_equal('rwx------', getfperm('Xtest'))
+ endif
+
+ call assert_equal(1, setfperm('Xtest', 'r--r--r--'))
+ call assert_equal('r--r--r--', getfperm('Xtest'))
+
+ call assert_fails("setfperm('Xtest', '---')")
+
+ call assert_equal(1, setfperm('Xtest', 'rwx------'))
+ call delete('Xtest')
+
+ call assert_fails("call setfperm(['Xfile'], 'rw-rw-rw-')", 'E730:')
+ call assert_fails("call setfperm('Xfile', [])", 'E730:')
+ call assert_fails("call setfperm('Xfile', 'rwxrwxrwxrw')", 'E475:')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim
index 1080a3c85b..98440ccdd7 100644
--- a/src/nvim/testdir/test_mapping.vim
+++ b/src/nvim/testdir/test_mapping.vim
@@ -646,4 +646,34 @@ func Test_abbreviate_multi_byte()
bwipe!
endfunc
+" Test for <Plug> always being mapped, even when used with "noremap".
+func Test_plug_remap()
+ let g:foo = 0
+ nnoremap <Plug>(Increase_x) <Cmd>let g:foo += 1<CR>
+ nmap <F2> <Plug>(Increase_x)
+ nnoremap <F3> <Plug>(Increase_x)
+ call feedkeys("\<F2>", 'xt')
+ call assert_equal(1, g:foo)
+ call feedkeys("\<F3>", 'xt')
+ call assert_equal(2, g:foo)
+ nnoremap x <Nop>
+ nmap <F4> x<Plug>(Increase_x)x
+ nnoremap <F5> x<Plug>(Increase_x)x
+ call setline(1, 'Some text')
+ normal! gg$
+ call feedkeys("\<F4>", 'xt')
+ call assert_equal(3, g:foo)
+ call assert_equal('Some text', getline(1))
+ call feedkeys("\<F5>", 'xt')
+ call assert_equal(4, g:foo)
+ call assert_equal('Some te', getline(1))
+ nunmap <Plug>(Increase_x)
+ nunmap <F2>
+ nunmap <F3>
+ nunmap <F4>
+ nunmap <F5>
+ unlet g:foo
+ %bw!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_searchpos.vim b/src/nvim/testdir/test_searchpos.vim
new file mode 100644
index 0000000000..dd13c305c5
--- /dev/null
+++ b/src/nvim/testdir/test_searchpos.vim
@@ -0,0 +1,30 @@
+" Tests for searchpos()
+
+func Test_searchpos()
+ new one
+ 0put ='1a3'
+ 1put ='123xyz'
+ call cursor(1, 1)
+ call assert_equal([1, 1, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
+ call cursor(1, 2)
+ call assert_equal([2, 1, 1], '\%(\([a-z]\)\|\_.\)\{-}xyz'->searchpos('pcW'))
+ set cpo-=c
+ call cursor(1, 2)
+ call assert_equal([1, 2, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
+ call cursor(1, 3)
+ call assert_equal([1, 3, 1], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
+
+ " Now with \zs, first match is in column 0, "a" is matched.
+ call cursor(1, 3)
+ call assert_equal([2, 4, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcW'))
+ " With z flag start at cursor column, don't see the "a".
+ call cursor(1, 3)
+ call assert_equal([2, 4, 1], searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcWz'))
+
+ set cpo+=c
+ " close the window
+ q!
+
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_set.vim b/src/nvim/testdir/test_set.vim
new file mode 100644
index 0000000000..2b1e9eeee0
--- /dev/null
+++ b/src/nvim/testdir/test_set.vim
@@ -0,0 +1,29 @@
+" Tests for the :set command
+
+function Test_set_backslash()
+ let isk_save = &isk
+
+ set isk=a,b,c
+ set isk+=d
+ call assert_equal('a,b,c,d', &isk)
+ set isk+=\\,e
+ call assert_equal('a,b,c,d,\,e', &isk)
+ set isk-=e
+ call assert_equal('a,b,c,d,\', &isk)
+ set isk-=\\
+ call assert_equal('a,b,c,d', &isk)
+
+ let &isk = isk_save
+endfunction
+
+function Test_set_add()
+ let wig_save = &wig
+
+ set wildignore=*.png,
+ set wildignore+=*.jpg
+ call assert_equal('*.png,*.jpg', &wig)
+
+ let &wig = wig_save
+endfunction
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_sort.vim b/src/nvim/testdir/test_sort.vim
index 570c4415c6..f72368fc59 100644
--- a/src/nvim/testdir/test_sort.vim
+++ b/src/nvim/testdir/test_sort.vim
@@ -12,6 +12,7 @@ func Compare2(a, b) abort
endfunc
func Test_sort_strings()
+ CheckNotMSWindows " FIXME: Why does this fail with MSVC?
" numbers compared as strings
call assert_equal([1, 2, 3], sort([3, 2, 1]))
call assert_equal([13, 28, 3], sort([3, 28, 13]))