blob: aea0572c305469716834048a004c263fe7a984c4 [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
Bram Moolenaar4b96df52020-01-26 22:00:26 +01004" while the test is run, the breakindent caching 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 Moolenaar0e05de42020-03-25 22:23:46 +0100420 call assert_equal(4, strdisplaywidth("\t", 4))
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200421endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100422
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200423func Test_breakindent11_vartabs()
424 if !has("vartabs")
425 return
426 endif
427 " test strdisplaywidth()
428 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4')
429 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200430 let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +0200431 call assert_equal(width, text->strdisplaywidth())
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200432 call s:close_windows('set sbr= vts&')
433endfunc
434
435func Test_breakindent12()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100436 " test breakindent with long indent
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200437 let s:input = "\t\t\t\t\t{"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100438 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 +0200439 let lines = s:screen_lines(2,16)
440 let expect = [
441 \ " 2 >--->--->--->",
442 \ " ---{ ",
443 \ "~ ",
444 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100445 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100446 call s:close_windows('set nuw=4 listchars=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200447endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100448
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200449func Test_breakindent12_vartabs()
450 if !has("vartabs")
451 return
452 endif
453 " test breakindent with long indent
454 let s:input = "\t\t\t\t\t{"
455 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4')
456 let lines = s:screen_lines(2,16)
457 let expect = [
458 \ " 2 >--->--->--->",
459 \ " ---{ ",
460 \ "~ ",
461 \ ]
462 call s:compare_lines(expect, lines)
463 call s:close_windows('set nuw=4 listchars= vts&')
464endfunc
465
466func Test_breakindent13()
467 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100468 call s:test_windows('setl breakindent briopt=min:10 ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100469 vert resize 20
470 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
471 1
472 norm! fbgj"ayl
473 2
474 norm! fygj"byl
475 call assert_equal('d', @a)
476 call assert_equal('w', @b)
477 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200478endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100479
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200480func Test_breakindent13_vartabs()
481 if !has("vartabs")
482 return
483 endif
484 let s:input = ""
485 call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8')
486 vert resize 20
487 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
488 1
489 norm! fbgj"ayl
490 2
491 norm! fygj"byl
492 call assert_equal('d', @a)
493 call assert_equal('w', @b)
494 call s:close_windows('set vts&')
495endfunc
496
497func Test_breakindent14()
498 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100499 call s:test_windows('setl breakindent briopt= ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100500 vert resize 30
501 norm! 3a1234567890
502 norm! a abcde
503 exec "norm! 0\<C-V>tex"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200504 let lines = s:screen_lines(line('.'),8)
505 let expect = [
506 \ "e ",
507 \ "~ ",
508 \ "~ ",
509 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100510 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100511 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200512endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100513
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200514func Test_breakindent14_vartabs()
515 if !has("vartabs")
516 return
517 endif
518 let s:input = ""
519 call s:test_windows('setl breakindent briopt= ts=8 vts=8')
520 vert resize 30
521 norm! 3a1234567890
522 norm! a abcde
523 exec "norm! 0\<C-V>tex"
524 let lines = s:screen_lines(line('.'),8)
525 let expect = [
526 \ "e ",
527 \ "~ ",
528 \ "~ ",
529 \ ]
530 call s:compare_lines(expect, lines)
531 call s:close_windows('set vts&')
532endfunc
533
534func Test_breakindent15()
535 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100536 call s:test_windows('setl breakindent briopt= ts=8 sw=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100537 vert resize 30
538 norm! 4a1234567890
539 exe "normal! >>\<C-V>3f0x"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200540 let lines = s:screen_lines(line('.'),20)
541 let expect = [
542 \ " 1234567890 ",
543 \ "~ ",
544 \ "~ ",
545 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100546 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100547 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200548endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100549
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200550func Test_breakindent15_vartabs()
551 if !has("vartabs")
552 return
553 endif
554 let s:input = ""
555 call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8')
556 vert resize 30
557 norm! 4a1234567890
558 exe "normal! >>\<C-V>3f0x"
559 let lines = s:screen_lines(line('.'),20)
560 let expect = [
561 \ " 1234567890 ",
562 \ "~ ",
563 \ "~ ",
564 \ ]
565 call s:compare_lines(expect, lines)
566 call s:close_windows('set vts&')
567endfunc
568
569func Test_breakindent16()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100570 " Check that overlong lines are indented correctly.
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200571 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100572 call s:test_windows('setl breakindent briopt=min:0 ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100573 call setline(1, "\t".repeat("1234567890", 10))
574 resize 6
575 norm! 1gg$
576 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200577 let lines = s:screen_lines(1,10)
578 let expect = [
579 \ " 789012",
580 \ " 345678",
581 \ " 901234",
582 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100583 call s:compare_lines(expect, lines)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200584 let lines = s:screen_lines(4,10)
585 let expect = [
586 \ " 567890",
587 \ " 123456",
588 \ " 7890 ",
589 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100590 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100591 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200592endfunc
593
594func Test_breakindent16_vartabs()
595 if !has("vartabs")
596 return
597 endif
598 " Check that overlong lines are indented correctly.
599 let s:input = ""
600 call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4')
601 call setline(1, "\t".repeat("1234567890", 10))
602 resize 6
603 norm! 1gg$
604 redraw!
605 let lines = s:screen_lines(1,10)
606 let expect = [
607 \ " 789012",
608 \ " 345678",
609 \ " 901234",
610 \ ]
611 call s:compare_lines(expect, lines)
612 let lines = s:screen_lines(4,10)
613 let expect = [
614 \ " 567890",
615 \ " 123456",
616 \ " 7890 ",
617 \ ]
618 call s:compare_lines(expect, lines)
619 call s:close_windows('set vts&')
620endfunc
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100621
622func Test_breakindent17_vartabs()
623 if !has("vartabs")
624 return
625 endif
626 let s:input = ""
627 call s:test_windows('setl breakindent list listchars=tab:<-> showbreak=+++')
628 call setline(1, "\t" . repeat('a', 63))
629 vert resize 30
630 norm! 1gg$
631 redraw!
632 let lines = s:screen_lines(1, 30)
633 let expect = [
634 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
635 \ " +++aaaaaaaaaaaaaaaaaaaaaaa",
636 \ " +++aaaaaaaaaaaaaa ",
637 \ ]
638 call s:compare_lines(expect, lines)
639 call s:close_windows('set breakindent& list& listchars& showbreak&')
640endfunc
641
642func Test_breakindent18_vartabs()
643 if !has("vartabs")
644 return
645 endif
646 let s:input = ""
647 call s:test_windows('setl breakindent list listchars=tab:<->')
648 call setline(1, "\t" . repeat('a', 63))
649 vert resize 30
650 norm! 1gg$
651 redraw!
652 let lines = s:screen_lines(1, 30)
653 let expect = [
654 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
655 \ " aaaaaaaaaaaaaaaaaaaaaaaaaa",
656 \ " aaaaaaaaaaa ",
657 \ ]
658 call s:compare_lines(expect, lines)
659 call s:close_windows('set breakindent& list& listchars&')
660endfunc
661
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100662func Test_breakindent19_sbr_nextpage()
663 let s:input = ""
664 call s:test_windows('setl breakindent briopt=shift:2,sbr,min:18 sbr=>')
665 call setline(1, repeat('a', 200))
666 norm! 1gg
667 redraw!
668 let lines = s:screen_lines(1, 20)
669 let expect = [
670 \ "aaaaaaaaaaaaaaaaaaaa",
671 \ "> aaaaaaaaaaaaaaaaaa",
672 \ "> aaaaaaaaaaaaaaaaaa",
673 \ ]
674 call s:compare_lines(expect, lines)
675 " Scroll down one screen line
676 setl scrolloff=5
677 norm! 5gj
678 redraw!
679 let lines = s:screen_lines(1, 20)
680 let expect = [
681 \ "> aaaaaaaaaaaaaaaaaa",
682 \ "> aaaaaaaaaaaaaaaaaa",
683 \ "> aaaaaaaaaaaaaaaaaa",
684 \ ]
685 call s:compare_lines(expect, lines)
Bram Moolenaar1aa76b82020-02-23 15:17:27 +0100686
687 setl breakindent briopt=min:18 sbr=>
688 norm! 5gj
689 let lines = s:screen_lines(1, 20)
690 let expect = [
691 \ ">aaaaaaaaaaaaaaaaaaa",
692 \ ">aaaaaaaaaaaaaaaaaaa",
693 \ ">aaaaaaaaaaaaaaaaaaa",
694 \ ]
695 call s:compare_lines(expect, lines)
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100696 call s:close_windows('set breakindent& briopt& sbr&')
697endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100698
699" vim: shiftwidth=2 sts=2 expandtab