]> granicus.if.org Git - vim/commitdiff
patch 8.2.1022: various parts of code not covered by tests v8.2.1022
authorBram Moolenaar <Bram@vim.org>
Sat, 20 Jun 2020 14:05:32 +0000 (16:05 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 20 Jun 2020 14:05:32 +0000 (16:05 +0200)
Problem:    Various parts of code not covered by tests.
Solution:   Add more tests. (Yegappan Lakshmanan, closes #6300)

15 files changed:
src/testdir/test_blob.vim
src/testdir/test_cpoptions.vim
src/testdir/test_digraph.vim
src/testdir/test_edit.vim
src/testdir/test_iminsert.vim
src/testdir/test_paste.vim
src/testdir/test_prompt_buffer.vim
src/testdir/test_selectmode.vim
src/testdir/test_tabpage.vim
src/testdir/test_tagjump.vim
src/testdir/test_textformat.vim
src/testdir/test_viminfo.vim
src/testdir/test_virtualedit.vim
src/testdir/test_visual.vim
src/version.c

index 46b7b0227f5fd989b4ffea4eff389238518567a3..69b3504799925ceed7b2fb4832012b4f0bd2a34e 100644 (file)
@@ -254,6 +254,7 @@ func Test_blob_func_remove()
   call assert_fails("call remove(b, 3, 2)", 'E979:')
   call assert_fails("call remove(1, 0)", 'E896:')
   call assert_fails("call remove(b, b)", 'E974:')
+  call assert_fails("call remove(b, 1, [])", 'E745:')
   call assert_fails("call remove(test_null_blob(), 1, 2)", 'E979:')
 endfunc
 
index 052b3f3685697490557440f12c95c9d3bcef2f51..ce4e00deb3eb05de6a253ccc9bff90eadba8c58e 100644 (file)
@@ -246,6 +246,7 @@ func Test_cpo_H()
 endfunc
 
 " TODO: Add a test for the 'i' flag in 'cpo'
+" Interrupting the reading of a file will leave it modified.
 
 " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys)
 func Test_cpo_I()
@@ -294,9 +295,12 @@ func Test_cpo_J()
   let &cpo = save_cpo
 endfunc
 
-" TODO: Add a test for the 'k' flag in 'cpo'
+" TODO: Add a test for the 'k' flag in 'cpo'.
+" Disable the recognition of raw key codes in mappings, abbreviations, and the
+" "to" part of menu commands.
 
-" TODO: Add a test for the 'K' flag in 'cpo'
+" TODO: Add a test for the 'K' flag in 'cpo'.
+" Don't wait for a key code to complete when it is halfway a mapping.
 
 " Test for the 'l' flag in 'cpo' (backslash in a [] range)
 func Test_cpo_l()
@@ -334,7 +338,9 @@ func Test_cpo_L()
   let &cpo = save_cpo
 endfunc
 
-" TODO: Add a test for the 'm' flag in 'cpo'
+" TODO: Add a test for the 'm' flag in 'cpo'.
+" When included, a showmatch will always wait half a second.  When not
+" included, a showmatch will wait half a second or until a character is typed.
 
 " Test for the 'M' flag in 'cpo' (% with escape parenthesis)
 func Test_cpo_M()
@@ -498,7 +504,9 @@ func Test_cpo_R()
   let &cpo = save_cpo
 endfunc
 
-" TODO: Add a test for the 's' flag in 'cpo'
+" TODO: Add a test for the 's' flag in 'cpo'.
+" Set buffer options when entering the buffer for the first time.  If not
+" present the options are set when the buffer is created.
 
 " Test for the 'S' flag in 'cpo' (copying buffer options)
 func Test_cpo_S()
@@ -543,8 +551,8 @@ func Test_cpo_u()
   let &cpo = save_cpo
 endfunc
 
-" TODO: Add a test for the 'v' flag in 'cpo' (backspace doesn't remove
-" characters from the screen)
+" TODO: Add a test for the 'v' flag in 'cpo'.
+" Backspaced characters remain visible on the screen in Insert mode.
 
 " Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one
 " character)
index 2a59994f05094f74bd6ba73b052992ba91250842..f73ed7cb0aa1b8d3c02df199a7022a8eeaf03bb9 100644 (file)
@@ -2,6 +2,7 @@
 
 source check.vim
 CheckFeature digraphs
+source term_util.vim
 
 func Put_Dig(chars)
   exe "norm! o\<c-k>".a:chars
@@ -502,4 +503,20 @@ func Test_loadkeymap_error()
   call delete('Xkeymap')
 endfunc
 
+" Test for the characters displayed one the screen when entering a digraph
+func Test_entering_digraph()
+  CheckRunVimInTerminal
+  let buf = RunVimInTerminal('', {'rows': 6})
+  call term_sendkeys(buf, "i\<C-K>")
+  call term_wait(buf)
+  call assert_equal('?', term_getline(buf, 1))
+  call term_sendkeys(buf, "1")
+  call term_wait(buf)
+  call assert_equal('1', term_getline(buf, 1))
+  call term_sendkeys(buf, "2")
+  call term_wait(buf)
+  call assert_equal('½', term_getline(buf, 1))
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index f973d5983a07be7e51ebb3f1ec3754bc04aec132..0200d9f56066ae5b9b209577dfe85663034a841a 100644 (file)
@@ -401,6 +401,14 @@ func Test_edit_13()
   call assert_equal("", getline(2))
   call assert_equal("    baz", getline(3))
   set autoindent&
+
+  " pressing <C-U> to erase line should keep the indent with 'autoindent'
+  set backspace=2 autoindent
+  %d
+  exe "normal i\tone\<CR>three\<C-U>two"
+  call assert_equal(["\tone", "\ttwo"], getline(1, '$'))
+  set backspace& autoindent&
+
   bwipe!
 endfunc
 
@@ -1301,9 +1309,7 @@ endfunc
 
 func Test_edit_rightleft()
   " Cursor in rightleft mode moves differently
-  if !exists("+rightleft")
-    return
-  endif
+  CheckFeature rightleft
   call NewWindow(10, 20)
   call setline(1, ['abc', 'def', 'ghi'])
   call cursor(1, 2)
@@ -1348,6 +1354,13 @@ func Test_edit_rightleft()
         \"                 ihg",
         \"                   ~"]
   call assert_equal(join(expect, "\n"), join(lines, "\n"))
+  %d _
+  call test_override('redraw_flag', 1)
+  call test_override('char_avail', 1)
+  call feedkeys("a\<C-V>x41", "xt")
+  redraw!
+  call assert_equal(repeat(' ', 19) .. 'A', Screenline(1))
+  call test_override('ALL', 0)
   set norightleft
   bw!
 endfunc
@@ -1683,4 +1696,103 @@ func Test_edit_file_no_read_perm()
   call delete('Xfile')
 endfunc
 
+" Pressing escape in 'insertmode' should beep
+func Test_edit_insertmode_esc_beeps()
+  new
+  set insertmode
+  call assert_beeps("call feedkeys(\"one\<Esc>\", 'xt')")
+  set insertmode&
+  " unsupported CTRL-G command should beep in insert mode.
+  call assert_beeps("normal i\<C-G>l")
+  close!
+endfunc
+
+" Test for 'hkmap' and 'hkmapp'
+func Test_edit_hkmap()
+  CheckFeature rightleft
+  if has('win32') && !has('gui')
+    " Test fails on the MS-Windows terminal version
+    return
+  endif
+  new
+
+  set revins hkmap
+  let str = 'abcdefghijklmnopqrstuvwxyz'
+  let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+  let str ..= '`/'',.;'
+  call feedkeys('i' .. str, 'xt')
+  let expected = "óõú,.;"
+  let expected ..= "ZYXWVUTSRQPONMLKJIHGFEDCBA"
+  let expected ..= "æèñ'äåàãø/ôíîöêìçïéòë÷âáðù"
+  call assert_equal(expected, getline(1))
+
+  %d
+  set revins hkmap hkmapp
+  let str = 'abcdefghijklmnopqrstuvwxyz'
+  let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+  call feedkeys('i' .. str, 'xt')
+  let expected = "õYXWVUTSRQóOïíLKJIHGFEDêBA"
+  let expected ..= "öòXùåèúæø'ôñðîì÷çéäâóǟãëáà"
+  call assert_equal(expected, getline(1))
+
+  set revins& hkmap& hkmapp&
+  close!
+endfunc
+
+" Test for 'allowrevins' and using CTRL-_ in insert mode
+func Test_edit_allowrevins()
+  CheckFeature rightleft
+  new
+  set allowrevins
+  call feedkeys("iABC\<C-_>DEF\<C-_>GHI", 'xt')
+  call assert_equal('ABCFEDGHI', getline(1))
+  set allowrevins&
+  close!
+endfunc
+
+" Test for inserting a register in insert mode using CTRL-R
+func Test_edit_insert_reg()
+  new
+  let g:Line = ''
+  func SaveFirstLine()
+    let g:Line = Screenline(1)
+    return 'r'
+  endfunc
+  inoremap <expr> <buffer> <F2> SaveFirstLine()
+  call test_override('redraw_flag', 1)
+  call test_override('char_avail', 1)
+  let @r = 'sample'
+  call feedkeys("a\<C-R>=SaveFirstLine()\<CR>", "xt")
+  call assert_equal('"', g:Line)
+  call test_override('ALL', 0)
+  close!
+endfunc
+
+" When a character is inserted at the last position of the last line in a
+" window, the window contents should be scrolled one line up. If the top line
+" is part of a fold, then the entire fold should be scrolled up.
+func Test_edit_lastline_scroll()
+  new
+  let h = winheight(0)
+  let lines = ['one', 'two', 'three']
+  let lines += repeat(['vim'], h - 4)
+  call setline(1, lines)
+  call setline(h, repeat('x', winwidth(0) - 1))
+  call feedkeys("GAx", 'xt')
+  redraw!
+  call assert_equal(h - 1, winline())
+  call assert_equal(2, line('w0'))
+
+  " scroll with a fold
+  1,2fold
+  normal gg
+  call setline(h + 1, repeat('x', winwidth(0) - 1))
+  call feedkeys("GAx", 'xt')
+  redraw!
+  call assert_equal(h - 1, winline())
+  call assert_equal(3, line('w0'))
+
+  close!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index d49cd07cca010432535e87dfadc7a9e41c0b9692..04c8a15995ba7c8f0e1f6b2c8596a0599299ac10 100644 (file)
@@ -7,7 +7,7 @@ let s:imstatus_active = 0
 
 func IM_activatefunc(active)
   let s:imactivatefunc_called = 1
-let s:imstatus_active = a:active
+  let s:imstatus_active = a:active
 endfunc
 
 func IM_statusfunc()
@@ -83,4 +83,30 @@ func Test_lmap_in_insert_mode()
   close!
 endfunc
 
+" Test for using CTRL-^ to toggle iminsert in insert mode
+func Test_iminsert_toggle()
+  CheckGui
+  if has('win32')
+    CheckFeature multi_byte_ime
+  elseif !has('gui_mac')
+    CheckFeature xim
+  endif
+  if has('gui_running') && !has('win32')
+    " this works only in Win32 GUI version (for some reason)
+    return
+  endif
+  new
+  let save_imdisable = &imdisable
+  let save_iminsert = &iminsert
+  set noimdisable
+  set iminsert=0
+  exe "normal i\<C-^>"
+  call assert_equal(2, &iminsert)
+  exe "normal i\<C-^>"
+  call assert_equal(0, &iminsert)
+  let &iminsert = save_iminsert
+  let &imdisable = save_imdisable
+  close!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index c30140f4397bd4a4a4c4a925f7bc80027687981c..194ae7d3773b8e1ddc8f7d1fc88790de52963078 100644 (file)
@@ -79,11 +79,27 @@ func Test_paste_clipboard()
   bwipe!
 endfunc
 
+" bracketed paste in command line
 func Test_paste_cmdline()
   call feedkeys(":a\<Esc>[200~foo\<CR>bar\<Esc>[201~b\<Home>\"\<CR>", 'xt')
   call assert_equal("\"afoo\<CR>barb", getreg(':'))
 endfunc
 
+" bracketed paste in Ex-mode
+func Test_paste_ex_mode()
+  unlet! foo
+  call feedkeys("Qlet foo=\"\<Esc>[200~foo\<CR>bar\<Esc>[201~\"\<CR>vi\<CR>", 'xt')
+  call assert_equal("foo\rbar", foo)
+endfunc
+
+func Test_paste_onechar()
+  new
+  let @f='abc'
+  call feedkeys("i\<C-R>\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt')
+  call assert_equal("abc", getline(1))
+  close!
+endfunc
+
 func Test_paste_visual_mode()
   new
   call setline(1, 'here are some words')
@@ -134,3 +150,5 @@ func Test_xrestore()
 
   bwipe!
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 760e1d9798cdb7d1aa79719bb3cab6c3f7553f33..ace83a80bdebf9b26b53d4d13947f806e4af9031 100644 (file)
@@ -147,6 +147,11 @@ func Test_prompt_buffer_edit()
   call assert_beeps('normal! S')
   call assert_beeps("normal! \<C-A>")
   call assert_beeps("normal! \<C-X>")
+  " pressing CTRL-W in the prompt buffer should trigger the window commands
+  call assert_equal(1, winnr())
+  exe "normal A\<C-W>\<C-W>"
+  call assert_equal(2, winnr())
+  wincmd w
   close!
   call assert_equal(0, prompt_setprompt([], ''))
 endfunc
index 92951efa67484ba1a6eccb49cbc1b44115172b39..3adb843cb847c7d30bc0cd33497114a799fefa5a 100644 (file)
@@ -38,6 +38,9 @@ func Test_selectmode_start()
   set selectmode=cmd
   call feedkeys('gvabc', 'xt')
   call assert_equal('abctdef', getline(1))
+  " arrow keys without shift should not start selection
+  call feedkeys("A\<Home>\<Right>\<Left>ro", 'xt')
+  call assert_equal('roabctdef', getline(1))
   set selectmode= keymodel=
   bw!
 endfunc
index a9bf7a12f029a1cd468613ad65bb1873d09c843e..44772fdaa72b69d61721129c1000bec18f097982 100644 (file)
@@ -623,4 +623,15 @@ func Test_tabpage_close_cmdwin()
   tabonly
 endfunc
 
+" Pressing <C-PageUp> in insert mode should go to the previous tab page
+" and <C-PageDown> should go to the next tab page
+func Test_tabpage_Ctrl_Pageup()
+  tabnew
+  call feedkeys("i\<C-PageUp>", 'xt')
+  call assert_equal(1, tabpagenr())
+  call feedkeys("i\<C-PageDown>", 'xt')
+  call assert_equal(2, tabpagenr())
+  %bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index e7b83e77235a30607ccb3654dcb1f4f423ac5141..a26ba9a0fc850ee341ee51644351f2a1591eb289 100644 (file)
@@ -240,6 +240,7 @@ func Test_tag_file_encoding()
   call delete('Xtags1')
 endfunc
 
+" Test for emacs-style tags file (TAGS)
 func Test_tagjump_etags()
   if !has('emacs_tags')
     return
@@ -1055,7 +1056,7 @@ func Test_tselect_listing()
   call writefile([
         \ "!_TAG_FILE_ENCODING\tutf-8\t//",
         \ "first\tXfoo\t1" .. ';"' .. "\tv\ttyperef:typename:int\tfile:",
-        \ "first\tXfoo\t2" .. ';"' .. "\tv\ttyperef:typename:char\tfile:"],
+        \ "first\tXfoo\t2" .. ';"' .. "\tkind:v\ttyperef:typename:char\tfile:"],
         \ 'Xtags')
   set tags=Xtags
 
@@ -1337,4 +1338,56 @@ func Test_tag_length()
   set tags& taglength&
 endfunc
 
+" Tests for errors in a tags file
+func Test_tagfile_errors()
+  set tags=Xtags
+
+  " missing search pattern or line number for a tag
+  call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
+        \ "foo\tXfile\t"], 'Xtags', 'b')
+  call writefile(['foo'], 'Xfile')
+
+  enew
+  tag foo
+  call assert_equal('', @%)
+  let caught_431 = v:false
+  try
+    eval taglist('.*')
+  catch /:E431:/
+    let caught_431 = v:true
+  endtry
+  call assert_equal(v:true, caught_431)
+
+  call delete('Xtags')
+  call delete('Xfile')
+  set tags&
+endfunc
+
+" When :stag fails to open the file, should close the new window
+func Test_stag_close_window_on_error()
+  new | only
+  set tags=Xtags
+  call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
+        \ "foo\tXfile\t1"], 'Xtags')
+  call writefile(['foo'], 'Xfile')
+  call writefile([], '.Xfile.swp')
+  " Remove the catch-all that runtest.vim adds
+  au! SwapExists
+  augroup StagTest
+    au!
+    autocmd SwapExists Xfile let v:swapchoice='q'
+  augroup END
+
+  stag foo
+  call assert_equal(1, winnr('$'))
+  call assert_equal('', @%)
+
+  augroup StagTest
+    au!
+  augroup END
+  call delete('Xfile')
+  call delete('.Xfile.swp')
+  set tags&
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 33daaab651beb1afc9d189f43fbcde84e6cf5e56..d529b8520afbfc2dcbbd7b5169e6be844ae89da1 100644 (file)
@@ -1116,6 +1116,20 @@ func Test_fo_a_w()
   call feedkeys("iabc abc a abc\<Esc>k0weade", 'xt')
   call assert_equal(['abc abcde ', 'a abc'], getline(1, '$'))
 
+  " when a line ends with space, it is not broken up.
+  %d
+  call feedkeys("ione two to    ", 'xt')
+  call assert_equal('one two to    ', getline(1))
+
+  " when a line ends with spaces and backspace is used in the next line, the
+  " last space in the previous line should be removed.
+  %d
+  set backspace=indent,eol,start
+  call setline(1, ['one    ', 'two'])
+  exe "normal 2Gi\<BS>"
+  call assert_equal(['one   two'], getline(1, '$'))
+  set backspace&
+
   " Test for 'a', 'w' and '1' options.
   setlocal textwidth=0
   setlocal fo=1aw
index 8650598216b1689f9e6dd7bfa5131e971b2fc041..1aadf59e22dba0120bcedad3d13a1ee491c434ba 100644 (file)
@@ -87,6 +87,28 @@ func Test_global_vars()
   call assert_equal(test_null, g:MY_GLOBAL_NULL)
   call assert_equal(test_none, g:MY_GLOBAL_NONE)
 
+  " Test for invalid values for a blob, list, dict in a viminfo file
+  call writefile([
+        \ "!GLOB_BLOB_1\tBLO\t123",
+        \ "!GLOB_BLOB_2\tBLO\t012",
+        \ "!GLOB_BLOB_3\tBLO\t0z1x",
+        \ "!GLOB_BLOB_4\tBLO\t0z12 ab",
+        \ "!GLOB_LIST_1\tLIS\t1 2",
+        \ "!GLOB_DICT_1\tDIC\t1 2"], 'Xviminfo')
+  call assert_fails('rv! Xviminfo', 'E15:')
+  call assert_equal('123', g:GLOB_BLOB_1)
+  call assert_equal(1, type(g:GLOB_BLOB_1))
+  call assert_equal('012', g:GLOB_BLOB_2)
+  call assert_equal(1, type(g:GLOB_BLOB_2))
+  call assert_equal('0z1x', g:GLOB_BLOB_3)
+  call assert_equal(1, type(g:GLOB_BLOB_3))
+  call assert_equal('0z12 ab', g:GLOB_BLOB_4)
+  call assert_equal(1, type(g:GLOB_BLOB_4))
+  call assert_equal('1 2', g:GLOB_LIST_1)
+  call assert_equal(1, type(g:GLOB_LIST_1))
+  call assert_equal('1 2', g:GLOB_DICT_1)
+  call assert_equal(1, type(g:GLOB_DICT_1))
+
   call delete('Xviminfo')
   set viminfo-=!
 endfunc
index 6f82f30f681e0789d1d36acf9f6b456902d994a2..e1cd20e83508cb094bb16b186a02492166f490ef 100644 (file)
@@ -357,4 +357,22 @@ func Test_delete_break_tab()
   close!
 endfunc
 
+" Test for using <BS>, <C-W> and <C-U> in virtual edit mode
+" to erase character, word and line.
+func Test_ve_backspace()
+  new
+  call setline(1, 'sample')
+  set virtualedit=all
+  set backspace=indent,eol,start
+  exe "normal 15|i\<BS>\<BS>"
+  call assert_equal([0, 1, 7, 5], getpos('.'))
+  exe "normal 15|i\<C-W>"
+  call assert_equal([0, 1, 6, 0], getpos('.'))
+  exe "normal 15|i\<C-U>"
+  call assert_equal([0, 1, 1, 0], getpos('.'))
+  set backspace&
+  set virtualedit&
+  close!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 87cf2a7ade431885e577d71866a5dc12fc5499b6..f286ba9c42cbc1bb42d0977e8adfe09156e5c7b6 100644 (file)
@@ -208,6 +208,15 @@ func Test_virtual_replace()
   exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR"
   call assert_equal(['AB......CDEFGHI.Jkl',
              \ 'AB     IJKLMNO QRst'], getline(12, 13))
+
+  " Test inserting Tab with 'noexpandtab' and 'softabstop' set to 4
+  %d
+  call setline(1, 'aaaaaaaaaaaaa')
+  set softtabstop=4
+  exe "normal gggR\<Tab>\<Tab>x"
+  call assert_equal("\txaaaa", getline(1))
+  set softtabstop&
+
   enew!
   set noai bs&vim
   if exists('save_t_kD')
index 94027af0f211d5e71713ca9c8f081baf43762983..870205ab0959bb3d1797b17d650749fe8d6b5515 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1022,
 /**/
     1021,
 /**/