Skip to content

Commit 8c50d50

Browse files
committed
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)
1 parent 507647d commit 8c50d50

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/testdir/test_substitute.vim

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,70 @@ function! Test_multiline_subst()
3939
call assert_equal('xxxxx', getline(13))
4040
enew!
4141
endfunction
42+
43+
function! Test_substitute_variants()
44+
" Validate that all the 2-/3-letter variants which embed the flags into the
45+
" command name actually work.
46+
enew!
47+
let ln = 'Testing string'
48+
let variants = [
49+
\ { 'cmd': ':s/Test/test/c', 'exp': 'testing string', 'prompt': 'y' },
50+
\ { 'cmd': ':s/foo/bar/ce', 'exp': ln },
51+
\ { 'cmd': ':s/t/r/cg', 'exp': 'Tesring srring', 'prompt': 'a' },
52+
\ { 'cmd': ':s/t/r/ci', 'exp': 'resting string', 'prompt': 'y' },
53+
\ { 'cmd': ':s/t/r/cI', 'exp': 'Tesring string', 'prompt': 'y' },
54+
\ { 'cmd': ':s/t/r/cn', 'exp': ln },
55+
\ { 'cmd': ':s/t/r/cp', 'exp': 'Tesring string', 'prompt': 'y' },
56+
\ { 'cmd': ':s/t/r/cl', 'exp': 'Tesring string', 'prompt': 'y' },
57+
\ { 'cmd': ':s/t/r/gc', 'exp': 'Tesring srring', 'prompt': 'a' },
58+
\ { 'cmd': ':s/foo/bar/ge', 'exp': ln },
59+
\ { 'cmd': ':s/t/r/g', 'exp': 'Tesring srring' },
60+
\ { 'cmd': ':s/t/r/gi', 'exp': 'resring srring' },
61+
\ { 'cmd': ':s/t/r/gI', 'exp': 'Tesring srring' },
62+
\ { 'cmd': ':s/t/r/gn', 'exp': ln },
63+
\ { 'cmd': ':s/t/r/gp', 'exp': 'Tesring srring' },
64+
\ { 'cmd': ':s/t/r/gl', 'exp': 'Tesring srring' },
65+
\ { 'cmd': ':s//r/gr', 'exp': 'Testr strr' },
66+
\ { 'cmd': ':s/t/r/ic', 'exp': 'resting string', 'prompt': 'y' },
67+
\ { 'cmd': ':s/foo/bar/ie', 'exp': ln },
68+
\ { 'cmd': ':s/t/r/i', 'exp': 'resting string' },
69+
\ { 'cmd': ':s/t/r/iI', 'exp': 'Tesring string' },
70+
\ { 'cmd': ':s/t/r/in', 'exp': ln },
71+
\ { 'cmd': ':s/t/r/ip', 'exp': 'resting string' },
72+
\ { 'cmd': ':s//r/ir', 'exp': 'Testr string' },
73+
\ { 'cmd': ':s/t/r/Ic', 'exp': 'Tesring string', 'prompt': 'y' },
74+
\ { 'cmd': ':s/foo/bar/Ie', 'exp': ln },
75+
\ { 'cmd': ':s/t/r/Ig', 'exp': 'Tesring srring' },
76+
\ { 'cmd': ':s/t/r/Ii', 'exp': 'resting string' },
77+
\ { 'cmd': ':s/t/r/I', 'exp': 'Tesring string' },
78+
\ { 'cmd': ':s/t/r/Ip', 'exp': 'Tesring string' },
79+
\ { 'cmd': ':s/t/r/Il', 'exp': 'Tesring string' },
80+
\ { 'cmd': ':s//r/Ir', 'exp': 'Testr string' },
81+
\ { 'cmd': ':s//r/rc', 'exp': 'Testr string', 'prompt': 'y' },
82+
\ { 'cmd': ':s//r/rg', 'exp': 'Testr strr' },
83+
\ { 'cmd': ':s//r/ri', 'exp': 'Testr string' },
84+
\ { 'cmd': ':s//r/rI', 'exp': 'Testr string' },
85+
\ { 'cmd': ':s//r/rn', 'exp': 'Testing string' },
86+
\ { 'cmd': ':s//r/rp', 'exp': 'Testr string' },
87+
\ { 'cmd': ':s//r/rl', 'exp': 'Testr string' },
88+
\ { 'cmd': ':s//r/r', 'exp': 'Testr string' },
89+
\]
90+
91+
for var in variants
92+
for run in [1, 2]
93+
let cmd = var.cmd
94+
if run == 2 && cmd =~ "/.*/.*/."
95+
" Change :s/from/to/{flags} to :s{flags}
96+
let cmd = substitute(cmd, '/.*/', '', '')
97+
endif
98+
call setline(1, [ln])
99+
let msg = printf('using "%s"', cmd)
100+
let @/='ing'
101+
let v:errmsg = ''
102+
call feedkeys(cmd . "\<CR>" . get(var, 'prompt', ''), 'ntx')
103+
" No error should exist (matters for testing e flag)
104+
call assert_equal('', v:errmsg, msg)
105+
call assert_equal(var.exp, getline('.'), msg)
106+
endfor
107+
endfor
108+
endfunction

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
336,
767769
/**/
768770
335,
769771
/**/

0 commit comments

Comments
 (0)