diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/nvim/getchar.c | 5 | ||||
-rw-r--r-- | src/nvim/globals.h | 4 | ||||
-rw-r--r-- | src/nvim/testdir/setup.vim | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_cmdline.vim | 128 | ||||
-rw-r--r-- | src/nvim/testdir/test_ex_mode.vim | 17 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 10 | ||||
-rw-r--r-- | src/nvim/testdir/test_history.vim | 29 | ||||
-rw-r--r-- | src/nvim/testdir/test_options.vim | 23 |
9 files changed, 217 insertions, 2 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index d4fe55392e..2899e17039 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7899,9 +7899,11 @@ void do_exedit(exarg_T *eap, win_T *old_curwin) need_wait_return = false; msg_scroll = 0; redraw_all_later(NOT_VALID); + pending_exmode_active = true; normal_enter(false, true); + pending_exmode_active = false; RedrawingDisabled = rd; no_wait_return = nwr; msg_scroll = ms; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 0f6eddef9d..00372d4f3d 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2475,6 +2475,11 @@ static int vgetorpeek(bool advance) } tc = c; + // return 0 in normal_check() + if (pending_exmode_active) { + exmode_active = true; + } + // no chars to block abbreviations for typebuf.tb_no_abbr_cnt = 0; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 0281eebcee..01d4ab086e 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -636,6 +636,10 @@ EXTERN int motion_force INIT(=0); // motion force for pending operator // Ex Mode (Q) state EXTERN bool exmode_active INIT(= false); // true if Ex mode is active + +/// Flag set when normal_check() should return 0 when entering Ex mode. +EXTERN bool pending_exmode_active INIT(= false); + EXTERN bool ex_no_reprint INIT(=false); // No need to print after z or p. // 'inccommand' command preview state diff --git a/src/nvim/testdir/setup.vim b/src/nvim/testdir/setup.vim index dfcde37f62..91e0b3bea7 100644 --- a/src/nvim/testdir/setup.vim +++ b/src/nvim/testdir/setup.vim @@ -15,6 +15,7 @@ set laststatus=1 set listchars=eol:$ set joinspaces set nohidden nosmarttab noautoindent noautoread complete-=i noruler noshowcmd +set nohlsearch noincsearch set nrformats+=octal set shortmess-=F set sidescroll=0 diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index b00764e0dd..5b9cd1c507 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -18,6 +18,11 @@ func Test_complete_list() " We can't see the output, but at least we check the code runs properly. call feedkeys(":e test\<C-D>\r", "tx") call assert_equal('test', expand('%:t')) + + " If a command doesn't support completion, then CTRL-D should be literally + " used. + call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt') + call assert_equal("\"chistory \<C-D>", @:) endfunc func Test_complete_wildmenu() @@ -71,6 +76,11 @@ func Test_complete_wildmenu() cunmap <C-K> endif + " Test for canceling the wild menu by adding a character + redrawstatus + call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt') + call assert_equal('"e Xdir1/Xdir2/x', @:) + " Completion using a relative path cd Xdir1/Xdir2 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx') @@ -591,6 +601,18 @@ func Test_cmdline_paste() " Use an invalid expression for <C-\>e call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') + " Try to paste an invalid register using <C-R> + call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt') + call assert_equal('"onetwo', @:) + + let @a = "xy\<C-H>z" + call feedkeys(":\"\<C-R>a\<CR>", 'xt') + call assert_equal('"xz', @:) + call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt') + call assert_equal("\"xy\<C-H>z", @:) + + call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")') + bwipe! endfunc @@ -1226,6 +1248,112 @@ func Test_cmdline_expand_home() call delete('Xdir', 'rf') endfunc +" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode +" or insert mode (when 'insertmode' is set) +func Test_cmdline_ctrl_g() + new + call setline(1, 'abc') + call cursor(1, 3) + " If command line is entered from insert mode, using C-\ C-G should back to + " insert mode + call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') + call assert_equal('abxyc', getline(1)) + call assert_equal(4, col('.')) + + " If command line is entered in 'insertmode', using C-\ C-G should back to + " 'insertmode' + " call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') + " call assert_equal('ab12xyc', getline(1)) + close! +endfunc + +" Return the 'len' characters in screen starting from (row,col) +func s:ScreenLine(row, col, len) + let s = '' + for i in range(a:len) + let s .= nr2char(screenchar(a:row, a:col + i)) + endfor + return s +endfunc + +" Test for 'wildmode' +func Test_wildmode() + func T(a, c, p) + return "oneA\noneB\noneC" + endfunc + command -nargs=1 -complete=custom,T MyCmd + + func SaveScreenLine() + let g:Sline = s:ScreenLine(&lines - 1, 1, 20) + return '' + endfunc + cnoremap <expr> <F2> SaveScreenLine() + + set nowildmenu + set wildmode=full,list + let g:Sline = '' + call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') + call assert_equal('oneA oneB oneC ', g:Sline) + call assert_equal('"MyCmd oneA', @:) + + set wildmode=longest,full + call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') + call assert_equal('"MyCmd one', @:) + call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') + call assert_equal('"MyCmd oneC', @:) + + set wildmode=longest + call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') + call assert_equal('"MyCmd one', @:) + + set wildmode=list:longest + let g:Sline = '' + call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') + call assert_equal('oneA oneB oneC ', g:Sline) + call assert_equal('"MyCmd one', @:) + + set wildmode="" + call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') + call assert_equal('"MyCmd oneA', @:) + + delcommand MyCmd + delfunc T + delfunc SaveScreenLine + cunmap <F2> + set wildmode& +endfunc + +" Test for interrupting the command-line completion +func Test_interrupt_compl() + func F(lead, cmdl, p) + if a:lead =~ 'tw' + call interrupt() + return + endif + return "one\ntwo\nthree" + endfunc + command -nargs=1 -complete=custom,F Tcmd + + set nowildmenu + set wildmode=full + let interrupted = 0 + try + call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') + catch /^Vim:Interrupt$/ + let interrupted = 1 + endtry + call assert_equal(1, interrupted) + + delcommand Tcmd + delfunc F + set wildmode& +endfunc + +func Test_cmdline_edit() + call feedkeys(":\"buffer\<Right>\<Home>\<Left>\<CR>", 'xt') + call assert_equal("\"buffer", @:) +endfunc + " Test for normal mode commands not supported in the cmd window func Test_cmdwin_blocked_commands() call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:') diff --git a/src/nvim/testdir/test_ex_mode.vim b/src/nvim/testdir/test_ex_mode.vim index c3f7fb45f4..cff78620d1 100644 --- a/src/nvim/testdir/test_ex_mode.vim +++ b/src/nvim/testdir/test_ex_mode.vim @@ -64,6 +64,23 @@ func Test_ex_mode() let &encoding = encoding_save endfunc +" Test for :g/pat/visual to run vi commands in Ex mode +" This used to hang Vim before 8.2.0274. +func Test_Ex_global() + new + call setline(1, ['', 'foo', 'bar', 'foo', 'bar', 'foo']) + call feedkeys("Q\<bs>g/bar/visual\<CR>$rxQ$ryQvisual\<CR>j", "xt") + call assert_equal('bax', getline(3)) + call assert_equal('bay', getline(5)) + bwipe! +endfunc + +" In Ex-mode, a backslash escapes a newline +func Test_Ex_escape_enter() + call feedkeys("gQlet l = \"a\\\<kEnter>b\"\<cr>vi\<cr>", 'xt') + call assert_equal("a\rb", l) +endfunc + func Test_ex_mode_errors() " Not allowed to enter ex mode when text is locked au InsertCharPre <buffer> normal! gQ<CR> diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 2391b4a485..3feb4d5f7f 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1218,6 +1218,16 @@ func Test_input_func() call assert_fails("call input('F:', '', [])", 'E730:') endfunc +" Test for the inputdialog() function +func Test_inputdialog() + CheckNotGui + + call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<CR>", 'xt') + call assert_equal('xx', v) + call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<Esc>", 'xt') + call assert_equal('yy', v) +endfunc + " Test for inputlist() func Test_inputlist() call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx') diff --git a/src/nvim/testdir/test_history.vim b/src/nvim/testdir/test_history.vim index b12eef008e..96006ac7e7 100644 --- a/src/nvim/testdir/test_history.vim +++ b/src/nvim/testdir/test_history.vim @@ -70,6 +70,14 @@ function History_Tests(hist) call assert_equal('', histget(a:hist, i)) call assert_equal('', histget(a:hist, i - 7 - 1)) endfor + + " Test for freeing an entry at the beginning of the history list + for i in range(1, 4) + call histadd(a:hist, 'text_' . i) + endfor + call histdel(a:hist, 1) + call assert_equal('', histget(a:hist, 1)) + call assert_equal('text_4', histget(a:hist, 4)) endfunction function Test_History() @@ -115,14 +123,14 @@ endfunc func Test_history_size() let save_histsz = &history call histdel(':') - set history=5 + set history=10 for i in range(1, 5) call histadd(':', 'cmd' .. i) endfor call assert_equal(5, histnr(':')) call assert_equal('cmd5', histget(':', -1)) - set history=10 + set history=15 for i in range(6, 10) call histadd(':', 'cmd' .. i) endfor @@ -137,6 +145,15 @@ func Test_history_size() call assert_equal('cmd7', histget(':', 7)) call assert_equal('abc', histget(':', -1)) + " This test works only when the language is English + if v:lang == "C" || v:lang =~ '^[Ee]n' + set history=0 + redir => v + call feedkeys(":history\<CR>", 'xt') + redir END + call assert_equal(["'history' option is zero"], split(v, "\n")) + endif + let &history=save_histsz endfunc @@ -158,4 +175,12 @@ func Test_history_search() delfunc SavePat endfunc +" Test for making sure the key value is not stored in history +func Test_history_crypt_key() + CheckFeature cryptv + call feedkeys(":set bs=2 key=abc ts=8\<CR>", 'xt') + call assert_equal('set bs=2 key= ts=8', histget(':')) + set key& bs& ts& +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 2a3d977254..7d1fbe7d3e 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -752,6 +752,29 @@ func Test_shellquote() call assert_match(': "#echo Hello#"', v) endfunc +" Test for the 'rightleftcmd' option +func Test_rightleftcmd() + CheckFeature rightleft + set rightleft + set rightleftcmd + + let g:l = [] + func AddPos() + call add(g:l, screencol()) + return '' + endfunc + cmap <expr> <F2> AddPos() + + call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. + \ "\<Left>\<F2>\<Esc>", 'xt') + call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l) + + cunmap <F2> + unlet g:l + set rightleftcmd& + set rightleft& +endfunc + " Test for setting option values using v:false and v:true func Test_opt_boolean() set number& |