blob: ee61cbc9db9ddf42ae5aeee6869ae9bf6cf0e68c [file] [log] [blame]
Bram Moolenaar6c896862016-11-17 19:46:51 +01001" Test for breakindent
2"
3" Note: if you get strange failures when adding new tests, it might be that
4" while the test is run, the breakindent cacheing gets in its way.
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01005" It helps to change the tabstop setting and force a redraw (e.g. see
Bram Moolenaar6c896862016-11-17 19:46:51 +01006" Test_breakindent08())
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02007source check.vim
8CheckOption breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +01009
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010010source view_util.vim
11
Bram Moolenaar6c896862016-11-17 19:46:51 +010012let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
13
Bram Moolenaar04958cb2018-06-23 19:23:02 +020014func s:screen_lines(lnum, width) abort
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010015 return ScreenLines([a:lnum, a:lnum + 2], a:width)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020016endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010017
Bram Moolenaar04958cb2018-06-23 19:23:02 +020018func s:compare_lines(expect, actual)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010019 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020020endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010021
Bram Moolenaar04958cb2018-06-23 19:23:02 +020022func s:test_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010023 call NewWindow(10, 20)
24 setl ts=4 sw=4 sts=4 breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +010025 put =s:input
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010026 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020027endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010028
Bram Moolenaar04958cb2018-06-23 19:23:02 +020029func s:close_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010030 call CloseWindow()
31 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020032endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010033
Bram Moolenaar04958cb2018-06-23 19:23:02 +020034func Test_breakindent01()
Bram Moolenaar6c896862016-11-17 19:46:51 +010035 " simple breakindent test
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010036 call s:test_windows('setl briopt=min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020037 let lines = s:screen_lines(line('.'),8)
38 let expect = [
39 \ " abcd",
40 \ " qrst",
41 \ " GHIJ",
42 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010043 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010044 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +020045endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010046
Bram Moolenaar04958cb2018-06-23 19:23:02 +020047func Test_breakindent01_vartabs()
48 " like 01 but with vartabs feature
49 if !has("vartabs")
50 return
51 endif
52 call s:test_windows('setl briopt=min:0 vts=4')
53 let lines = s:screen_lines(line('.'),8)
54 let expect = [
55 \ " abcd",
56 \ " qrst",
57 \ " GHIJ",
58 \ ]
59 call s:compare_lines(expect, lines)
60 call s:close_windows('set vts&')
61endfunc
62
63func Test_breakindent02()
Bram Moolenaar6c896862016-11-17 19:46:51 +010064 " simple breakindent test with showbreak set
Bram Moolenaaree857022019-11-09 23:26:40 +010065 set sbr=>>
66 call s:test_windows('setl briopt=min:0 sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020067 let lines = s:screen_lines(line('.'),8)
68 let expect = [
69 \ " abcd",
70 \ " >>qr",
71 \ " >>EF",
72 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010073 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010074 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020075endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010076
Bram Moolenaar04958cb2018-06-23 19:23:02 +020077func Test_breakindent02_vartabs()
78 if !has("vartabs")
79 return
80 endif
81 " simple breakindent test with showbreak set
82 call s:test_windows('setl briopt=min:0 sbr=>> vts=4')
83 let lines = s:screen_lines(line('.'),8)
84 let expect = [
85 \ " abcd",
86 \ " >>qr",
87 \ " >>EF",
88 \ ]
89 call s:compare_lines(expect, lines)
90 call s:close_windows('set sbr= vts&')
91endfunc
92
93func Test_breakindent03()
Bram Moolenaar6c896862016-11-17 19:46:51 +010094 " simple breakindent test with showbreak set and briopt including sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010095 call s:test_windows('setl briopt=sbr,min:0 sbr=++')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020096 let lines = s:screen_lines(line('.'),8)
97 let expect = [
98 \ " abcd",
99 \ "++ qrst",
100 \ "++ GHIJ",
101 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100102 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100103 " clean up
104 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200105endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100106
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200107func Test_breakindent03_vartabs()
108 " simple breakindent test with showbreak set and briopt including sbr
109 if !has("vartabs")
110 return
111 endif
112 call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4')
113 let lines = s:screen_lines(line('.'),8)
114 let expect = [
115 \ " abcd",
116 \ "++ qrst",
117 \ "++ GHIJ",
118 \ ]
119 call s:compare_lines(expect, lines)
120 " clean up
121 call s:close_windows('set sbr= vts&')
122endfunc
123
124func Test_breakindent04()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100125 " breakindent set with min width 18
Bram Moolenaaree857022019-11-09 23:26:40 +0100126 set sbr=<<<
127 call s:test_windows('setl sbr=NONE briopt=min:18')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200128 let lines = s:screen_lines(line('.'),8)
129 let expect = [
130 \ " abcd",
131 \ " qrstuv",
132 \ " IJKLMN",
133 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100134 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100135 " clean up
136 call s:close_windows('set sbr=')
Bram Moolenaaree857022019-11-09 23:26:40 +0100137 set sbr=
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200138endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100139
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200140func Test_breakindent04_vartabs()
141 " breakindent set with min width 18
142 if !has("vartabs")
143 return
144 endif
145 call s:test_windows('setl sbr= briopt=min:18 vts=4')
146 let lines = s:screen_lines(line('.'),8)
147 let expect = [
148 \ " abcd",
149 \ " qrstuv",
150 \ " IJKLMN",
151 \ ]
152 call s:compare_lines(expect, lines)
153 " clean up
154 call s:close_windows('set sbr= vts&')
155endfunc
156
157func Test_breakindent05()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100158 " breakindent set and shift by 2
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100159 call s:test_windows('setl briopt=shift:2,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200160 let lines = s:screen_lines(line('.'),8)
161 let expect = [
162 \ " abcd",
163 \ " qr",
164 \ " EF",
165 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100166 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100167 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200168endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100169
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200170func Test_breakindent05_vartabs()
171 " breakindent set and shift by 2
172 if !has("vartabs")
173 return
174 endif
175 call s:test_windows('setl briopt=shift:2,min:0 vts=4')
176 let lines = s:screen_lines(line('.'),8)
177 let expect = [
178 \ " abcd",
179 \ " qr",
180 \ " EF",
181 \ ]
182 call s:compare_lines(expect, lines)
183 call s:close_windows('set vts&')
184endfunc
185
186func Test_breakindent06()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100187 " breakindent set and shift by -1
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100188 call s:test_windows('setl briopt=shift:-1,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200189 let lines = s:screen_lines(line('.'),8)
190 let expect = [
191 \ " abcd",
192 \ " qrstu",
193 \ " HIJKL",
194 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100195 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100196 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200197endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100198
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200199func Test_breakindent06_vartabs()
200 " breakindent set and shift by -1
201 if !has("vartabs")
202 return
203 endif
204 call s:test_windows('setl briopt=shift:-1,min:0 vts=4')
205 let lines = s:screen_lines(line('.'),8)
206 let expect = [
207 \ " abcd",
208 \ " qrstu",
209 \ " HIJKL",
210 \ ]
211 call s:compare_lines(expect, lines)
212 call s:close_windows('set vts&')
213endfunc
214
215func Test_breakindent07()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100216 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100217 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200218 let lines = s:screen_lines(line('.'),10)
219 let expect = [
220 \ " 2 ab",
221 \ "? m",
222 \ "? x",
223 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100224 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100225 " clean up
226 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200227endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100228
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200229func Test_breakindent07_vartabs()
230 if !has("vartabs")
231 return
232 endif
233 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
234 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4')
235 let lines = s:screen_lines(line('.'),10)
236 let expect = [
237 \ " 2 ab",
238 \ "? m",
239 \ "? x",
240 \ ]
241 call s:compare_lines(expect, lines)
242 " clean up
243 call s:close_windows('set sbr= cpo-=n vts&')
244endfunc
245
246func Test_breakindent07a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100247 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100248 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200249 let lines = s:screen_lines(line('.'),10)
250 let expect = [
251 \ " 2 ab",
252 \ " ? m",
253 \ " ? x",
254 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100255 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100256 " clean up
257 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200258endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100259
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200260func Test_breakindent07a_vartabs()
261 if !has("vartabs")
262 return
263 endif
264 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
265 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4')
266 let lines = s:screen_lines(line('.'),10)
267 let expect = [
268 \ " 2 ab",
269 \ " ? m",
270 \ " ? x",
271 \ ]
272 call s:compare_lines(expect, lines)
273 " clean up
274 call s:close_windows('set sbr= vts&')
275endfunc
276
277func Test_breakindent08()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100278 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100279 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100280 " make sure, cache is invalidated!
281 set ts=8
282 redraw!
283 set ts=4
284 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200285 let lines = s:screen_lines(line('.'),10)
286 let expect = [
287 \ " 2 ^Iabcd",
288 \ "# opq",
289 \ "# BCD",
290 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100291 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100292 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200293endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100294
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200295func Test_breakindent08_vartabs()
296 if !has("vartabs")
297 return
298 endif
299 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
300 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4')
301 " make sure, cache is invalidated!
302 set ts=8
303 redraw!
304 set ts=4
305 redraw!
306 let lines = s:screen_lines(line('.'),10)
307 let expect = [
308 \ " 2 ^Iabcd",
309 \ "# opq",
310 \ "# BCD",
311 \ ]
312 call s:compare_lines(expect, lines)
313 call s:close_windows('set sbr= cpo-=n vts&')
314endfunc
315
316func Test_breakindent08a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100317 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100318 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200319 let lines = s:screen_lines(line('.'),10)
320 let expect = [
321 \ " 2 ^Iabcd",
322 \ " # opq",
323 \ " # BCD",
324 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100325 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100326 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200327endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100328
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200329func Test_breakindent08a_vartabs()
330 if !has("vartabs")
331 return
332 endif
333 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
334 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4')
335 let lines = s:screen_lines(line('.'),10)
336 let expect = [
337 \ " 2 ^Iabcd",
338 \ " # opq",
339 \ " # BCD",
340 \ ]
341 call s:compare_lines(expect, lines)
342 call s:close_windows('set sbr= vts&')
343endfunc
344
345func Test_breakindent09()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100346 " breakindent set and shift by 1, Number and list set sbr=#
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100347 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200348 let lines = s:screen_lines(line('.'),10)
349 let expect = [
350 \ " 2 ^Iabcd",
351 \ " #op",
352 \ " #AB",
353 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100354 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100355 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200356endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100357
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200358func Test_breakindent09_vartabs()
359 if !has("vartabs")
360 return
361 endif
362 " breakindent set and shift by 1, Number and list set sbr=#
363 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4')
364 let lines = s:screen_lines(line('.'),10)
365 let expect = [
366 \ " 2 ^Iabcd",
367 \ " #op",
368 \ " #AB",
369 \ ]
370 call s:compare_lines(expect, lines)
371 call s:close_windows('set sbr= vts&')
372endfunc
373
374func Test_breakindent10()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100375 " breakindent set, Number set sbr=~
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100376 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100377 " make sure, cache is invalidated!
378 set ts=8
379 redraw!
380 set ts=4
381 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200382 let lines = s:screen_lines(line('.'),10)
383 let expect = [
384 \ " 2 ab",
385 \ "~ mn",
386 \ "~ yz",
387 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100388 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100389 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200390endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100391
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200392func Test_breakindent10_vartabs()
393 if !has("vartabs")
394 return
395 endif
396 " breakindent set, Number set sbr=~
397 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4')
398 " make sure, cache is invalidated!
399 set ts=8
400 redraw!
401 set ts=4
402 redraw!
403 let lines = s:screen_lines(line('.'),10)
404 let expect = [
405 \ " 2 ab",
406 \ "~ mn",
407 \ "~ yz",
408 \ ]
409 call s:compare_lines(expect, lines)
410 call s:close_windows('set sbr= cpo-=n vts&')
411endfunc
412
413func Test_breakindent11()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100414 " test strdisplaywidth()
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100415 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200416 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200417 let width = strlen(text[1:]) + indent(2) + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaar6c896862016-11-17 19:46:51 +0100418 call assert_equal(width, strdisplaywidth(text))
419 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200420endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100421
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200422func Test_breakindent11_vartabs()
423 if !has("vartabs")
424 return
425 endif
426 " test strdisplaywidth()
427 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4')
428 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200429 let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +0200430 call assert_equal(width, text->strdisplaywidth())
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200431 call s:close_windows('set sbr= vts&')
432endfunc
433
434func Test_breakindent12()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100435 " test breakindent with long indent
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200436 let s:input = "\t\t\t\t\t{"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100437 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200438 let lines = s:screen_lines(2,16)
439 let expect = [
440 \ " 2 >--->--->--->",
441 \ " ---{ ",
442 \ "~ ",
443 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100444 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100445 call s:close_windows('set nuw=4 listchars=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200446endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100447
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200448func Test_breakindent12_vartabs()
449 if !has("vartabs")
450 return
451 endif
452 " test breakindent with long indent
453 let s:input = "\t\t\t\t\t{"
454 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4')
455 let lines = s:screen_lines(2,16)
456 let expect = [
457 \ " 2 >--->--->--->",
458 \ " ---{ ",
459 \ "~ ",
460 \ ]
461 call s:compare_lines(expect, lines)
462 call s:close_windows('set nuw=4 listchars= vts&')
463endfunc
464
465func Test_breakindent13()
466 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100467 call s:test_windows('setl breakindent briopt=min:10 ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100468 vert resize 20
469 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
470 1
471 norm! fbgj"ayl
472 2
473 norm! fygj"byl
474 call assert_equal('d', @a)
475 call assert_equal('w', @b)
476 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200477endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100478
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200479func Test_breakindent13_vartabs()
480 if !has("vartabs")
481 return
482 endif
483 let s:input = ""
484 call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8')
485 vert resize 20
486 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
487 1
488 norm! fbgj"ayl
489 2
490 norm! fygj"byl
491 call assert_equal('d', @a)
492 call assert_equal('w', @b)
493 call s:close_windows('set vts&')
494endfunc
495
496func Test_breakindent14()
497 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100498 call s:test_windows('setl breakindent briopt= ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100499 vert resize 30
500 norm! 3a1234567890
501 norm! a abcde
502 exec "norm! 0\<C-V>tex"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200503 let lines = s:screen_lines(line('.'),8)
504 let expect = [
505 \ "e ",
506 \ "~ ",
507 \ "~ ",
508 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100509 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100510 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200511endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100512
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200513func Test_breakindent14_vartabs()
514 if !has("vartabs")
515 return
516 endif
517 let s:input = ""
518 call s:test_windows('setl breakindent briopt= ts=8 vts=8')
519 vert resize 30
520 norm! 3a1234567890
521 norm! a abcde
522 exec "norm! 0\<C-V>tex"
523 let lines = s:screen_lines(line('.'),8)
524 let expect = [
525 \ "e ",
526 \ "~ ",
527 \ "~ ",
528 \ ]
529 call s:compare_lines(expect, lines)
530 call s:close_windows('set vts&')
531endfunc
532
533func Test_breakindent15()
534 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100535 call s:test_windows('setl breakindent briopt= ts=8 sw=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100536 vert resize 30
537 norm! 4a1234567890
538 exe "normal! >>\<C-V>3f0x"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200539 let lines = s:screen_lines(line('.'),20)
540 let expect = [
541 \ " 1234567890 ",
542 \ "~ ",
543 \ "~ ",
544 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100545 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100546 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200547endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100548
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200549func Test_breakindent15_vartabs()
550 if !has("vartabs")
551 return
552 endif
553 let s:input = ""
554 call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8')
555 vert resize 30
556 norm! 4a1234567890
557 exe "normal! >>\<C-V>3f0x"
558 let lines = s:screen_lines(line('.'),20)
559 let expect = [
560 \ " 1234567890 ",
561 \ "~ ",
562 \ "~ ",
563 \ ]
564 call s:compare_lines(expect, lines)
565 call s:close_windows('set vts&')
566endfunc
567
568func Test_breakindent16()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100569 " Check that overlong lines are indented correctly.
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200570 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100571 call s:test_windows('setl breakindent briopt=min:0 ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100572 call setline(1, "\t".repeat("1234567890", 10))
573 resize 6
574 norm! 1gg$
575 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200576 let lines = s:screen_lines(1,10)
577 let expect = [
578 \ " 789012",
579 \ " 345678",
580 \ " 901234",
581 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100582 call s:compare_lines(expect, lines)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200583 let lines = s:screen_lines(4,10)
584 let expect = [
585 \ " 567890",
586 \ " 123456",
587 \ " 7890 ",
588 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100589 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100590 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200591endfunc
592
593func Test_breakindent16_vartabs()
594 if !has("vartabs")
595 return
596 endif
597 " Check that overlong lines are indented correctly.
598 let s:input = ""
599 call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4')
600 call setline(1, "\t".repeat("1234567890", 10))
601 resize 6
602 norm! 1gg$
603 redraw!
604 let lines = s:screen_lines(1,10)
605 let expect = [
606 \ " 789012",
607 \ " 345678",
608 \ " 901234",
609 \ ]
610 call s:compare_lines(expect, lines)
611 let lines = s:screen_lines(4,10)
612 let expect = [
613 \ " 567890",
614 \ " 123456",
615 \ " 7890 ",
616 \ ]
617 call s:compare_lines(expect, lines)
618 call s:close_windows('set vts&')
619endfunc
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100620
621func Test_breakindent17_vartabs()
622 if !has("vartabs")
623 return
624 endif
625 let s:input = ""
626 call s:test_windows('setl breakindent list listchars=tab:<-> showbreak=+++')
627 call setline(1, "\t" . repeat('a', 63))
628 vert resize 30
629 norm! 1gg$
630 redraw!
631 let lines = s:screen_lines(1, 30)
632 let expect = [
633 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
634 \ " +++aaaaaaaaaaaaaaaaaaaaaaa",
635 \ " +++aaaaaaaaaaaaaa ",
636 \ ]
637 call s:compare_lines(expect, lines)
638 call s:close_windows('set breakindent& list& listchars& showbreak&')
639endfunc
640
641func Test_breakindent18_vartabs()
642 if !has("vartabs")
643 return
644 endif
645 let s:input = ""
646 call s:test_windows('setl breakindent list listchars=tab:<->')
647 call setline(1, "\t" . repeat('a', 63))
648 vert resize 30
649 norm! 1gg$
650 redraw!
651 let lines = s:screen_lines(1, 30)
652 let expect = [
653 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
654 \ " aaaaaaaaaaaaaaaaaaaaaaaaaa",
655 \ " aaaaaaaaaaa ",
656 \ ]
657 call s:compare_lines(expect, lines)
658 call s:close_windows('set breakindent& list& listchars&')
659endfunc
660