annotate src/testdir/test_substitute.vim @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents d6b579475543
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1 " Tests for the substitute (:s) command
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
3 source shared.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
4 source check.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
5 source screendump.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
6
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
7 func Test_multiline_subst()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
8 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
9 call append(0, ["1 aa",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
10 \ "bb",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
11 \ "cc",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
12 \ "2 dd",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
13 \ "ee",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
14 \ "3 ef",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
15 \ "gh",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
16 \ "4 ij",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
17 \ "5 a8",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
18 \ "8b c9",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
19 \ "9d",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
20 \ "6 e7",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
21 \ "77f",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
22 \ "xxxxx"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
23
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
24 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
25 " test if replacing a line break works with a back reference
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
26 /^1/,/^2/s/\n\(.\)/ \1/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
27 " test if inserting a line break works with a back reference
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
28 /^3/,/^4/s/\(.\)$/\r\1/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
29 " test if replacing a line break with another line break works
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
30 /^5/,/^6/s/\(\_d\{3}\)/x\1x/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
31 call assert_equal('1 aa bb cc 2 dd ee', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
32 call assert_equal('3 e', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
33 call assert_equal('f', getline(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
34 call assert_equal('g', getline(4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
35 call assert_equal('h', getline(5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
36 call assert_equal('4 i', getline(6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
37 call assert_equal('j', getline(7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
38 call assert_equal('5 ax8', getline(8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
39 call assert_equal('8xb cx9', getline(9))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
40 call assert_equal('9xd', getline(10))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
41 call assert_equal('6 ex7', getline(11))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
42 call assert_equal('7x7f', getline(12))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
43 call assert_equal('xxxxx', getline(13))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
44 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
45 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
46
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
47 func Test_substitute_variants()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
48 " Validate that all the 2-/3-letter variants which embed the flags into the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
49 " command name actually work.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
50 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
51 let ln = 'Testing string'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
52 let variants = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
53 \ { 'cmd': ':s/Test/test/c', 'exp': 'testing string', 'prompt': 'y' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
54 \ { 'cmd': ':s/foo/bar/ce', 'exp': ln },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
55 \ { 'cmd': ':s/t/r/cg', 'exp': 'Tesring srring', 'prompt': 'a' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
56 \ { 'cmd': ':s/t/r/ci', 'exp': 'resting string', 'prompt': 'y' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
57 \ { 'cmd': ':s/t/r/cI', 'exp': 'Tesring string', 'prompt': 'y' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
58 \ { 'cmd': ':s/t/r/c', 'exp': 'Testing string', 'prompt': 'n' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
59 \ { 'cmd': ':s/t/r/cn', 'exp': ln },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
60 \ { 'cmd': ':s/t/r/cp', 'exp': 'Tesring string', 'prompt': 'y' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
61 \ { 'cmd': ':s/t/r/cl', 'exp': 'Tesring string', 'prompt': 'y' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
62 \ { 'cmd': ':s/t/r/gc', 'exp': 'Tesring srring', 'prompt': 'a' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
63 \ { 'cmd': ':s/i/I/gc', 'exp': 'TestIng string', 'prompt': 'l' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
64 \ { 'cmd': ':s/foo/bar/ge', 'exp': ln },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
65 \ { 'cmd': ':s/t/r/g', 'exp': 'Tesring srring' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
66 \ { 'cmd': ':s/t/r/gi', 'exp': 'resring srring' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
67 \ { 'cmd': ':s/t/r/gI', 'exp': 'Tesring srring' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
68 \ { 'cmd': ':s/t/r/gn', 'exp': ln },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
69 \ { 'cmd': ':s/t/r/gp', 'exp': 'Tesring srring' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
70 \ { 'cmd': ':s/t/r/gl', 'exp': 'Tesring srring' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
71 \ { 'cmd': ':s//r/gr', 'exp': 'Testr strr' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
72 \ { 'cmd': ':s/t/r/ic', 'exp': 'resting string', 'prompt': 'y' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
73 \ { 'cmd': ':s/foo/bar/ie', 'exp': ln },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
74 \ { 'cmd': ':s/t/r/i', 'exp': 'resting string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
75 \ { 'cmd': ':s/t/r/iI', 'exp': 'Tesring string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
76 \ { 'cmd': ':s/t/r/in', 'exp': ln },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
77 \ { 'cmd': ':s/t/r/ip', 'exp': 'resting string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
78 \ { 'cmd': ':s//r/ir', 'exp': 'Testr string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
79 \ { 'cmd': ':s/t/r/Ic', 'exp': 'Tesring string', 'prompt': 'y' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
80 \ { 'cmd': ':s/foo/bar/Ie', 'exp': ln },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
81 \ { 'cmd': ':s/t/r/Ig', 'exp': 'Tesring srring' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
82 \ { 'cmd': ':s/t/r/Ii', 'exp': 'resting string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
83 \ { 'cmd': ':s/t/r/I', 'exp': 'Tesring string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
84 \ { 'cmd': ':s/t/r/Ip', 'exp': 'Tesring string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
85 \ { 'cmd': ':s/t/r/Il', 'exp': 'Tesring string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
86 \ { 'cmd': ':s//r/Ir', 'exp': 'Testr string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
87 \ { 'cmd': ':s//r/rc', 'exp': 'Testr string', 'prompt': 'y' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
88 \ { 'cmd': ':s//r/rg', 'exp': 'Testr strr' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
89 \ { 'cmd': ':s//r/ri', 'exp': 'Testr string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
90 \ { 'cmd': ':s//r/rI', 'exp': 'Testr string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
91 \ { 'cmd': ':s//r/rn', 'exp': 'Testing string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
92 \ { 'cmd': ':s//r/rp', 'exp': 'Testr string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
93 \ { 'cmd': ':s//r/rl', 'exp': 'Testr string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
94 \ { 'cmd': ':s//r/r', 'exp': 'Testr string' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
95 \ { 'cmd': ':s/i/I/gc', 'exp': 'Testing string', 'prompt': 'q' },
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
96 \]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
97
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
98 for var in variants
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
99 for run in [1, 2]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
100 let cmd = var.cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
101 if run == 2 && cmd =~ "/.*/.*/."
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
102 " Change :s/from/to/{flags} to :s{flags}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
103 let cmd = substitute(cmd, '/.*/', '', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
104 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
105 call setline(1, [ln])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
106 let msg = printf('using "%s"', cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
107 let @/='ing'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
108 let v:errmsg = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
109 call feedkeys(cmd . "\<CR>" . get(var, 'prompt', ''), 'ntx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
110 " No error should exist (matters for testing e flag)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
111 call assert_equal('', v:errmsg, msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
112 call assert_equal(var.exp, getline('.'), msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
113 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
114 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
115 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
116
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
117 " Test the l, p, # flags.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
118 func Test_substitute_flags_lp()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
119 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
120 call setline(1, "abc\tdef\<C-h>ghi")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
121
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
122 let a = execute('s/a/a/p')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
123 call assert_equal("\nabc def^Hghi", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
124
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
125 let a = execute('s/a/a/l')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
126 call assert_equal("\nabc^Idef^Hghi$", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
127
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
128 let a = execute('s/a/a/#')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
129 call assert_equal("\n 1 abc def^Hghi", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
130
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
131 let a = execute('s/a/a/p#')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
132 call assert_equal("\n 1 abc def^Hghi", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
133
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
134 let a = execute('s/a/a/l#')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
135 call assert_equal("\n 1 abc^Idef^Hghi$", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
136
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
137 let a = execute('s/a/a/')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
138 call assert_equal("", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
139
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
140 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
141 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
142
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
143 func Test_substitute_repeat()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
144 " This caused an invalid memory access.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
145 split Xsubfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
146 s/^/x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
147 call feedkeys("Qsc\<CR>y", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
148 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
149 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
150
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
151 " Test %s/\n// which is implemented as a special case to use a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
152 " more efficient join rather than doing a regular substitution.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
153 func Test_substitute_join()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
154 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
156 call setline(1, ["foo\tbar", "bar\<C-H>foo"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
157 let a = execute('%s/\n//')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
158 call assert_equal("", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
159 call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
160 call assert_equal('\n', histget("search", -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
161
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
162 call setline(1, ["foo\tbar", "bar\<C-H>foo"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
163 let a = execute('%s/\n//g')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
164 call assert_equal("", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
165 call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
166 call assert_equal('\n', histget("search", -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
168 call setline(1, ["foo\tbar", "bar\<C-H>foo"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
169 let a = execute('%s/\n//p')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
170 call assert_equal("\nfoo barbar^Hfoo", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
171 call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
172 call assert_equal('\n', histget("search", -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
174 call setline(1, ["foo\tbar", "bar\<C-H>foo"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
175 let a = execute('%s/\n//l')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
176 call assert_equal("\nfoo^Ibarbar^Hfoo$", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
177 call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
178 call assert_equal('\n', histget("search", -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
179
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
180 call setline(1, ["foo\tbar", "bar\<C-H>foo"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
181 let a = execute('%s/\n//#')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
182 call assert_equal("\n 1 foo barbar^Hfoo", a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
183 call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
184 call assert_equal('\n', histget("search", -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
185
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
186 call setline(1, ['foo', 'bar', 'baz', 'qux'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
187 call execute('1,2s/\n//')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
188 call assert_equal(['foobarbaz', 'qux'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
189
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
190 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
191 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
193 func Test_substitute_count()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
194 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
195 call setline(1, ['foo foo', 'foo foo', 'foo foo', 'foo foo', 'foo foo'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
196 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
197
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
198 s/foo/bar/3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
199 call assert_equal(['foo foo', 'bar foo', 'bar foo', 'bar foo', 'foo foo'],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
200 \ getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
202 call assert_fails('s/foo/bar/0', 'E939:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
203
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
204 call setline(1, ['foo foo', 'foo foo', 'foo foo', 'foo foo', 'foo foo'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
205 2,4s/foo/bar/ 10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
206 call assert_equal(['foo foo', 'foo foo', 'foo foo', 'bar foo', 'bar foo'],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
207 \ getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
208
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
209 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
210 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
211
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
212 " Test substitute 'n' flag (report number of matches, do not substitute).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
213 func Test_substitute_flag_n()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
214 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
215 let lines = ['foo foo', 'foo foo', 'foo foo', 'foo foo', 'foo foo']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
216 call setline(1, lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
217
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
218 call assert_equal("\n3 matches on 3 lines", execute('2,4s/foo/bar/n'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
219 call assert_equal("\n6 matches on 3 lines", execute('2,4s/foo/bar/gn'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
220
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
221 " c flag (confirm) should be ignored when using n flag.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
222 call assert_equal("\n3 matches on 3 lines", execute('2,4s/foo/bar/nc'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
224 " No substitution should have been done.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
225 call assert_equal(lines, getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
226
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
227 %delete _
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
228 call setline(1, ['A', 'Bar', 'Baz'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
229 call assert_equal("\n1 match on 1 line", execute('s/\nB\@=//gn'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
230
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
231 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
232 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
233
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
234 func Test_substitute_errors()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
235 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
236 call setline(1, 'foobar')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
237
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
238 call assert_fails('s/FOO/bar/', 'E486:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
239 call assert_fails('s/foo/bar/@', 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
240 call assert_fails('s/\(/bar/', 'E54:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
241 call assert_fails('s afooabara', 'E146:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
242 call assert_fails('s\\a', 'E10:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
244 setl nomodifiable
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
245 call assert_fails('s/foo/bar/', 'E21:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
246
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
247 call assert_fails("let s=substitute([], 'a', 'A', 'g')", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
248 call assert_fails("let s=substitute('abcda', [], 'A', 'g')", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
249 call assert_fails("let s=substitute('abcda', 'a', [], 'g')", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
250 call assert_fails("let s=substitute('abcda', 'a', 'A', [])", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
251 call assert_fails("let s=substitute('abc', '\\%(', 'A', 'g')", 'E53:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
252
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
253 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
254 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
256 " Test for *sub-replace-special* and *sub-replace-expression* on substitute().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
257 func Test_sub_replace_1()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
258 " Run the tests with 'magic' on
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
259 set magic
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
260 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
261 call assert_equal('AA', substitute('A', 'A', '&&', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
262 call assert_equal('&', substitute('B', 'B', '\&', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
263 call assert_equal('C123456789987654321', substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
264 call assert_equal('d', substitute('D', 'D', 'd', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
265 call assert_equal('~', substitute('E', 'E', '~', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
266 call assert_equal('~', substitute('F', 'F', '\~', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
267 call assert_equal('Gg', substitute('G', 'G', '\ugg', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
268 call assert_equal('Hh', substitute('H', 'H', '\Uh\Eh', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
269 call assert_equal('iI', substitute('I', 'I', '\lII', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
270 call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
271 call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
272 call assert_equal("l\<C-V>\<C-M>l",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
273 \ substitute('lLl', 'L', "\<C-V>\<C-M>", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
274 call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
275 call assert_equal("n\<C-V>\<C-M>n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
276 \ substitute('nNn', 'N', "\\\<C-V>\<C-M>", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
277 call assert_equal("o\no", substitute('oOo', 'O', '\n', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
278 call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
279 call assert_equal("q\tq", substitute('qQq', 'Q', '\t', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
280 call assert_equal('r\r', substitute('rRr', 'R', '\\', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
281 call assert_equal('scs', substitute('sSs', 'S', '\c', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
282 call assert_equal("u\nu", substitute('uUu', 'U', "\n", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
283 call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
284 call assert_equal("w\\w", substitute('wWw', 'W', "\\", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
285 call assert_equal("x\<C-M>x", substitute('xXx', 'X', "\r", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
286 call assert_equal("YyyY", substitute('Y', 'Y', '\L\uyYy\l\EY', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
287 call assert_equal("zZZz", substitute('Z', 'Z', '\U\lZzZ\u\Ez', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
288 " \v or \V after $
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
289 call assert_equal('abxx', substitute('abcd', 'xy$\v|cd$', 'xx', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
290 call assert_equal('abxx', substitute('abcd', 'xy$\V\|cd\$', 'xx', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
291 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
292
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
293 func Test_sub_replace_2()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
294 " Run the tests with 'magic' off
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
295 set nomagic
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
296 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
297 call assert_equal('AA', substitute('A', 'A', '&&', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
298 call assert_equal('&', substitute('B', 'B', '\&', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
299 call assert_equal('C123456789987654321', substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
300 call assert_equal('d', substitute('D', 'D', 'd', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
301 call assert_equal('~', substitute('E', 'E', '~', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
302 call assert_equal('~', substitute('F', 'F', '\~', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
303 call assert_equal('Gg', substitute('G', 'G', '\ugg', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
304 call assert_equal('Hh', substitute('H', 'H', '\Uh\Eh', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
305 call assert_equal('iI', substitute('I', 'I', '\lII', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
306 call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
307 call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
308 call assert_equal("l\<C-V>\<C-M>l",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
309 \ substitute('lLl', 'L', "\<C-V>\<C-M>", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
310 call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
311 call assert_equal("n\<C-V>\<C-M>n",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
312 \ substitute('nNn', 'N', "\\\<C-V>\<C-M>", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
313 call assert_equal("o\no", substitute('oOo', 'O', '\n', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
314 call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
315 call assert_equal("q\tq", substitute('qQq', 'Q', '\t', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
316 call assert_equal('r\r', substitute('rRr', 'R', '\\', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
317 call assert_equal('scs', substitute('sSs', 'S', '\c', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
318 call assert_equal("t\<C-M>t", substitute('tTt', 'T', "\r", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
319 call assert_equal("u\nu", substitute('uUu', 'U', "\n", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
320 call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
321 call assert_equal('w\w', substitute('wWw', 'W', "\\", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
322 call assert_equal('XxxX', substitute('X', 'X', '\L\uxXx\l\EX', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
323 call assert_equal('yYYy', substitute('Y', 'Y', '\U\lYyY\u\Ey', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
324 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
325
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
326 func Test_sub_replace_3()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
327 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
328 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
329 call assert_equal('a\a', substitute('aAa', 'A', '\="\\"', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
330 call assert_equal('b\\b', substitute('bBb', 'B', '\="\\\\"', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
331 call assert_equal("c\rc", substitute('cCc', 'C', "\\=\"\r\"", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
332 call assert_equal("d\\\rd", substitute('dDd', 'D', "\\=\"\\\\\r\"", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
333 call assert_equal("e\\\\\re", substitute('eEe', 'E', "\\=\"\\\\\\\\\r\"", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
334 call assert_equal('f\rf', substitute('fFf', 'F', '\="\\r"', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
335 call assert_equal('j\nj', substitute('jJj', 'J', '\="\\n"', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
336 call assert_equal("k\<C-M>k", substitute('kKk', 'K', '\="\r"', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
337 call assert_equal("l\nl", substitute('lLl', 'L', '\="\n"', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
338 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
339
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
340 " Test for submatch() on substitute().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
341 func Test_sub_replace_4()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
342 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
343 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
344 call assert_equal('a\a', substitute('aAa', 'A',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
345 \ '\=substitute(submatch(0), ".", "\\", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
346 call assert_equal('b\b', substitute('bBb', 'B',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
347 \ '\=substitute(submatch(0), ".", "\\\\", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
348 call assert_equal("c\<C-V>\<C-M>c", substitute('cCc', 'C', '\=substitute(submatch(0), ".", "\<C-V>\<C-M>", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
349 call assert_equal("d\<C-V>\<C-M>d", substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\\<C-V>\<C-M>", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
350 call assert_equal("e\\\<C-V>\<C-M>e", substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-M>", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
351 call assert_equal("f\<C-M>f", substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
352 call assert_equal("j\nj", substitute('jJj', 'J', '\=substitute(submatch(0), ".", "\\n", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
353 call assert_equal("k\rk", substitute('kKk', 'K', '\=substitute(submatch(0), ".", "\r", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
354 call assert_equal("l\nl", substitute('lLl', 'L', '\=substitute(submatch(0), ".", "\n", "")', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
355 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
356
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
357 func Test_sub_replace_5()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
358 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
359 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
360 call assert_equal('A123456789987654321', substitute('A123456789',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
361 \ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
362 \ '\=submatch(0) . submatch(9) . submatch(8) . ' .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
363 \ 'submatch(7) . submatch(6) . submatch(5) . ' .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
364 \ 'submatch(4) . submatch(3) . submatch(2) . submatch(1)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
365 \ ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
366 call assert_equal("[['A123456789'], ['9'], ['8'], ['7'], ['6'], " .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
367 \ "['5'], ['4'], ['3'], ['2'], ['1']]",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
368 \ substitute('A123456789',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
369 \ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
370 \ '\=string([submatch(0, 1), submatch(9, 1), ' .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
371 \ 'submatch(8, 1), 7->submatch(1), submatch(6, 1), ' .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
372 \ 'submatch(5, 1), submatch(4, 1), submatch(3, 1), ' .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
373 \ 'submatch(2, 1), submatch(1, 1)])',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
374 \ ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
375 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
377 func Test_sub_replace_6()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
378 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
379 set cpo+=/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
380 call assert_equal('a', substitute('A', 'A', 'a', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
381 call assert_equal('%', substitute('B', 'B', '%', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
382 set cpo-=/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
383 call assert_equal('c', substitute('C', 'C', 'c', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
384 call assert_equal('%', substitute('D', 'D', '%', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
385 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
386
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
387 func Test_sub_replace_7()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
388 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
389 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
390 call assert_equal('AA', substitute('AA', 'A.', '\=submatch(0)', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
391 call assert_equal("B\nB", substitute("B\nB", 'B.', '\=submatch(0)', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
392 call assert_equal("['B\n']B", substitute("B\nB", 'B.', '\=string(submatch(0, 1))', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
393 call assert_equal('-abab', substitute('-bb', '\zeb', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
394 call assert_equal('c-cbcbc', substitute('-bb', '\ze', 'c', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
395 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
396
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
397 " Test for *:s%* on :substitute.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
398 func Test_sub_replace_8()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
399 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
400 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
401 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
402 $put =',,X'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
403 s/\(^\|,\)\ze\(,\|X\)/\1N/g
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
404 call assert_equal('N,,NX', getline("$"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
405 $put =',,Y'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
406 let cmd = ':s/\(^\|,\)\ze\(,\|Y\)/\1N/gc'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
407 call feedkeys(cmd . "\<CR>a", "xt")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
408 call assert_equal('N,,NY', getline("$"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
409 :$put =',,Z'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
410 let cmd = ':s/\(^\|,\)\ze\(,\|Z\)/\1N/gc'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
411 call feedkeys(cmd . "\<CR>yy", "xt")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
412 call assert_equal('N,,NZ', getline("$"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
413 enew! | close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
414 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
415
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
416 func Test_sub_replace_9()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
417 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
418 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
419 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
420 $put ='xxx'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
421 call feedkeys(":s/x/X/gc\<CR>yyq", "xt")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
422 call assert_equal('XXx', getline("$"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
423 enew! | close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
424 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
425
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
426 func Test_sub_replace_10()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
427 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
428 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
429 call assert_equal('a1a2a3a', substitute('123', '\zs', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
430 call assert_equal('aaa', substitute('123', '\zs.', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
431 call assert_equal('1a2a3a', substitute('123', '.\zs', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
432 call assert_equal('a1a2a3a', substitute('123', '\ze', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
433 call assert_equal('a1a2a3', substitute('123', '\ze.', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
434 call assert_equal('aaa', substitute('123', '.\ze', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
435 call assert_equal('aa2a3a', substitute('123', '1\|\ze', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
436 call assert_equal('1aaa', substitute('123', '1\zs\|[23]', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
437 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
438
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
439 func SubReplacer(text, submatches)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
440 return a:text .. a:submatches[0] .. a:text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
441 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
442 func SubReplacerVar(text, ...)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
443 return a:text .. a:1[0] .. a:text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
444 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
445 def SubReplacerVar9(text: string, ...args: list<list<string>>): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
446 return text .. args[0][0] .. text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
447 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
448 func SubReplacer20(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, submatches)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
449 return a:t3 .. a:submatches[0] .. a:t11
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
450 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
451
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
452 func Test_substitute_partial()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
453 call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacer', ['foo']), 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
454 call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacerVar', ['foo']), 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
455 call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacerVar9', ['foo']), 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
456
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
457 " 19 arguments plus one is just OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
458 let Replacer = function('SubReplacer20', repeat(['foo'], 19))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
459 call assert_equal('1foo2foo3', substitute('123', '2', Replacer, 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
460
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
461 " 20 arguments plus one is too many
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
462 let Replacer = function('SubReplacer20', repeat(['foo'], 20))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
463 call assert_fails("call substitute('123', '2', Replacer, 'g')", 'E118:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
464 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
465
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
466 func Test_substitute_float()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
467 call assert_equal('number 1.23', substitute('number ', '$', { -> 1.23 }, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
468 vim9 assert_equal('number 1.23', substitute('number ', '$', () => 1.23, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
469 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
471 " Tests for *sub-replace-special* and *sub-replace-expression* on :substitute.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
472
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
473 " Execute a list of :substitute command tests
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
474 func Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
475 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
476 for t in a:tests
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
477 let start = line('.') + 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
478 let end = start + len(t[2]) - 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
479 exe "normal o" . t[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
480 call cursor(start, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
481 exe t[1]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
482 call assert_equal(t[2], getline(start, end), t[1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
483 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
484 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
485 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
486
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
487 func Test_sub_cmd_1()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
488 set magic
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
489 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
491 " List entry format: [input, cmd, output]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
492 let tests = [['A', 's/A/&&/', ['AA']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
493 \ ['B', 's/B/\&/', ['&']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
494 \ ['C123456789', 's/C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/', ['C123456789987654321']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
495 \ ['D', 's/D/d/', ['d']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
496 \ ['E', 's/E/~/', ['d']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
497 \ ['F', 's/F/\~/', ['~']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
498 \ ['G', 's/G/\ugg/', ['Gg']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
499 \ ['H', 's/H/\Uh\Eh/', ['Hh']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
500 \ ['I', 's/I/\lII/', ['iI']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
501 \ ['J', 's/J/\LJ\EJ/', ['jJ']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
502 \ ['K', 's/K/\Uk\ek/', ['Kk']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
503 \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
504 \ ['mMm', 's/M/\r/', ['m', 'm']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
505 \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
506 \ ['oOo', 's/O/\n/', ["o\no"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
507 \ ['pPp', 's/P/\b/', ["p\<C-H>p"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
508 \ ['qQq', 's/Q/\t/', ["q\tq"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
509 \ ['rRr', 's/R/\\/', ['r\r']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
510 \ ['sSs', 's/S/\c/', ['scs']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
511 \ ['tTt', "s/T/\<C-V>\<C-J>/", ["t\<C-V>\<C-J>t"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
512 \ ['U', 's/U/\L\uuUu\l\EU/', ['UuuU']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
513 \ ['V', 's/V/\U\lVvV\u\Ev/', ['vVVv']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
514 \ ['\', 's/\\/\\\\/', ['\\']]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
515 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
516 call Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
517 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
518
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
519 func Test_sub_cmd_2()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
520 set nomagic
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
521 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
523 " List entry format: [input, cmd, output]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
524 let tests = [['A', 's/A/&&/', ['&&']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
525 \ ['B', 's/B/\&/', ['B']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
526 \ ['C123456789', 's/\mC\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/', ['C123456789987654321']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
527 \ ['D', 's/D/d/', ['d']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
528 \ ['E', 's/E/~/', ['~']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
529 \ ['F', 's/F/\~/', ['~']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
530 \ ['G', 's/G/\ugg/', ['Gg']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
531 \ ['H', 's/H/\Uh\Eh/', ['Hh']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
532 \ ['I', 's/I/\lII/', ['iI']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
533 \ ['J', 's/J/\LJ\EJ/', ['jJ']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
534 \ ['K', 's/K/\Uk\ek/', ['Kk']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
535 \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
536 \ ['mMm', 's/M/\r/', ['m', 'm']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
537 \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
538 \ ['oOo', 's/O/\n/', ["o\no"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
539 \ ['pPp', 's/P/\b/', ["p\<C-H>p"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
540 \ ['qQq', 's/Q/\t/', ["q\tq"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
541 \ ['rRr', 's/R/\\/', ['r\r']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
542 \ ['sSs', 's/S/\c/', ['scs']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
543 \ ['tTt', "s/T/\<C-V>\<C-J>/", ["t\<C-V>\<C-J>t"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
544 \ ['U', 's/U/\L\uuUu\l\EU/', ['UuuU']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
545 \ ['V', 's/V/\U\lVvV\u\Ev/', ['vVVv']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
546 \ ['\', 's/\\/\\\\/', ['\\']]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
547 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
548 call Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
549 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
550
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
551 func Test_sub_cmd_3()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
552 set nomagic
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
553 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
554
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
555 " List entry format: [input, cmd, output]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
556 let tests = [['aAa', "s/A/\\='\\'/", ['a\a']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
557 \ ['bBb', "s/B/\\='\\\\'/", ['b\\b']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
558 \ ['cCc', "s/C/\\='\<C-V>\<C-M>'/", ["c\<C-V>", 'c']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
559 \ ['dDd', "s/D/\\='\\\<C-V>\<C-M>'/", ["d\\\<C-V>", 'd']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
560 \ ['eEe', "s/E/\\='\\\\\<C-V>\<C-M>'/", ["e\\\\\<C-V>", 'e']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
561 \ ['fFf', "s/F/\\='\r'/", ['f', 'f']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
562 \ ['gGg', "s/G/\\='\<C-V>\<C-J>'/", ["g\<C-V>", 'g']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
563 \ ['hHh', "s/H/\\='\\\<C-V>\<C-J>'/", ["h\\\<C-V>", 'h']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
564 \ ['iIi', "s/I/\\='\\\\\<C-V>\<C-J>'/", ["i\\\\\<C-V>", 'i']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
565 \ ['jJj', "s/J/\\='\n'/", ['j', 'j']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
566 \ ['kKk', 's/K/\="\r"/', ['k', 'k']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
567 \ ['lLl', 's/L/\="\n"/', ['l', 'l']]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
568 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
569 call Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
570 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
571
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
572 " Test for submatch() on :substitute.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
573 func Test_sub_cmd_4()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
574 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
575 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
576
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
577 " List entry format: [input, cmd, output]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
578 let tests = [ ['aAa', "s/A/\\=substitute(submatch(0), '.', '\\', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
579 \ ['a\a']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
580 \ ['bBb', "s/B/\\=substitute(submatch(0), '.', '\\', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
581 \ ['b\b']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
582 \ ['cCc', "s/C/\\=substitute(submatch(0), '.', '\<C-V>\<C-M>', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
583 \ ["c\<C-V>", 'c']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
584 \ ['dDd', "s/D/\\=substitute(submatch(0), '.', '\\\<C-V>\<C-M>', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
585 \ ["d\<C-V>", 'd']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
586 \ ['eEe', "s/E/\\=substitute(submatch(0), '.', '\\\\\<C-V>\<C-M>', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
587 \ ["e\\\<C-V>", 'e']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
588 \ ['fFf', "s/F/\\=substitute(submatch(0), '.', '\\r', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
589 \ ['f', 'f']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
590 \ ['gGg', 's/G/\=substitute(submatch(0), ".", "\<C-V>\<C-J>", "")/',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
591 \ ["g\<C-V>", 'g']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
592 \ ['hHh', 's/H/\=substitute(submatch(0), ".", "\\\<C-V>\<C-J>", "")/',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
593 \ ["h\<C-V>", 'h']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
594 \ ['iIi', 's/I/\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-J>", "")/',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
595 \ ["i\\\<C-V>", 'i']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
596 \ ['jJj', "s/J/\\=substitute(submatch(0), '.', '\\n', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
597 \ ['j', 'j']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
598 \ ['kKk', "s/K/\\=substitute(submatch(0), '.', '\\r', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
599 \ ['k', 'k']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
600 \ ['lLl', "s/L/\\=substitute(submatch(0), '.', '\\n', '')/",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
601 \ ['l', 'l']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
602 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
603 call Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
604 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
605
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
606 func Test_sub_cmd_5()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
607 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
608 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
609
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
610 " List entry format: [input, cmd, output]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
611 let tests = [ ['A123456789', 's/A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)/', ['A123456789987654321']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
612 \ ['B123456789', 's/B\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), submatch(3, 1), submatch(2, 1), submatch(1, 1)])/', ["[['B123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], ['2'], ['1']]"]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
613 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
614 call Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
615 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
616
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
617 " Test for *:s%* on :substitute.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
618 func Test_sub_cmd_6()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
619 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
620 set cpo+=/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
622 " List entry format: [input, cmd, output]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
623 let tests = [ ['A', 's/A/a/', ['a']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
624 \ ['B', 's/B/%/', ['a']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
625 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
626 call Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
627
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
628 set cpo-=/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
629 let tests = [ ['C', 's/C/c/', ['c']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
630 \ ['D', 's/D/%/', ['%']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
631 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
632 call Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
633
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
634 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
635 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
636
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
637 " Test for :s replacing \n with line break.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
638 func Test_sub_cmd_7()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
639 set magic&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
640 set cpo&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
641
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
642 " List entry format: [input, cmd, output]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
643 let tests = [ ["A\<C-V>\<C-M>A", 's/A./\=submatch(0)/', ['A', 'A']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
644 \ ["B\<C-V>\<C-J>B", 's/B./\=submatch(0)/', ['B', 'B']],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
645 \ ["C\<C-V>\<C-J>C", 's/C./\=strtrans(string(submatch(0, 1)))/', [strtrans("['C\<C-J>']C")]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
646 \ ["D\<C-V>\<C-J>\nD", 's/D.\nD/\=strtrans(string(submatch(0, 1)))/', [strtrans("['D\<C-J>', 'D']")]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
647 \ ["E\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>E", 's/E\_.\{-}E/\=strtrans(string(submatch(0, 1)))/', [strtrans("['E\<C-J>', '\<C-J>', '\<C-J>', '\<C-J>', '\<C-J>E']")]],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
648 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
649 call Run_SubCmd_Tests(tests)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
650
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
651 exe "normal oQ\nQ\<Esc>k"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
652 call assert_fails('s/Q[^\n]Q/\=submatch(0)."foobar"/', 'E486:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
653 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
654 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
655
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
656 func TitleString()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
657 let check = 'foo' =~ 'bar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
658 return ""
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
659 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
660
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
661 func Test_sub_cmd_8()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
662 set titlestring=%{TitleString()}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
663
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
664 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
665 call append(0, ['', 'test_one', 'test_two'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
666 call cursor(1,1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
667 /^test_one/s/.*/\="foo\nbar"/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
668 call assert_equal('foo', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
669 call assert_equal('bar', getline(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
670 call feedkeys(':/^test_two/s/.*/\="foo\nbar"/c', "t")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
671 call feedkeys("\<CR>y", "xt")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
672 call assert_equal('foo', getline(4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
673 call assert_equal('bar', getline(5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
674
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
675 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
676 set titlestring&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
677 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
678
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
679 func Test_sub_cmd_9()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
680 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
681 let input = ['1 aaa', '2 aaa', '3 aaa']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
682 call setline(1, input)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
683 func Foo()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
684 return submatch(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
685 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
686 %s/aaa/\=Foo()/gn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
687 call assert_equal(input, getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
688 call assert_equal(1, &modifiable)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
689
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
690 delfunc Foo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
691 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
692 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
693
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
694 func Test_sub_highlight_zero_match()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
695 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
696
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
697 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
698 call setline(1, ['one', 'two', 'three'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
699 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
700 call writefile(lines, 'XscriptSubHighlight', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
701 let buf = RunVimInTerminal('-S XscriptSubHighlight', #{rows: 8, cols: 60})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
702 call term_sendkeys(buf, ":%s/^/ /c\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
703 call VerifyScreenDump(buf, 'Test_sub_highlight_zer_match_1', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
704
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
705 call term_sendkeys(buf, "\<Esc>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
706 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
707 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
709 func Test_nocatch_sub_failure_handling()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
710 " normal error results in all replacements
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
711 func Foo()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
712 foobar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
713 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
714 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
715 call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
716 " need silent! to avoid a delay when entering Insert mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
717 silent! %s/aaa/\=Foo()/g
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
718 call assert_equal(['1 0', '2 0', '3 0'], getline(1, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
719
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
720 " Throw without try-catch causes abort after the first line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
721 " We cannot test this, since it would stop executing the test script.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
722
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
723 " try/catch does not result in any changes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
724 func! Foo()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
725 throw 'error'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
726 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
727 call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
728 let error_caught = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
729 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
730 %s/aaa/\=Foo()/g
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
731 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
732 let error_caught = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
733 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
734 call assert_equal(1, error_caught)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
735 call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
736
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
737 " Same, but using "n" flag so that "sandbox" gets set
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
738 call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
739 let error_caught = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
740 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
741 %s/aaa/\=Foo()/gn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
742 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
743 let error_caught = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
744 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
745 call assert_equal(1, error_caught)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
746 call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
747
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
748 delfunc Foo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
749 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
750 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
751
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
752 " Test ":s/pat/sub/" with different ~s in sub.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
753 func Test_replace_with_tilde()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
754 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
755 " Set the last replace string to empty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
756 s/^$//
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
757 call append(0, ['- Bug in "vPPPP" on this text:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
758 normal gg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
759 s/u/~u~/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
760 call assert_equal('- Bug in "vPPPP" on this text:', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
761 s/i/~u~/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
762 call assert_equal('- Bug uuun "vPPPP" on this text:', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
763 s/o/~~~/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
764 call assert_equal('- Bug uuun "vPPPP" uuuuuuuuun this text:', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
765 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
766 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
768 func Test_replace_keeppatterns()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
769 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
770 a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
771 foobar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
772
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
773 substitute foo asdf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
774
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
775 one two
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
776 .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
777
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
778 normal gg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
779 /^substitute
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
780 s/foo/bar/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
781 call assert_equal('foo', @/)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
782 call assert_equal('substitute bar asdf', getline('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
783
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
784 /^substitute
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
785 keeppatterns s/asdf/xyz/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
786 call assert_equal('^substitute', @/)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
787 call assert_equal('substitute bar xyz', getline('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
788
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
789 exe "normal /bar /e\<CR>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
790 call assert_equal(15, col('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
791 normal -
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
792 keeppatterns /xyz
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
793 call assert_equal('bar ', @/)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
794 call assert_equal('substitute bar xyz', getline('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
795 exe "normal 0dn"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
796 call assert_equal('xyz', getline('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
797
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
798 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
799 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
800
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
801 func Test_sub_beyond_end()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
802 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
803 call setline(1, '#')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
804 let @/ = '^#\n\zs'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
805 s///e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
806 call assert_equal('#', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
807 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
808 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
809
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
810 " Test for repeating last substitution using :~ and :&r
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
811 func Test_repeat_last_sub()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
812 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
813 call setline(1, ['blue green yellow orange white'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
814 s/blue/red/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
815 let @/ = 'yellow'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
816 ~
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
817 let @/ = 'white'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
818 :&r
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
819 let @/ = 'green'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
820 s//gray
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
821 call assert_equal('red gray red orange red', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
822 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
823 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
824
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
825 " Test for Vi compatible substitution:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
826 " \/{string}/, \?{string}? and \&{string}&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
827 func Test_sub_vi_compatibility()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
828 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
829 call setline(1, ['blue green yellow orange blue'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
830 let @/ = 'orange'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
831 s\/white/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
832 let @/ = 'blue'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
833 s\?amber?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
834 let @/ = 'white'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
835 s\&green&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
836 call assert_equal('amber green yellow white green', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
837 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
839 call assert_fails('vim9cmd s\/white/', 'E1270:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
840 call assert_fails('vim9cmd s\?white?', 'E1270:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
841 call assert_fails('vim9cmd s\&white&', 'E1270:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
842 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
843
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
844 " Test for substitute with the new text longer than the original text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
845 func Test_sub_expand_text()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
846 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
847 call setline(1, 'abcabcabcabcabcabcabcabc')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
848 s/b/\=repeat('B', 10)/g
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
849 call assert_equal(repeat('aBBBBBBBBBBc', 8), getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
850 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
851 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
852
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
853 " Test for command failures when the last substitute pattern is not set.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
854 func Test_sub_with_no_last_pat()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
855 let lines =<< trim [SCRIPT]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
856 call assert_fails('~', 'E33:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
857 call assert_fails('s//abc/g', 'E35:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
858 call assert_fails('s\/bar', 'E35:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
859 call assert_fails('s\&bar&', 'E33:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
860 call writefile(v:errors, 'Xresult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
861 qall!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
862 [SCRIPT]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
863 call writefile(lines, 'Xscript', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
864 if RunVim([], [], '--clean -S Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
865 call assert_equal([], readfile('Xresult'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
866 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
867
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
868 let lines =<< trim [SCRIPT]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
869 set cpo+=/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
870 call assert_fails('s/abc/%/', 'E33:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
871 call writefile(v:errors, 'Xresult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
872 qall!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
873 [SCRIPT]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
874 call writefile(lines, 'Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
875 if RunVim([], [], '--clean -S Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
876 call assert_equal([], readfile('Xresult'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
877 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
878
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
879 call delete('Xresult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
880 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
881
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
882 func Test_substitute()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
883 call assert_equal('a1a2a3a', substitute('123', '\zs', 'a', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
884 " Substitute with special keys
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
885 call assert_equal("a\<End>c", substitute('abc', "a.c", "a\<End>c", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
886 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
887
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
888 func Test_substitute_expr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
889 let g:val = 'XXX'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
890 call assert_equal('XXX', substitute('yyy', 'y*', '\=g:val', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
891 call assert_equal('XXX', substitute('yyy', 'y*', {-> g:val}, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
892 call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
893 \ '\=nr2char("0x" . submatch(1))', 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
894 call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
895 \ {-> nr2char("0x" . submatch(1))}, 'g'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
896
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
897 call assert_equal('231', substitute('123', '\(.\)\(.\)\(.\)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
898 \ {-> submatch(2) . submatch(3) . submatch(1)}, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
899
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
900 func Recurse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
901 return substitute('yyy', 'y\(.\)y', {-> submatch(1)}, '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
902 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
903 " recursive call works
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
904 call assert_equal('-y-x-', substitute('xxx', 'x\(.\)x', {-> '-' . Recurse() . '-' . submatch(1) . '-'}, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
905
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
906 call assert_fails("let s=submatch([])", 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
907 call assert_fails("let s=submatch(2, [])", 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
908 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
909
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
910 func Test_invalid_submatch()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
911 " This was causing invalid memory access in Vim-7.4.2232 and older
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
912 call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
913 call assert_fails('eval submatch(-1)', 'E935:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
914 call assert_equal('', submatch(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
915 call assert_equal('', submatch(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
916 call assert_equal([], submatch(0, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
917 call assert_equal([], submatch(1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
918 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
920 func Test_submatch_list_concatenate()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
921 let pat = 'A\(.\)'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
922 let Rep = {-> string([submatch(0, 1)] + [[submatch(1)]])}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
923 call substitute('A1', pat, Rep, '')->assert_equal("[['A1'], ['1']]")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
924 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
925
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
926 func Test_substitute_expr_arg()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
927 call assert_equal('123456789-123456789=', substitute('123456789',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
928 \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
929 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
930
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
931 call assert_equal('123456-123456=789', substitute('123456789',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
932 \ '\(.\)\(.\)\(.\)\(a*\)\(n*\)\(.\)\(.\)\(.\)\(x*\)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
933 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
934
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
935 call assert_equal('123456789-123456789x=', substitute('123456789',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
936 \ '\(.\)\(.\)\(.*\)',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
937 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . 'x' . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
938
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
939 call assert_fails("call substitute('xxx', '.', {m -> string(add(m, 'x'))}, '')", 'E742:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
940 call assert_fails("call substitute('xxx', '.', {m -> string(insert(m, 'x'))}, '')", 'E742:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
941 call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
942 call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
943 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
944
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
945 " Test for using a function to supply the substitute string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
946 func Test_substitute_using_func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
947 func Xfunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
948 return '1234'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
949 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
950 call assert_equal('a1234f', substitute('abcdef', 'b..e',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
951 \ function("Xfunc"), ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
952 delfunc Xfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
953 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
954
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
955 " Test for using submatch() with a multiline match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
956 func Test_substitute_multiline_submatch()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
957 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
958 call setline(1, ['line1', 'line2', 'line3', 'line4'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
959 %s/^line1\(\_.\+\)line4$/\=submatch(1)/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
960 call assert_equal(['', 'line2', 'line3', ''], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
961 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
962 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
963
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
964 func Test_substitute_skipped_range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
965 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
966 if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
967 /1/5/2/2/\n
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
968 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
969 call assert_equal([0, 1, 1, 0, 1], getcurpos())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
970 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
971 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
972
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
973 " Test using the 'gdefault' option (when on, flag 'g' is default on).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
974 func Test_substitute_gdefault()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
975 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
976
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
977 " First check without 'gdefault'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
978 call setline(1, 'foo bar foo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
979 s/foo/FOO/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
980 call assert_equal('FOO bar foo', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
981 call setline(1, 'foo bar foo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
982 s/foo/FOO/g
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
983 call assert_equal('FOO bar FOO', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
984 call setline(1, 'foo bar foo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
985 s/foo/FOO/gg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
986 call assert_equal('FOO bar foo', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
987
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
988 " Then check with 'gdefault'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
989 set gdefault
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
990 call setline(1, 'foo bar foo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
991 s/foo/FOO/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
992 call assert_equal('FOO bar FOO', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
993 call setline(1, 'foo bar foo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
994 s/foo/FOO/g
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
995 call assert_equal('FOO bar foo', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
996 call setline(1, 'foo bar foo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
997 s/foo/FOO/gg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
998 call assert_equal('FOO bar FOO', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1000 " Setting 'compatible' should reset 'gdefault'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1001 call assert_equal(1, &gdefault)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1002 set compatible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1003 call assert_equal(0, &gdefault)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1004 set nocompatible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1005 call assert_equal(0, &gdefault)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1006
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1007 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1008 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1009
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1010 " This was using "old_sub" after it was freed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1011 func Test_using_old_sub()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1012 set compatible maxfuncdepth=10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1013 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1014 call setline(1, 'some text.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1015 func Repl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1016 ~
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1017 s/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1018 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1019 silent! s/\%')/\=Repl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1020
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1021 delfunc Repl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1022 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1023 set nocompatible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1024 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1025
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1026 " This was switching windows in between computing the length and using it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1027 func Test_sub_change_window()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1028 silent! lfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1029 sil! norm o0000000000000000000000000000000000000000000000000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1030 func Repl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1031 lopen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1032 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1033 silent! s/\%')/\=Repl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1034 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1035 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1036 delfunc Repl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1037 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1038
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1039 " This was undoign a change in between computing the length and using it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1040 func Do_Test_sub_undo_change()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1041 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1042 norm o0000000000000000000000000000000000000000000000000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1043 silent! s/\%')/\=Repl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1044 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1045 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1047 func Test_sub_undo_change()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1048 func Repl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1049 silent! norm g-
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1050 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1051 call Do_Test_sub_undo_change()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1052
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1053 func! Repl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1054 silent earlier
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1055 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1056 call Do_Test_sub_undo_change()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1057
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1058 delfunc Repl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1059 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1060
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1061 " This was opening a command line window from the expression
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1062 func Test_sub_open_cmdline_win()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1063 " the error only happens in a very specific setup, run a new Vim instance to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1064 " get a clean starting point.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1065 let lines =<< trim [SCRIPT]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1066 set vb t_vb=
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1067 norm o0000000000000000000000000000000000000000000000000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1068 func Replace()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1069 norm q/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1070 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1071 s/\%')/\=Replace()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1072 redir >Xresult
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1073 messages
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1074 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1075 qall!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1076 [SCRIPT]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1077 call writefile(lines, 'Xscript', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1078 if RunVim([], [], '-u NONE -S Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1079 call assert_match('E565: Not allowed to change text or change window',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1080 \ readfile('Xresult')->join('XX'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1081 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1082
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1083 call delete('Xresult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1084 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1085
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1086 " This was editing a script file from the expression
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1087 func Test_sub_edit_scriptfile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1088 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1089 norm o0000000000000000000000000000000000000000000000000000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1090 func EditScript()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1091 silent! scr! Xsedfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1092 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1093 s/\%')/\=EditScript()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1094
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1095 delfunc EditScript
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1096 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1097 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1098
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1099 " This was editing another file from the expression.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1100 func Test_sub_expr_goto_other_file()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1101 call writefile([''], 'Xfileone', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1102 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1103 call setline(1, ['a', 'b', 'c', 'd',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1104 \ 'Xfileone zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1106 func g:SplitGotoFile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1107 exe "sil! norm 0\<C-W>gf"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1108 return ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1109 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1110
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1111 $
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1112 s/\%')/\=g:SplitGotoFile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1113
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1114 delfunc g:SplitGotoFile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1115 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1116 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1117
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1118 func Test_recursive_expr_substitute()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1119 " this was reading invalid memory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1120 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1121 func Repl(g, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1122 s
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1123 r%:s000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1124 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1125 next 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1126 let caught = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1127 s/\%')/\=Repl(0, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1128 qall!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1129 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1130 call writefile(lines, 'XexprSubst', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1131 call RunVim([], [], '--clean -S XexprSubst')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1132 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1133
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1134 " Test for the 2-letter and 3-letter :substitute commands
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1135 func Test_substitute_short_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1136 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1137 call setline(1, ['one', 'one one one'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1138 s/one/two
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1139 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1141 " :sc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1142 call feedkeys(":sc\<CR>y", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1143 call assert_equal('two one one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1144
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1145 " :scg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1146 call setline(2, 'one one one')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1147 call feedkeys(":scg\<CR>nyq", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1148 call assert_equal('one two one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1149
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1150 " :sci
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1151 call setline(2, 'ONE One onE')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1152 call feedkeys(":sci\<CR>y", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1153 call assert_equal('two One onE', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1155 " :scI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1156 set ignorecase
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1157 call setline(2, 'ONE One one')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1158 call feedkeys(":scI\<CR>y", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1159 call assert_equal('ONE One two', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1160 set ignorecase&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1161
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1162 " :scn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1163 call setline(2, 'one one one')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1164 let t = execute('scn')->split("\n")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1165 call assert_equal(['1 match on 1 line'], t)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1166 call assert_equal('one one one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1168 " :scp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1169 call setline(2, "\tone one one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1170 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1171 call feedkeys(":scp\<CR>y", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1172 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1173 call assert_equal(' two one one', output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1174 call assert_equal("\ttwo one one", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1175
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1176 " :scl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1177 call setline(2, "\tone one one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1178 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1179 call feedkeys(":scl\<CR>y", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1180 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1181 call assert_equal("^Itwo one one$", output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1182 call assert_equal("\ttwo one one", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1183
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1184 " :sgc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1185 call setline(2, 'one one one one one')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1186 call feedkeys(":sgc\<CR>nyyq", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1187 call assert_equal('one two two one one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1189 " :sg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1190 call setline(2, 'one one one')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1191 sg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1192 call assert_equal('two two two', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1193
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1194 " :sgi
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1195 call setline(2, 'ONE One onE')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1196 sgi
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1197 call assert_equal('two two two', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1198
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1199 " :sgI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1200 set ignorecase
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1201 call setline(2, 'ONE One one')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1202 sgI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1203 call assert_equal('ONE One two', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1204 set ignorecase&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1205
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1206 " :sgn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1207 call setline(2, 'one one one')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1208 let t = execute('sgn')->split("\n")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1209 call assert_equal(['3 matches on 1 line'], t)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1210 call assert_equal('one one one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1211
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1212 " :sgp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1213 call setline(2, "\tone one one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1214 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1215 sgp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1216 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1217 call assert_equal(' two two two', output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1218 call assert_equal("\ttwo two two", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1219
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1220 " :sgl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1221 call setline(2, "\tone one one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1222 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1223 sgl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1224 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1225 call assert_equal("^Itwo two two$", output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1226 call assert_equal("\ttwo two two", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1227
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1228 " :sgr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1229 call setline(2, "one one one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1230 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1231 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1232 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1233 sgr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1234 call assert_equal('xyz xyz xyz', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1235
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1236 " :sic
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1237 call cursor(1, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1238 s/one/two/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1239 call setline(2, "ONE One one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1240 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1241 call feedkeys(":sic\<CR>y", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1242 call assert_equal('two One one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1244 " :si
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1245 call setline(2, "ONE One one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1246 si
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1247 call assert_equal('two One one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1248
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1249 " :siI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1250 call setline(2, "ONE One one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1251 siI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1252 call assert_equal('ONE One two', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1253
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1254 " :sin
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1255 call setline(2, 'ONE One onE')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1256 let t = execute('sin')->split("\n")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1257 call assert_equal(['1 match on 1 line'], t)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1258 call assert_equal('ONE One onE', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1260 " :sip
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1261 call setline(2, "\tONE One onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1262 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1263 sip
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1264 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1265 call assert_equal(' two One onE', output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1266 call assert_equal("\ttwo One onE", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1267
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1268 " :sir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1269 call setline(2, "ONE One onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1270 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1271 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1272 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1273 sir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1274 call assert_equal('xyz One onE', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1275
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1276 " :sIc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1277 call cursor(1, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1278 s/one/two/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1279 call setline(2, "ONE One one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1280 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1281 call feedkeys(":sIc\<CR>y", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1282 call assert_equal('ONE One two', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1283
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1284 " :sIg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1285 call setline(2, "ONE one onE one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1286 sIg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1287 call assert_equal('ONE two onE two', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1288
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1289 " :sIi
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1290 call setline(2, "ONE One one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1291 sIi
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1292 call assert_equal('two One one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1293
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1294 " :sI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1295 call setline(2, "ONE One one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1296 sI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1297 call assert_equal('ONE One two', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1298
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1299 " :sIn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1300 call setline(2, 'ONE One one')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1301 let t = execute('sIn')->split("\n")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1302 call assert_equal(['1 match on 1 line'], t)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1303 call assert_equal('ONE One one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1304
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1305 " :sIp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1306 call setline(2, "\tONE One one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1307 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1308 sIp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1309 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1310 call assert_equal(' ONE One two', output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1311 call assert_equal("\tONE One two", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1313 " :sIl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1314 call setline(2, "\tONE onE one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1315 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1316 sIl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1317 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1318 call assert_equal("^IONE onE two$", output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1319 call assert_equal("\tONE onE two", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1320
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1321 " :sIr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1322 call setline(2, "ONE one onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1323 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1324 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1325 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1326 sIr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1327 call assert_equal('ONE xyz onE', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1328
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1329 " :src
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1330 call setline(2, "ONE one one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1331 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1332 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1333 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1334 call feedkeys(":src\<CR>y", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1335 call assert_equal('ONE xyz one', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1336
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1337 " :srg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1338 call setline(2, "one one one")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1339 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1340 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1341 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1342 srg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1343 call assert_equal('xyz xyz xyz', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1345 " :sri
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1346 call setline(2, "ONE one onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1347 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1348 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1349 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1350 sri
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1351 call assert_equal('xyz one onE', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1352
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1353 " :srI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1354 call setline(2, "ONE one onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1355 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1356 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1357 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1358 srI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1359 call assert_equal('ONE xyz onE', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1360
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1361 " :srn
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1362 call setline(2, "ONE one onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1363 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1364 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1365 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1366 let t = execute('srn')->split("\n")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1367 call assert_equal(['1 match on 1 line'], t)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1368 call assert_equal('ONE one onE', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1369
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1370 " :srp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1371 call setline(2, "\tONE one onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1372 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1373 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1374 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1375 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1376 srp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1377 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1378 call assert_equal(' ONE xyz onE', output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1379 call assert_equal("\tONE xyz onE", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1381 " :srl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1382 call setline(2, "\tONE one onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1383 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1384 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1385 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1386 redir => output
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1387 srl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1388 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1389 call assert_equal("^IONE xyz onE$", output->split("\n")[-1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1390 call assert_equal("\tONE xyz onE", getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1391
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1392 " :sr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1393 call setline(2, "ONE one onE")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1394 call cursor(2, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1395 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1396 let @/ = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1397 sr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1398 call assert_equal('ONE xyz onE', getline(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1399
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1400 " :sce
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1401 s/abc/xyz/e
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1402 call assert_fails("sc", 'E486:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1403 sce
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1404 " :sge
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1405 call assert_fails("sg", 'E486:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1406 sge
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1407 " :sie
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1408 call assert_fails("si", 'E486:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1409 sie
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1410 " :sIe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1411 call assert_fails("sI", 'E486:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1412 sIe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1413
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1414 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1415 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1417 " Check handling expanding "~" resulting in extremely long text.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1418 " FIXME: disabled, it takes too long to run on CI
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1419 "func Test_substitute_tilde_too_long()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1420 " enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1421 "
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1422 " s/.*/ixxx
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1423 " s//~~~~~~~~~AAAAAAA@(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1424 "
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1425 " " Either fails with "out of memory" or "text too long".
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1426 " " This can take a long time.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1427 " call assert_fails('sil! norm &&&&&&&&&', ['E1240:\|E342:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1428 "
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1429 " bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1430 "endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1431
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1432 " This should be done last to reveal a memory leak when vim_regsub_both() is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1433 " called to evaluate an expression but it is not used in a second call.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1434 func Test_z_substitute_expr_leak()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1435 func SubExpr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1436 ~n
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1437 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1438 silent! s/\%')/\=SubExpr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1439 delfunc SubExpr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1440 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1441
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32407
diff changeset
1442 " vim: shiftwidth=2 sts=2 expandtab