blob: 8d4b7cc604bec6b91367305b8bbb7975fd58a540 [file] [log] [blame]
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +02001" Test for the search command
2
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +01003source shared.vim
Bram Moolenaar9d34d902018-04-27 22:18:12 +02004source screendump.vim
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +01005
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +02006func Test_search_cmdline()
7 if !exists('+incsearch')
8 return
9 endif
10 " need to disable char_avail,
11 " so that expansion of commandline works
Bram Moolenaareb992cb2017-03-09 18:20:16 +010012 call test_override("char_avail", 1)
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020013 new
14 call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar'])
15 " Test 1
16 " CTRL-N / CTRL-P skips through the previous search history
17 set noincsearch
18 :1
19 call feedkeys("/foobar\<cr>", 'tx')
20 call feedkeys("/the\<cr>",'tx')
21 call assert_equal('the', @/)
Bram Moolenaar11956692016-08-27 16:26:56 +020022 call feedkeys("/thes\<C-P>\<C-P>\<cr>",'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020023 call assert_equal('foobar', @/)
24
25 " Test 2
Bram Moolenaar11956692016-08-27 16:26:56 +020026 " Ctrl-G goes from one match to the next
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020027 " until the end of the buffer
28 set incsearch nowrapscan
29 :1
30 " first match
31 call feedkeys("/the\<cr>", 'tx')
32 call assert_equal(' 2 these', getline('.'))
33 :1
34 " second match
Bram Moolenaar11956692016-08-27 16:26:56 +020035 call feedkeys("/the\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020036 call assert_equal(' 3 the', getline('.'))
Bram Moolenaardda933d2016-09-03 21:04:58 +020037 call assert_equal([0, 0, 0, 0], getpos('"'))
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020038 :1
39 " third match
Bram Moolenaar11956692016-08-27 16:26:56 +020040 call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020041 call assert_equal(' 4 their', getline('.'))
42 :1
43 " fourth match
Bram Moolenaar11956692016-08-27 16:26:56 +020044 call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020045 call assert_equal(' 5 there', getline('.'))
46 :1
47 " fifth match
Bram Moolenaar11956692016-08-27 16:26:56 +020048 call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020049 call assert_equal(' 6 their', getline('.'))
50 :1
51 " sixth match
Bram Moolenaar11956692016-08-27 16:26:56 +020052 call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020053 call assert_equal(' 7 the', getline('.'))
54 :1
55 " seventh match
Bram Moolenaar11956692016-08-27 16:26:56 +020056 call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020057 call assert_equal(' 8 them', getline('.'))
58 :1
59 " eigth match
Bram Moolenaar11956692016-08-27 16:26:56 +020060 call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020061 call assert_equal(' 9 these', getline('.'))
62 :1
63 " no further match
Bram Moolenaar11956692016-08-27 16:26:56 +020064 call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020065 call assert_equal(' 9 these', getline('.'))
Bram Moolenaardda933d2016-09-03 21:04:58 +020066 call assert_equal([0, 0, 0, 0], getpos('"'))
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020067
68 " Test 3
Bram Moolenaar11956692016-08-27 16:26:56 +020069 " Ctrl-G goes from one match to the next
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020070 " and continues back at the top
71 set incsearch wrapscan
72 :1
73 " first match
74 call feedkeys("/the\<cr>", 'tx')
75 call assert_equal(' 2 these', getline('.'))
76 :1
77 " second match
Bram Moolenaar11956692016-08-27 16:26:56 +020078 call feedkeys("/the\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020079 call assert_equal(' 3 the', getline('.'))
80 :1
81 " third match
Bram Moolenaar11956692016-08-27 16:26:56 +020082 call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020083 call assert_equal(' 4 their', getline('.'))
84 :1
85 " fourth match
Bram Moolenaar11956692016-08-27 16:26:56 +020086 call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020087 call assert_equal(' 5 there', getline('.'))
88 :1
89 " fifth match
Bram Moolenaar11956692016-08-27 16:26:56 +020090 call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020091 call assert_equal(' 6 their', getline('.'))
92 :1
93 " sixth match
Bram Moolenaar11956692016-08-27 16:26:56 +020094 call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020095 call assert_equal(' 7 the', getline('.'))
96 :1
97 " seventh match
Bram Moolenaar11956692016-08-27 16:26:56 +020098 call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +020099 call assert_equal(' 8 them', getline('.'))
100 :1
101 " eigth match
Bram Moolenaar11956692016-08-27 16:26:56 +0200102 call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200103 call assert_equal(' 9 these', getline('.'))
104 :1
105 " back at first match
Bram Moolenaar11956692016-08-27 16:26:56 +0200106 call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200107 call assert_equal(' 2 these', getline('.'))
108
109 " Test 4
Bram Moolenaar11956692016-08-27 16:26:56 +0200110 " CTRL-T goes to the previous match
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200111 set incsearch nowrapscan
112 $
113 " first match
114 call feedkeys("?the\<cr>", 'tx')
115 call assert_equal(' 9 these', getline('.'))
116 $
117 " first match
Bram Moolenaar11956692016-08-27 16:26:56 +0200118 call feedkeys("?the\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200119 call assert_equal(' 9 these', getline('.'))
120 $
121 " second match
Bram Moolenaar11956692016-08-27 16:26:56 +0200122 call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200123 call assert_equal(' 8 them', getline('.'))
124 $
125 " last match
Bram Moolenaar11956692016-08-27 16:26:56 +0200126 call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200127 call assert_equal(' 2 these', getline('.'))
128 $
129 " last match
Bram Moolenaar11956692016-08-27 16:26:56 +0200130 call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200131 call assert_equal(' 2 these', getline('.'))
132
133 " Test 5
Bram Moolenaar11956692016-08-27 16:26:56 +0200134 " CTRL-T goes to the previous match
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200135 set incsearch wrapscan
136 $
137 " first match
138 call feedkeys("?the\<cr>", 'tx')
139 call assert_equal(' 9 these', getline('.'))
140 $
141 " first match at the top
Bram Moolenaar11956692016-08-27 16:26:56 +0200142 call feedkeys("?the\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200143 call assert_equal(' 2 these', getline('.'))
144 $
145 " second match
Bram Moolenaar11956692016-08-27 16:26:56 +0200146 call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200147 call assert_equal(' 8 them', getline('.'))
148 $
149 " last match
Bram Moolenaar11956692016-08-27 16:26:56 +0200150 call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200151 call assert_equal(' 2 these', getline('.'))
152 $
153 " back at the bottom of the buffer
Bram Moolenaar11956692016-08-27 16:26:56 +0200154 call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200155 call assert_equal(' 9 these', getline('.'))
156
157 " Test 6
158 " CTRL-L adds to the search pattern
159 set incsearch wrapscan
160 1
161 " first match
162 call feedkeys("/the\<c-l>\<cr>", 'tx')
163 call assert_equal(' 2 these', getline('.'))
164 1
165 " go to next match of 'thes'
Bram Moolenaar11956692016-08-27 16:26:56 +0200166 call feedkeys("/the\<c-l>\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200167 call assert_equal(' 9 these', getline('.'))
168 1
169 " wrap around
Bram Moolenaar11956692016-08-27 16:26:56 +0200170 call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200171 call assert_equal(' 2 these', getline('.'))
172 1
173 " wrap around
174 set nowrapscan
Bram Moolenaar11956692016-08-27 16:26:56 +0200175 call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200176 call assert_equal(' 9 these', getline('.'))
177
178 " Test 7
179 " <bs> remove from match, but stay at current match
180 set incsearch wrapscan
181 1
182 " first match
183 call feedkeys("/thei\<cr>", 'tx')
184 call assert_equal(' 4 their', getline('.'))
185 1
186 " delete one char, add another
187 call feedkeys("/thei\<bs>s\<cr>", 'tx')
Bram Moolenaardda933d2016-09-03 21:04:58 +0200188 call assert_equal(' 2 these', getline('.'))
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200189 1
190 " delete one char, add another, go to previous match, add one char
Bram Moolenaar11956692016-08-27 16:26:56 +0200191 call feedkeys("/thei\<bs>s\<bs>\<C-T>\<c-l>\<cr>", 'tx')
Bram Moolenaardda933d2016-09-03 21:04:58 +0200192 call assert_equal(' 9 these', getline('.'))
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200193 1
194 " delete all chars, start from the beginning again
195 call feedkeys("/them". repeat("\<bs>",4).'the\>'."\<cr>", 'tx')
196 call assert_equal(' 3 the', getline('.'))
197
198 " clean up
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100199 call test_override("char_avail", 0)
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200200 bw!
201endfunc
202
203func Test_search_cmdline2()
204 if !exists('+incsearch')
205 return
206 endif
207 " need to disable char_avail,
208 " so that expansion of commandline works
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100209 call test_override("char_avail", 1)
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200210 new
211 call setline(1, [' 1', ' 2 these', ' 3 the theother'])
212 " Test 1
Bram Moolenaar11956692016-08-27 16:26:56 +0200213 " Ctrl-T goes correctly back and forth
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200214 set incsearch
215 1
216 " first match
217 call feedkeys("/the\<cr>", 'tx')
218 call assert_equal(' 2 these', getline('.'))
219 1
220 " go to next match (on next line)
Bram Moolenaar11956692016-08-27 16:26:56 +0200221 call feedkeys("/the\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200222 call assert_equal(' 3 the theother', getline('.'))
223 1
224 " go to next match (still on line 3)
Bram Moolenaar11956692016-08-27 16:26:56 +0200225 call feedkeys("/the\<C-G>\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200226 call assert_equal(' 3 the theother', getline('.'))
227 1
228 " go to next match (still on line 3)
Bram Moolenaar11956692016-08-27 16:26:56 +0200229 call feedkeys("/the\<C-G>\<C-G>\<C-G>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200230 call assert_equal(' 3 the theother', getline('.'))
231 1
232 " go to previous match (on line 3)
Bram Moolenaar11956692016-08-27 16:26:56 +0200233 call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200234 call assert_equal(' 3 the theother', getline('.'))
235 1
236 " go to previous match (on line 3)
Bram Moolenaar11956692016-08-27 16:26:56 +0200237 call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200238 call assert_equal(' 3 the theother', getline('.'))
239 1
240 " go to previous match (on line 2)
Bram Moolenaar11956692016-08-27 16:26:56 +0200241 call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<C-T>\<cr>", 'tx')
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200242 call assert_equal(' 2 these', getline('.'))
243
Bram Moolenaardda933d2016-09-03 21:04:58 +0200244 " Test 2: keep the view,
245 " after deleting a character from the search cmd
246 call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar'])
247 resize 5
248 1
249 call feedkeys("/foo\<bs>\<cr>", 'tx')
250 redraw
251 call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview())
252
253 " remove all history entries
254 for i in range(10)
255 call histdel('/')
256 endfor
257
258 " Test 3: reset the view,
259 " after deleting all characters from the search cmd
260 norm! 1gg0
261 " unfortunately, neither "/foo\<c-w>\<cr>", nor "/foo\<bs>\<bs>\<bs>\<cr>",
262 " nor "/foo\<c-u>\<cr>" works to delete the commandline.
263 " In that case Vim should return "E35 no previous regular expression",
264 " but it looks like Vim still sees /foo and therefore the test fails.
265 " Therefore, disableing this test
266 "call assert_fails(feedkeys("/foo\<c-w>\<cr>", 'tx'), 'E35')
267 "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview())
268
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200269 " clean up
Bram Moolenaardda933d2016-09-03 21:04:58 +0200270 set noincsearch
Bram Moolenaareb992cb2017-03-09 18:20:16 +0100271 call test_override("char_avail", 0)
Bram Moolenaar4d6f32c2016-08-26 19:13:46 +0200272 bw!
273endfunc
Bram Moolenaarea683da2016-09-09 21:41:34 +0200274
275func Test_use_sub_pat()
276 split
277 let @/ = ''
278 func X()
279 s/^/a/
280 /
281 endfunc
282 call X()
283 bwipe!
284endfunc
Bram Moolenaar6e450a52017-01-06 20:03:58 +0100285
286func Test_searchpair()
287 new
288 call setline(1, ['other code here', '', '[', '" cursor here', ']'])
289 4
Bram Moolenaar3dddb092018-06-24 19:01:59 +0200290 let a = searchpair('\[','',']','bW')
Bram Moolenaar6e450a52017-01-06 20:03:58 +0100291 call assert_equal(3, a)
292 set nomagic
293 4
Bram Moolenaar3dddb092018-06-24 19:01:59 +0200294 let a = searchpair('\[','',']','bW')
Bram Moolenaar6e450a52017-01-06 20:03:58 +0100295 call assert_equal(3, a)
296 set magic
297 q!
298endfunc
299
Bram Moolenaar3dddb092018-06-24 19:01:59 +0200300func Test_searchpair_errors()
301 call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String')
302 call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String')
303 call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String')
304 call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags')
305 call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 0, 99, 100)", 'E475: Invalid argument: 0')
306 call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99')
307 call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100')
308endfunc
309
Bram Moolenaar48570482017-10-30 21:48:41 +0100310func Test_searchpair_skip()
311 func Zero()
312 return 0
313 endfunc
314 func Partial(x)
315 return a:x
316 endfunc
317 new
318 call setline(1, ['{', 'foo', 'foo', 'foo', '}'])
319 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', ''))
320 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '0'))
321 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0}))
322 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero')))
323 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0])))
Bram Moolenaar48570482017-10-30 21:48:41 +0100324 bw!
325endfunc
326
Bram Moolenaara43ebe92018-07-14 17:25:01 +0200327func Test_searchpair_leak()
328 new
329 call setline(1, 'if one else another endif')
330
331 " The error in the skip expression caused memory to leak.
332 call assert_fails("call searchpair('\\<if\\>', '\\<else\\>', '\\<endif\\>', '', '\"foo\" 2')", 'E15:')
333
334 bwipe!
335endfunc
336
Bram Moolenaar66727e12017-03-01 22:17:05 +0100337func Test_searchc()
338 " These commands used to cause memory overflow in searchc().
339 new
340 norm ixx
341 exe "norm 0t\u93cf"
342 bw!
343endfunc
Bram Moolenaara693d052017-06-29 22:23:06 +0200344
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200345func Cmdline3_prep()
346 " need to disable char_avail,
347 " so that expansion of commandline works
348 call test_override("char_avail", 1)
349 new
350 call setline(1, [' 1', ' 2 the~e', ' 3 the theother'])
351 set incsearch
352endfunc
353
Bram Moolenaar976b8472018-08-12 15:49:47 +0200354func Incsearch_cleanup()
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200355 set noincsearch
356 call test_override("char_avail", 0)
357 bw!
358endfunc
359
Bram Moolenaar21f990e2018-08-11 19:20:49 +0200360func Test_search_cmdline3()
361 if !exists('+incsearch')
362 return
363 endif
364 call Cmdline3_prep()
365 1
366 " first match
367 call feedkeys("/the\<c-l>\<cr>", 'tx')
368 call assert_equal(' 2 the~e', getline('.'))
369
Bram Moolenaar976b8472018-08-12 15:49:47 +0200370 call Incsearch_cleanup()
Bram Moolenaar21f990e2018-08-11 19:20:49 +0200371endfunc
372
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200373func Test_search_cmdline3s()
374 if !exists('+incsearch')
375 return
376 endif
377 call Cmdline3_prep()
378 1
379 call feedkeys(":%s/the\<c-l>/xxx\<cr>", 'tx')
380 call assert_equal(' 2 xxxe', getline('.'))
Bram Moolenaar21f990e2018-08-11 19:20:49 +0200381 undo
382 call feedkeys(":%subs/the\<c-l>/xxx\<cr>", 'tx')
383 call assert_equal(' 2 xxxe', getline('.'))
384 undo
385 call feedkeys(":%substitute/the\<c-l>/xxx\<cr>", 'tx')
386 call assert_equal(' 2 xxxe', getline('.'))
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200387
Bram Moolenaar976b8472018-08-12 15:49:47 +0200388 call Incsearch_cleanup()
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200389endfunc
390
391func Test_search_cmdline3g()
392 if !exists('+incsearch')
393 return
394 endif
395 call Cmdline3_prep()
396 1
397 call feedkeys(":g/the\<c-l>/d\<cr>", 'tx')
398 call assert_equal(' 3 the theother', getline(2))
Bram Moolenaar21f990e2018-08-11 19:20:49 +0200399 undo
400 call feedkeys(":global/the\<c-l>/d\<cr>", 'tx')
401 call assert_equal(' 3 the theother', getline(2))
Bram Moolenaardef7b1d2018-08-13 22:54:35 +0200402 undo
403 call feedkeys(":g!/the\<c-l>/d\<cr>", 'tx')
404 call assert_equal(1, line('$'))
405 call assert_equal(' 2 the~e', getline(1))
406 undo
407 call feedkeys(":global!/the\<c-l>/d\<cr>", 'tx')
408 call assert_equal(1, line('$'))
409 call assert_equal(' 2 the~e', getline(1))
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200410
Bram Moolenaar976b8472018-08-12 15:49:47 +0200411 call Incsearch_cleanup()
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200412endfunc
413
414func Test_search_cmdline3v()
415 if !exists('+incsearch')
416 return
417 endif
418 call Cmdline3_prep()
419 1
420 call feedkeys(":v/the\<c-l>/d\<cr>", 'tx')
421 call assert_equal(1, line('$'))
422 call assert_equal(' 2 the~e', getline(1))
Bram Moolenaar21f990e2018-08-11 19:20:49 +0200423 undo
424 call feedkeys(":vglobal/the\<c-l>/d\<cr>", 'tx')
425 call assert_equal(1, line('$'))
426 call assert_equal(' 2 the~e', getline(1))
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200427
Bram Moolenaar976b8472018-08-12 15:49:47 +0200428 call Incsearch_cleanup()
Bram Moolenaarb0acacd2018-08-11 16:40:43 +0200429endfunc
430
Bram Moolenaarda5116d2017-07-01 23:11:17 +0200431func Test_search_cmdline4()
432 if !exists('+incsearch')
433 return
434 endif
435 " need to disable char_avail,
436 " so that expansion of commandline works
437 call test_override("char_avail", 1)
438 new
439 call setline(1, [' 1 the first', ' 2 the second', ' 3 the third'])
440 set incsearch
441 $
442 call feedkeys("?the\<c-g>\<cr>", 'tx')
443 call assert_equal(' 3 the third', getline('.'))
444 $
445 call feedkeys("?the\<c-g>\<c-g>\<cr>", 'tx')
446 call assert_equal(' 1 the first', getline('.'))
447 $
448 call feedkeys("?the\<c-g>\<c-g>\<c-g>\<cr>", 'tx')
449 call assert_equal(' 2 the second', getline('.'))
450 $
451 call feedkeys("?the\<c-t>\<cr>", 'tx')
452 call assert_equal(' 1 the first', getline('.'))
453 $
454 call feedkeys("?the\<c-t>\<c-t>\<cr>", 'tx')
455 call assert_equal(' 3 the third', getline('.'))
456 $
457 call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx')
458 call assert_equal(' 2 the second', getline('.'))
459 " clean up
460 set noincsearch
461 call test_override("char_avail", 0)
462 bw!
463endfunc
Bram Moolenaardb510072017-09-28 21:52:17 +0200464
Bram Moolenaarf8e8c062017-10-22 14:44:17 +0200465func Test_search_cmdline5()
466 if !exists('+incsearch')
467 return
468 endif
469 " Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work
470 " regardless char_avail.
471 new
472 call setline(1, [' 1 the first', ' 2 the second', ' 3 the third'])
473 set incsearch
474 1
475 call feedkeys("/the\<c-g>\<c-g>\<cr>", 'tx')
476 call assert_equal(' 3 the third', getline('.'))
477 $
478 call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx')
479 call assert_equal(' 2 the second', getline('.'))
480 " clean up
481 set noincsearch
482 bw!
483endfunc
484
Bram Moolenaarf8f8b2e2017-11-02 19:08:48 +0100485func Test_search_cmdline6()
486 " Test that consecutive matches
487 " are caught by <c-g>/<c-t>
488 if !exists('+incsearch')
489 return
490 endif
491 " need to disable char_avail,
492 " so that expansion of commandline works
493 call test_override("char_avail", 1)
494 new
495 call setline(1, [' bbvimb', ''])
496 set incsearch
497 " first match
498 norm! gg0
499 call feedkeys("/b\<cr>", 'tx')
500 call assert_equal([0,1,2,0], getpos('.'))
501 " second match
502 norm! gg0
503 call feedkeys("/b\<c-g>\<cr>", 'tx')
504 call assert_equal([0,1,3,0], getpos('.'))
505 " third match
506 norm! gg0
507 call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx')
508 call assert_equal([0,1,7,0], getpos('.'))
509 " first match again
510 norm! gg0
511 call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx')
512 call assert_equal([0,1,2,0], getpos('.'))
513 set nowrapscan
514 " last match
515 norm! gg0
516 call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx')
517 call assert_equal([0,1,7,0], getpos('.'))
518 " clean up
519 set wrapscan&vim
520 set noincsearch
521 call test_override("char_avail", 0)
522 bw!
523endfunc
524
525func Test_search_cmdline7()
526 " Test that an pressing <c-g> in an empty command line
527 " does not move the cursor
528 if !exists('+incsearch')
529 return
530 endif
531 " need to disable char_avail,
532 " so that expansion of commandline works
533 call test_override("char_avail", 1)
534 new
Bram Moolenaar21f990e2018-08-11 19:20:49 +0200535 let @/ = 'b'
Bram Moolenaarf8f8b2e2017-11-02 19:08:48 +0100536 call setline(1, [' bbvimb', ''])
537 set incsearch
538 " first match
539 norm! gg0
540 " moves to next match of previous search pattern, just like /<cr>
541 call feedkeys("/\<c-g>\<cr>", 'tx')
542 call assert_equal([0,1,2,0], getpos('.'))
543 " moves to next match of previous search pattern, just like /<cr>
544 call feedkeys("/\<cr>", 'tx')
545 call assert_equal([0,1,3,0], getpos('.'))
546 " moves to next match of previous search pattern, just like /<cr>
547 call feedkeys("/\<c-t>\<cr>", 'tx')
548 call assert_equal([0,1,7,0], getpos('.'))
Bram Moolenaard0480092017-11-16 22:20:39 +0100549
550 " using an offset uses the last search pattern
551 call cursor(1, 1)
552 call setline(1, ['1 bbvimb', ' 2 bbvimb'])
553 let @/ = 'b'
554 call feedkeys("//e\<c-g>\<cr>", 'tx')
555 call assert_equal('1 bbvimb', getline('.'))
556 call assert_equal(4, col('.'))
557
Bram Moolenaarf8f8b2e2017-11-02 19:08:48 +0100558 set noincsearch
559 call test_override("char_avail", 0)
560 bw!
561endfunc
562
563func Test_search_cmdline8()
564 " Highlighting is cleared in all windows
565 " since hls applies to all windows
566 if !exists('+incsearch') || !has('terminal') || has('gui_running') || winwidth(0) < 30
567 return
568 endif
569 if has("win32")
570 throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet"
571 endif
572 let h = winheight(0)
573 if h < 3
574 return
575 endif
576 " Prepare buffer text
577 let lines = ['abb vim vim vi', 'vimvivim']
578 call writefile(lines, 'Xsearch.txt')
Bram Moolenaar13deab82017-11-04 18:48:43 +0100579 let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3})
Bram Moolenaarf8f8b2e2017-11-02 19:08:48 +0100580
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200581 call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])})
Bram Moolenaarf8f8b2e2017-11-02 19:08:48 +0100582
Bram Moolenaar13deab82017-11-04 18:48:43 +0100583 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>")
584 call term_sendkeys(buf, ":14vsp\<cr>")
585 call term_sendkeys(buf, "/vim\<cr>")
586 call term_sendkeys(buf, "/b\<esc>")
587 call term_sendkeys(buf, "gg0")
588 call term_wait(buf, 500)
589 let screen_line = term_scrape(buf, 1)
Bram Moolenaarf8f8b2e2017-11-02 19:08:48 +0100590 let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr,
591 \ screen_line[18].attr, screen_line[19].attr]
592 call assert_notequal(a0, a1)
593 call assert_notequal(a0, a3)
594 call assert_notequal(a1, a2)
595 call assert_equal(a0, a2)
596 call assert_equal(a1, a3)
597 " clean up
598 call delete('Xsearch.txt')
599
600 bwipe!
601endfunc
602
Bram Moolenaardb510072017-09-28 21:52:17 +0200603" Tests for regexp with various magic settings
604func Test_search_regexp()
605 enew!
606
607 put ='1 a aa abb abbccc'
608 exe 'normal! /a*b\{2}c\+/e' . "\<CR>"
609 call assert_equal([0, 2, 17, 0], getpos('.'))
610
611 put ='2 d dd dee deefff'
612 exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>"
613 call assert_equal([0, 3, 17, 0], getpos('.'))
614
615 set nomagic
616 put ='3 g gg ghh ghhiii'
617 exe 'normal! /g\*h\{2}i\+/e' . "\<CR>"
618 call assert_equal([0, 4, 17, 0], getpos('.'))
619
620 put ='4 j jj jkk jkklll'
621 exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>"
622 call assert_equal([0, 5, 17, 0], getpos('.'))
623
624 put ='5 m mm mnn mnnooo'
625 exe 'normal! /\vm*n{2}o+/e' . "\<CR>"
626 call assert_equal([0, 6, 17, 0], getpos('.'))
627
628 put ='6 x ^aa$ x'
629 exe 'normal! /\V^aa$' . "\<CR>"
630 call assert_equal([0, 7, 5, 0], getpos('.'))
631
632 set magic
633 put ='7 (a)(b) abbaa'
634 exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>"
635 call assert_equal([0, 8, 14, 0], getpos('.'))
636
637 put ='8 axx [ab]xx'
638 exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>"
639 call assert_equal([0, 9, 7, 0], getpos('.'))
640
641 set undolevels=100
642 put ='9 foobar'
643 put =''
644 exe "normal! a\<C-G>u\<Esc>"
645 normal G
646 exe 'normal! dv?bar?' . "\<CR>"
647 call assert_equal('9 foo', getline('.'))
648 call assert_equal([0, 10, 5, 0], getpos('.'))
649 call assert_equal(10, line('$'))
650 normal u
651 call assert_equal('9 foobar', getline('.'))
652 call assert_equal([0, 10, 6, 0], getpos('.'))
653 call assert_equal(11, line('$'))
654
655 set undolevels&
656 enew!
657endfunc
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100658
659func Test_search_cmdline_incsearch_highlight()
660 if !exists('+incsearch')
661 return
662 endif
663 set incsearch hlsearch
664 " need to disable char_avail,
665 " so that expansion of commandline works
666 call test_override("char_avail", 1)
667 new
668 call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third'])
669
670 1
671 call feedkeys("/second\<cr>", 'tx')
672 call assert_equal('second', @/)
673 call assert_equal(' 2 the second', getline('.'))
674
675 " Canceling search won't change @/
676 1
677 let @/ = 'last pattern'
678 call feedkeys("/third\<C-c>", 'tx')
679 call assert_equal('last pattern', @/)
680 call feedkeys("/third\<Esc>", 'tx')
681 call assert_equal('last pattern', @/)
682 call feedkeys("/3\<bs>\<bs>", 'tx')
683 call assert_equal('last pattern', @/)
684 call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx')
685 call assert_equal('last pattern', @/)
686
687 " clean up
688 set noincsearch nohlsearch
689 bw!
690endfunc
691
692func Test_search_cmdline_incsearch_highlight_attr()
693 if !exists('+incsearch') || !has('terminal') || has('gui_running')
694 return
695 endif
696 let h = winheight(0)
697 if h < 3
698 return
699 endif
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100700
701 " Prepare buffer text
Bram Moolenaar13deab82017-11-04 18:48:43 +0100702 let lines = ['abb vim vim vi', 'vimvivim']
703 call writefile(lines, 'Xsearch.txt')
704 let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3})
705
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200706 call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])})
Bram Moolenaarb50773c2018-01-30 22:31:19 +0100707 " wait for vim to complete initialization
708 call term_wait(buf)
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100709
710 " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight
Bram Moolenaar13deab82017-11-04 18:48:43 +0100711 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>")
712 call term_sendkeys(buf, '/b')
713 call term_wait(buf, 200)
714 let screen_line1 = term_scrape(buf, 1)
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100715 call assert_true(len(screen_line1) > 2)
716 " a0: attr_normal
717 let a0 = screen_line1[0].attr
718 " a1: attr_incsearch
719 let a1 = screen_line1[1].attr
720 " a2: attr_hlsearch
721 let a2 = screen_line1[2].attr
722 call assert_notequal(a0, a1)
723 call assert_notequal(a0, a2)
724 call assert_notequal(a1, a2)
Bram Moolenaar13deab82017-11-04 18:48:43 +0100725 call term_sendkeys(buf, "\<cr>gg0")
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100726
727 " Test incremental highlight search
Bram Moolenaar13deab82017-11-04 18:48:43 +0100728 call term_sendkeys(buf, "/vim")
729 call term_wait(buf, 200)
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100730 " Buffer:
731 " abb vim vim vi
732 " vimvivim
733 " Search: /vim
734 let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0]
735 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2]
Bram Moolenaar13deab82017-11-04 18:48:43 +0100736 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
737 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100738
739 " Test <C-g>
Bram Moolenaar13deab82017-11-04 18:48:43 +0100740 call term_sendkeys(buf, "\<C-g>\<C-g>")
741 call term_wait(buf, 200)
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100742 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0]
743 let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2]
Bram Moolenaar13deab82017-11-04 18:48:43 +0100744 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
745 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100746
747 " Test <C-t>
Bram Moolenaar13deab82017-11-04 18:48:43 +0100748 call term_sendkeys(buf, "\<C-t>")
749 call term_wait(buf, 200)
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100750 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0]
751 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2]
Bram Moolenaar13deab82017-11-04 18:48:43 +0100752 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
753 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100754
755 " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight)
Bram Moolenaar13deab82017-11-04 18:48:43 +0100756 call term_sendkeys(buf, "\<cr>")
757 call term_wait(buf, 200)
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100758 let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0]
759 let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2]
Bram Moolenaar13deab82017-11-04 18:48:43 +0100760 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
761 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100762
763 " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight)
Bram Moolenaar13deab82017-11-04 18:48:43 +0100764 call term_sendkeys(buf, ":1\<cr>")
765 call term_sendkeys(buf, ":set nohlsearch\<cr>")
766 call term_sendkeys(buf, "/vim")
767 call term_wait(buf, 200)
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100768 let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0]
769 let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0]
Bram Moolenaar13deab82017-11-04 18:48:43 +0100770 call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
771 call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
Bram Moolenaarf8f8b2e2017-11-02 19:08:48 +0100772 call delete('Xsearch.txt')
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100773
Bram Moolenaarb94340c2017-11-02 16:16:31 +0100774 call delete('Xsearch.txt')
Bram Moolenaar2e51d9a2017-10-29 16:40:30 +0100775 bwipe!
776endfunc
Bram Moolenaarf45938c2017-11-02 15:59:57 +0100777
Bram Moolenaar9d34d902018-04-27 22:18:12 +0200778func Test_incsearch_scrolling()
779 if !CanRunVimInTerminal()
780 return
781 endif
782 call assert_equal(0, &scrolloff)
783 call writefile([
784 \ 'let dots = repeat(".", 120)',
785 \ 'set incsearch cmdheight=2 scrolloff=0',
786 \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])',
787 \ 'normal gg',
788 \ 'redraw',
789 \ ], 'Xscript')
790 let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70})
791 " Need to send one key at a time to force a redraw
792 call term_sendkeys(buf, '/')
793 sleep 100m
794 call term_sendkeys(buf, 't')
795 sleep 100m
796 call term_sendkeys(buf, 'a')
797 sleep 100m
798 call term_sendkeys(buf, 'r')
799 sleep 100m
800 call term_sendkeys(buf, 'g')
801 call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {})
802
803 call term_sendkeys(buf, "\<Esc>")
804 call StopVimInTerminal(buf)
805 call delete('Xscript')
806endfunc
807
Bram Moolenaar976b8472018-08-12 15:49:47 +0200808func Test_incsearch_substitute()
809 if !exists('+incsearch')
810 return
811 endif
812 call test_override("char_avail", 1)
813 new
814 set incsearch
815 for n in range(1, 10)
816 call setline(n, 'foo ' . n)
817 endfor
818 4
819 call feedkeys(":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>", 'tx')
820 call assert_equal('foo 3', getline(3))
821 call assert_equal('xxx 4', getline(4))
822 call assert_equal('xxx 5', getline(5))
823 call assert_equal('xxx 6', getline(6))
824 call assert_equal('foo 7', getline(7))
825
826 call Incsearch_cleanup()
827endfunc
828
Bram Moolenaar164251f2018-08-12 16:26:58 +0200829" Similar to Test_incsearch_substitute() but with a screendump halfway.
830func Test_incsearch_substitute_dump()
831 if !exists('+incsearch')
832 return
833 endif
834 if !CanRunVimInTerminal()
835 return
836 endif
837 call writefile([
838 \ 'set incsearch hlsearch scrolloff=0',
839 \ 'for n in range(1, 10)',
840 \ ' call setline(n, "foo " . n)',
841 \ 'endfor',
842 \ '3',
843 \ ], 'Xis_subst_script')
844 let buf = RunVimInTerminal('-S Xis_subst_script', {'rows': 9, 'cols': 70})
845 " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by
846 " the 'ambiwidth' check.
847 sleep 100m
848
849 " Need to send one key at a time to force a redraw.
Bram Moolenaarc7f08b72018-08-12 17:39:14 +0200850 " Select three lines at the cursor with typed pattern.
Bram Moolenaar164251f2018-08-12 16:26:58 +0200851 call term_sendkeys(buf, ':.,.+2s/')
852 sleep 100m
853 call term_sendkeys(buf, 'f')
854 sleep 100m
855 call term_sendkeys(buf, 'o')
856 sleep 100m
857 call term_sendkeys(buf, 'o')
Bram Moolenaarc7f08b72018-08-12 17:39:14 +0200858 sleep 100m
Bram Moolenaar164251f2018-08-12 16:26:58 +0200859 call VerifyScreenDump(buf, 'Test_incsearch_substitute_01', {})
Bram Moolenaarc7f08b72018-08-12 17:39:14 +0200860 call term_sendkeys(buf, "\<Esc>")
861
862 " Select three lines at the cursor using previous pattern.
863 call term_sendkeys(buf, "/foo\<CR>")
864 sleep 100m
865 call term_sendkeys(buf, ':.,.+2s//')
866 sleep 100m
867 call VerifyScreenDump(buf, 'Test_incsearch_substitute_02', {})
868
869 " Deleting last slash should remove the match.
870 call term_sendkeys(buf, "\<BS>")
871 sleep 100m
872 call VerifyScreenDump(buf, 'Test_incsearch_substitute_03', {})
Bram Moolenaar60d08712018-08-12 21:53:15 +0200873 call term_sendkeys(buf, "\<Esc>")
874
875 " Reverse range is accepted
876 call term_sendkeys(buf, ':5,2s/foo')
877 sleep 100m
878 call VerifyScreenDump(buf, 'Test_incsearch_substitute_04', {})
Bram Moolenaar164251f2018-08-12 16:26:58 +0200879 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaar2b926fc2018-08-13 11:07:57 +0200880
881 " White space after the command is skipped
882 call term_sendkeys(buf, ':2,3sub /fo')
883 sleep 100m
884 call VerifyScreenDump(buf, 'Test_incsearch_substitute_05', {})
885 call term_sendkeys(buf, "\<Esc>")
886
Bram Moolenaar164251f2018-08-12 16:26:58 +0200887 call StopVimInTerminal(buf)
888 call delete('Xis_subst_script')
889endfunc
890
Bram Moolenaarf45938c2017-11-02 15:59:57 +0100891func Test_search_undefined_behaviour()
892 if !has("terminal")
893 return
894 endif
895 let h = winheight(0)
896 if h < 3
897 return
898 endif
899 " did cause an undefined left shift
900 let g:buf = term_start([GetVimProg(), '--clean', '-e', '-s', '-c', 'call search(getline("."))', 'samples/test000'], {'term_rows': 3})
901 call assert_equal([''], getline(1, '$'))
902 call term_sendkeys(g:buf, ":qa!\<cr>")
903 bwipe!
904endfunc
Bram Moolenaar2973daa2017-11-02 23:15:40 +0100905
906func Test_search_undefined_behaviour2()
907 call search("\%UC0000000")
908endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +0100909
910" Test for search('multi-byte char', 'bce')
911func Test_search_multibyte()
912 if !has('multi_byte')
913 return
914 endif
915 let save_enc = &encoding
916 set encoding=utf8
917 enew!
918 call append('$', 'A')
919 call cursor(2, 1)
920 call assert_equal(2, search('A', 'bce', line('.')))
921 enew!
922 let &encoding = save_enc
923endfunc
Bram Moolenaar890dd052017-12-16 19:59:37 +0100924
925" This was causing E874. Also causes an invalid read?
926func Test_look_behind()
927 new
928 call setline(1, '0\|\&\n\@<=')
929 call search(getline("."))
930 bwipe!
931endfunc
Bram Moolenaar8ada6aa2017-12-19 21:23:21 +0100932
933func Test_search_sentence()
934 new
935 " this used to cause a crash
Bram Moolenaar1bd999f2017-12-19 22:25:40 +0100936 call assert_fails("/\\%')", 'E486')
Bram Moolenaar8ada6aa2017-12-19 21:23:21 +0100937 call assert_fails("/", 'E486')
Bram Moolenaar1bd999f2017-12-19 22:25:40 +0100938 /\%'(
939 /
Bram Moolenaar8ada6aa2017-12-19 21:23:21 +0100940endfunc