changeset 10893:fbed07965b6a v8.0.0336

patch 8.0.0336: flags of :substitute not sufficiently tested commit https://github.com/vim/vim/commit/8c50d50b6e19b755d7bad7b2724d14ead29364a7 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 17 18:28:24 2017 +0100 patch 8.0.0336: flags of :substitute not sufficiently tested Problem: Flags of :substitute not sufficiently tested. Solution: Test up to two letter flag combinations. (James McCoy, closes #1479)
author Christian Brabandt <cb@256bit.org>
date Fri, 17 Feb 2017 18:30:04 +0100
parents 1a04998ddb16
children f1cb20e3550e
files src/testdir/test_substitute.vim src/version.c
diffstat 2 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -39,3 +39,70 @@ function! Test_multiline_subst()
   call assert_equal('xxxxx', getline(13))
   enew!
 endfunction
+
+function! Test_substitute_variants()
+  " Validate that all the 2-/3-letter variants which embed the flags into the
+  " command name actually work.
+  enew!
+  let ln = 'Testing string'
+  let variants = [
+	\ { 'cmd': ':s/Test/test/c', 'exp': 'testing string', 'prompt': 'y' },
+	\ { 'cmd': ':s/foo/bar/ce', 'exp': ln },
+	\ { 'cmd': ':s/t/r/cg', 'exp': 'Tesring srring', 'prompt': 'a' },
+	\ { 'cmd': ':s/t/r/ci', 'exp': 'resting string', 'prompt': 'y' },
+	\ { 'cmd': ':s/t/r/cI', 'exp': 'Tesring string', 'prompt': 'y' },
+	\ { 'cmd': ':s/t/r/cn', 'exp': ln },
+	\ { 'cmd': ':s/t/r/cp', 'exp': 'Tesring string', 'prompt': 'y' },
+	\ { 'cmd': ':s/t/r/cl', 'exp': 'Tesring string', 'prompt': 'y' },
+	\ { 'cmd': ':s/t/r/gc', 'exp': 'Tesring srring', 'prompt': 'a' },
+	\ { 'cmd': ':s/foo/bar/ge', 'exp': ln },
+	\ { 'cmd': ':s/t/r/g', 'exp': 'Tesring srring' },
+	\ { 'cmd': ':s/t/r/gi', 'exp': 'resring srring' },
+	\ { 'cmd': ':s/t/r/gI', 'exp': 'Tesring srring' },
+	\ { 'cmd': ':s/t/r/gn', 'exp': ln },
+	\ { 'cmd': ':s/t/r/gp', 'exp': 'Tesring srring' },
+	\ { 'cmd': ':s/t/r/gl', 'exp': 'Tesring srring' },
+	\ { 'cmd': ':s//r/gr', 'exp': 'Testr strr' },
+	\ { 'cmd': ':s/t/r/ic', 'exp': 'resting string', 'prompt': 'y' },
+	\ { 'cmd': ':s/foo/bar/ie', 'exp': ln },
+	\ { 'cmd': ':s/t/r/i', 'exp': 'resting string' },
+	\ { 'cmd': ':s/t/r/iI', 'exp': 'Tesring string' },
+	\ { 'cmd': ':s/t/r/in', 'exp': ln },
+	\ { 'cmd': ':s/t/r/ip', 'exp': 'resting string' },
+	\ { 'cmd': ':s//r/ir', 'exp': 'Testr string' },
+	\ { 'cmd': ':s/t/r/Ic', 'exp': 'Tesring string', 'prompt': 'y' },
+	\ { 'cmd': ':s/foo/bar/Ie', 'exp': ln },
+	\ { 'cmd': ':s/t/r/Ig', 'exp': 'Tesring srring' },
+	\ { 'cmd': ':s/t/r/Ii', 'exp': 'resting string' },
+	\ { 'cmd': ':s/t/r/I', 'exp': 'Tesring string' },
+	\ { 'cmd': ':s/t/r/Ip', 'exp': 'Tesring string' },
+	\ { 'cmd': ':s/t/r/Il', 'exp': 'Tesring string' },
+	\ { 'cmd': ':s//r/Ir', 'exp': 'Testr string' },
+	\ { 'cmd': ':s//r/rc', 'exp': 'Testr string', 'prompt': 'y' },
+	\ { 'cmd': ':s//r/rg', 'exp': 'Testr strr' },
+	\ { 'cmd': ':s//r/ri', 'exp': 'Testr string' },
+	\ { 'cmd': ':s//r/rI', 'exp': 'Testr string' },
+	\ { 'cmd': ':s//r/rn', 'exp': 'Testing string' },
+	\ { 'cmd': ':s//r/rp', 'exp': 'Testr string' },
+	\ { 'cmd': ':s//r/rl', 'exp': 'Testr string' },
+	\ { 'cmd': ':s//r/r', 'exp': 'Testr string' },
+	\]
+
+  for var in variants
+    for run in [1, 2]
+      let cmd = var.cmd
+      if run == 2 && cmd =~ "/.*/.*/."
+	" Change  :s/from/to/{flags}  to  :s{flags}
+	let cmd = substitute(cmd, '/.*/', '', '')
+      endif
+      call setline(1, [ln])
+      let msg = printf('using "%s"', cmd)
+      let @/='ing'
+      let v:errmsg = ''
+      call feedkeys(cmd . "\<CR>" . get(var, 'prompt', ''), 'ntx')
+      " No error should exist (matters for testing e flag)
+      call assert_equal('', v:errmsg, msg)
+      call assert_equal(var.exp, getline('.'), msg)
+    endfor
+  endfor
+endfunction
--- a/src/version.c
+++ b/src/version.c
@@ -765,6 +765,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    336,
+/**/
     335,
 /**/
     334,