blob: 5d598eb2335b7dd9092225c7ac9ff230ac3e4064 [file] [log] [blame]
Bram Moolenaard76a0c12016-08-06 15:29:22 +02001" Test for :match, :2match, :3match, clearmatches(), getmatches(), matchadd(),
Bram Moolenaar1190cf62017-09-14 14:31:18 +02002" matchaddpos(), matcharg(), matchdelete(), and setmatches().
Bram Moolenaard76a0c12016-08-06 15:29:22 +02003
Christian Brabandteb380b92025-07-07 20:53:55 +02004source util/screendump.vim
Bram Moolenaar06029a82019-07-24 14:25:26 +02005
Bram Moolenaar4f416e42016-08-16 16:08:18 +02006function Test_match()
Bram Moolenaard76a0c12016-08-06 15:29:22 +02007 highlight MyGroup1 term=bold ctermbg=red guibg=red
8 highlight MyGroup2 term=italic ctermbg=green guibg=green
9 highlight MyGroup3 term=underline ctermbg=blue guibg=blue
10
11 " --- Check that "matcharg()" returns the correct group and pattern if a match
12 " --- is defined.
13 match MyGroup1 /TODO/
14 2match MyGroup2 /FIXME/
15 3match MyGroup3 /XXX/
16 call assert_equal(['MyGroup1', 'TODO'], matcharg(1))
Bram Moolenaara1449832019-09-01 20:16:52 +020017 call assert_equal(['MyGroup2', 'FIXME'], 2->matcharg())
Bram Moolenaard76a0c12016-08-06 15:29:22 +020018 call assert_equal(['MyGroup3', 'XXX'], matcharg(3))
19
20 " --- Check that "matcharg()" returns an empty list if the argument is not 1,
21 " --- 2 or 3 (only 0 and 4 are tested).
22 call assert_equal([], matcharg(0))
23 call assert_equal([], matcharg(4))
24
25 " --- Check that "matcharg()" returns ['', ''] if a match is not defined.
26 match
27 2match
28 3match
29 call assert_equal(['', ''], matcharg(1))
30 call assert_equal(['', ''], matcharg(2))
31 call assert_equal(['', ''], matcharg(3))
32
33 " --- Check that "matchadd()" and "getmatches()" agree on added matches and
34 " --- that default values apply.
35 let m1 = matchadd("MyGroup1", "TODO")
36 let m2 = matchadd("MyGroup2", "FIXME", 42)
37 let m3 = matchadd("MyGroup3", "XXX", 60, 17)
Bram Moolenaar9f573a82022-09-29 13:50:08 +010038 let ans = [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1000},
39 \ {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 42, 'id': 1001},
Bram Moolenaard76a0c12016-08-06 15:29:22 +020040 \ {'group': 'MyGroup3', 'pattern': 'XXX', 'priority': 60, 'id': 17}]
41 call assert_equal(ans, getmatches())
42
43 " --- Check that "matchdelete()" deletes the matches defined in the previous
44 " --- test correctly.
45 call matchdelete(m1)
Bram Moolenaara1449832019-09-01 20:16:52 +020046 eval m2->matchdelete()
Bram Moolenaard76a0c12016-08-06 15:29:22 +020047 call matchdelete(m3)
48 call assert_equal([], getmatches())
49
50 " --- Check that "matchdelete()" returns 0 if successful and otherwise -1.
51 let m = matchadd("MyGroup1", "TODO")
52 call assert_equal(0, matchdelete(m))
53 call assert_fails('call matchdelete(42)', 'E803:')
54
55 " --- Check that "clearmatches()" clears all matches defined by ":match" and
56 " --- "matchadd()".
57 let m1 = matchadd("MyGroup1", "TODO")
Bram Moolenaara1449832019-09-01 20:16:52 +020058 let m2 = "MyGroup2"->matchadd("FIXME", 42)
Bram Moolenaard76a0c12016-08-06 15:29:22 +020059 let m3 = matchadd("MyGroup3", "XXX", 60, 17)
60 match MyGroup1 /COFFEE/
61 2match MyGroup2 /HUMPPA/
62 3match MyGroup3 /VIM/
63 call clearmatches()
64 call assert_equal([], getmatches())
65
66 " --- Check that "setmatches()" restores a list of matches saved by
67 " --- "getmatches()" without changes. (Matches with equal priority must also
68 " --- remain in the same order.)
69 let m1 = matchadd("MyGroup1", "TODO")
70 let m2 = matchadd("MyGroup2", "FIXME", 42)
71 let m3 = matchadd("MyGroup3", "XXX", 60, 17)
72 match MyGroup1 /COFFEE/
73 2match MyGroup2 /HUMPPA/
74 3match MyGroup3 /VIM/
75 let ml = getmatches()
76 call clearmatches()
77 call setmatches(ml)
78 call assert_equal(ml, getmatches())
79 call clearmatches()
80
81 " --- Check that "setmatches()" will not add two matches with the same ID. The
82 " --- expected behaviour (for now) is to add the first match but not the
83 " --- second and to return 0 (even though it is a matter of debate whether
84 " --- this can be considered successful behaviour).
85 let data = [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1},
86 \ {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}]
87 call assert_fails('call setmatches(data)', 'E801:')
88 call assert_equal([data[0]], getmatches())
89 call clearmatches()
90
91 " --- Check that "setmatches()" returns 0 if successful and otherwise -1.
92 " --- (A range of valid and invalid input values are tried out to generate the
93 " --- return values.)
94 call assert_equal(0, setmatches([]))
95 call assert_equal(0, setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}]))
96 call clearmatches()
Bram Moolenaard83392a2022-09-01 12:22:46 +010097 call assert_fails('call setmatches(0)', 'E1211:')
Bram Moolenaard76a0c12016-08-06 15:29:22 +020098 call assert_fails('call setmatches([0])', 'E474:')
99 call assert_fails("call setmatches([{'wrong key': 'wrong value'}])", 'E474:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200100 call assert_equal(-1, setmatches([{'group' : 'Search', 'priority' : 10, 'id' : 5, 'pos1' : {}}]))
Bram Moolenaard76a0c12016-08-06 15:29:22 +0200101
102 call setline(1, 'abcdefghijklmnopq')
103 call matchaddpos("MyGroup1", [[1, 5], [1, 8, 3]], 10, 3)
104 1
105 redraw!
106 let v1 = screenattr(1, 1)
107 let v5 = screenattr(1, 5)
108 let v6 = screenattr(1, 6)
109 let v8 = screenattr(1, 8)
110 let v10 = screenattr(1, 10)
111 let v11 = screenattr(1, 11)
112 call assert_notequal(v1, v5)
113 call assert_equal(v6, v1)
114 call assert_equal(v8, v5)
115 call assert_equal(v10, v5)
116 call assert_equal(v11, v1)
117 call assert_equal([{'group': 'MyGroup1', 'id': 3, 'priority': 10, 'pos1': [1, 5, 1], 'pos2': [1, 8, 3]}], getmatches())
118 call clearmatches()
119
Bram Moolenaar30276f22019-01-24 17:59:39 +0100120 call setline(1, 'abcdΣabcdef')
Bram Moolenaar9f573a82022-09-29 13:50:08 +0100121 eval "MyGroup1"->matchaddpos([[1, 4, 2], [1, 9, 2]], 10, 42)
Bram Moolenaar30276f22019-01-24 17:59:39 +0100122 1
123 redraw!
124 let v1 = screenattr(1, 1)
125 let v4 = screenattr(1, 4)
126 let v5 = screenattr(1, 5)
127 let v6 = screenattr(1, 6)
128 let v7 = screenattr(1, 7)
129 let v8 = screenattr(1, 8)
130 let v9 = screenattr(1, 9)
131 let v10 = screenattr(1, 10)
Bram Moolenaar9f573a82022-09-29 13:50:08 +0100132 call assert_equal([{'group': 'MyGroup1', 'id': 42, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}], getmatches())
Bram Moolenaar30276f22019-01-24 17:59:39 +0100133 call assert_notequal(v1, v4)
134 call assert_equal(v5, v4)
135 call assert_equal(v6, v1)
136 call assert_equal(v7, v1)
137 call assert_equal(v8, v4)
138 call assert_equal(v9, v4)
139 call assert_equal(v10, v1)
Bram Moolenaard76a0c12016-08-06 15:29:22 +0200140
Bram Moolenaar30276f22019-01-24 17:59:39 +0100141 " Check, that setmatches() can correctly restore the matches from matchaddpos()
142 call matchadd('MyGroup1', '\%2lmatchadd')
143 let m=getmatches()
144 call clearmatches()
145 call setmatches(m)
Bram Moolenaar9f573a82022-09-29 13:50:08 +0100146 call assert_equal([{'group': 'MyGroup1', 'id': 42, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1,9, 2]}, {'group': 'MyGroup1', 'pattern': '\%2lmatchadd', 'priority': 10, 'id': 1106}], getmatches())
Bram Moolenaard76a0c12016-08-06 15:29:22 +0200147
148 highlight MyGroup1 NONE
149 highlight MyGroup2 NONE
150 highlight MyGroup3 NONE
151endfunc
152
Bram Moolenaar49d68bf2019-12-24 15:17:00 +0100153func Test_match_error()
154 call assert_fails('match Error', 'E475:')
155 call assert_fails('match Error /', 'E475:')
156 call assert_fails('4match Error /x/', 'E476:')
157 call assert_fails('match Error /x/ x', 'E488:')
158endfunc
159
160func Test_matchadd_error()
161 call assert_fails("call matchadd('GroupDoesNotExist', 'X')", 'E28:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200162 call assert_fails("call matchadd('Search', '\\(')", 'E54:')
Bram Moolenaar49d68bf2019-12-24 15:17:00 +0100163 call assert_fails("call matchadd('Search', 'XXX', 1, 123, 1)", 'E715:')
164 call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:')
165 call assert_fails("call matchadd('Error', 'XXX', 1, 0)", 'E799:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200166 call assert_fails("call matchadd('Error', 'XXX', [], 0)", 'E745:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200167 call assert_equal(-1, matchadd('', 'pat'))
168 call assert_equal(-1, matchadd('Search', ''))
Bram Moolenaar49d68bf2019-12-24 15:17:00 +0100169endfunc
170
Bram Moolenaar4f416e42016-08-16 16:08:18 +0200171func Test_matchaddpos()
172 syntax on
173 set hlsearch
174
175 call setline(1, ['12345', 'NP'])
176 call matchaddpos('Error', [[1,2], [1,6], [2,2]])
177 redraw!
178 call assert_notequal(screenattr(2,2), 0)
179 call assert_equal(screenattr(2,2), screenattr(1,2))
180 call assert_notequal(screenattr(2,2), screenattr(1,6))
181 1
182 call matchadd('Search', 'N\|\n')
183 redraw!
184 call assert_notequal(screenattr(2,1), 0)
185 call assert_equal(screenattr(2,1), screenattr(1,6))
186 exec "norm! i0\<Esc>"
187 redraw!
188 call assert_equal(screenattr(2,2), screenattr(1,6))
189
Bram Moolenaara6c27ee2016-10-15 14:56:30 +0200190 " Check overlapping pos
191 call clearmatches()
192 call setline(1, ['1234567890', 'NH'])
193 call matchaddpos('Error', [[1,1,5], [1,3,5], [2,2]])
194 redraw!
195 call assert_notequal(screenattr(2,2), 0)
196 call assert_equal(screenattr(2,2), screenattr(1,5))
197 call assert_equal(screenattr(2,2), screenattr(1,7))
198 call assert_notequal(screenattr(2,2), screenattr(1,8))
199
Bram Moolenaar85077472016-10-16 14:35:48 +0200200 call clearmatches()
201 call matchaddpos('Error', [[1], [2,2]])
202 redraw!
203 call assert_equal(screenattr(2,2), screenattr(1,1))
204 call assert_equal(screenattr(2,2), screenattr(1,10))
205 call assert_notequal(screenattr(2,2), screenattr(1,11))
206
Bram Moolenaar75e15672020-06-28 13:10:22 +0200207 " matchaddpos() with line number as 0
208 call clearmatches()
209 let id = matchaddpos('Search', [[0], [3], [0]])
210 call assert_equal([{'group' : 'Search', 'priority' : 10, 'id' : id, 'pos1' : [3]}], getmatches())
211 call clearmatches()
212 let id = matchaddpos('Search', [0, 3, 0])
213 call assert_equal([{'group' : 'Search', 'priority' : 10, 'id' : id, 'pos1' : [3]}], getmatches())
214
Bram Moolenaar4f416e42016-08-16 16:08:18 +0200215 nohl
Bram Moolenaar85077472016-10-16 14:35:48 +0200216 call clearmatches()
Bram Moolenaar4f416e42016-08-16 16:08:18 +0200217 syntax off
218 set hlsearch&
219endfunc
220
Bram Moolenaar50faf022022-09-29 12:50:17 +0100221" Add 12 match positions (previously the limit was 8 positions).
222func Test_matchaddpos_dump()
223 CheckScreendump
224
225 let lines =<< trim END
226 call setline(1, ['1234567890123']->repeat(14))
227 call matchaddpos('Search', range(1, 12)->map({i, v -> [v, v]}))
228 END
229 call writefile(lines, 'Xmatchaddpos', 'D')
230 let buf = RunVimInTerminal('-S Xmatchaddpos', #{rows: 14})
231 call VerifyScreenDump(buf, 'Test_matchaddpos_1', {})
232
233 call StopVimInTerminal(buf)
234endfunc
235
Bram Moolenaar95e51472018-07-28 16:55:56 +0200236func Test_matchaddpos_otherwin()
237 syntax on
238 new
239 call setline(1, ['12345', 'NP'])
240 let winid = win_getid()
241
242 wincmd w
243 call matchadd('Search', '4', 10, -1, {'window': winid})
244 call matchaddpos('Error', [[1,2], [2,2]], 10, -1, {'window': winid})
245 redraw!
246 call assert_notequal(screenattr(1,2), 0)
247 call assert_notequal(screenattr(1,4), 0)
248 call assert_notequal(screenattr(2,2), 0)
249 call assert_equal(screenattr(1,2), screenattr(2,2))
250 call assert_notequal(screenattr(1,2), screenattr(1,4))
251
Bram Moolenaaraff74912019-03-30 18:11:49 +0100252 let savematches = getmatches(winid)
253 let expect = [
Bram Moolenaar9f573a82022-09-29 13:50:08 +0100254 \ {'group': 'Search', 'pattern': '4', 'priority': 10, 'id': 1000},
255 \ {'group': 'Error', 'id': 1001, 'priority': 10, 'pos1': [1, 2, 1], 'pos2': [2, 2, 1]},
Bram Moolenaaraff74912019-03-30 18:11:49 +0100256 \]
257 call assert_equal(expect, savematches)
258
Bram Moolenaar1a3a8912019-08-23 22:31:37 +0200259 eval winid->clearmatches()
Bram Moolenaaraff74912019-03-30 18:11:49 +0100260 call assert_equal([], getmatches(winid))
Bram Moolenaar75e15672020-06-28 13:10:22 +0200261 call assert_fails('echo getmatches(-1)', 'E957:')
Bram Moolenaaraff74912019-03-30 18:11:49 +0100262
263 call setmatches(savematches, winid)
264 call assert_equal(expect, savematches)
265
Bram Moolenaar95e51472018-07-28 16:55:56 +0200266 wincmd w
267 bwipe!
268 call clearmatches()
269 syntax off
270endfunc
271
Bram Moolenaare17bdff2016-08-27 18:34:29 +0200272func Test_matchaddpos_using_negative_priority()
273 set hlsearch
274
275 call clearmatches()
276
277 call setline(1, 'x')
278 let @/='x'
279 redraw!
280 let search_attr = screenattr(1,1)
281
282 let @/=''
283 call matchaddpos('Error', [1], 10)
284 redraw!
285 let error_attr = screenattr(1,1)
286
287 call setline(2, '-1 match priority')
288 call matchaddpos('Error', [2], -1)
289 redraw!
290 let negative_match_priority_attr = screenattr(2,1)
291
292 call assert_notequal(negative_match_priority_attr, search_attr, "Match with negative priority is incorrectly highlighted with Search highlight.")
293 call assert_equal(negative_match_priority_attr, error_attr)
294
295 nohl
296 set hlsearch&
297endfunc
298
Bram Moolenaar49d68bf2019-12-24 15:17:00 +0100299func Test_matchaddpos_error()
300 call assert_fails("call matchaddpos('Error', 1)", 'E686:')
301 call assert_fails("call matchaddpos('Error', [1], 1, 1)", 'E798:')
302 call assert_fails("call matchaddpos('Error', [1], 1, 2)", 'E798:')
303 call assert_fails("call matchaddpos('Error', [1], 1, 0)", 'E799:')
304 call assert_fails("call matchaddpos('Error', [1], 1, 123, 1)", 'E715:')
305 call assert_fails("call matchaddpos('Error', [1], 1, 5, {'window':12345})", 'E957:')
306 " Why doesn't the following error have an error code E...?
307 call assert_fails("call matchaddpos('Error', [{}])", 'E290:')
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200308 call assert_equal(-1, matchaddpos('Error', test_null_list()))
Christian Brabandtf7d31ad2024-04-16 22:23:17 +0200309 call assert_equal(-1, matchaddpos('Error', []))
Bram Moolenaar99fa7212020-04-26 15:59:55 +0200310 call assert_fails("call matchaddpos('Error', [1], [], 1)", 'E745:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200311 call assert_equal(-1, matchaddpos('Search', [[]]))
312 call assert_fails("call matchaddpos('Search', [[{}]])", 'E728:')
313 call assert_fails("call matchaddpos('Search', [[2, {}]])", 'E728:')
314 call assert_fails("call matchaddpos('Search', [[3, 4, {}]])", 'E728:')
Bram Moolenaar49d68bf2019-12-24 15:17:00 +0100315endfunc
316
Bram Moolenaar4ef18dc2019-07-24 15:28:18 +0200317func OtherWindowCommon()
Bram Moolenaar06029a82019-07-24 14:25:26 +0200318 let lines =<< trim END
319 call setline(1, 'Hello Vim world')
320 let mid = matchadd('Error', 'world', 1)
321 let winid = win_getid()
322 new
323 END
Bram Moolenaar4ef18dc2019-07-24 15:28:18 +0200324 call writefile(lines, 'XscriptMatchCommon')
325 let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200326 call TermWait(buf)
Bram Moolenaar4ef18dc2019-07-24 15:28:18 +0200327 return buf
328endfunc
329
330func Test_matchdelete_other_window()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200331 CheckScreendump
332
Bram Moolenaar4ef18dc2019-07-24 15:28:18 +0200333 let buf = OtherWindowCommon()
Bram Moolenaar06029a82019-07-24 14:25:26 +0200334 call term_sendkeys(buf, ":call matchdelete(mid, winid)\<CR>")
335 call VerifyScreenDump(buf, 'Test_matchdelete_1', {})
336
337 call StopVimInTerminal(buf)
Bram Moolenaar4ef18dc2019-07-24 15:28:18 +0200338 call delete('XscriptMatchCommon')
339endfunc
340
Bram Moolenaar49d68bf2019-12-24 15:17:00 +0100341func Test_matchdelete_error()
342 call assert_fails("call matchdelete(0)", 'E802:')
343 call assert_fails("call matchdelete(1, -1)", 'E957:')
344endfunc
345
Bram Moolenaar4ef18dc2019-07-24 15:28:18 +0200346func Test_matchclear_other_window()
Drew Vogelea67ba72025-05-07 22:05:17 +0200347 CheckScreendump
Bram Moolenaar494e9062020-05-31 21:28:02 +0200348 CheckRunVimInTerminal
Bram Moolenaar4ef18dc2019-07-24 15:28:18 +0200349 let buf = OtherWindowCommon()
350 call term_sendkeys(buf, ":call clearmatches(winid)\<CR>")
351 call VerifyScreenDump(buf, 'Test_matchclear_1', {})
352
353 call StopVimInTerminal(buf)
354 call delete('XscriptMatchCommon')
355endfunc
356
357func Test_matchadd_other_window()
Drew Vogelea67ba72025-05-07 22:05:17 +0200358 CheckScreendump
Bram Moolenaar494e9062020-05-31 21:28:02 +0200359 CheckRunVimInTerminal
Bram Moolenaar4ef18dc2019-07-24 15:28:18 +0200360 let buf = OtherWindowCommon()
361 call term_sendkeys(buf, ":call matchadd('Search', 'Hello', 1, -1, #{window: winid})\<CR>")
362 call term_sendkeys(buf, ":\<CR>")
363 call VerifyScreenDump(buf, 'Test_matchadd_1', {})
364
365 call StopVimInTerminal(buf)
366 call delete('XscriptMatchCommon')
Bram Moolenaar06029a82019-07-24 14:25:26 +0200367endfunc
368
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000369func Test_match_in_linebreak()
Drew Vogelea67ba72025-05-07 22:05:17 +0200370 CheckScreendump
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000371 CheckRunVimInTerminal
372
373 let lines =<< trim END
374 set breakindent linebreak breakat+=]
375 call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1)
376 call matchaddpos('ErrorMsg', [[1, 51]])
377 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100378 call writefile(lines, 'XscriptMatchLinebreak', 'D')
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000379 let buf = RunVimInTerminal('-S XscriptMatchLinebreak', #{rows: 10})
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000380 call VerifyScreenDump(buf, 'Test_match_linebreak', {})
381
382 call StopVimInTerminal(buf)
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000383endfunc
384
Bram Moolenaar94fb8272021-12-29 19:22:44 +0000385func Test_match_with_incsearch()
Drew Vogelea67ba72025-05-07 22:05:17 +0200386 CheckScreendump
Bram Moolenaar94fb8272021-12-29 19:22:44 +0000387 CheckRunVimInTerminal
388
389 let lines =<< trim END
390 set incsearch
391 call setline(1, range(20))
392 call matchaddpos('ErrorMsg', [3])
393 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100394 call writefile(lines, 'XmatchWithIncsearch', 'D')
Bram Moolenaar94fb8272021-12-29 19:22:44 +0000395 let buf = RunVimInTerminal('-S XmatchWithIncsearch', #{rows: 6})
Bram Moolenaar94fb8272021-12-29 19:22:44 +0000396 call VerifyScreenDump(buf, 'Test_match_with_incsearch_1', {})
397
398 call term_sendkeys(buf, ":s/0")
399 call VerifyScreenDump(buf, 'Test_match_with_incsearch_2', {})
400
401 call term_sendkeys(buf, "\<CR>")
402 call StopVimInTerminal(buf)
Bram Moolenaar94fb8272021-12-29 19:22:44 +0000403endfunc
404
Bram Moolenaar75e15672020-06-28 13:10:22 +0200405" Test for deleting matches outside of the screen redraw top/bottom lines
406" This should cause a redraw of those lines.
407func Test_matchdelete_redraw()
408 new
409 call setline(1, range(1, 500))
410 call cursor(250, 1)
411 let m1 = matchaddpos('Search', [[250]])
412 let m2 = matchaddpos('Search', [[10], [450]])
413 redraw!
414 let m3 = matchaddpos('Search', [[240], [260]])
415 call matchdelete(m2)
416 let m = getmatches()
417 call assert_equal(2, len(m))
418 call assert_equal([250], m[0].pos1)
419 redraw!
420 call matchdelete(m1)
421 call assert_equal(1, len(getmatches()))
422 bw!
423endfunc
424
Bram Moolenaar0bbca542022-01-11 13:14:54 +0000425func Test_match_tab_with_linebreak()
Drew Vogelea67ba72025-05-07 22:05:17 +0200426 CheckScreendump
Bram Moolenaar0bbca542022-01-11 13:14:54 +0000427 CheckRunVimInTerminal
428
429 let lines =<< trim END
430 set linebreak
431 call setline(1, "\tix")
432 call matchadd('ErrorMsg', '\t')
433 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100434 call writefile(lines, 'XscriptMatchTabLinebreak', 'D')
Bram Moolenaar0bbca542022-01-11 13:14:54 +0000435 let buf = RunVimInTerminal('-S XscriptMatchTabLinebreak', #{rows: 10})
Bram Moolenaar0bbca542022-01-11 13:14:54 +0000436 call VerifyScreenDump(buf, 'Test_match_tab_linebreak', {})
437
438 call StopVimInTerminal(buf)
Bram Moolenaar0bbca542022-01-11 13:14:54 +0000439endfunc
440
Bram Moolenaar9e4d8212016-08-18 23:04:48 +0200441" vim: shiftwidth=2 sts=2 expandtab