blob: 1c02294bc4299e6c8dc0ec516a243e3752114a97 [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()
719 call s:test_windows('setl breakindent breakindentopt= linebreak')
720 " default:
721 call setline(1, [' 1. Congress shall make no law',
722 \ ' 2.) Congress shall make no law',
723 \ ' 3.] Congress shall make no law'])
724 norm! 1gg
725 redraw!
726 let lines = s:screen_lines2(1, 6, 20)
727 let expect = [
728 \ " 1. Congress ",
729 \ "shall make no law ",
730 \ " 2.) Congress ",
731 \ "shall make no law ",
732 \ " 3.] Congress ",
733 \ "shall make no law ",
734 \ ]
735 call s:compare_lines(expect, lines)
Dominique Pelle81b573d2022-03-22 21:14:55 +0000736 " set minimum indent
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200737 setl briopt=min:5
738 redraw!
739 let lines = s:screen_lines2(1, 6, 20)
740 let expect = [
741 \ " 1. Congress ",
742 \ " shall make no law ",
743 \ " 2.) Congress ",
744 \ " shall make no law ",
745 \ " 3.] Congress ",
746 \ " shall make no law ",
747 \ ]
748 call s:compare_lines(expect, lines)
749 " set additional handing indent
750 setl briopt+=list:4
751 redraw!
752 let expect = [
753 \ " 1. Congress ",
754 \ " shall make no ",
755 \ " law ",
756 \ " 2.) Congress ",
757 \ " shall make no ",
758 \ " law ",
759 \ " 3.] Congress ",
760 \ " shall make no ",
761 \ " law ",
762 \ ]
763 let lines = s:screen_lines2(1, 9, 20)
764 call s:compare_lines(expect, lines)
Maxim Kimf674b352021-07-22 11:46:59 +0200765
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200766 " reset linebreak option
767 " Note: it indents by one additional
768 " space, because of the leading space.
769 setl linebreak&vim list listchars=eol:$,space:_
770 redraw!
771 let expect = [
772 \ "__1.__Congress_shall",
773 \ " _make_no_law$ ",
774 \ "__2.)_Congress_shall",
775 \ " _make_no_law$ ",
776 \ "__3.]_Congress_shall",
777 \ " _make_no_law$ ",
778 \ ]
779 let lines = s:screen_lines2(1, 6, 20)
780 call s:compare_lines(expect, lines)
781
Maxim Kimf674b352021-07-22 11:46:59 +0200782 " check formatlistpat indent
783 setl briopt=min:5,list:-1
784 setl linebreak list&vim listchars&vim
785 let &l:flp = '^\s*\d\+\.\?[\]:)}\t ]\s*'
786 redraw!
787 let expect = [
788 \ " 1. Congress ",
789 \ " shall make no ",
790 \ " law ",
791 \ " 2.) Congress ",
792 \ " shall make no ",
793 \ " law ",
794 \ " 3.] Congress ",
795 \ " shall make no ",
796 \ " law ",
797 \ ]
798 let lines = s:screen_lines2(1, 9, 20)
799 call s:compare_lines(expect, lines)
800 " check formatlistpat indent with different list levels
801 let &l:flp = '^\s*\*\+\s\+'
Maxim Kimf674b352021-07-22 11:46:59 +0200802 %delete _
803 call setline(1, ['* Congress shall make no law',
804 \ '*** Congress shall make no law',
805 \ '**** Congress shall make no law'])
806 norm! 1gg
Bram Moolenaarc2a79b82022-07-01 13:15:35 +0100807 redraw!
Maxim Kimf674b352021-07-22 11:46:59 +0200808 let expect = [
809 \ "* Congress shall ",
810 \ " make no law ",
811 \ "*** Congress shall ",
812 \ " make no law ",
813 \ "**** Congress shall ",
814 \ " make no law ",
815 \ ]
816 let lines = s:screen_lines2(1, 6, 20)
817 call s:compare_lines(expect, lines)
818
819 " check formatlistpat indent with different list level
820 " showbreak and sbr
Maxim Kim11916722022-09-02 14:08:53 +0100821 setl briopt=min:5,sbr,list:-1
Maxim Kimf674b352021-07-22 11:46:59 +0200822 setl showbreak=>
823 redraw!
824 let expect = [
825 \ "* Congress shall ",
826 \ "> make no law ",
827 \ "*** Congress shall ",
828 \ "> make no law ",
829 \ "**** Congress shall ",
830 \ "> make no law ",
831 \ ]
832 let lines = s:screen_lines2(1, 6, 20)
833 call s:compare_lines(expect, lines)
Maxim Kim11916722022-09-02 14:08:53 +0100834
835 " check formatlistpat indent with different list level
836 " showbreak sbr and shift
837 setl briopt=min:5,sbr,list:-1,shift:2
838 setl showbreak=>
839 redraw!
840 let expect = [
841 \ "* Congress shall ",
842 \ "> make no law ",
843 \ "*** Congress shall ",
844 \ "> make no law ",
845 \ "**** Congress shall ",
846 \ "> make no law ",
847 \ ]
848 let lines = s:screen_lines2(1, 6, 20)
849 call s:compare_lines(expect, lines)
850
851 " check breakindent works if breakindentopt=list:-1
852 " for a non list content
853 %delete _
854 call setline(1, [' Congress shall make no law',
855 \ ' Congress shall make no law',
856 \ ' Congress shall make no law'])
857 norm! 1gg
858 setl briopt=min:5,list:-1
859 setl showbreak=
860 redraw!
861 let expect = [
862 \ " Congress shall ",
863 \ " make no law ",
864 \ " Congress shall ",
865 \ " 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
Maxim Kimf674b352021-07-22 11:46:59 +0200872 call s:close_windows('set breakindent& briopt& linebreak& list& listchars& showbreak&')
Christian Brabandt4a0b85a2021-07-14 20:00:27 +0200873endfunc
874
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200875" The following used to crash Vim. This is fixed by 8.2.3391.
876" This is a regression introduced by 8.2.2903.
877func Test_window_resize_with_linebreak()
878 new
879 53vnew
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100880 setl linebreak
881 setl showbreak=>>
882 setl breakindent
883 setl breakindentopt=shift:4
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200884 call setline(1, "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a")
885 redraw!
886 call assert_equal([" >>aa^@\"a: "], ScreenLines(2, 14))
887 vertical resize 52
888 redraw!
889 call assert_equal([" >>aaa^@\"a:"], ScreenLines(2, 14))
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100890 set linebreak& showbreak& breakindent& breakindentopt&
Yegappan Lakshmanan03d25792021-09-02 20:05:26 +0200891 %bw!
892endfunc
893
Bram Moolenaar21efafe2022-03-03 20:04:03 +0000894func Test_cursor_position_with_showbreak()
895 CheckScreendump
896
897 let lines =<< trim END
898 vim9script
899 &signcolumn = 'yes'
900 &showbreak = '+ '
901 var leftcol: number = win_getid()->getwininfo()->get(0, {})->get('textoff')
902 repeat('x', &columns - leftcol - 1)->setline(1)
903 'second line'->setline(2)
904 END
905 call writefile(lines, 'XscriptShowbreak')
906 let buf = RunVimInTerminal('-S XscriptShowbreak', #{rows: 6})
907
908 call term_sendkeys(buf, "AX")
909 call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak', {})
910
911 call StopVimInTerminal(buf)
912 call delete('XscriptShowbreak')
913endfunc
914
Christian Brabandtc53b4672022-01-15 10:01:05 +0000915func Test_no_spurious_match()
916 let s:input = printf('- y %s y %s', repeat('x', 50), repeat('x', 50))
917 call s:test_windows('setl breakindent breakindentopt=list:-1 formatlistpat=^- hls')
918 let @/ = '\%>3v[y]'
919 redraw!
920 call searchcount().total->assert_equal(1)
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100921
Christian Brabandtc53b4672022-01-15 10:01:05 +0000922 " cleanup
923 set hls&vim
Christian Brabandtc53b4672022-01-15 10:01:05 +0000924 bwipeout!
925endfunc
926
927func Test_no_extra_indent()
928 call s:test_windows('setl breakindent breakindentopt=list:-1,min:10')
929 %d
930 let &l:formatlistpat='^\s*\d\+\.\s\+'
931 let text = 'word '
932 let len = text->strcharlen()
933 let line1 = text->repeat((winwidth(0) / len) * 2)
934 let line2 = repeat(' ', 2) .. '1. ' .. line1
935 call setline(1, [line2])
936 redraw!
937 " 1) matches formatlist pattern, so indent
938 let expect = [
939 \ " 1. word word word ",
940 \ " word word word ",
941 \ " word word ",
942 \ "~ ",
943 \ ]
944 let lines = s:screen_lines2(1, 4, 20)
945 call s:compare_lines(expect, lines)
946 " 2) change formatlist pattern
947 " -> indent adjusted
948 let &l:formatlistpat='^\s*\d\+\.'
949 let expect = [
950 \ " 1. word word word ",
951 \ " word word word ",
952 \ " word word ",
953 \ "~ ",
954 \ ]
955 let lines = s:screen_lines2(1, 4, 20)
Bram Moolenaar04b871d2022-01-15 18:31:43 +0000956 " 3) no local formatlist pattern,
957 " so use global one -> indent
958 let g_flp = &g:flp
959 let &g:formatlistpat='^\s*\d\+\.\s\+'
960 let &l:formatlistpat=''
961 let expect = [
962 \ " 1. word word word ",
963 \ " word word word ",
964 \ " word word ",
965 \ "~ ",
966 \ ]
967 let lines = s:screen_lines2(1, 4, 20)
968 call s:compare_lines(expect, lines)
969 let &g:flp = g_flp
970 let &l:formatlistpat='^\s*\d\+\.'
971 " 4) add something in front, no additional indent
Christian Brabandtc53b4672022-01-15 10:01:05 +0000972 norm! gg0
973 exe ":norm! 5iword \<esc>"
974 redraw!
975 let expect = [
976 \ "word word word word ",
977 \ "word 1. word word ",
978 \ "word word word word ",
979 \ "word word ",
980 \ "~ ",
981 \ ]
982 let lines = s:screen_lines2(1, 5, 20)
983 call s:compare_lines(expect, lines)
984 bwipeout!
985endfunc
986
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100987func Test_breakindent_column()
Christian Brabandte7d6dbc2022-05-06 12:21:04 +0100988 call s:test_windows('setl breakindent breakindentopt=column:10')
989 redraw!
990 " 1) default: does not indent, too wide :(
991 let expect = [
992 \ " ",
993 \ " abcdefghijklmnop",
994 \ "qrstuvwxyzABCDEFGHIJ",
995 \ "KLMNOP "
996 \ ]
997 let lines = s:screen_lines2(1, 4, 20)
998 call s:compare_lines(expect, lines)
999 " 2) lower min value, so that breakindent works
1000 setl breakindentopt+=min:5
1001 redraw!
1002 let expect = [
1003 \ " ",
1004 \ " abcdefghijklmnop",
1005 \ " qrstuvwxyz",
1006 \ " ABCDEFGHIJ",
1007 \ " KLMNOP "
1008 \ ]
1009 let lines = s:screen_lines2(1, 5, 20)
1010 " 3) set shift option -> no influence
1011 setl breakindentopt+=shift:5
1012 redraw!
1013 let expect = [
1014 \ " ",
1015 \ " abcdefghijklmnop",
1016 \ " qrstuvwxyz",
1017 \ " ABCDEFGHIJ",
1018 \ " KLMNOP "
1019 \ ]
1020 let lines = s:screen_lines2(1, 5, 20)
1021 call s:compare_lines(expect, lines)
1022 " 4) add showbreak value
1023 setl showbreak=++
1024 redraw!
1025 let expect = [
1026 \ " ",
1027 \ " abcdefghijklmnop",
1028 \ " ++qrstuvwx",
1029 \ " ++yzABCDEF",
1030 \ " ++GHIJKLMN",
1031 \ " ++OP "
1032 \ ]
1033 let lines = s:screen_lines2(1, 6, 20)
1034 call s:compare_lines(expect, lines)
1035 bwipeout!
1036endfunc
1037
Bram Moolenaar0e05de42020-03-25 22:23:46 +01001038" vim: shiftwidth=2 sts=2 expandtab