blob: 0c143b1943b01549d4e152b5a6dbbadb8614b798 [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
Christian Brabandt4a0b85a2021-07-14 20:00:27 +020018func s:screen_lines2(lnums, lnume, width) abort
19 return ScreenLines([a:lnums, a:lnume], a:width)
20endfunc
21
Bram Moolenaar04958cb2018-06-23 19:23:02 +020022func s:compare_lines(expect, actual)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010023 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020024endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010025
Bram Moolenaar04958cb2018-06-23 19:23:02 +020026func s:test_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010027 call NewWindow(10, 20)
28 setl ts=4 sw=4 sts=4 breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +010029 put =s:input
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010030 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020031endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010032
Bram Moolenaar04958cb2018-06-23 19:23:02 +020033func s:close_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010034 call CloseWindow()
35 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020036endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010037
Bram Moolenaar04958cb2018-06-23 19:23:02 +020038func Test_breakindent01()
Bram Moolenaar6c896862016-11-17 19:46:51 +010039 " simple breakindent test
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010040 call s:test_windows('setl briopt=min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020041 let lines = s:screen_lines(line('.'),8)
42 let expect = [
43 \ " abcd",
44 \ " qrst",
45 \ " GHIJ",
46 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010047 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010048 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +020049endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010050
Bram Moolenaar04958cb2018-06-23 19:23:02 +020051func Test_breakindent01_vartabs()
52 " like 01 but with vartabs feature
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020053 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +020054 call s:test_windows('setl briopt=min:0 vts=4')
55 let lines = s:screen_lines(line('.'),8)
56 let expect = [
57 \ " abcd",
58 \ " qrst",
59 \ " GHIJ",
60 \ ]
61 call s:compare_lines(expect, lines)
62 call s:close_windows('set vts&')
63endfunc
64
65func Test_breakindent02()
Bram Moolenaar6c896862016-11-17 19:46:51 +010066 " simple breakindent test with showbreak set
Bram Moolenaaree857022019-11-09 23:26:40 +010067 set sbr=>>
68 call s:test_windows('setl briopt=min:0 sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020069 let lines = s:screen_lines(line('.'),8)
70 let expect = [
71 \ " abcd",
72 \ " >>qr",
73 \ " >>EF",
74 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010075 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010076 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020077endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010078
Bram Moolenaar04958cb2018-06-23 19:23:02 +020079func Test_breakindent02_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020080 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +020081 " 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
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200109 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200110 call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4')
111 let lines = s:screen_lines(line('.'),8)
112 let expect = [
113 \ " abcd",
114 \ "++ qrst",
115 \ "++ GHIJ",
116 \ ]
117 call s:compare_lines(expect, lines)
118 " clean up
119 call s:close_windows('set sbr= vts&')
120endfunc
121
122func Test_breakindent04()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100123 " breakindent set with min width 18
Bram Moolenaaree857022019-11-09 23:26:40 +0100124 set sbr=<<<
125 call s:test_windows('setl sbr=NONE briopt=min:18')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200126 let lines = s:screen_lines(line('.'),8)
127 let expect = [
128 \ " abcd",
129 \ " qrstuv",
130 \ " IJKLMN",
131 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100132 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100133 " clean up
134 call s:close_windows('set sbr=')
Bram Moolenaaree857022019-11-09 23:26:40 +0100135 set sbr=
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200136endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100137
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200138func Test_breakindent04_vartabs()
139 " breakindent set with min width 18
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200140 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200141 call s:test_windows('setl sbr= briopt=min:18 vts=4')
142 let lines = s:screen_lines(line('.'),8)
143 let expect = [
144 \ " abcd",
145 \ " qrstuv",
146 \ " IJKLMN",
147 \ ]
148 call s:compare_lines(expect, lines)
149 " clean up
150 call s:close_windows('set sbr= vts&')
151endfunc
152
153func Test_breakindent05()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100154 " breakindent set and shift by 2
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100155 call s:test_windows('setl briopt=shift:2,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200156 let lines = s:screen_lines(line('.'),8)
157 let expect = [
158 \ " abcd",
159 \ " qr",
160 \ " EF",
161 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100162 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100163 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200164endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100165
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200166func Test_breakindent05_vartabs()
167 " breakindent set and shift by 2
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200168 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200169 call s:test_windows('setl briopt=shift:2,min:0 vts=4')
170 let lines = s:screen_lines(line('.'),8)
171 let expect = [
172 \ " abcd",
173 \ " qr",
174 \ " EF",
175 \ ]
176 call s:compare_lines(expect, lines)
177 call s:close_windows('set vts&')
178endfunc
179
180func Test_breakindent06()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100181 " breakindent set and shift by -1
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100182 call s:test_windows('setl briopt=shift:-1,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200183 let lines = s:screen_lines(line('.'),8)
184 let expect = [
185 \ " abcd",
186 \ " qrstu",
187 \ " HIJKL",
188 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100189 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100190 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200191endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100192
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200193func Test_breakindent06_vartabs()
194 " breakindent set and shift by -1
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200195 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200196 call s:test_windows('setl briopt=shift:-1,min:0 vts=4')
197 let lines = s:screen_lines(line('.'),8)
198 let expect = [
199 \ " abcd",
200 \ " qrstu",
201 \ " HIJKL",
202 \ ]
203 call s:compare_lines(expect, lines)
204 call s:close_windows('set vts&')
205endfunc
206
207func Test_breakindent07()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100208 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100209 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200210 let lines = s:screen_lines(line('.'),10)
211 let expect = [
212 \ " 2 ab",
213 \ "? m",
214 \ "? x",
215 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100216 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100217 " clean up
218 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200219endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100220
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200221func Test_breakindent07_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200222 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200223 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
224 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4')
225 let lines = s:screen_lines(line('.'),10)
226 let expect = [
227 \ " 2 ab",
228 \ "? m",
229 \ "? x",
230 \ ]
231 call s:compare_lines(expect, lines)
232 " clean up
233 call s:close_windows('set sbr= cpo-=n vts&')
234endfunc
235
236func Test_breakindent07a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100237 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100238 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200239 let lines = s:screen_lines(line('.'),10)
240 let expect = [
241 \ " 2 ab",
242 \ " ? m",
243 \ " ? x",
244 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100245 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100246 " clean up
247 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200248endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100249
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200250func Test_breakindent07a_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200251 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200252 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
253 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4')
254 let lines = s:screen_lines(line('.'),10)
255 let expect = [
256 \ " 2 ab",
257 \ " ? m",
258 \ " ? x",
259 \ ]
260 call s:compare_lines(expect, lines)
261 " clean up
262 call s:close_windows('set sbr= vts&')
263endfunc
264
265func Test_breakindent08()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100266 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100267 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 +0100268 " make sure, cache is invalidated!
269 set ts=8
270 redraw!
271 set ts=4
272 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200273 let lines = s:screen_lines(line('.'),10)
274 let expect = [
275 \ " 2 ^Iabcd",
276 \ "# opq",
277 \ "# BCD",
278 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100279 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100280 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200281endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100282
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200283func Test_breakindent08_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200284 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200285 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
286 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4')
287 " make sure, cache is invalidated!
288 set ts=8
289 redraw!
290 set ts=4
291 redraw!
292 let lines = s:screen_lines(line('.'),10)
293 let expect = [
294 \ " 2 ^Iabcd",
295 \ "# opq",
296 \ "# BCD",
297 \ ]
298 call s:compare_lines(expect, lines)
299 call s:close_windows('set sbr= cpo-=n vts&')
300endfunc
301
302func Test_breakindent08a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100303 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100304 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200305 let lines = s:screen_lines(line('.'),10)
306 let expect = [
307 \ " 2 ^Iabcd",
308 \ " # opq",
309 \ " # BCD",
310 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100311 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100312 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200313endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100314
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200315func Test_breakindent08a_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200316 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200317 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
318 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4')
319 let lines = s:screen_lines(line('.'),10)
320 let expect = [
321 \ " 2 ^Iabcd",
322 \ " # opq",
323 \ " # BCD",
324 \ ]
325 call s:compare_lines(expect, lines)
326 call s:close_windows('set sbr= vts&')
327endfunc
328
329func Test_breakindent09()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100330 " breakindent set and shift by 1, Number and list set sbr=#
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100331 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200332 let lines = s:screen_lines(line('.'),10)
333 let expect = [
334 \ " 2 ^Iabcd",
335 \ " #op",
336 \ " #AB",
337 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100338 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100339 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200340endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100341
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200342func Test_breakindent09_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200343 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200344 " breakindent set and shift by 1, Number and list set sbr=#
345 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4')
346 let lines = s:screen_lines(line('.'),10)
347 let expect = [
348 \ " 2 ^Iabcd",
349 \ " #op",
350 \ " #AB",
351 \ ]
352 call s:compare_lines(expect, lines)
353 call s:close_windows('set sbr= vts&')
354endfunc
355
356func Test_breakindent10()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100357 " breakindent set, Number set sbr=~
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100358 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100359 " make sure, cache is invalidated!
360 set ts=8
361 redraw!
362 set ts=4
363 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200364 let lines = s:screen_lines(line('.'),10)
365 let expect = [
366 \ " 2 ab",
367 \ "~ mn",
368 \ "~ yz",
369 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100370 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100371 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200372endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100373
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200374func Test_breakindent10_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200375 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200376 " breakindent set, Number set sbr=~
377 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4')
378 " make sure, cache is invalidated!
379 set ts=8
380 redraw!
381 set ts=4
382 redraw!
383 let lines = s:screen_lines(line('.'),10)
384 let expect = [
385 \ " 2 ab",
386 \ "~ mn",
387 \ "~ yz",
388 \ ]
389 call s:compare_lines(expect, lines)
390 call s:close_windows('set sbr= cpo-=n vts&')
391endfunc
392
393func Test_breakindent11()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100394 " test strdisplaywidth()
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100395 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200396 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200397 let width = strlen(text[1:]) + indent(2) + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaar6c896862016-11-17 19:46:51 +0100398 call assert_equal(width, strdisplaywidth(text))
399 call s:close_windows('set sbr=')
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100400 call assert_equal(4, strdisplaywidth("\t", 4))
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200401endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100402
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200403func Test_breakindent11_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200404 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200405 " test strdisplaywidth()
406 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4')
407 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200408 let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +0200409 call assert_equal(width, text->strdisplaywidth())
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200410 call s:close_windows('set sbr= vts&')
411endfunc
412
413func Test_breakindent12()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100414 " test breakindent with long indent
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200415 let s:input = "\t\t\t\t\t{"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100416 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 +0200417 let lines = s:screen_lines(2,16)
418 let expect = [
419 \ " 2 >--->--->--->",
420 \ " ---{ ",
421 \ "~ ",
422 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100423 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100424 call s:close_windows('set nuw=4 listchars=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200425endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100426
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200427func Test_breakindent12_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200428 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200429 " test breakindent with long indent
430 let s:input = "\t\t\t\t\t{"
431 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4')
432 let lines = s:screen_lines(2,16)
433 let expect = [
434 \ " 2 >--->--->--->",
435 \ " ---{ ",
436 \ "~ ",
437 \ ]
438 call s:compare_lines(expect, lines)
439 call s:close_windows('set nuw=4 listchars= vts&')
440endfunc
441
442func Test_breakindent13()
443 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100444 call s:test_windows('setl breakindent briopt=min:10 ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100445 vert resize 20
446 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
447 1
448 norm! fbgj"ayl
449 2
450 norm! fygj"byl
451 call assert_equal('d', @a)
452 call assert_equal('w', @b)
453 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200454endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100455
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200456func Test_breakindent13_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200457 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200458 let s:input = ""
459 call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8')
460 vert resize 20
461 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
462 1
463 norm! fbgj"ayl
464 2
465 norm! fygj"byl
466 call assert_equal('d', @a)
467 call assert_equal('w', @b)
468 call s:close_windows('set vts&')
469endfunc
470
471func Test_breakindent14()
472 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100473 call s:test_windows('setl breakindent briopt= ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100474 vert resize 30
475 norm! 3a1234567890
476 norm! a abcde
477 exec "norm! 0\<C-V>tex"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200478 let lines = s:screen_lines(line('.'),8)
479 let expect = [
480 \ "e ",
481 \ "~ ",
482 \ "~ ",
483 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100484 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100485 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200486endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100487
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200488func Test_breakindent14_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200489 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200490 let s:input = ""
491 call s:test_windows('setl breakindent briopt= ts=8 vts=8')
492 vert resize 30
493 norm! 3a1234567890
494 norm! a abcde
495 exec "norm! 0\<C-V>tex"
496 let lines = s:screen_lines(line('.'),8)
497 let expect = [
498 \ "e ",
499 \ "~ ",
500 \ "~ ",
501 \ ]
502 call s:compare_lines(expect, lines)
503 call s:close_windows('set vts&')
504endfunc
505
506func Test_breakindent15()
507 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100508 call s:test_windows('setl breakindent briopt= ts=8 sw=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100509 vert resize 30
510 norm! 4a1234567890
511 exe "normal! >>\<C-V>3f0x"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200512 let lines = s:screen_lines(line('.'),20)
513 let expect = [
514 \ " 1234567890 ",
515 \ "~ ",
516 \ "~ ",
517 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100518 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100519 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200520endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100521
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200522func Test_breakindent15_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200523 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200524 let s:input = ""
525 call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8')
526 vert resize 30
527 norm! 4a1234567890
528 exe "normal! >>\<C-V>3f0x"
529 let lines = s:screen_lines(line('.'),20)
530 let expect = [
531 \ " 1234567890 ",
532 \ "~ ",
533 \ "~ ",
534 \ ]
535 call s:compare_lines(expect, lines)
536 call s:close_windows('set vts&')
537endfunc
538
539func Test_breakindent16()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100540 " Check that overlong lines are indented correctly.
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200541 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100542 call s:test_windows('setl breakindent briopt=min:0 ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100543 call setline(1, "\t".repeat("1234567890", 10))
544 resize 6
545 norm! 1gg$
546 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200547 let lines = s:screen_lines(1,10)
548 let expect = [
549 \ " 789012",
550 \ " 345678",
551 \ " 901234",
552 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100553 call s:compare_lines(expect, lines)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200554 let lines = s:screen_lines(4,10)
555 let expect = [
556 \ " 567890",
557 \ " 123456",
558 \ " 7890 ",
559 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100560 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100561 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200562endfunc
563
564func Test_breakindent16_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200565 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200566 " Check that overlong lines are indented correctly.
567 let s:input = ""
568 call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4')
569 call setline(1, "\t".repeat("1234567890", 10))
570 resize 6
571 norm! 1gg$
572 redraw!
573 let lines = s:screen_lines(1,10)
574 let expect = [
575 \ " 789012",
576 \ " 345678",
577 \ " 901234",
578 \ ]
579 call s:compare_lines(expect, lines)
580 let lines = s:screen_lines(4,10)
581 let expect = [
582 \ " 567890",
583 \ " 123456",
584 \ " 7890 ",
585 \ ]
586 call s:compare_lines(expect, lines)
587 call s:close_windows('set vts&')
588endfunc
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100589
590func Test_breakindent17_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200591 CheckFeature vartabs
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100592 let s:input = ""
593 call s:test_windows('setl breakindent list listchars=tab:<-> showbreak=+++')
594 call setline(1, "\t" . repeat('a', 63))
595 vert resize 30
596 norm! 1gg$
597 redraw!
598 let lines = s:screen_lines(1, 30)
599 let expect = [
600 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
601 \ " +++aaaaaaaaaaaaaaaaaaaaaaa",
602 \ " +++aaaaaaaaaaaaaa ",
603 \ ]
604 call s:compare_lines(expect, lines)
605 call s:close_windows('set breakindent& list& listchars& showbreak&')
606endfunc
607
608func Test_breakindent18_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200609 CheckFeature vartabs
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100610 let s:input = ""
611 call s:test_windows('setl breakindent list listchars=tab:<->')
612 call setline(1, "\t" . repeat('a', 63))
613 vert resize 30
614 norm! 1gg$
615 redraw!
616 let lines = s:screen_lines(1, 30)
617 let expect = [
618 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
619 \ " aaaaaaaaaaaaaaaaaaaaaaaaaa",
620 \ " aaaaaaaaaaa ",
621 \ ]
622 call s:compare_lines(expect, lines)
623 call s:close_windows('set breakindent& list& listchars&')
624endfunc
625
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100626func Test_breakindent19_sbr_nextpage()
627 let s:input = ""
628 call s:test_windows('setl breakindent briopt=shift:2,sbr,min:18 sbr=>')
629 call setline(1, repeat('a', 200))
630 norm! 1gg
631 redraw!
632 let lines = s:screen_lines(1, 20)
633 let expect = [
634 \ "aaaaaaaaaaaaaaaaaaaa",
635 \ "> aaaaaaaaaaaaaaaaaa",
636 \ "> aaaaaaaaaaaaaaaaaa",
637 \ ]
638 call s:compare_lines(expect, lines)
639 " Scroll down one screen line
640 setl scrolloff=5
Bram Moolenaar52029292021-02-10 21:20:30 +0100641 norm! 5gj
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100642 let lines = s:screen_lines(1, 20)
643 let expect = [
Bram Moolenaar52029292021-02-10 21:20:30 +0100644 \ "aaaaaaaaaaaaaaaaaaaa",
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100645 \ "> aaaaaaaaaaaaaaaaaa",
646 \ "> aaaaaaaaaaaaaaaaaa",
647 \ ]
648 call s:compare_lines(expect, lines)
Bram Moolenaar52029292021-02-10 21:20:30 +0100649 redraw!
650 " moving the cursor doesn't change the text offset
651 norm! l
652 redraw!
653 let lines = s:screen_lines(1, 20)
654 call s:compare_lines(expect, lines)
Bram Moolenaar1aa76b82020-02-23 15:17:27 +0100655
656 setl breakindent briopt=min:18 sbr=>
657 norm! 5gj
658 let lines = s:screen_lines(1, 20)
659 let expect = [
660 \ ">aaaaaaaaaaaaaaaaaaa",
661 \ ">aaaaaaaaaaaaaaaaaaa",
662 \ ">aaaaaaaaaaaaaaaaaaa",
663 \ ]
664 call s:compare_lines(expect, lines)
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100665 call s:close_windows('set breakindent& briopt& sbr&')
666endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100667
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200668func Test_breakindent20_cpo_n_nextpage()
669 let s:input = ""
670 call s:test_windows('setl breakindent briopt=min:14 cpo+=n number')
671 call setline(1, repeat('a', 200))
672 norm! 1gg
673 redraw!
674 let lines = s:screen_lines(1, 20)
675 let expect = [
676 \ " 1 aaaaaaaaaaaaaaaa",
677 \ " aaaaaaaaaaaaaaaa",
678 \ " aaaaaaaaaaaaaaaa",
679 \ ]
680 call s:compare_lines(expect, lines)
681 " Scroll down one screen line
682 setl scrolloff=5
683 norm! 5gj
684 redraw!
685 let lines = s:screen_lines(1, 20)
686 let expect = [
687 \ "--1 aaaaaaaaaaaaaaaa",
688 \ " aaaaaaaaaaaaaaaa",
689 \ " aaaaaaaaaaaaaaaa",
690 \ ]
691 call s:compare_lines(expect, lines)
692
693 setl briopt+=shift:2
694 norm! 1gg
695 let lines = s:screen_lines(1, 20)
696 let expect = [
697 \ " 1 aaaaaaaaaaaaaaaa",
698 \ " aaaaaaaaaaaaaa",
699 \ " aaaaaaaaaaaaaa",
700 \ ]
701 call s:compare_lines(expect, lines)
702 " Scroll down one screen line
703 norm! 5gj
704 let lines = s:screen_lines(1, 20)
705 let expect = [
706 \ "--1 aaaaaaaaaaaaaa",
707 \ " aaaaaaaaaaaaaa",
708 \ " aaaaaaaaaaaaaa",
709 \ ]
710 call s:compare_lines(expect, lines)
711
712 call s:close_windows('set breakindent& briopt& cpo& number&')
713endfunc
714
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200715func Test_breakindent20_list()
716 call s:test_windows('setl breakindent breakindentopt= linebreak')
717 " default:
718 call setline(1, [' 1. Congress shall make no law',
719 \ ' 2.) Congress shall make no law',
720 \ ' 3.] Congress shall make no law'])
721 norm! 1gg
722 redraw!
723 let lines = s:screen_lines2(1, 6, 20)
724 let expect = [
725 \ " 1. Congress ",
726 \ "shall make no law ",
727 \ " 2.) Congress ",
728 \ "shall make no law ",
729 \ " 3.] Congress ",
730 \ "shall make no law ",
731 \ ]
732 call s:compare_lines(expect, lines)
733 " set mininum indent
734 setl briopt=min:5
735 redraw!
736 let lines = s:screen_lines2(1, 6, 20)
737 let expect = [
738 \ " 1. Congress ",
739 \ " shall make no law ",
740 \ " 2.) Congress ",
741 \ " shall make no law ",
742 \ " 3.] Congress ",
743 \ " shall make no law ",
744 \ ]
745 call s:compare_lines(expect, lines)
746 " set additional handing indent
747 setl briopt+=list:4
748 redraw!
749 let expect = [
750 \ " 1. Congress ",
751 \ " shall make no ",
752 \ " law ",
753 \ " 2.) Congress ",
754 \ " shall make no ",
755 \ " law ",
756 \ " 3.] Congress ",
757 \ " shall make no ",
758 \ " law ",
759 \ ]
760 let lines = s:screen_lines2(1, 9, 20)
761 call s:compare_lines(expect, lines)
Maxim Kimf674b352021-07-22 11:46:59 +0200762
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200763 " reset linebreak option
764 " Note: it indents by one additional
765 " space, because of the leading space.
766 setl linebreak&vim list listchars=eol:$,space:_
767 redraw!
768 let expect = [
769 \ "__1.__Congress_shall",
770 \ " _make_no_law$ ",
771 \ "__2.)_Congress_shall",
772 \ " _make_no_law$ ",
773 \ "__3.]_Congress_shall",
774 \ " _make_no_law$ ",
775 \ ]
776 let lines = s:screen_lines2(1, 6, 20)
777 call s:compare_lines(expect, lines)
778
Maxim Kimf674b352021-07-22 11:46:59 +0200779 " check formatlistpat indent
780 setl briopt=min:5,list:-1
781 setl linebreak list&vim listchars&vim
782 let &l:flp = '^\s*\d\+\.\?[\]:)}\t ]\s*'
783 redraw!
784 let expect = [
785 \ " 1. Congress ",
786 \ " shall make no ",
787 \ " law ",
788 \ " 2.) Congress ",
789 \ " shall make no ",
790 \ " law ",
791 \ " 3.] Congress ",
792 \ " shall make no ",
793 \ " law ",
794 \ ]
795 let lines = s:screen_lines2(1, 9, 20)
796 call s:compare_lines(expect, lines)
797 " check formatlistpat indent with different list levels
798 let &l:flp = '^\s*\*\+\s\+'
799 redraw!
800 %delete _
801 call setline(1, ['* Congress shall make no law',
802 \ '*** Congress shall make no law',
803 \ '**** Congress shall make no law'])
804 norm! 1gg
805 let expect = [
806 \ "* Congress shall ",
807 \ " make no law ",
808 \ "*** Congress shall ",
809 \ " make no law ",
810 \ "**** Congress shall ",
811 \ " make no law ",
812 \ ]
813 let lines = s:screen_lines2(1, 6, 20)
814 call s:compare_lines(expect, lines)
815
816 " check formatlistpat indent with different list level
817 " showbreak and sbr
818 setl briopt=min:5,sbr,list:-1,shift:2
819 setl showbreak=>
820 redraw!
821 let expect = [
822 \ "* Congress shall ",
823 \ "> make no law ",
824 \ "*** Congress shall ",
825 \ "> make no law ",
826 \ "**** Congress shall ",
827 \ "> make no law ",
828 \ ]
829 let lines = s:screen_lines2(1, 6, 20)
830 call s:compare_lines(expect, lines)
831 call s:close_windows('set breakindent& briopt& linebreak& list& listchars& showbreak&')
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200832endfunc
833
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200834" The following used to crash Vim. This is fixed by 8.2.3391.
835" This is a regression introduced by 8.2.2903.
836func Test_window_resize_with_linebreak()
837 new
838 53vnew
839 set linebreak
840 set showbreak=>>
841 set breakindent
842 set breakindentopt=shift:4
843 call setline(1, "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a")
844 redraw!
845 call assert_equal([" >>aa^@\"a: "], ScreenLines(2, 14))
846 vertical resize 52
847 redraw!
848 call assert_equal([" >>aaa^@\"a:"], ScreenLines(2, 14))
849 %bw!
850endfunc
851
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100852" vim: shiftwidth=2 sts=2 expandtab