]> granicus.if.org Git - vim/commitdiff
patch 8.2.0023: command line editing not sufficiently tested v8.2.0023
authorBram Moolenaar <Bram@vim.org>
Wed, 18 Dec 2019 21:26:31 +0000 (22:26 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 18 Dec 2019 21:26:31 +0000 (22:26 +0100)
Problem:    Command line editing not sufficiently tested.
Solution:   Add more tests. (Dominique Pelle, closes #5374)

src/testdir/Make_all.mak
src/testdir/test_alot.vim
src/testdir/test_cmdline.vim
src/testdir/test_ex_mode.vim [new file with mode: 0644]
src/version.c

index db6b4fa6d7a76920d89f008ad11e3c0e6b53d925..fab1460b62d983e9b02614bb7ced63d75dd53234 100644 (file)
@@ -97,6 +97,7 @@ NEW_TESTS = \
        test_ex_equal \
        test_ex_undo \
        test_ex_z \
+       test_ex_mode \
        test_excmd \
        test_exec_while_if \
        test_execute_func \
index 894ec5848fe113e614f7d23699d5b387a4ad78e9..25241b22996ce8049f95cf6747ec89b75a5f3053 100644 (file)
@@ -13,6 +13,7 @@ source test_delete.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_dllpath.vim
index 529795144b6b13b6af9a7c6ef2c9f0bbbd5cf83d..837ef63ddafccc2b1b38d48f50b37df2793811a3 100644 (file)
@@ -419,7 +419,7 @@ func Test_expand_star_star()
   call delete('a', 'rf')
 endfunc
 
-func Test_paste_in_cmdline()
+func Test_cmdline_paste()
   let @a = "def"
   call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
   call assert_equal('"abc def ghi', @:)
@@ -459,18 +459,37 @@ func Test_paste_in_cmdline()
   bwipe!
 endfunc
 
-func Test_remove_char_in_cmdline()
-  call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
-  call assert_equal('"abc ef', @:)
+func Test_cmdline_remove_char()
+  let encoding_save = &encoding
+
+  for e in ['utf8', 'latin1']
+    exe 'set encoding=' . e
+
+    call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
+    call assert_equal('"abc ef', @:, e)
+
+    call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
+    call assert_equal('"abcdef', @:)
+
+    call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
+    call assert_equal('"abc ghi', @:, e)
 
-  call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
-  call assert_equal('"abcdef', @:)
+    call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
+    call assert_equal('"def', @:, e)
+  endfor
+
+  let &encoding = encoding_save
+endfunc
 
-  call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
-  call assert_equal('"abc ghi', @:)
+func Test_cmdline_keymap_ctrl_hat()
+  if !has('keymap')
+    return
+  endif
 
-  call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
-  call assert_equal('"def', @:)
+  set keymap=esperanto
+  call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
+  call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
+  set keymap=
 endfunc
 
 func Test_illegal_address1()
@@ -741,20 +760,20 @@ func Test_cmdline_overstrike()
 
     " Test overstrike in the middle of the command line.
     call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
-    call assert_equal('"0ab1cd4', @:)
+    call assert_equal('"0ab1cd4', @:, e)
 
     " Test overstrike going beyond end of command line.
     call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
-    call assert_equal('"0ab1cdefgh', @:)
+    call assert_equal('"0ab1cdefgh', @:, e)
 
     " Test toggling insert/overstrike a few times.
     call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
-    call assert_equal('"ab0cd3ef4', @:)
+    call assert_equal('"ab0cd3ef4', @:, e)
   endfor
 
   " Test overstrike with multi-byte characters.
   call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
-  call assert_equal('"テabキcdエディタ', @:)
+  call assert_equal('"テabキcdエディタ', @:, e)
 
   let &encoding = encoding_save
 endfunc
diff --git a/src/testdir/test_ex_mode.vim b/src/testdir/test_ex_mode.vim
new file mode 100644 (file)
index 0000000..00a35a3
--- /dev/null
@@ -0,0 +1,54 @@
+" Test editing line in Ex mode (see :help Q and :help gQ).
+
+" Helper function to test editing line in Q Ex mode
+func Ex_Q(cmd)
+  " Is there a simpler way to test editing Ex line?
+  call feedkeys("Q"
+        \    .. "let s:test_ex =<< END\<CR>"
+        \    .. a:cmd .. "\<CR>"
+        \    .. "END\<CR>"
+        \    .. "visual\<CR>", 'tx')
+  return s:test_ex[0]
+endfunc
+
+" Helper function to test editing line in gQ Ex mode
+func Ex_gQ(cmd)
+  call feedkeys("gQ" .. a:cmd .. "\<C-b>\"\<CR>", 'tx')
+  let ret = @:[1:] " Remove leading quote.
+  call feedkeys("visual\<CR>", 'tx')
+  return ret
+endfunc
+
+" Helper function to test editing line with both Q and gQ Ex mode.
+func Ex(cmd)
+ return [Ex_Q(a:cmd), Ex_gQ(a:cmd)]
+endfunc
+
+" Test editing line in Ex mode (both Q and gQ)
+func Test_ex_mode()
+  let encoding_save = &encoding
+  set sw=2
+
+  for e in ['utf8', 'latin1']
+    exe 'set encoding=' . e
+
+    call assert_equal(['bar', 'bar'],             Ex("foo bar\<C-u>bar"), e)
+    call assert_equal(["1\<C-u>2", "1\<C-u>2"],   Ex("1\<C-v>\<C-u>2"), e)
+    call assert_equal(["1\<C-b>2\<C-e>3", '213'], Ex("1\<C-b>2\<C-e>3"), e)
+    call assert_equal(['0123', '2013'],           Ex("01\<Home>2\<End>3"), e)
+    call assert_equal(['0123', '0213'],           Ex("01\<Left>2\<Right>3"), e)
+    call assert_equal(['01234', '0342'],          Ex("012\<Left>\<Left>\<Insert>3\<Insert>4"), e)
+    call assert_equal(["foo bar\<C-w>", 'foo '],  Ex("foo bar\<C-w>"), e)
+    call assert_equal(['foo', 'foo'],             Ex("fooba\<Del>\<Del>"), e)
+    call assert_equal(["foo\tbar", 'foobar'],     Ex("foo\<Tab>bar"), e)
+    call assert_equal(["abbrev\t", 'abbreviate'], Ex("abbrev\<Tab>"), e)
+    call assert_equal(['    1', "1\<C-t>\<C-t>"], Ex("1\<C-t>\<C-t>"), e)
+    call assert_equal(['  1', "1\<C-t>\<C-t>"],   Ex("1\<C-t>\<C-t>\<C-d>"), e)
+    call assert_equal(['  foo', '    foo'],       Ex("    foo\<C-d>"), e)
+    call assert_equal(['foo', '    foo0'],        Ex("    foo0\<C-d>"), e)
+    call assert_equal(['foo', '    foo^'],        Ex("    foo^\<C-d>"), e)
+  endfor
+
+  set sw&
+  let &encoding = encoding_save
+endfunc
index 286770288e86098a8d602f7b4fb76236b70c9784..5096633e646fb26139977bd995809c7e2f2362c4 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    23,
 /**/
     22,
 /**/