blob: 6fc4181d65d040df6dd54675486f61990116c8ef [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
Bram Moolenaar21efafe2022-03-03 20:04:03 +000011source screendump.vim
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010012
Bram Moolenaarfa4873c2022-06-30 22:13:59 +010013func SetUp()
14 let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
15endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010016
Bram Moolenaar04958cb2018-06-23 19:23:02 +020017func s:screen_lines(lnum, width) abort
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010018 return ScreenLines([a:lnum, a:lnum + 2], a:width)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020019endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010020
Christian Brabandt4a0b85a2021-07-14 20:00:27 +020021func s:screen_lines2(lnums, lnume, width) abort
22 return ScreenLines([a:lnums, a:lnume], a:width)
23endfunc
24
Bram Moolenaar04958cb2018-06-23 19:23:02 +020025func s:compare_lines(expect, actual)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010026 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020027endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010028
Bram Moolenaar04958cb2018-06-23 19:23:02 +020029func s:test_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010030 call NewWindow(10, 20)
31 setl ts=4 sw=4 sts=4 breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +010032 put =s:input
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010033 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020034endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010035
Bram Moolenaar04958cb2018-06-23 19:23:02 +020036func s:close_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010037 call CloseWindow()
38 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020039endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010040
Bram Moolenaar04958cb2018-06-23 19:23:02 +020041func Test_breakindent01()
Bram Moolenaar6c896862016-11-17 19:46:51 +010042 " simple breakindent test
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010043 call s:test_windows('setl briopt=min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020044 let lines = s:screen_lines(line('.'),8)
45 let expect = [
46 \ " abcd",
47 \ " qrst",
48 \ " GHIJ",
49 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010050 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010051 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +020052endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010053
Bram Moolenaar04958cb2018-06-23 19:23:02 +020054func Test_breakindent01_vartabs()
55 " like 01 but with vartabs feature
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020056 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +020057 call s:test_windows('setl briopt=min:0 vts=4')
58 let lines = s:screen_lines(line('.'),8)
59 let expect = [
60 \ " abcd",
61 \ " qrst",
62 \ " GHIJ",
63 \ ]
64 call s:compare_lines(expect, lines)
65 call s:close_windows('set vts&')
66endfunc
67
68func Test_breakindent02()
Bram Moolenaar6c896862016-11-17 19:46:51 +010069 " simple breakindent test with showbreak set
Bram Moolenaaree857022019-11-09 23:26:40 +010070 set sbr=>>
71 call s:test_windows('setl briopt=min:0 sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020072 let lines = s:screen_lines(line('.'),8)
73 let expect = [
74 \ " abcd",
75 \ " >>qr",
76 \ " >>EF",
77 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010078 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010079 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020080endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010081
Bram Moolenaar04958cb2018-06-23 19:23:02 +020082func Test_breakindent02_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020083 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +020084 " simple breakindent test with showbreak set
85 call s:test_windows('setl briopt=min:0 sbr=>> vts=4')
86 let lines = s:screen_lines(line('.'),8)
87 let expect = [
88 \ " abcd",
89 \ " >>qr",
90 \ " >>EF",
91 \ ]
92 call s:compare_lines(expect, lines)
93 call s:close_windows('set sbr= vts&')
94endfunc
95
96func Test_breakindent03()
Bram Moolenaar6c896862016-11-17 19:46:51 +010097 " simple breakindent test with showbreak set and briopt including sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010098 call s:test_windows('setl briopt=sbr,min:0 sbr=++')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020099 let lines = s:screen_lines(line('.'),8)
100 let expect = [
101 \ " abcd",
102 \ "++ qrst",
103 \ "++ GHIJ",
104 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100105 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100106 " clean up
107 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200108endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100109
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200110func Test_breakindent03_vartabs()
111 " simple breakindent test with showbreak set and briopt including sbr
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200112 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200113 call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4')
114 let lines = s:screen_lines(line('.'),8)
115 let expect = [
116 \ " abcd",
117 \ "++ qrst",
118 \ "++ GHIJ",
119 \ ]
120 call s:compare_lines(expect, lines)
121 " clean up
122 call s:close_windows('set sbr= vts&')
123endfunc
124
125func Test_breakindent04()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100126 " breakindent set with min width 18
Bram Moolenaaree857022019-11-09 23:26:40 +0100127 set sbr=<<<
128 call s:test_windows('setl sbr=NONE briopt=min:18')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200129 let lines = s:screen_lines(line('.'),8)
130 let expect = [
131 \ " abcd",
132 \ " qrstuv",
133 \ " IJKLMN",
134 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100135 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100136 " clean up
137 call s:close_windows('set sbr=')
Bram Moolenaaree857022019-11-09 23:26:40 +0100138 set sbr=
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200139endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100140
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200141func Test_breakindent04_vartabs()
142 " breakindent set with min width 18
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200143 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200144 call s:test_windows('setl sbr= briopt=min:18 vts=4')
145 let lines = s:screen_lines(line('.'),8)
146 let expect = [
147 \ " abcd",
148 \ " qrstuv",
149 \ " IJKLMN",
150 \ ]
151 call s:compare_lines(expect, lines)
152 " clean up
153 call s:close_windows('set sbr= vts&')
154endfunc
155
156func Test_breakindent05()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100157 " breakindent set and shift by 2
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100158 call s:test_windows('setl briopt=shift:2,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200159 let lines = s:screen_lines(line('.'),8)
160 let expect = [
161 \ " abcd",
162 \ " qr",
163 \ " EF",
164 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100165 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100166 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200167endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100168
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200169func Test_breakindent05_vartabs()
170 " breakindent set and shift by 2
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200171 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200172 call s:test_windows('setl briopt=shift:2,min:0 vts=4')
173 let lines = s:screen_lines(line('.'),8)
174 let expect = [
175 \ " abcd",
176 \ " qr",
177 \ " EF",
178 \ ]
179 call s:compare_lines(expect, lines)
180 call s:close_windows('set vts&')
181endfunc
182
183func Test_breakindent06()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100184 " breakindent set and shift by -1
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100185 call s:test_windows('setl briopt=shift:-1,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200186 let lines = s:screen_lines(line('.'),8)
187 let expect = [
188 \ " abcd",
189 \ " qrstu",
190 \ " HIJKL",
191 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100192 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100193 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200194endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100195
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200196func Test_breakindent06_vartabs()
197 " breakindent set and shift by -1
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200198 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200199 call s:test_windows('setl briopt=shift:-1,min:0 vts=4')
200 let lines = s:screen_lines(line('.'),8)
201 let expect = [
202 \ " abcd",
203 \ " qrstu",
204 \ " HIJKL",
205 \ ]
206 call s:compare_lines(expect, lines)
207 call s:close_windows('set vts&')
208endfunc
209
210func Test_breakindent07()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100211 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100212 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200213 let lines = s:screen_lines(line('.'),10)
214 let expect = [
215 \ " 2 ab",
216 \ "? m",
217 \ "? x",
218 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100219 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100220 " clean up
221 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200222endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100223
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200224func Test_breakindent07_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200225 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200226 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
227 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4')
228 let lines = s:screen_lines(line('.'),10)
229 let expect = [
230 \ " 2 ab",
231 \ "? m",
232 \ "? x",
233 \ ]
234 call s:compare_lines(expect, lines)
235 " clean up
236 call s:close_windows('set sbr= cpo-=n vts&')
237endfunc
238
239func Test_breakindent07a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100240 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100241 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200242 let lines = s:screen_lines(line('.'),10)
243 let expect = [
244 \ " 2 ab",
245 \ " ? m",
246 \ " ? x",
247 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100248 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100249 " clean up
250 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200251endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100252
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200253func Test_breakindent07a_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200254 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200255 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
256 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4')
257 let lines = s:screen_lines(line('.'),10)
258 let expect = [
259 \ " 2 ab",
260 \ " ? m",
261 \ " ? x",
262 \ ]
263 call s:compare_lines(expect, lines)
264 " clean up
265 call s:close_windows('set sbr= vts&')
266endfunc
267
268func Test_breakindent08()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100269 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100270 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 +0100271 " make sure, cache is invalidated!
272 set ts=8
273 redraw!
274 set ts=4
275 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200276 let lines = s:screen_lines(line('.'),10)
277 let expect = [
278 \ " 2 ^Iabcd",
279 \ "# opq",
280 \ "# BCD",
281 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100282 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100283 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200284endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100285
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200286func Test_breakindent08_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200287 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200288 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
289 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4')
290 " make sure, cache is invalidated!
291 set ts=8
292 redraw!
293 set ts=4
294 redraw!
295 let lines = s:screen_lines(line('.'),10)
296 let expect = [
297 \ " 2 ^Iabcd",
298 \ "# opq",
299 \ "# BCD",
300 \ ]
301 call s:compare_lines(expect, lines)
302 call s:close_windows('set sbr= cpo-=n vts&')
303endfunc
304
305func Test_breakindent08a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100306 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100307 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200308 let lines = s:screen_lines(line('.'),10)
309 let expect = [
310 \ " 2 ^Iabcd",
311 \ " # opq",
312 \ " # BCD",
313 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100314 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100315 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200316endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100317
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200318func Test_breakindent08a_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200319 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200320 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
321 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4')
322 let lines = s:screen_lines(line('.'),10)
323 let expect = [
324 \ " 2 ^Iabcd",
325 \ " # opq",
326 \ " # BCD",
327 \ ]
328 call s:compare_lines(expect, lines)
329 call s:close_windows('set sbr= vts&')
330endfunc
331
332func Test_breakindent09()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100333 " breakindent set and shift by 1, Number and list set sbr=#
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100334 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200335 let lines = s:screen_lines(line('.'),10)
336 let expect = [
337 \ " 2 ^Iabcd",
338 \ " #op",
339 \ " #AB",
340 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100341 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100342 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200343endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100344
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200345func Test_breakindent09_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200346 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200347 " breakindent set and shift by 1, Number and list set sbr=#
348 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4')
349 let lines = s:screen_lines(line('.'),10)
350 let expect = [
351 \ " 2 ^Iabcd",
352 \ " #op",
353 \ " #AB",
354 \ ]
355 call s:compare_lines(expect, lines)
356 call s:close_windows('set sbr= vts&')
357endfunc
358
359func Test_breakindent10()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100360 " breakindent set, Number set sbr=~
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100361 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100362 " make sure, cache is invalidated!
363 set ts=8
364 redraw!
365 set ts=4
366 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200367 let lines = s:screen_lines(line('.'),10)
368 let expect = [
369 \ " 2 ab",
370 \ "~ mn",
371 \ "~ yz",
372 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100373 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100374 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200375endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100376
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200377func Test_breakindent10_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200378 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200379 " breakindent set, Number set sbr=~
380 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4')
381 " make sure, cache is invalidated!
382 set ts=8
383 redraw!
384 set ts=4
385 redraw!
386 let lines = s:screen_lines(line('.'),10)
387 let expect = [
388 \ " 2 ab",
389 \ "~ mn",
390 \ "~ yz",
391 \ ]
392 call s:compare_lines(expect, lines)
393 call s:close_windows('set sbr= cpo-=n vts&')
394endfunc
395
396func Test_breakindent11()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100397 " test strdisplaywidth()
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100398 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200399 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200400 let width = strlen(text[1:]) + indent(2) + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaar6c896862016-11-17 19:46:51 +0100401 call assert_equal(width, strdisplaywidth(text))
402 call s:close_windows('set sbr=')
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100403 call assert_equal(4, strdisplaywidth("\t", 4))
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200404endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100405
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200406func Test_breakindent11_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200407 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200408 " test strdisplaywidth()
409 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4')
410 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200411 let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +0200412 call assert_equal(width, text->strdisplaywidth())
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200413 call s:close_windows('set sbr= vts&')
414endfunc
415
416func Test_breakindent12()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100417 " test breakindent with long indent
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200418 let s:input = "\t\t\t\t\t{"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100419 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 +0200420 let lines = s:screen_lines(2,16)
421 let expect = [
422 \ " 2 >--->--->--->",
423 \ " ---{ ",
424 \ "~ ",
425 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100426 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100427 call s:close_windows('set nuw=4 listchars=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200428endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100429
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200430func Test_breakindent12_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200431 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200432 " test breakindent with long indent
433 let s:input = "\t\t\t\t\t{"
434 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4')
435 let lines = s:screen_lines(2,16)
436 let expect = [
437 \ " 2 >--->--->--->",
438 \ " ---{ ",
439 \ "~ ",
440 \ ]
441 call s:compare_lines(expect, lines)
442 call s:close_windows('set nuw=4 listchars= vts&')
443endfunc
444
445func Test_breakindent13()
446 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100447 call s:test_windows('setl breakindent briopt=min:10 ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100448 vert resize 20
449 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
450 1
451 norm! fbgj"ayl
452 2
453 norm! fygj"byl
454 call assert_equal('d', @a)
455 call assert_equal('w', @b)
456 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200457endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100458
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200459func Test_breakindent13_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200460 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200461 let s:input = ""
462 call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8')
463 vert resize 20
464 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
465 1
466 norm! fbgj"ayl
467 2
468 norm! fygj"byl
469 call assert_equal('d', @a)
470 call assert_equal('w', @b)
471 call s:close_windows('set vts&')
472endfunc
473
474func Test_breakindent14()
475 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100476 call s:test_windows('setl breakindent briopt= ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100477 vert resize 30
478 norm! 3a1234567890
479 norm! a abcde
480 exec "norm! 0\<C-V>tex"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200481 let lines = s:screen_lines(line('.'),8)
482 let expect = [
483 \ "e ",
484 \ "~ ",
485 \ "~ ",
486 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100487 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100488 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200489endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100490
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200491func Test_breakindent14_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200492 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200493 let s:input = ""
494 call s:test_windows('setl breakindent briopt= ts=8 vts=8')
495 vert resize 30
496 norm! 3a1234567890
497 norm! a abcde
498 exec "norm! 0\<C-V>tex"
499 let lines = s:screen_lines(line('.'),8)
500 let expect = [
501 \ "e ",
502 \ "~ ",
503 \ "~ ",
504 \ ]
505 call s:compare_lines(expect, lines)
506 call s:close_windows('set vts&')
507endfunc
508
509func Test_breakindent15()
510 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100511 call s:test_windows('setl breakindent briopt= ts=8 sw=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100512 vert resize 30
513 norm! 4a1234567890
514 exe "normal! >>\<C-V>3f0x"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200515 let lines = s:screen_lines(line('.'),20)
516 let expect = [
517 \ " 1234567890 ",
518 \ "~ ",
519 \ "~ ",
520 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100521 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100522 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200523endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100524
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200525func Test_breakindent15_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200526 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200527 let s:input = ""
528 call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8')
529 vert resize 30
530 norm! 4a1234567890
531 exe "normal! >>\<C-V>3f0x"
532 let lines = s:screen_lines(line('.'),20)
533 let expect = [
534 \ " 1234567890 ",
535 \ "~ ",
536 \ "~ ",
537 \ ]
538 call s:compare_lines(expect, lines)
539 call s:close_windows('set vts&')
540endfunc
541
542func Test_breakindent16()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100543 " Check that overlong lines are indented correctly.
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200544 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100545 call s:test_windows('setl breakindent briopt=min:0 ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100546 call setline(1, "\t".repeat("1234567890", 10))
547 resize 6
548 norm! 1gg$
549 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200550 let lines = s:screen_lines(1,10)
551 let expect = [
552 \ " 789012",
553 \ " 345678",
554 \ " 901234",
555 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100556 call s:compare_lines(expect, lines)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200557 let lines = s:screen_lines(4,10)
558 let expect = [
559 \ " 567890",
560 \ " 123456",
561 \ " 7890 ",
562 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100563 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100564 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200565endfunc
566
567func Test_breakindent16_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200568 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200569 " Check that overlong lines are indented correctly.
570 let s:input = ""
571 call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4')
572 call setline(1, "\t".repeat("1234567890", 10))
573 resize 6
574 norm! 1gg$
575 redraw!
576 let lines = s:screen_lines(1,10)
577 let expect = [
578 \ " 789012",
579 \ " 345678",
580 \ " 901234",
581 \ ]
582 call s:compare_lines(expect, lines)
583 let lines = s:screen_lines(4,10)
584 let expect = [
585 \ " 567890",
586 \ " 123456",
587 \ " 7890 ",
588 \ ]
589 call s:compare_lines(expect, lines)
590 call s:close_windows('set vts&')
591endfunc
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100592
593func Test_breakindent17_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200594 CheckFeature vartabs
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100595 let s:input = ""
596 call s:test_windows('setl breakindent list listchars=tab:<-> showbreak=+++')
597 call setline(1, "\t" . repeat('a', 63))
598 vert resize 30
599 norm! 1gg$
600 redraw!
601 let lines = s:screen_lines(1, 30)
602 let expect = [
603 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
604 \ " +++aaaaaaaaaaaaaaaaaaaaaaa",
605 \ " +++aaaaaaaaaaaaaa ",
606 \ ]
607 call s:compare_lines(expect, lines)
608 call s:close_windows('set breakindent& list& listchars& showbreak&')
609endfunc
610
611func Test_breakindent18_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200612 CheckFeature vartabs
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100613 let s:input = ""
614 call s:test_windows('setl breakindent list listchars=tab:<->')
615 call setline(1, "\t" . repeat('a', 63))
616 vert resize 30
617 norm! 1gg$
618 redraw!
619 let lines = s:screen_lines(1, 30)
620 let expect = [
621 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
622 \ " aaaaaaaaaaaaaaaaaaaaaaaaaa",
623 \ " aaaaaaaaaaa ",
624 \ ]
625 call s:compare_lines(expect, lines)
626 call s:close_windows('set breakindent& list& listchars&')
627endfunc
628
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100629func Test_breakindent19_sbr_nextpage()
630 let s:input = ""
631 call s:test_windows('setl breakindent briopt=shift:2,sbr,min:18 sbr=>')
632 call setline(1, repeat('a', 200))
633 norm! 1gg
634 redraw!
635 let lines = s:screen_lines(1, 20)
636 let expect = [
637 \ "aaaaaaaaaaaaaaaaaaaa",
638 \ "> aaaaaaaaaaaaaaaaaa",
639 \ "> aaaaaaaaaaaaaaaaaa",
640 \ ]
641 call s:compare_lines(expect, lines)
642 " Scroll down one screen line
643 setl scrolloff=5
Bram Moolenaar52029292021-02-10 21:20:30 +0100644 norm! 5gj
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100645 let lines = s:screen_lines(1, 20)
646 let expect = [
Bram Moolenaar52029292021-02-10 21:20:30 +0100647 \ "aaaaaaaaaaaaaaaaaaaa",
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100648 \ "> aaaaaaaaaaaaaaaaaa",
649 \ "> aaaaaaaaaaaaaaaaaa",
650 \ ]
651 call s:compare_lines(expect, lines)
Bram Moolenaar52029292021-02-10 21:20:30 +0100652 redraw!
653 " moving the cursor doesn't change the text offset
654 norm! l
655 redraw!
656 let lines = s:screen_lines(1, 20)
657 call s:compare_lines(expect, lines)
Bram Moolenaar1aa76b82020-02-23 15:17:27 +0100658
659 setl breakindent briopt=min:18 sbr=>
660 norm! 5gj
661 let lines = s:screen_lines(1, 20)
662 let expect = [
663 \ ">aaaaaaaaaaaaaaaaaaa",
664 \ ">aaaaaaaaaaaaaaaaaaa",
665 \ ">aaaaaaaaaaaaaaaaaaa",
666 \ ]
667 call s:compare_lines(expect, lines)
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100668 call s:close_windows('set breakindent& briopt& sbr&')
669endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100670
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200671func Test_breakindent20_cpo_n_nextpage()
672 let s:input = ""
673 call s:test_windows('setl breakindent briopt=min:14 cpo+=n number')
674 call setline(1, repeat('a', 200))
675 norm! 1gg
676 redraw!
677 let lines = s:screen_lines(1, 20)
678 let expect = [
679 \ " 1 aaaaaaaaaaaaaaaa",
680 \ " aaaaaaaaaaaaaaaa",
681 \ " aaaaaaaaaaaaaaaa",
682 \ ]
683 call s:compare_lines(expect, lines)
684 " Scroll down one screen line
685 setl scrolloff=5
686 norm! 5gj
687 redraw!
688 let lines = s:screen_lines(1, 20)
689 let expect = [
690 \ "--1 aaaaaaaaaaaaaaaa",
691 \ " aaaaaaaaaaaaaaaa",
692 \ " aaaaaaaaaaaaaaaa",
693 \ ]
694 call s:compare_lines(expect, lines)
695
696 setl briopt+=shift:2
697 norm! 1gg
698 let lines = s:screen_lines(1, 20)
699 let expect = [
700 \ " 1 aaaaaaaaaaaaaaaa",
701 \ " aaaaaaaaaaaaaa",
702 \ " aaaaaaaaaaaaaa",
703 \ ]
704 call s:compare_lines(expect, lines)
705 " Scroll down one screen line
706 norm! 5gj
707 let lines = s:screen_lines(1, 20)
708 let expect = [
709 \ "--1 aaaaaaaaaaaaaa",
710 \ " aaaaaaaaaaaaaa",
711 \ " aaaaaaaaaaaaaa",
712 \ ]
713 call s:compare_lines(expect, lines)
714
715 call s:close_windows('set breakindent& briopt& cpo& number&')
716endfunc
717
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200718func Test_breakindent20_list()
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100719 " FIXME - this should not matter
720 call test_override('alloc_lines', 0)
721
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200722 call s:test_windows('setl breakindent breakindentopt= linebreak')
723 " default:
724 call setline(1, [' 1. Congress shall make no law',
725 \ ' 2.) Congress shall make no law',
726 \ ' 3.] Congress shall make no law'])
727 norm! 1gg
728 redraw!
729 let lines = s:screen_lines2(1, 6, 20)
730 let expect = [
731 \ " 1. Congress ",
732 \ "shall make no law ",
733 \ " 2.) Congress ",
734 \ "shall make no law ",
735 \ " 3.] Congress ",
736 \ "shall make no law ",
737 \ ]
738 call s:compare_lines(expect, lines)
Dominique Pelle81b573d2022-03-22 21:14:55 +0000739 " set minimum indent
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200740 setl briopt=min:5
741 redraw!
742 let lines = s:screen_lines2(1, 6, 20)
743 let expect = [
744 \ " 1. Congress ",
745 \ " shall make no law ",
746 \ " 2.) Congress ",
747 \ " shall make no law ",
748 \ " 3.] Congress ",
749 \ " shall make no law ",
750 \ ]
751 call s:compare_lines(expect, lines)
752 " set additional handing indent
753 setl briopt+=list:4
754 redraw!
755 let expect = [
756 \ " 1. Congress ",
757 \ " shall make no ",
758 \ " law ",
759 \ " 2.) Congress ",
760 \ " shall make no ",
761 \ " law ",
762 \ " 3.] Congress ",
763 \ " shall make no ",
764 \ " law ",
765 \ ]
766 let lines = s:screen_lines2(1, 9, 20)
767 call s:compare_lines(expect, lines)
Maxim Kimf674b352021-07-22 11:46:59 +0200768
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200769 " reset linebreak option
770 " Note: it indents by one additional
771 " space, because of the leading space.
772 setl linebreak&vim list listchars=eol:$,space:_
773 redraw!
774 let expect = [
775 \ "__1.__Congress_shall",
776 \ " _make_no_law$ ",
777 \ "__2.)_Congress_shall",
778 \ " _make_no_law$ ",
779 \ "__3.]_Congress_shall",
780 \ " _make_no_law$ ",
781 \ ]
782 let lines = s:screen_lines2(1, 6, 20)
783 call s:compare_lines(expect, lines)
784
Maxim Kimf674b352021-07-22 11:46:59 +0200785 " check formatlistpat indent
786 setl briopt=min:5,list:-1
787 setl linebreak list&vim listchars&vim
788 let &l:flp = '^\s*\d\+\.\?[\]:)}\t ]\s*'
789 redraw!
790 let expect = [
791 \ " 1. Congress ",
792 \ " shall make no ",
793 \ " law ",
794 \ " 2.) Congress ",
795 \ " shall make no ",
796 \ " law ",
797 \ " 3.] Congress ",
798 \ " shall make no ",
799 \ " law ",
800 \ ]
801 let lines = s:screen_lines2(1, 9, 20)
802 call s:compare_lines(expect, lines)
803 " check formatlistpat indent with different list levels
804 let &l:flp = '^\s*\*\+\s\+'
805 redraw!
806 %delete _
807 call setline(1, ['* Congress shall make no law',
808 \ '*** Congress shall make no law',
809 \ '**** Congress shall make no law'])
810 norm! 1gg
811 let expect = [
812 \ "* Congress shall ",
813 \ " make no law ",
814 \ "*** Congress shall ",
815 \ " make no law ",
816 \ "**** Congress shall ",
817 \ " make no law ",
818 \ ]
819 let lines = s:screen_lines2(1, 6, 20)
820 call s:compare_lines(expect, lines)
821
822 " check formatlistpat indent with different list level
823 " showbreak and sbr
824 setl briopt=min:5,sbr,list:-1,shift:2
825 setl showbreak=>
826 redraw!
827 let expect = [
828 \ "* Congress shall ",
829 \ "> make no law ",
830 \ "*** Congress shall ",
831 \ "> make no law ",
832 \ "**** Congress shall ",
833 \ "> make no law ",
834 \ ]
835 let lines = s:screen_lines2(1, 6, 20)
836 call s:compare_lines(expect, lines)
837 call s:close_windows('set breakindent& briopt& linebreak& list& listchars& showbreak&')
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100838
839 " FIXME - this should not matter
840 call test_override('alloc_lines', 1)
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200841endfunc
842
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200843" The following used to crash Vim. This is fixed by 8.2.3391.
844" This is a regression introduced by 8.2.2903.
845func Test_window_resize_with_linebreak()
846 new
847 53vnew
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100848 setl linebreak
849 setl showbreak=>>
850 setl breakindent
851 setl breakindentopt=shift:4
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200852 call setline(1, "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a")
853 redraw!
854 call assert_equal([" >>aa^@\"a: "], ScreenLines(2, 14))
855 vertical resize 52
856 redraw!
857 call assert_equal([" >>aaa^@\"a:"], ScreenLines(2, 14))
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100858 set linebreak& showbreak& breakindent& breakindentopt&
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200859 %bw!
860endfunc
861
Bram Moolenaar21efafe2022-03-03 20:04:03 +0000862func Test_cursor_position_with_showbreak()
863 CheckScreendump
864
865 let lines =<< trim END
866 vim9script
867 &signcolumn = 'yes'
868 &showbreak = '+ '
869 var leftcol: number = win_getid()->getwininfo()->get(0, {})->get('textoff')
870 repeat('x', &columns - leftcol - 1)->setline(1)
871 'second line'->setline(2)
872 END
873 call writefile(lines, 'XscriptShowbreak')
874 let buf = RunVimInTerminal('-S XscriptShowbreak', #{rows: 6})
875
876 call term_sendkeys(buf, "AX")
877 call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak', {})
878
879 call StopVimInTerminal(buf)
880 call delete('XscriptShowbreak')
881endfunc
882
Christian Brabandtc53b4672022-01-15 10:01:05 +0000883func Test_no_spurious_match()
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100884 " FIXME - fails under valgrind - this should not matter - timing issue?
885 call test_override('alloc_lines', 0)
886
Christian Brabandtc53b4672022-01-15 10:01:05 +0000887 let s:input = printf('- y %s y %s', repeat('x', 50), repeat('x', 50))
888 call s:test_windows('setl breakindent breakindentopt=list:-1 formatlistpat=^- hls')
889 let @/ = '\%>3v[y]'
890 redraw!
891 call searchcount().total->assert_equal(1)
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100892
Christian Brabandtc53b4672022-01-15 10:01:05 +0000893 " cleanup
894 set hls&vim
Christian Brabandtc53b4672022-01-15 10:01:05 +0000895 bwipeout!
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100896 " FIXME - this should not matter
897 call test_override('alloc_lines', 1)
Christian Brabandtc53b4672022-01-15 10:01:05 +0000898endfunc
899
900func Test_no_extra_indent()
901 call s:test_windows('setl breakindent breakindentopt=list:-1,min:10')
902 %d
903 let &l:formatlistpat='^\s*\d\+\.\s\+'
904 let text = 'word '
905 let len = text->strcharlen()
906 let line1 = text->repeat((winwidth(0) / len) * 2)
907 let line2 = repeat(' ', 2) .. '1. ' .. line1
908 call setline(1, [line2])
909 redraw!
910 " 1) matches formatlist pattern, so indent
911 let expect = [
912 \ " 1. word word word ",
913 \ " word word word ",
914 \ " word word ",
915 \ "~ ",
916 \ ]
917 let lines = s:screen_lines2(1, 4, 20)
918 call s:compare_lines(expect, lines)
919 " 2) change formatlist pattern
920 " -> indent adjusted
921 let &l:formatlistpat='^\s*\d\+\.'
922 let expect = [
923 \ " 1. word word word ",
924 \ " word word word ",
925 \ " word word ",
926 \ "~ ",
927 \ ]
928 let lines = s:screen_lines2(1, 4, 20)
Bram Moolenaar04b871d2022-01-15 18:31:43 +0000929 " 3) no local formatlist pattern,
930 " so use global one -> indent
931 let g_flp = &g:flp
932 let &g:formatlistpat='^\s*\d\+\.\s\+'
933 let &l:formatlistpat=''
934 let expect = [
935 \ " 1. word word word ",
936 \ " word word word ",
937 \ " word word ",
938 \ "~ ",
939 \ ]
940 let lines = s:screen_lines2(1, 4, 20)
941 call s:compare_lines(expect, lines)
942 let &g:flp = g_flp
943 let &l:formatlistpat='^\s*\d\+\.'
944 " 4) add something in front, no additional indent
Christian Brabandtc53b4672022-01-15 10:01:05 +0000945 norm! gg0
946 exe ":norm! 5iword \<esc>"
947 redraw!
948 let expect = [
949 \ "word word word word ",
950 \ "word 1. word word ",
951 \ "word word word word ",
952 \ "word word ",
953 \ "~ ",
954 \ ]
955 let lines = s:screen_lines2(1, 5, 20)
956 call s:compare_lines(expect, lines)
957 bwipeout!
958endfunc
959
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100960func Test_breakindent_column()
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100961 call s:test_windows('setl breakindent breakindentopt=column:10')
962 redraw!
963 " 1) default: does not indent, too wide :(
964 let expect = [
965 \ " ",
966 \ " abcdefghijklmnop",
967 \ "qrstuvwxyzABCDEFGHIJ",
968 \ "KLMNOP "
969 \ ]
970 let lines = s:screen_lines2(1, 4, 20)
971 call s:compare_lines(expect, lines)
972 " 2) lower min value, so that breakindent works
973 setl breakindentopt+=min:5
974 redraw!
975 let expect = [
976 \ " ",
977 \ " abcdefghijklmnop",
978 \ " qrstuvwxyz",
979 \ " ABCDEFGHIJ",
980 \ " KLMNOP "
981 \ ]
982 let lines = s:screen_lines2(1, 5, 20)
983 " 3) set shift option -> no influence
984 setl breakindentopt+=shift:5
985 redraw!
986 let expect = [
987 \ " ",
988 \ " abcdefghijklmnop",
989 \ " qrstuvwxyz",
990 \ " ABCDEFGHIJ",
991 \ " KLMNOP "
992 \ ]
993 let lines = s:screen_lines2(1, 5, 20)
994 call s:compare_lines(expect, lines)
995 " 4) add showbreak value
996 setl showbreak=++
997 redraw!
998 let expect = [
999 \ " ",
1000 \ " abcdefghijklmnop",
1001 \ " ++qrstuvwx",
1002 \ " ++yzABCDEF",
1003 \ " ++GHIJKLMN",
1004 \ " ++OP "
1005 \ ]
1006 let lines = s:screen_lines2(1, 6, 20)
1007 call s:compare_lines(expect, lines)
1008 bwipeout!
1009endfunc
1010
Bram Moolenaar0e05de42020-03-25 22:23:46 +01001011" vim: shiftwidth=2 sts=2 expandtab