blob: bb164f70ea8582508d5e76365a2888c6daf4fca3 [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 +02007CheckOption breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +01008
Christian Brabandteb380b92025-07-07 20:53:55 +02009source util/screendump.vim
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010010
Bram Moolenaarfa4873c2022-06-30 22:13:59 +010011func SetUp()
12 let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
13endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010014
Bram Moolenaar04958cb2018-06-23 19:23:02 +020015func s:screen_lines(lnum, width) abort
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010016 return ScreenLines([a:lnum, a:lnum + 2], a:width)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020017endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010018
Christian Brabandt4a0b85a2021-07-14 20:00:27 +020019func s:screen_lines2(lnums, lnume, width) abort
20 return ScreenLines([a:lnums, a:lnume], a:width)
21endfunc
22
Bram Moolenaar04958cb2018-06-23 19:23:02 +020023func s:compare_lines(expect, actual)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010024 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020025endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010026
Bram Moolenaar04958cb2018-06-23 19:23:02 +020027func s:test_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010028 call NewWindow(10, 20)
29 setl ts=4 sw=4 sts=4 breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +010030 put =s:input
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010031 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 s:close_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010035 call CloseWindow()
36 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020037endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010038
Bram Moolenaar04958cb2018-06-23 19:23:02 +020039func Test_breakindent01()
Bram Moolenaar6c896862016-11-17 19:46:51 +010040 " simple breakindent test
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010041 call s:test_windows('setl briopt=min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020042 let lines = s:screen_lines(line('.'),8)
43 let expect = [
44 \ " abcd",
45 \ " qrst",
46 \ " GHIJ",
47 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010048 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010049 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +020050endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010051
Bram Moolenaar04958cb2018-06-23 19:23:02 +020052func Test_breakindent01_vartabs()
53 " like 01 but with vartabs feature
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020054 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +020055 call s:test_windows('setl briopt=min:0 vts=4')
56 let lines = s:screen_lines(line('.'),8)
57 let expect = [
58 \ " abcd",
59 \ " qrst",
60 \ " GHIJ",
61 \ ]
62 call s:compare_lines(expect, lines)
63 call s:close_windows('set vts&')
64endfunc
65
66func Test_breakindent02()
Bram Moolenaar6c896862016-11-17 19:46:51 +010067 " simple breakindent test with showbreak set
Bram Moolenaaree857022019-11-09 23:26:40 +010068 set sbr=>>
69 call s:test_windows('setl briopt=min:0 sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020070 let lines = s:screen_lines(line('.'),8)
71 let expect = [
72 \ " abcd",
73 \ " >>qr",
74 \ " >>EF",
75 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010076 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010077 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020078endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010079
Bram Moolenaar04958cb2018-06-23 19:23:02 +020080func Test_breakindent02_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020081 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +020082 " simple breakindent test with showbreak set
83 call s:test_windows('setl briopt=min:0 sbr=>> vts=4')
Bram Moolenaar0466d392022-10-03 17:07:34 +010084 let lines = s:screen_lines(line('.'), 8)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020085 let expect = [
86 \ " abcd",
87 \ " >>qr",
88 \ " >>EF",
89 \ ]
90 call s:compare_lines(expect, lines)
91 call s:close_windows('set sbr= vts&')
92endfunc
93
94func Test_breakindent03()
Bram Moolenaar6c896862016-11-17 19:46:51 +010095 " simple breakindent test with showbreak set and briopt including sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010096 call s:test_windows('setl briopt=sbr,min:0 sbr=++')
Bram Moolenaar0466d392022-10-03 17:07:34 +010097 let lines = s:screen_lines(line('.'), 8)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020098 let expect = [
99 \ " abcd",
100 \ "++ qrst",
101 \ "++ GHIJ",
102 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100103 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100104 " clean up
105 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200106endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100107
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200108func Test_breakindent03_vartabs()
109 " simple breakindent test with showbreak set and briopt including sbr
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200110 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200111 call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4')
Bram Moolenaar0466d392022-10-03 17:07:34 +0100112 let lines = s:screen_lines(line('.'), 8)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200113 let expect = [
114 \ " abcd",
115 \ "++ qrst",
116 \ "++ GHIJ",
117 \ ]
118 call s:compare_lines(expect, lines)
119 " clean up
120 call s:close_windows('set sbr= vts&')
121endfunc
122
123func Test_breakindent04()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100124 " breakindent set with min width 18
Bram Moolenaaree857022019-11-09 23:26:40 +0100125 set sbr=<<<
126 call s:test_windows('setl sbr=NONE briopt=min:18')
Bram Moolenaar0466d392022-10-03 17:07:34 +0100127 let lines = s:screen_lines(line('.'), 8)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200128 let expect = [
129 \ " abcd",
130 \ " qrstuv",
131 \ " IJKLMN",
132 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100133 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100134 " clean up
135 call s:close_windows('set sbr=')
Bram Moolenaaree857022019-11-09 23:26:40 +0100136 set sbr=
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200137endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100138
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200139func Test_breakindent04_vartabs()
140 " breakindent set with min width 18
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200141 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200142 call s:test_windows('setl sbr= briopt=min:18 vts=4')
Bram Moolenaar0466d392022-10-03 17:07:34 +0100143 let lines = s:screen_lines(line('.'), 8)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200144 let expect = [
145 \ " abcd",
146 \ " qrstuv",
147 \ " IJKLMN",
148 \ ]
149 call s:compare_lines(expect, lines)
150 " clean up
151 call s:close_windows('set sbr= vts&')
152endfunc
153
154func Test_breakindent05()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100155 " breakindent set and shift by 2
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100156 call s:test_windows('setl briopt=shift:2,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200157 let lines = s:screen_lines(line('.'),8)
158 let expect = [
159 \ " abcd",
160 \ " qr",
161 \ " EF",
162 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100163 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100164 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200165endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100166
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200167func Test_breakindent05_vartabs()
168 " breakindent set and shift by 2
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200169 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200170 call s:test_windows('setl briopt=shift:2,min:0 vts=4')
171 let lines = s:screen_lines(line('.'),8)
172 let expect = [
173 \ " abcd",
174 \ " qr",
175 \ " EF",
176 \ ]
177 call s:compare_lines(expect, lines)
178 call s:close_windows('set vts&')
179endfunc
180
181func Test_breakindent06()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100182 " breakindent set and shift by -1
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100183 call s:test_windows('setl briopt=shift:-1,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200184 let lines = s:screen_lines(line('.'),8)
185 let expect = [
186 \ " abcd",
187 \ " qrstu",
188 \ " HIJKL",
189 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100190 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100191 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200192endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100193
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200194func Test_breakindent06_vartabs()
195 " breakindent set and shift by -1
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200196 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200197 call s:test_windows('setl briopt=shift:-1,min:0 vts=4')
198 let lines = s:screen_lines(line('.'),8)
199 let expect = [
200 \ " abcd",
201 \ " qrstu",
202 \ " HIJKL",
203 \ ]
204 call s:compare_lines(expect, lines)
205 call s:close_windows('set vts&')
206endfunc
207
208func Test_breakindent07()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100209 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100210 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200211 let lines = s:screen_lines(line('.'),10)
212 let expect = [
213 \ " 2 ab",
214 \ "? m",
215 \ "? x",
216 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100217 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100218 " clean up
219 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200220endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100221
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200222func Test_breakindent07_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200223 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200224 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
225 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4')
226 let lines = s:screen_lines(line('.'),10)
227 let expect = [
228 \ " 2 ab",
229 \ "? m",
230 \ "? x",
231 \ ]
232 call s:compare_lines(expect, lines)
233 " clean up
234 call s:close_windows('set sbr= cpo-=n vts&')
235endfunc
236
237func Test_breakindent07a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100238 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100239 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200240 let lines = s:screen_lines(line('.'),10)
241 let expect = [
242 \ " 2 ab",
243 \ " ? m",
244 \ " ? x",
245 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100246 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100247 " clean up
248 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200249endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100250
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200251func Test_breakindent07a_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200252 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200253 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
254 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4')
255 let lines = s:screen_lines(line('.'),10)
256 let expect = [
257 \ " 2 ab",
258 \ " ? m",
259 \ " ? x",
260 \ ]
261 call s:compare_lines(expect, lines)
262 " clean up
263 call s:close_windows('set sbr= vts&')
264endfunc
265
266func Test_breakindent08()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100267 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100268 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 +0100269 " make sure, cache is invalidated!
270 set ts=8
271 redraw!
272 set ts=4
273 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200274 let lines = s:screen_lines(line('.'),10)
275 let expect = [
276 \ " 2 ^Iabcd",
277 \ "# opq",
278 \ "# BCD",
279 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100280 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100281 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200282endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100283
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200284func Test_breakindent08_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200285 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200286 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
287 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4')
288 " make sure, cache is invalidated!
289 set ts=8
290 redraw!
291 set ts=4
292 redraw!
293 let lines = s:screen_lines(line('.'),10)
294 let expect = [
295 \ " 2 ^Iabcd",
296 \ "# opq",
297 \ "# BCD",
298 \ ]
299 call s:compare_lines(expect, lines)
300 call s:close_windows('set sbr= cpo-=n vts&')
301endfunc
302
303func Test_breakindent08a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100304 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100305 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200306 let lines = s:screen_lines(line('.'),10)
307 let expect = [
308 \ " 2 ^Iabcd",
309 \ " # opq",
310 \ " # BCD",
311 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100312 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100313 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200314endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100315
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200316func Test_breakindent08a_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200317 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200318 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
319 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4')
320 let lines = s:screen_lines(line('.'),10)
321 let expect = [
322 \ " 2 ^Iabcd",
323 \ " # opq",
324 \ " # BCD",
325 \ ]
326 call s:compare_lines(expect, lines)
327 call s:close_windows('set sbr= vts&')
328endfunc
329
330func Test_breakindent09()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100331 " breakindent set and shift by 1, Number and list set sbr=#
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100332 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200333 let lines = s:screen_lines(line('.'),10)
334 let expect = [
335 \ " 2 ^Iabcd",
336 \ " #op",
337 \ " #AB",
338 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100339 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100340 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200341endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100342
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200343func Test_breakindent09_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200344 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200345 " breakindent set and shift by 1, Number and list set sbr=#
346 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4')
347 let lines = s:screen_lines(line('.'),10)
348 let expect = [
349 \ " 2 ^Iabcd",
350 \ " #op",
351 \ " #AB",
352 \ ]
353 call s:compare_lines(expect, lines)
354 call s:close_windows('set sbr= vts&')
355endfunc
356
357func Test_breakindent10()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100358 " breakindent set, Number set sbr=~
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100359 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100360 " make sure, cache is invalidated!
361 set ts=8
362 redraw!
363 set ts=4
364 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200365 let lines = s:screen_lines(line('.'),10)
366 let expect = [
367 \ " 2 ab",
368 \ "~ mn",
369 \ "~ yz",
370 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100371 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100372 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200373endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100374
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200375func Test_breakindent10_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200376 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200377 " breakindent set, Number set sbr=~
378 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4')
379 " make sure, cache is invalidated!
380 set ts=8
381 redraw!
382 set ts=4
383 redraw!
384 let lines = s:screen_lines(line('.'),10)
385 let expect = [
386 \ " 2 ab",
387 \ "~ mn",
388 \ "~ yz",
389 \ ]
390 call s:compare_lines(expect, lines)
391 call s:close_windows('set sbr= cpo-=n vts&')
392endfunc
393
394func Test_breakindent11()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100395 " test strdisplaywidth()
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100396 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200397 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200398 let width = strlen(text[1:]) + indent(2) + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaar6c896862016-11-17 19:46:51 +0100399 call assert_equal(width, strdisplaywidth(text))
400 call s:close_windows('set sbr=')
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100401 call assert_equal(4, strdisplaywidth("\t", 4))
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200402endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100403
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200404func Test_breakindent11_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200405 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200406 " test strdisplaywidth()
407 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4')
408 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200409 let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +0200410 call assert_equal(width, text->strdisplaywidth())
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200411 call s:close_windows('set sbr= vts&')
412endfunc
413
414func Test_breakindent12()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100415 " test breakindent with long indent
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200416 let s:input = "\t\t\t\t\t{"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100417 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 +0200418 let lines = s:screen_lines(2,16)
419 let expect = [
420 \ " 2 >--->--->--->",
421 \ " ---{ ",
422 \ "~ ",
423 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100424 call s:compare_lines(expect, lines)
zeertzjqefabd7c2024-02-11 17:16:19 +0100425 call s:close_windows('set nuw=4 listchars&')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200426endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100427
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200428func Test_breakindent12_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200429 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200430 " test breakindent with long indent
431 let s:input = "\t\t\t\t\t{"
432 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4')
433 let lines = s:screen_lines(2,16)
434 let expect = [
435 \ " 2 >--->--->--->",
436 \ " ---{ ",
437 \ "~ ",
438 \ ]
439 call s:compare_lines(expect, lines)
zeertzjqefabd7c2024-02-11 17:16:19 +0100440 call s:close_windows('set nuw=4 listchars& vts&')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200441endfunc
442
443func Test_breakindent13()
444 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100445 call s:test_windows('setl breakindent briopt=min:10 ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100446 vert resize 20
447 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
448 1
449 norm! fbgj"ayl
450 2
451 norm! fygj"byl
452 call assert_equal('d', @a)
453 call assert_equal('w', @b)
454 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200455endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100456
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200457func Test_breakindent13_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200458 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200459 let s:input = ""
460 call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8')
461 vert resize 20
462 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
463 1
464 norm! fbgj"ayl
465 2
466 norm! fygj"byl
467 call assert_equal('d', @a)
468 call assert_equal('w', @b)
469 call s:close_windows('set vts&')
470endfunc
471
472func Test_breakindent14()
473 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100474 call s:test_windows('setl breakindent briopt= ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100475 vert resize 30
476 norm! 3a1234567890
477 norm! a abcde
478 exec "norm! 0\<C-V>tex"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200479 let lines = s:screen_lines(line('.'),8)
480 let expect = [
481 \ "e ",
482 \ "~ ",
483 \ "~ ",
484 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100485 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100486 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200487endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100488
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200489func Test_breakindent14_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200490 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200491 let s:input = ""
492 call s:test_windows('setl breakindent briopt= ts=8 vts=8')
493 vert resize 30
494 norm! 3a1234567890
495 norm! a abcde
496 exec "norm! 0\<C-V>tex"
497 let lines = s:screen_lines(line('.'),8)
498 let expect = [
499 \ "e ",
500 \ "~ ",
501 \ "~ ",
502 \ ]
503 call s:compare_lines(expect, lines)
504 call s:close_windows('set vts&')
505endfunc
506
507func Test_breakindent15()
508 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100509 call s:test_windows('setl breakindent briopt= ts=8 sw=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100510 vert resize 30
511 norm! 4a1234567890
512 exe "normal! >>\<C-V>3f0x"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200513 let lines = s:screen_lines(line('.'),20)
514 let expect = [
515 \ " 1234567890 ",
516 \ "~ ",
517 \ "~ ",
518 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100519 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100520 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200521endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100522
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200523func Test_breakindent15_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200524 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200525 let s:input = ""
526 call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8')
527 vert resize 30
528 norm! 4a1234567890
529 exe "normal! >>\<C-V>3f0x"
530 let lines = s:screen_lines(line('.'),20)
531 let expect = [
532 \ " 1234567890 ",
533 \ "~ ",
534 \ "~ ",
535 \ ]
536 call s:compare_lines(expect, lines)
537 call s:close_windows('set vts&')
538endfunc
539
540func Test_breakindent16()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100541 " Check that overlong lines are indented correctly.
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200542 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100543 call s:test_windows('setl breakindent briopt=min:0 ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100544 call setline(1, "\t".repeat("1234567890", 10))
545 resize 6
546 norm! 1gg$
547 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200548 let lines = s:screen_lines(1,10)
549 let expect = [
Bram Moolenaar0466d392022-10-03 17:07:34 +0100550 \ "<<< 789012",
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200551 \ " 345678",
552 \ " 901234",
553 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100554 call s:compare_lines(expect, lines)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200555 let lines = s:screen_lines(4,10)
556 let expect = [
557 \ " 567890",
558 \ " 123456",
559 \ " 7890 ",
560 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100561 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100562 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200563endfunc
564
565func Test_breakindent16_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200566 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200567 " Check that overlong lines are indented correctly.
568 let s:input = ""
569 call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4')
570 call setline(1, "\t".repeat("1234567890", 10))
571 resize 6
572 norm! 1gg$
573 redraw!
574 let lines = s:screen_lines(1,10)
575 let expect = [
Bram Moolenaar0466d392022-10-03 17:07:34 +0100576 \ "<<< 789012",
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200577 \ " 345678",
578 \ " 901234",
579 \ ]
580 call s:compare_lines(expect, lines)
581 let lines = s:screen_lines(4,10)
582 let expect = [
583 \ " 567890",
584 \ " 123456",
585 \ " 7890 ",
586 \ ]
587 call s:compare_lines(expect, lines)
588 call s:close_windows('set vts&')
589endfunc
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100590
591func Test_breakindent17_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200592 CheckFeature vartabs
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100593 let s:input = ""
594 call s:test_windows('setl breakindent list listchars=tab:<-> showbreak=+++')
595 call setline(1, "\t" . repeat('a', 63))
596 vert resize 30
597 norm! 1gg$
598 redraw!
599 let lines = s:screen_lines(1, 30)
600 let expect = [
601 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
602 \ " +++aaaaaaaaaaaaaaaaaaaaaaa",
603 \ " +++aaaaaaaaaaaaaa ",
604 \ ]
605 call s:compare_lines(expect, lines)
606 call s:close_windows('set breakindent& list& listchars& showbreak&')
607endfunc
608
609func Test_breakindent18_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200610 CheckFeature vartabs
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100611 let s:input = ""
612 call s:test_windows('setl breakindent list listchars=tab:<->')
613 call setline(1, "\t" . repeat('a', 63))
614 vert resize 30
615 norm! 1gg$
616 redraw!
617 let lines = s:screen_lines(1, 30)
618 let expect = [
619 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
620 \ " aaaaaaaaaaaaaaaaaaaaaaaaaa",
621 \ " aaaaaaaaaaa ",
622 \ ]
623 call s:compare_lines(expect, lines)
624 call s:close_windows('set breakindent& list& listchars&')
625endfunc
626
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100627func Test_breakindent19_sbr_nextpage()
628 let s:input = ""
629 call s:test_windows('setl breakindent briopt=shift:2,sbr,min:18 sbr=>')
630 call setline(1, repeat('a', 200))
631 norm! 1gg
632 redraw!
633 let lines = s:screen_lines(1, 20)
634 let expect = [
635 \ "aaaaaaaaaaaaaaaaaaaa",
636 \ "> aaaaaaaaaaaaaaaaaa",
637 \ "> aaaaaaaaaaaaaaaaaa",
638 \ ]
639 call s:compare_lines(expect, lines)
640 " Scroll down one screen line
641 setl scrolloff=5
Bram Moolenaar52029292021-02-10 21:20:30 +0100642 norm! 5gj
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100643 let lines = s:screen_lines(1, 20)
644 let expect = [
Bram Moolenaar52029292021-02-10 21:20:30 +0100645 \ "aaaaaaaaaaaaaaaaaaaa",
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100646 \ "> aaaaaaaaaaaaaaaaaa",
647 \ "> aaaaaaaaaaaaaaaaaa",
648 \ ]
649 call s:compare_lines(expect, lines)
Bram Moolenaar52029292021-02-10 21:20:30 +0100650 redraw!
651 " moving the cursor doesn't change the text offset
652 norm! l
653 redraw!
654 let lines = s:screen_lines(1, 20)
655 call s:compare_lines(expect, lines)
Bram Moolenaar1aa76b82020-02-23 15:17:27 +0100656
657 setl breakindent briopt=min:18 sbr=>
658 norm! 5gj
659 let lines = s:screen_lines(1, 20)
660 let expect = [
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100661 \ ">aaaaaaaaaaaaaaaaaaa",
Bram Moolenaar1aa76b82020-02-23 15:17:27 +0100662 \ ">aaaaaaaaaaaaaaaaaaa",
663 \ ">aaaaaaaaaaaaaaaaaaa",
664 \ ]
665 call s:compare_lines(expect, lines)
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100666 call s:close_windows('set breakindent& briopt& sbr&')
667endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100668
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200669func Test_breakindent20_cpo_n_nextpage()
670 let s:input = ""
671 call s:test_windows('setl breakindent briopt=min:14 cpo+=n number')
Bram Moolenaar06618f92022-10-06 19:21:20 +0100672 call setline(1, repeat('abcdefghijklmnopqrst', 10))
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200673 norm! 1gg
674 redraw!
675 let lines = s:screen_lines(1, 20)
676 let expect = [
Bram Moolenaar06618f92022-10-06 19:21:20 +0100677 \ " 1 abcdefghijklmnop",
678 \ " qrstabcdefghijkl",
679 \ " mnopqrstabcdefgh",
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200680 \ ]
681 call s:compare_lines(expect, lines)
682 " Scroll down one screen line
683 setl scrolloff=5
Bram Moolenaar856c5d22022-10-13 21:54:28 +0100684 norm! 6gj
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200685 redraw!
686 let lines = s:screen_lines(1, 20)
687 let expect = [
Bram Moolenaar06618f92022-10-06 19:21:20 +0100688 \ "<<< qrstabcdefghijkl",
689 \ " mnopqrstabcdefgh",
690 \ " ijklmnopqrstabcd",
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200691 \ ]
Bram Moolenaar856c5d22022-10-13 21:54:28 +0100692 call s:compare_lines(expect, lines)
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200693
694 setl briopt+=shift:2
695 norm! 1gg
696 let lines = s:screen_lines(1, 20)
697 let expect = [
Bram Moolenaar06618f92022-10-06 19:21:20 +0100698 \ " 1 abcdefghijklmnop",
699 \ " qrstabcdefghij",
700 \ " klmnopqrstabcd",
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200701 \ ]
702 call s:compare_lines(expect, lines)
703 " Scroll down one screen line
Bram Moolenaar856c5d22022-10-13 21:54:28 +0100704 norm! 6gj
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200705 let lines = s:screen_lines(1, 20)
706 let expect = [
Bram Moolenaar06618f92022-10-06 19:21:20 +0100707 \ "<<< qrstabcdefghij",
708 \ " klmnopqrstabcd",
709 \ " efghijklmnopqr",
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200710 \ ]
Bram Moolenaar856c5d22022-10-13 21:54:28 +0100711 call s:compare_lines(expect, lines)
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200712
713 call s:close_windows('set breakindent& briopt& cpo& number&')
714endfunc
715
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200716func Test_breakindent20_list()
717 call s:test_windows('setl breakindent breakindentopt= linebreak')
718 " default:
719 call setline(1, [' 1. Congress shall make no law',
720 \ ' 2.) Congress shall make no law',
721 \ ' 3.] Congress shall make no law'])
722 norm! 1gg
723 redraw!
724 let lines = s:screen_lines2(1, 6, 20)
725 let expect = [
726 \ " 1. Congress ",
727 \ "shall make no law ",
728 \ " 2.) Congress ",
729 \ "shall make no law ",
730 \ " 3.] Congress ",
731 \ "shall make no law ",
732 \ ]
733 call s:compare_lines(expect, lines)
zeertzjqf0a9d652024-02-12 22:53:20 +0100734 " set minimum text width
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200735 setl briopt=min:5
736 redraw!
737 let lines = s:screen_lines2(1, 6, 20)
738 let expect = [
739 \ " 1. Congress ",
740 \ " shall make no law ",
741 \ " 2.) Congress ",
742 \ " shall make no law ",
743 \ " 3.] Congress ",
744 \ " shall make no law ",
745 \ ]
746 call s:compare_lines(expect, lines)
747 " set additional handing indent
748 setl briopt+=list:4
749 redraw!
750 let expect = [
751 \ " 1. Congress ",
752 \ " shall make no ",
753 \ " law ",
754 \ " 2.) Congress ",
755 \ " shall make no ",
756 \ " law ",
757 \ " 3.] Congress ",
758 \ " shall make no ",
759 \ " law ",
760 \ ]
761 let lines = s:screen_lines2(1, 9, 20)
762 call s:compare_lines(expect, lines)
Maxim Kimf674b352021-07-22 11:46:59 +0200763
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200764 " reset linebreak option
765 " Note: it indents by one additional
766 " space, because of the leading space.
767 setl linebreak&vim list listchars=eol:$,space:_
768 redraw!
769 let expect = [
770 \ "__1.__Congress_shall",
771 \ " _make_no_law$ ",
772 \ "__2.)_Congress_shall",
773 \ " _make_no_law$ ",
774 \ "__3.]_Congress_shall",
775 \ " _make_no_law$ ",
776 \ ]
777 let lines = s:screen_lines2(1, 6, 20)
778 call s:compare_lines(expect, lines)
779
Maxim Kimf674b352021-07-22 11:46:59 +0200780 " check formatlistpat indent
781 setl briopt=min:5,list:-1
782 setl linebreak list&vim listchars&vim
783 let &l:flp = '^\s*\d\+\.\?[\]:)}\t ]\s*'
784 redraw!
785 let expect = [
786 \ " 1. Congress ",
787 \ " shall make no ",
788 \ " law ",
789 \ " 2.) Congress ",
790 \ " shall make no ",
791 \ " law ",
792 \ " 3.] Congress ",
793 \ " shall make no ",
794 \ " law ",
795 \ ]
796 let lines = s:screen_lines2(1, 9, 20)
797 call s:compare_lines(expect, lines)
zeertzjq61a6ac42024-09-07 11:23:54 +0200798
799 " check with TABs
800 call setline(1, ["\t1.\tCongress shall make no law",
801 \ "\t2.) Congress shall make no law",
802 \ "\t3.] Congress shall make no law"])
803 setl tabstop=4 list listchars=tab:<->
804 norm! 1gg
805 redraw!
806 let expect = [
807 \ "<-->1.<>Congress ",
808 \ " shall make ",
809 \ " no law ",
810 \ "<-->2.) Congress ",
811 \ " shall make ",
812 \ " no law ",
813 \ "<-->3.] Congress ",
814 \ " shall make ",
815 \ " no law ",
816 \ ]
817 let lines = s:screen_lines2(1, 9, 20)
818 call s:compare_lines(expect, lines)
819
820 setl tabstop=2 nolist
821 redraw!
822 let expect = [
823 \ " 1. Congress ",
824 \ " shall make no ",
825 \ " law ",
826 \ " 2.) Congress ",
827 \ " shall make no ",
828 \ " law ",
829 \ " 3.] Congress ",
830 \ " shall make no ",
831 \ " law ",
832 \ ]
833 let lines = s:screen_lines2(1, 9, 20)
834 call s:compare_lines(expect, lines)
835
836 setl tabstop& list listchars=space:_
837 redraw!
838 let expect = [
839 \ "^I1.^ICongress_ ",
840 \ " shall_make_no_",
841 \ " law ",
842 \ "^I2.)_Congress_ ",
843 \ " shall_make_no_",
844 \ " law ",
845 \ "^I3.]_Congress_ ",
846 \ " shall_make_no_",
847 \ " law ",
848 \ ]
849 let lines = s:screen_lines2(1, 9, 20)
850 call s:compare_lines(expect, lines)
851
Maxim Kimf674b352021-07-22 11:46:59 +0200852 " check formatlistpat indent with different list levels
zeertzjq61a6ac42024-09-07 11:23:54 +0200853 let &l:flp = '^\s*\(\*\|\)\+\s\+'
854 setl list&vim listchars&vim
Maxim Kimf674b352021-07-22 11:46:59 +0200855 %delete _
856 call setline(1, ['* Congress shall make no law',
zeertzjq61a6ac42024-09-07 11:23:54 +0200857 \ '••• Congress shall make no law',
Maxim Kimf674b352021-07-22 11:46:59 +0200858 \ '**** Congress shall make no law'])
859 norm! 1gg
Bram Moolenaarc2a79b82022-07-01 13:15:35 +0100860 redraw!
Maxim Kimf674b352021-07-22 11:46:59 +0200861 let expect = [
862 \ "* Congress shall ",
863 \ " make no law ",
zeertzjq61a6ac42024-09-07 11:23:54 +0200864 \ "••• Congress shall ",
Maxim Kimf674b352021-07-22 11:46:59 +0200865 \ " make no law ",
866 \ "**** Congress shall ",
867 \ " make no law ",
868 \ ]
869 let lines = s:screen_lines2(1, 6, 20)
870 call s:compare_lines(expect, lines)
871
872 " check formatlistpat indent with different list level
873 " showbreak and sbr
Maxim Kim11916722022-09-02 14:08:53 +0100874 setl briopt=min:5,sbr,list:-1
Maxim Kimf674b352021-07-22 11:46:59 +0200875 setl showbreak=>
876 redraw!
877 let expect = [
878 \ "* Congress shall ",
879 \ "> make no law ",
zeertzjq61a6ac42024-09-07 11:23:54 +0200880 \ "••• Congress shall ",
Maxim Kimf674b352021-07-22 11:46:59 +0200881 \ "> make no law ",
882 \ "**** Congress shall ",
883 \ "> make no law ",
884 \ ]
885 let lines = s:screen_lines2(1, 6, 20)
886 call s:compare_lines(expect, lines)
Maxim Kim11916722022-09-02 14:08:53 +0100887
888 " check formatlistpat indent with different list level
889 " showbreak sbr and shift
890 setl briopt=min:5,sbr,list:-1,shift:2
891 setl showbreak=>
892 redraw!
893 let expect = [
894 \ "* Congress shall ",
895 \ "> make no law ",
zeertzjq61a6ac42024-09-07 11:23:54 +0200896 \ "••• Congress shall ",
Maxim Kim11916722022-09-02 14:08:53 +0100897 \ "> make no law ",
898 \ "**** Congress shall ",
899 \ "> make no law ",
900 \ ]
901 let lines = s:screen_lines2(1, 6, 20)
902 call s:compare_lines(expect, lines)
903
904 " check breakindent works if breakindentopt=list:-1
905 " for a non list content
906 %delete _
907 call setline(1, [' Congress shall make no law',
908 \ ' Congress shall make no law',
909 \ ' Congress shall make no law'])
910 norm! 1gg
911 setl briopt=min:5,list:-1
912 setl showbreak=
913 redraw!
914 let expect = [
915 \ " Congress shall ",
916 \ " make no law ",
917 \ " Congress shall ",
918 \ " make no law ",
919 \ " Congress shall ",
920 \ " make no law ",
921 \ ]
922 let lines = s:screen_lines2(1, 6, 20)
923 call s:compare_lines(expect, lines)
924
Maxim Kimf674b352021-07-22 11:46:59 +0200925 call s:close_windows('set breakindent& briopt& linebreak& list& listchars& showbreak&')
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200926endfunc
927
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200928" The following used to crash Vim. This is fixed by 8.2.3391.
929" This is a regression introduced by 8.2.2903.
930func Test_window_resize_with_linebreak()
931 new
932 53vnew
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100933 setl linebreak
934 setl showbreak=>>
935 setl breakindent
936 setl breakindentopt=shift:4
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200937 call setline(1, "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a")
938 redraw!
939 call assert_equal([" >>aa^@\"a: "], ScreenLines(2, 14))
940 vertical resize 52
941 redraw!
942 call assert_equal([" >>aaa^@\"a:"], ScreenLines(2, 14))
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100943 set linebreak& showbreak& breakindent& breakindentopt&
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200944 %bw!
945endfunc
946
Bram Moolenaar21efafe2022-03-03 20:04:03 +0000947func Test_cursor_position_with_showbreak()
948 CheckScreendump
949
950 let lines =<< trim END
951 vim9script
952 &signcolumn = 'yes'
zeertzjq11939512023-08-23 20:58:01 +0200953 &showbreak = '++'
zeertzjq11939512023-08-23 20:58:01 +0200954 &breakindentopt = 'shift:2'
Bram Moolenaar21efafe2022-03-03 20:04:03 +0000955 var leftcol: number = win_getid()->getwininfo()->get(0, {})->get('textoff')
956 repeat('x', &columns - leftcol - 1)->setline(1)
957 'second line'->setline(2)
958 END
Bram Moolenaar34112652022-09-05 21:40:44 +0100959 call writefile(lines, 'XscriptShowbreak', 'D')
Bram Moolenaar21efafe2022-03-03 20:04:03 +0000960 let buf = RunVimInTerminal('-S XscriptShowbreak', #{rows: 6})
961
962 call term_sendkeys(buf, "AX")
zeertzjq11939512023-08-23 20:58:01 +0200963 call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_1', {})
964 " No line wraps, so changing 'showbreak' should lead to the same screen.
965 call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal showbreak=+\<CR>")
966 call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_1', {})
zeertzjq6a389722023-08-27 19:04:14 +0200967 " No line wraps, so setting 'breakindent' should lead to the same screen.
968 call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal breakindent\<CR>")
969 call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_1', {})
zeertzjq11939512023-08-23 20:58:01 +0200970 " The first line now wraps because of "eol" in 'listchars'.
971 call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal list\<CR>")
972 call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_2', {})
zeertzjq6a389722023-08-27 19:04:14 +0200973 call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal nobreakindent\<CR>")
974 call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_3', {})
Bram Moolenaar21efafe2022-03-03 20:04:03 +0000975
976 call StopVimInTerminal(buf)
Bram Moolenaar21efafe2022-03-03 20:04:03 +0000977endfunc
978
zeertzjq23627722023-12-27 19:08:53 +0100979func Test_visual_starts_before_skipcol()
980 CheckScreendump
981
982 let lines =<< trim END
983 1new
984 setlocal breakindent
985 call setline(1, "\t" .. join(range(100)))
986 END
987 call writefile(lines, 'XvisualStartsBeforeSkipcol', 'D')
988 let buf = RunVimInTerminal('-S XvisualStartsBeforeSkipcol', #{rows: 6})
989
990 call term_sendkeys(buf, "v$")
991 call VerifyScreenDump(buf, 'Test_visual_starts_before_skipcol_1', {})
992 call term_sendkeys(buf, "\<Esc>:setlocal showbreak=+++\<CR>gv")
993 call VerifyScreenDump(buf, 'Test_visual_starts_before_skipcol_2', {})
994 call term_sendkeys(buf, "\<Esc>:setlocal breakindentopt+=sbr\<CR>gv")
995 call VerifyScreenDump(buf, 'Test_visual_starts_before_skipcol_3', {})
996 call term_sendkeys(buf, "\<Esc>:setlocal nobreakindent\<CR>gv")
997 call VerifyScreenDump(buf, 'Test_visual_starts_before_skipcol_4', {})
998
999 call StopVimInTerminal(buf)
1000endfunc
1001
Christian Brabandtc53b4672022-01-15 10:01:05 +00001002func Test_no_spurious_match()
1003 let s:input = printf('- y %s y %s', repeat('x', 50), repeat('x', 50))
1004 call s:test_windows('setl breakindent breakindentopt=list:-1 formatlistpat=^- hls')
1005 let @/ = '\%>3v[y]'
1006 redraw!
1007 call searchcount().total->assert_equal(1)
Bram Moolenaarfa4873c2022-06-30 22:13:59 +01001008
Christian Brabandtc53b4672022-01-15 10:01:05 +00001009 " cleanup
1010 set hls&vim
Christian Brabandtc53b4672022-01-15 10:01:05 +00001011 bwipeout!
1012endfunc
1013
1014func Test_no_extra_indent()
1015 call s:test_windows('setl breakindent breakindentopt=list:-1,min:10')
1016 %d
1017 let &l:formatlistpat='^\s*\d\+\.\s\+'
1018 let text = 'word '
1019 let len = text->strcharlen()
1020 let line1 = text->repeat((winwidth(0) / len) * 2)
1021 let line2 = repeat(' ', 2) .. '1. ' .. line1
1022 call setline(1, [line2])
1023 redraw!
1024 " 1) matches formatlist pattern, so indent
1025 let expect = [
1026 \ " 1. word word word ",
1027 \ " word word word ",
1028 \ " word word ",
1029 \ "~ ",
1030 \ ]
1031 let lines = s:screen_lines2(1, 4, 20)
1032 call s:compare_lines(expect, lines)
1033 " 2) change formatlist pattern
1034 " -> indent adjusted
1035 let &l:formatlistpat='^\s*\d\+\.'
1036 let expect = [
1037 \ " 1. word word word ",
1038 \ " word word word ",
1039 \ " word word ",
1040 \ "~ ",
1041 \ ]
1042 let lines = s:screen_lines2(1, 4, 20)
Bram Moolenaar04b871d2022-01-15 18:31:43 +00001043 " 3) no local formatlist pattern,
1044 " so use global one -> indent
1045 let g_flp = &g:flp
1046 let &g:formatlistpat='^\s*\d\+\.\s\+'
1047 let &l:formatlistpat=''
1048 let expect = [
1049 \ " 1. word word word ",
1050 \ " word word word ",
1051 \ " word word ",
1052 \ "~ ",
1053 \ ]
1054 let lines = s:screen_lines2(1, 4, 20)
1055 call s:compare_lines(expect, lines)
1056 let &g:flp = g_flp
1057 let &l:formatlistpat='^\s*\d\+\.'
1058 " 4) add something in front, no additional indent
Christian Brabandtc53b4672022-01-15 10:01:05 +00001059 norm! gg0
1060 exe ":norm! 5iword \<esc>"
1061 redraw!
1062 let expect = [
1063 \ "word word word word ",
1064 \ "word 1. word word ",
1065 \ "word word word word ",
1066 \ "word word ",
1067 \ "~ ",
1068 \ ]
1069 let lines = s:screen_lines2(1, 5, 20)
1070 call s:compare_lines(expect, lines)
1071 bwipeout!
1072endfunc
1073
Christian Brabandte7d6dbc2022-05-06 12:21:04 +01001074func Test_breakindent_column()
Christian Brabandte7d6dbc2022-05-06 12:21:04 +01001075 call s:test_windows('setl breakindent breakindentopt=column:10')
1076 redraw!
1077 " 1) default: does not indent, too wide :(
1078 let expect = [
1079 \ " ",
1080 \ " abcdefghijklmnop",
1081 \ "qrstuvwxyzABCDEFGHIJ",
1082 \ "KLMNOP "
1083 \ ]
1084 let lines = s:screen_lines2(1, 4, 20)
1085 call s:compare_lines(expect, lines)
1086 " 2) lower min value, so that breakindent works
1087 setl breakindentopt+=min:5
1088 redraw!
1089 let expect = [
1090 \ " ",
1091 \ " abcdefghijklmnop",
1092 \ " qrstuvwxyz",
1093 \ " ABCDEFGHIJ",
1094 \ " KLMNOP "
1095 \ ]
1096 let lines = s:screen_lines2(1, 5, 20)
1097 " 3) set shift option -> no influence
1098 setl breakindentopt+=shift:5
1099 redraw!
1100 let expect = [
1101 \ " ",
1102 \ " abcdefghijklmnop",
1103 \ " qrstuvwxyz",
1104 \ " ABCDEFGHIJ",
1105 \ " KLMNOP "
1106 \ ]
1107 let lines = s:screen_lines2(1, 5, 20)
1108 call s:compare_lines(expect, lines)
1109 " 4) add showbreak value
1110 setl showbreak=++
1111 redraw!
1112 let expect = [
1113 \ " ",
1114 \ " abcdefghijklmnop",
1115 \ " ++qrstuvwx",
1116 \ " ++yzABCDEF",
1117 \ " ++GHIJKLMN",
1118 \ " ++OP "
1119 \ ]
1120 let lines = s:screen_lines2(1, 6, 20)
1121 call s:compare_lines(expect, lines)
1122 bwipeout!
1123endfunc
1124
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00001125func Test_linebreak_list()
1126 " This was setting wlv.c_extra to NUL while wlv.p_extra is NULL
1127 filetype plugin on
1128 syntax enable
1129 edit! $VIMRUNTIME/doc/index.txt
1130 /v_P
1131
1132 setlocal list
1133 setlocal listchars=tab:>-
1134 setlocal linebreak
1135 setlocal nowrap
1136 setlocal filetype=help
1137 redraw!
1138
1139 bwipe!
1140endfunc
1141
zeertzjqefabd7c2024-02-11 17:16:19 +01001142func Test_breakindent_change_display_uhex()
1143 call s:test_windows('setl briopt=min:0 list listchars=eol:$')
1144 redraw!
1145 let lines = s:screen_lines(line('.'), 20)
1146 let expect = [
1147 \ "^Iabcdefghijklmnopqr",
1148 \ " stuvwxyzABCDEFGHIJ",
1149 \ " KLMNOP$ "
1150 \ ]
1151 call s:compare_lines(expect, lines)
1152 set display+=uhex
1153 redraw!
1154 let lines = s:screen_lines(line('.'), 20)
1155 let expect = [
1156 \ "<09>abcdefghijklmnop",
1157 \ " qrstuvwxyzABCDEF",
1158 \ " GHIJKLMNOP$ "
1159 \ ]
1160 call s:compare_lines(expect, lines)
1161 set display&
1162
1163 call s:close_windows()
1164endfunc
1165
1166func Test_breakindent_list_split()
1167 10new
1168 61vsplit
1169 setlocal tabstop=8 breakindent list listchars=tab:<->,eol:$
1170 put =s:input
1171 30vsplit
1172 setlocal listchars=eol:$
1173 let expect = [
1174 \ "^IabcdefghijklmnopqrstuvwxyzAB|<------>abcdefghijklmnopqrstuv",
1175 \ " CDEFGHIJKLMNOP$ | wxyzABCDEFGHIJKLMNOP$ ",
1176 \ "~ |~ "
1177 \ ]
1178 redraw!
1179 let lines = s:screen_lines(line('.'), 61)
1180 call s:compare_lines(expect, lines)
1181 wincmd p
1182 redraw!
1183 let lines = s:screen_lines(line('.'), 61)
1184 call s:compare_lines(expect, lines)
1185
1186 bwipe!
1187endfunc
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00001188
zeertzjqf0a9d652024-02-12 22:53:20 +01001189func Test_breakindent_min_with_signcol()
1190 call s:test_windows('setl briopt=min:15 signcolumn=yes')
1191 redraw!
1192 let expect = [
1193 \ " abcdefghijklmn",
1194 \ " opqrstuvwxyzABC",
1195 \ " DEFGHIJKLMNOP "
1196 \ ]
1197 let lines = s:screen_lines(line('.'), 20)
1198 call s:compare_lines(expect, lines)
1199 setl briopt=min:17
1200 redraw!
1201 let expect = [
1202 \ " abcdefghijklmn",
1203 \ " opqrstuvwxyzABCDE",
1204 \ " FGHIJKLMNOP "
1205 \ ]
1206 let lines = s:screen_lines(line('.'), 20)
1207 call s:compare_lines(expect, lines)
1208 setl briopt=min:19
1209 redraw!
1210 let expect = [
1211 \ " abcdefghijklmn",
1212 \ " opqrstuvwxyzABCDEF",
1213 \ " GHIJKLMNOP "
1214 \ ]
1215 let lines = s:screen_lines(line('.'), 20)
1216 call s:compare_lines(expect, lines)
1217
1218 call s:close_windows()
1219endfunc
1220
zeertzjqb5d6b5c2024-07-18 21:13:31 +02001221func Test_breakindent_with_double_width_wrap()
1222 50vnew
1223 setlocal tabstop=8 breakindent nolist
1224 call setline(1, "\t" .. repeat('a', winwidth(0) - 9) .. '口口口')
1225 normal! $g0
1226 call assert_equal(2, winline())
1227 call assert_equal(9, wincol())
1228
1229 bwipe!
1230endfunc
1231
Bram Moolenaar0e05de42020-03-25 22:23:46 +01001232" vim: shiftwidth=2 sts=2 expandtab