@@ -39,3 +39,70 @@ function! Test_multiline_subst()
3939 call assert_equal (' xxxxx' , getline (13 ))
4040 enew !
4141endfunction
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
0 commit comments