robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40542 from zeertzjq/vim-9.2.0392f33364a41d

master
32.5 KiB1275 linesraw
1" Test for breakindent
2"
3" Note: if you get strange failures when adding new tests, it might be that
4" while the test is run, the breakindent caching gets in its way.
5" It helps to change the tabstop setting and force a redraw (e.g. see
6" Test_breakindent08())
7source check.vim
8CheckOption breakindent
9
10source view_util.vim
11source screendump.vim
12
13func SetUp()
14  let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
15endfunc
16
17func s:screen_lines(lnum, width) abort
18  return ScreenLines([a:lnum, a:lnum + 2], a:width)
19endfunc
20
21func s:screen_lines2(lnums, lnume, width) abort
22  return ScreenLines([a:lnums, a:lnume], a:width)
23endfunc
24
25func s:compare_lines(expect, actual)
26  call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
27endfunc
28
29func s:test_windows(...)
30  call NewWindow(10, 20)
31  setl ts=4 sw=4 sts=4 breakindent
32  put =s:input
33  exe get(a:000, 0, '')
34endfunc
35
36func s:close_windows(...)
37  call CloseWindow()
38  exe get(a:000, 0, '')
39endfunc
40
41func Test_breakindent01()
42  " simple breakindent test
43  call s:test_windows('setl briopt=min:0')
44  let lines = s:screen_lines(line('.'),8)
45  let expect = [
46	\ "    abcd",
47	\ "    qrst",
48	\ "    GHIJ",
49	\ ]
50  call s:compare_lines(expect, lines)
51  call s:close_windows()
52endfunc
53
54func Test_breakindent01_vartabs()
55  " like 01 but with vartabs feature
56  if !has("vartabs")
57    return
58  endif
59  call s:test_windows('setl briopt=min:0 vts=4')
60  let lines = s:screen_lines(line('.'),8)
61  let expect = [
62	\ "    abcd",
63	\ "    qrst",
64	\ "    GHIJ",
65	\ ]
66  call s:compare_lines(expect, lines)
67  call s:close_windows('set vts&')
68endfunc
69
70func Test_breakindent02()
71  " simple breakindent test with showbreak set
72  set sbr=>>
73  call s:test_windows('setl briopt=min:0 sbr=')
74  let lines = s:screen_lines(line('.'),8)
75  let expect = [
76	\ "    abcd",
77	\ "    >>qr",
78	\ "    >>EF",
79	\ ]
80  call s:compare_lines(expect, lines)
81  call s:close_windows('set sbr=')
82endfunc
83
84func Test_breakindent02_vartabs()
85  if !has("vartabs")
86    return
87  endif
88  " simple breakindent test with showbreak set
89  call s:test_windows('setl briopt=min:0 sbr=>> vts=4')
90  let lines = s:screen_lines(line('.'), 8)
91  let expect = [
92	\ "    abcd",
93	\ "    >>qr",
94	\ "    >>EF",
95	\ ]
96  call s:compare_lines(expect, lines)
97  call s:close_windows('set sbr= vts&')
98endfunc
99
100func Test_breakindent03()
101  " simple breakindent test with showbreak set and briopt including sbr
102  call s:test_windows('setl briopt=sbr,min:0 sbr=++')
103  let lines = s:screen_lines(line('.'), 8)
104  let expect=[
105\ "    abcd",
106\ "++  qrst",
107\ "++  GHIJ",
108\ ]
109  call s:compare_lines(expect, lines)
110  " clean up
111  call s:close_windows('set sbr=')
112endfunc
113
114func Test_breakindent03_vartabs()
115  " simple breakindent test with showbreak set and briopt including sbr
116  if !has("vartabs")
117    return
118  endif
119  call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4')
120  let lines = s:screen_lines(line('.'), 8)
121  let expect = [
122	\ "    abcd",
123	\ "++  qrst",
124	\ "++  GHIJ",
125	\ ]
126  call s:compare_lines(expect, lines)
127  " clean up
128  call s:close_windows('set sbr= vts&')
129endfunc
130
131func Test_breakindent04()
132  " breakindent set with min width 18
133  set sbr=<<<
134  call s:test_windows('setl sbr=NONE briopt=min:18')
135  let lines = s:screen_lines(line('.'), 8)
136  let expect = [
137	\ "    abcd",
138	\ "  qrstuv",
139	\ "  IJKLMN",
140	\ ]
141  call s:compare_lines(expect, lines)
142  " clean up
143  call s:close_windows('set sbr=')
144  set sbr=
145endfunc
146
147func Test_breakindent04_vartabs()
148  " breakindent set with min width 18
149  if !has("vartabs")
150    return
151  endif
152  call s:test_windows('setl sbr= briopt=min:18 vts=4')
153  let lines = s:screen_lines(line('.'), 8)
154  let expect = [
155	\ "    abcd",
156	\ "  qrstuv",
157	\ "  IJKLMN",
158	\ ]
159  call s:compare_lines(expect, lines)
160  " clean up
161  call s:close_windows('set sbr= vts&')
162endfunc
163
164func Test_breakindent05()
165  " breakindent set and shift by 2
166  call s:test_windows('setl briopt=shift:2,min:0')
167  let lines = s:screen_lines(line('.'),8)
168  let expect = [
169	\ "    abcd",
170	\ "      qr",
171	\ "      EF",
172	\ ]
173  call s:compare_lines(expect, lines)
174  call s:close_windows()
175endfunc
176
177func Test_breakindent05_vartabs()
178  " breakindent set and shift by 2
179  if !has("vartabs")
180    return
181  endif
182  call s:test_windows('setl briopt=shift:2,min:0 vts=4')
183  let lines = s:screen_lines(line('.'),8)
184  let expect = [
185	\ "    abcd",
186	\ "      qr",
187	\ "      EF",
188	\ ]
189  call s:compare_lines(expect, lines)
190  call s:close_windows('set vts&')
191endfunc
192
193func Test_breakindent06()
194  " breakindent set and shift by -1
195  call s:test_windows('setl briopt=shift:-1,min:0')
196  let lines = s:screen_lines(line('.'),8)
197  let expect = [
198	\ "    abcd",
199	\ "   qrstu",
200	\ "   HIJKL",
201	\ ]
202  call s:compare_lines(expect, lines)
203  call s:close_windows()
204endfunc
205
206func Test_breakindent06_vartabs()
207  " breakindent set and shift by -1
208  if !has("vartabs")
209    return
210  endif
211  call s:test_windows('setl briopt=shift:-1,min:0 vts=4')
212  let lines = s:screen_lines(line('.'),8)
213  let expect = [
214	\ "    abcd",
215	\ "   qrstu",
216	\ "   HIJKL",
217	\ ]
218  call s:compare_lines(expect, lines)
219  call s:close_windows('set vts&')
220endfunc
221
222func Test_breakindent07()
223  " breakindent set and shift by 1, Number  set sbr=? and briopt:sbr
224  call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n')
225  let lines = s:screen_lines(line('.'),10)
226  let expect = [
227	\ "  2     ab",
228	\ "?        m",
229	\ "?        x",
230	\ ]
231  call s:compare_lines(expect, lines)
232  " clean up
233  call s:close_windows('set sbr= cpo-=n')
234endfunc
235
236func Test_breakindent07_vartabs()
237  if !has("vartabs")
238    return
239  endif
240  " breakindent set and shift by 1, Number  set sbr=? and briopt:sbr
241  call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4')
242  let lines = s:screen_lines(line('.'),10)
243  let expect = [
244	\ "  2     ab",
245	\ "?        m",
246	\ "?        x",
247	\ ]
248  call s:compare_lines(expect, lines)
249  " clean up
250  call s:close_windows('set sbr= cpo-=n vts&')
251endfunc
252
253func Test_breakindent07a()
254  " breakindent set and shift by 1, Number  set sbr=? and briopt:sbr
255  call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4')
256  let lines = s:screen_lines(line('.'),10)
257  let expect = [
258	\ "  2     ab",
259	\ "    ?    m",
260	\ "    ?    x",
261	\ ]
262  call s:compare_lines(expect, lines)
263  " clean up
264  call s:close_windows('set sbr=')
265endfunc
266
267func Test_breakindent07a_vartabs()
268  if !has("vartabs")
269    return
270  endif
271  " breakindent set and shift by 1, Number  set sbr=? and briopt:sbr
272  call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4')
273  let lines = s:screen_lines(line('.'),10)
274  let expect = [
275	\ "  2     ab",
276	\ "    ?    m",
277	\ "    ?    x",
278	\ ]
279  call s:compare_lines(expect, lines)
280  " clean up
281  call s:close_windows('set sbr= vts&')
282endfunc
283
284func Test_breakindent08()
285  " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
286  call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4')
287  " make sure, cache is invalidated!
288  set ts=8
289  redraw!
290  set ts=4
291  redraw!
292  let lines = s:screen_lines(line('.'),10)
293  let expect = [
294	\ "  2 ^Iabcd",
295	\ "#      opq",
296	\ "#      BCD",
297	\ ]
298  call s:compare_lines(expect, lines)
299  call s:close_windows('set sbr= cpo-=n')
300endfunc
301
302func Test_breakindent08_vartabs()
303  if !has("vartabs")
304    return
305  endif
306  " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
307  call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4')
308  " make sure, cache is invalidated!
309  set ts=8
310  redraw!
311  set ts=4
312  redraw!
313  let lines = s:screen_lines(line('.'),10)
314  let expect = [
315	\ "  2 ^Iabcd",
316	\ "#      opq",
317	\ "#      BCD",
318	\ ]
319  call s:compare_lines(expect, lines)
320  call s:close_windows('set sbr= cpo-=n vts&')
321endfunc
322
323func Test_breakindent08a()
324  " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
325  call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list')
326  let lines = s:screen_lines(line('.'),10)
327  let expect = [
328	\ "  2 ^Iabcd",
329	\ "    #  opq",
330	\ "    #  BCD",
331	\ ]
332  call s:compare_lines(expect, lines)
333  call s:close_windows('set sbr=')
334endfunc
335
336func Test_breakindent08a_vartabs()
337  if !has("vartabs")
338    return
339  endif
340  " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
341  call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4')
342  let lines = s:screen_lines(line('.'),10)
343  let expect = [
344	\ "  2 ^Iabcd",
345	\ "    #  opq",
346	\ "    #  BCD",
347	\ ]
348  call s:compare_lines(expect, lines)
349  call s:close_windows('set sbr= vts&')
350endfunc
351
352func Test_breakindent09()
353  " breakindent set and shift by 1, Number and list set sbr=#
354  call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list')
355  let lines = s:screen_lines(line('.'),10)
356  let expect = [
357	\ "  2 ^Iabcd",
358	\ "       #op",
359	\ "       #AB",
360	\ ]
361  call s:compare_lines(expect, lines)
362  call s:close_windows('set sbr=')
363endfunc
364
365func Test_breakindent09_vartabs()
366  if !has("vartabs")
367    return
368  endif
369  " breakindent set and shift by 1, Number and list set sbr=#
370  call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4')
371  let lines = s:screen_lines(line('.'),10)
372  let expect = [
373	\ "  2 ^Iabcd",
374	\ "       #op",
375	\ "       #AB",
376	\ ]
377  call s:compare_lines(expect, lines)
378  call s:close_windows('set sbr= vts&')
379endfunc
380
381func Test_breakindent10()
382  " breakindent set, Number set sbr=~
383  call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0')
384  " make sure, cache is invalidated!
385  set ts=8
386  redraw!
387  set ts=4
388  redraw!
389  let lines = s:screen_lines(line('.'),10)
390  let expect = [
391	\ "  2     ab",
392	\ "~       mn",
393	\ "~       yz",
394	\ ]
395  call s:compare_lines(expect, lines)
396  call s:close_windows('set sbr= cpo-=n')
397endfunc
398
399func Test_breakindent10_vartabs()
400  if !has("vartabs")
401    return
402  endif
403  " breakindent set, Number set sbr=~
404  call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4')
405  " make sure, cache is invalidated!
406  set ts=8
407  redraw!
408  set ts=4
409  redraw!
410  let lines = s:screen_lines(line('.'),10)
411  let expect = [
412	\ "  2     ab",
413	\ "~       mn",
414	\ "~       yz",
415	\ ]
416  call s:compare_lines(expect, lines)
417  call s:close_windows('set sbr= cpo-=n vts&')
418endfunc
419
420func Test_breakindent11()
421  " test strdisplaywidth()
422  call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4')
423  let text = getline(2)
424  let width = strlen(text[1:]) + indent(2) + strlen(&sbr) * 3 " text wraps 3 times
425  call assert_equal(width, strdisplaywidth(text))
426  call s:close_windows('set sbr=')
427  call assert_equal(4, strdisplaywidth("\t", 4))
428endfunc
429
430func Test_breakindent11_vartabs()
431  if !has("vartabs")
432    return
433  endif
434  " test strdisplaywidth()
435  call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4')
436  let text = getline(2)
437  let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times
438  call assert_equal(width, text->strdisplaywidth())
439  call s:close_windows('set sbr= vts&')
440endfunc
441
442func Test_breakindent12()
443  " test breakindent with long indent
444  let s:input="\t\t\t\t\t{"
445  call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-')
446  let lines = s:screen_lines(2,16)
447  let expect = [
448	\ " 2 >--->--->--->",
449	\ "          ---{  ",
450	\ "~               ",
451	\ ]
452  call s:compare_lines(expect, lines)
453  call s:close_windows('set nuw=4 listchars&')
454endfunc
455
456func Test_breakindent12_vartabs()
457  if !has("vartabs")
458    return
459  endif
460  " test breakindent with long indent
461  let s:input = "\t\t\t\t\t{"
462  call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4')
463  let lines = s:screen_lines(2,16)
464  let expect = [
465	\ " 2 >--->--->--->",
466	\ "          ---{  ",
467	\ "~               ",
468	\ ]
469  call s:compare_lines(expect, lines)
470  call s:close_windows('set nuw=4 listchars& vts&')
471endfunc
472
473func Test_breakindent13()
474  let s:input = ""
475  call s:test_windows('setl breakindent briopt=min:10 ts=8')
476  vert resize 20
477  call setline(1, ["    a\tb\tc\td\te", "    z   y       x       w       v"])
478  1
479  norm! fbgj"ayl
480  2
481  norm! fygj"byl
482  call assert_equal('d', @a)
483  call assert_equal('w', @b)
484  call s:close_windows()
485endfunc
486
487func Test_breakindent13_vartabs()
488  if !has("vartabs")
489    return
490  endif
491  let s:input = ""
492  call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8')
493  vert resize 20
494  call setline(1, ["    a\tb\tc\td\te", "    z   y       x       w       v"])
495  1
496  norm! fbgj"ayl
497  2
498  norm! fygj"byl
499  call assert_equal('d', @a)
500  call assert_equal('w', @b)
501  call s:close_windows('set vts&')
502endfunc
503
504func Test_breakindent14()
505  let s:input = ""
506  call s:test_windows('setl breakindent briopt= ts=8')
507  vert resize 30
508  norm! 3a1234567890
509  norm! a    abcde
510  exec "norm! 0\<C-V>tex"
511  let lines = s:screen_lines(line('.'),8)
512  let expect = [
513	\ "e       ",
514	\ "~       ",
515	\ "~       ",
516	\ ]
517  call s:compare_lines(expect, lines)
518  call s:close_windows()
519endfunc
520
521func Test_breakindent14_vartabs()
522  if !has("vartabs")
523    return
524  endif
525  let s:input = ""
526  call s:test_windows('setl breakindent briopt= ts=8 vts=8')
527  vert resize 30
528  norm! 3a1234567890
529  norm! a    abcde
530  exec "norm! 0\<C-V>tex"
531  let lines = s:screen_lines(line('.'),8)
532  let expect = [
533	\ "e       ",
534	\ "~       ",
535	\ "~       ",
536	\ ]
537  call s:compare_lines(expect, lines)
538  call s:close_windows('set vts&')
539endfunc
540
541func Test_breakindent15()
542  let s:input = ""
543  call s:test_windows('setl breakindent briopt= ts=8 sw=8')
544  vert resize 30
545  norm! 4a1234567890
546  exe "normal! >>\<C-V>3f0x"
547  let lines = s:screen_lines(line('.'),20)
548  let expect = [
549	\ "        1234567890  ",
550	\ "~                   ",
551	\ "~                   ",
552	\ ]
553  call s:compare_lines(expect, lines)
554  call s:close_windows()
555endfunc
556
557func Test_breakindent15_vartabs()
558  if !has("vartabs")
559    return
560  endif
561  let s:input = ""
562  call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8')
563  vert resize 30
564  norm! 4a1234567890
565  exe "normal! >>\<C-V>3f0x"
566  let lines = s:screen_lines(line('.'),20)
567  let expect = [
568	\ "        1234567890  ",
569	\ "~                   ",
570	\ "~                   ",
571	\ ]
572  call s:compare_lines(expect, lines)
573  call s:close_windows('set vts&')
574endfunc
575
576func Test_breakindent16()
577  " Check that overlong lines are indented correctly.
578  let s:input = ""
579  call s:test_windows('setl breakindent briopt=min:0 ts=4')
580  call setline(1, "\t".repeat("1234567890", 10))
581  resize 6
582  norm! 1gg$
583  redraw!
584  let lines = s:screen_lines(1,10)
585  let expect = [
586	\ "<<< 789012",
587	\ "    345678",
588	\ "    901234",
589	\ ]
590  call s:compare_lines(expect, lines)
591  let lines = s:screen_lines(4,10)
592  let expect = [
593	\ "    567890",
594	\ "    123456",
595	\ "    7890  ",
596	\ ]
597  call s:compare_lines(expect, lines)
598  call s:close_windows()
599endfunc
600
601func Test_breakindent16_vartabs()
602  if !has("vartabs")
603    return
604  endif
605  " Check that overlong lines are indented correctly.
606  let s:input = ""
607  call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4')
608  call setline(1, "\t".repeat("1234567890", 10))
609  resize 6
610  norm! 1gg$
611  redraw!
612  let lines = s:screen_lines(1,10)
613  let expect = [
614	\ "<<< 789012",
615	\ "    345678",
616	\ "    901234",
617	\ ]
618  call s:compare_lines(expect, lines)
619  let lines = s:screen_lines(4,10)
620  let expect = [
621	\ "    567890",
622	\ "    123456",
623	\ "    7890  ",
624	\ ]
625  call s:compare_lines(expect, lines)
626  call s:close_windows('set vts&')
627endfunc
628
629func Test_breakindent17_vartabs()
630  if !has("vartabs")
631    return
632  endif
633  let s:input = ""
634  call s:test_windows('setl breakindent list listchars=tab:<-> showbreak=+++')
635  call setline(1, "\t" . repeat('a', 63))
636  vert resize 30
637  norm! 1gg$
638  redraw!
639  let lines = s:screen_lines(1, 30)
640  let expect = [
641	\ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
642	\ "    +++aaaaaaaaaaaaaaaaaaaaaaa",
643	\ "    +++aaaaaaaaaaaaaa         ",
644	\ ]
645  call s:compare_lines(expect, lines)
646  call s:close_windows('set breakindent& list& listchars& showbreak&')
647endfunc
648
649func Test_breakindent18_vartabs()
650  if !has("vartabs")
651    return
652  endif
653  let s:input = ""
654  call s:test_windows('setl breakindent list listchars=tab:<->')
655  call setline(1, "\t" . repeat('a', 63))
656  vert resize 30
657  norm! 1gg$
658  redraw!
659  let lines = s:screen_lines(1, 30)
660  let expect = [
661	\ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
662	\ "    aaaaaaaaaaaaaaaaaaaaaaaaaa",
663	\ "    aaaaaaaaaaa               ",
664	\ ]
665  call s:compare_lines(expect, lines)
666  call s:close_windows('set breakindent& list& listchars&')
667endfunc
668
669func Test_breakindent19_sbr_nextpage()
670  let s:input = ""
671  call s:test_windows('setl breakindent briopt=shift:2,sbr,min:18 sbr=>')
672  call setline(1, repeat('a', 200))
673  norm! 1gg
674  redraw!
675  let lines = s:screen_lines(1, 20)
676  let expect = [
677	\ "aaaaaaaaaaaaaaaaaaaa",
678	\ "> aaaaaaaaaaaaaaaaaa",
679	\ "> aaaaaaaaaaaaaaaaaa",
680	\ ]
681  call s:compare_lines(expect, lines)
682  " Scroll down one screen line
683  setl scrolloff=5
684  norm! 5gj
685  let lines = s:screen_lines(1, 20)
686  let expect = [
687	\ "aaaaaaaaaaaaaaaaaaaa",
688	\ "> aaaaaaaaaaaaaaaaaa",
689	\ "> aaaaaaaaaaaaaaaaaa",
690	\ ]
691  call s:compare_lines(expect, lines)
692  redraw!
693  " moving the cursor doesn't change the text offset
694  norm! l
695  redraw!
696  let lines = s:screen_lines(1, 20)
697  call s:compare_lines(expect, lines)
698
699  setl breakindent briopt=min:18 sbr=>
700  norm! 5gj
701  let lines = s:screen_lines(1, 20)
702  let expect = [
703	\ ">aaaaaaaaaaaaaaaaaaa",
704	\ ">aaaaaaaaaaaaaaaaaaa",
705	\ ">aaaaaaaaaaaaaaaaaaa",
706	\ ]
707  call s:compare_lines(expect, lines)
708  call s:close_windows('set breakindent& briopt& sbr&')
709endfunc
710
711func Test_breakindent20_cpo_n_nextpage()
712  let s:input = ""
713  call s:test_windows('setl breakindent briopt=min:14 cpo+=n number')
714  call setline(1, repeat('abcdefghijklmnopqrst', 10))
715  norm! 1gg
716  redraw!
717  let lines = s:screen_lines(1, 20)
718  let expect = [
719	\ "  1 abcdefghijklmnop",
720	\ "    qrstabcdefghijkl",
721	\ "    mnopqrstabcdefgh",
722	\ ]
723  call s:compare_lines(expect, lines)
724  " Scroll down one screen line
725  setl scrolloff=5
726  norm! 6gj
727  redraw!
728  let lines = s:screen_lines(1, 20)
729  let expect = [
730	\ "<<< qrstabcdefghijkl",
731	\ "    mnopqrstabcdefgh",
732	\ "    ijklmnopqrstabcd",
733	\ ]
734  call s:compare_lines(expect, lines)
735
736  setl briopt+=shift:2
737  norm! 1gg
738  let lines = s:screen_lines(1, 20)
739  let expect = [
740	\ "  1 abcdefghijklmnop",
741	\ "      qrstabcdefghij",
742	\ "      klmnopqrstabcd",
743	\ ]
744  call s:compare_lines(expect, lines)
745  " Scroll down one screen line
746  norm! 6gj
747  let lines = s:screen_lines(1, 20)
748  let expect = [
749	\ "<<<   qrstabcdefghij",
750	\ "      klmnopqrstabcd",
751	\ "      efghijklmnopqr",
752	\ ]
753  call s:compare_lines(expect, lines)
754
755  call s:close_windows('set breakindent& briopt& cpo& number&')
756endfunc
757
758func Test_breakindent20_list()
759  call s:test_windows('setl breakindent breakindentopt= linebreak')
760  " default:
761  call setline(1, ['  1.  Congress shall make no law',
762        \ '  2.) Congress shall make no law',
763        \ '  3.] Congress shall make no law'])
764  norm! 1gg
765  redraw!
766  let lines = s:screen_lines2(1, 6, 20)
767  let expect = [
768	\ "  1.  Congress      ",
769	\ "shall make no law   ",
770	\ "  2.) Congress      ",
771	\ "shall make no law   ",
772	\ "  3.] Congress      ",
773	\ "shall make no law   ",
774	\ ]
775  call s:compare_lines(expect, lines)
776  " set minimum text width
777  setl briopt=min:5
778  redraw!
779  let lines = s:screen_lines2(1, 6, 20)
780  let expect = [
781	\ "  1.  Congress      ",
782	\ "  shall make no law ",
783	\ "  2.) Congress      ",
784	\ "  shall make no law ",
785	\ "  3.] Congress      ",
786	\ "  shall make no law ",
787	\ ]
788  call s:compare_lines(expect, lines)
789  " set additional handing indent
790  setl briopt+=list:4
791  redraw!
792  let expect = [
793	\ "  1.  Congress      ",
794	\ "      shall make no ",
795	\ "      law           ",
796	\ "  2.) Congress      ",
797	\ "      shall make no ",
798	\ "      law           ",
799	\ "  3.] Congress      ",
800	\ "      shall make no ",
801	\ "      law           ",
802	\ ]
803  let lines = s:screen_lines2(1, 9, 20)
804  call s:compare_lines(expect, lines)
805
806  " reset linebreak option
807  " Note: it indents by one additional
808  " space, because of the leading space.
809  setl linebreak&vim list listchars=eol:$,space:_
810  redraw!
811  let expect = [
812	\ "__1.__Congress_shall",
813	\ "      _make_no_law$ ",
814	\ "__2.)_Congress_shall",
815	\ "      _make_no_law$ ",
816	\ "__3.]_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
823  setl briopt=min:5,list:-1
824  setl linebreak list&vim listchars&vim
825  let &l:flp = '^\s*\d\+\.\?[\]:)}\t ]\s*'
826  redraw!
827  let expect = [
828	\ "  1.  Congress      ",
829	\ "      shall make no ",
830	\ "      law           ",
831	\ "  2.) Congress      ",
832	\ "      shall make no ",
833	\ "      law           ",
834	\ "  3.] Congress      ",
835	\ "      shall make no ",
836	\ "      law           ",
837	\ ]
838  let lines = s:screen_lines2(1, 9, 20)
839  call s:compare_lines(expect, lines)
840
841  " check with TABs
842  call setline(1, ["\t1.\tCongress shall make no law",
843        \ "\t2.) Congress shall make no law",
844        \ "\t3.] Congress shall make no law"])
845  setl tabstop=4 list listchars=tab:<->
846  norm! 1gg
847  redraw!
848  let expect = [
849	\ "<-->1.<>Congress    ",
850	\ "        shall make  ",
851	\ "        no law      ",
852	\ "<-->2.) Congress    ",
853	\ "        shall make  ",
854	\ "        no law      ",
855	\ "<-->3.] Congress    ",
856	\ "        shall make  ",
857	\ "        no law      ",
858	\ ]
859  let lines = s:screen_lines2(1, 9, 20)
860  call s:compare_lines(expect, lines)
861
862  setl tabstop=2 nolist
863  redraw!
864  let expect = [
865	\ "  1.  Congress      ",
866	\ "      shall make no ",
867	\ "      law           ",
868	\ "  2.) Congress      ",
869	\ "      shall make no ",
870	\ "      law           ",
871	\ "  3.] Congress      ",
872	\ "      shall make no ",
873	\ "      law           ",
874	\ ]
875  let lines = s:screen_lines2(1, 9, 20)
876  call s:compare_lines(expect, lines)
877
878  setl tabstop& list listchars=space:_
879  redraw!
880  let expect = [
881	\ "^I1.^ICongress_     ",
882	\ "      shall_make_no_",
883	\ "      law           ",
884	\ "^I2.)_Congress_     ",
885	\ "      shall_make_no_",
886	\ "      law           ",
887	\ "^I3.]_Congress_     ",
888	\ "      shall_make_no_",
889	\ "      law           ",
890	\ ]
891  let lines = s:screen_lines2(1, 9, 20)
892  call s:compare_lines(expect, lines)
893
894  " check formatlistpat indent with different list levels
895  let &l:flp = '^\s*\(\*\|•\)\+\s\+'
896  setl list&vim listchars&vim
897  %delete _
898  call setline(1, ['* Congress shall make no law',
899        \ '••• Congress shall make no law',
900        \ '**** Congress shall make no law'])
901  norm! 1gg
902  redraw!
903  let expect = [
904	\ "* Congress shall    ",
905	\ "  make no law       ",
906	\ "••• Congress shall  ",
907	\ "    make no law     ",
908	\ "**** Congress shall ",
909	\ "     make no law    ",
910	\ ]
911  let lines = s:screen_lines2(1, 6, 20)
912  call s:compare_lines(expect, lines)
913
914  " check formatlistpat indent with different list level
915  " showbreak and sbr
916  setl briopt=min:5,sbr,list:-1
917  setl showbreak=>
918  redraw!
919  let expect = [
920	\ "* Congress shall    ",
921	\ "> make no law       ",
922	\ "••• Congress shall  ",
923	\ ">   make no law     ",
924	\ "**** Congress shall ",
925	\ ">    make no law    ",
926	\ ]
927  let lines = s:screen_lines2(1, 6, 20)
928  call s:compare_lines(expect, lines)
929
930  " check formatlistpat indent with different list level
931  " showbreak sbr and shift
932  setl briopt=min:5,sbr,list:-1,shift:2
933  setl showbreak=>
934  redraw!
935  let expect = [
936	\ "* Congress shall    ",
937	\ ">   make no law     ",
938	\ "••• Congress shall  ",
939	\ ">     make no law   ",
940	\ "**** Congress shall ",
941	\ ">      make no law  ",
942	\ ]
943  let lines = s:screen_lines2(1, 6, 20)
944  call s:compare_lines(expect, lines)
945
946  " check breakindent works if breakindentopt=list:-1
947  " for a non list content
948  %delete _
949  call setline(1, ['  Congress shall make no law',
950        \ '    Congress shall make no law',
951        \ '     Congress shall make no law'])
952  norm! 1gg
953  setl briopt=min:5,list:-1
954  setl showbreak=
955  redraw!
956  let expect = [
957	\ "  Congress shall    ",
958	\ "  make no law       ",
959	\ "    Congress shall  ",
960	\ "    make no law     ",
961	\ "     Congress shall ",
962	\ "     make no law    ",
963	\ ]
964  let lines = s:screen_lines2(1, 6, 20)
965  call s:compare_lines(expect, lines)
966
967  call s:close_windows('set breakindent& briopt& linebreak& list& listchars& showbreak&')
968endfunc
969
970" The following used to crash Vim. This is fixed by 8.2.3391.
971" This is a regression introduced by 8.2.2903.
972func Test_window_resize_with_linebreak()
973  new
974  53vnew
975  setl linebreak
976  setl showbreak=>>
977  setl breakindent
978  setl breakindentopt=shift:4
979  call setline(1, "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a")
980  redraw!
981  call assert_equal(["    >>aa^@\"a: "], ScreenLines(2, 14))
982  vertical resize 52
983  redraw!
984  call assert_equal(["    >>aaa^@\"a:"], ScreenLines(2, 14))
985  set linebreak& showbreak& breakindent& breakindentopt&
986  %bw!
987endfunc
988
989func Test_cursor_position_with_showbreak()
990  CheckScreendump
991
992  let lines =<< trim END
993      vim9script
994      &signcolumn = 'yes'
995      &showbreak = '++'
996      &breakindentopt = 'shift:2'
997      var leftcol: number = win_getid()->getwininfo()->get(0, {})->get('textoff')
998      repeat('x', &columns - leftcol - 1)->setline(1)
999      'second line'->setline(2)
1000  END
1001  call writefile(lines, 'XscriptShowbreak', 'D')
1002  let buf = RunVimInTerminal('-S XscriptShowbreak', #{rows: 6})
1003
1004  call term_sendkeys(buf, "AX")
1005  call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_1', {})
1006  " No line wraps, so changing 'showbreak' should lead to the same screen.
1007  call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal showbreak=+\<CR>")
1008  call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_1', {})
1009  " No line wraps, so setting 'breakindent' should lead to the same screen.
1010  call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal breakindent\<CR>")
1011  call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_1', {})
1012  " The first line now wraps because of "eol" in 'listchars'.
1013  call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal list\<CR>")
1014  call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_2', {})
1015  call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal nobreakindent\<CR>")
1016  call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak_3', {})
1017
1018  call StopVimInTerminal(buf)
1019endfunc
1020
1021func Test_visual_starts_before_skipcol()
1022  CheckScreendump
1023
1024  let lines =<< trim END
1025    1new
1026    setlocal breakindent
1027    call setline(1, "\t" .. join(range(100)))
1028  END
1029  call writefile(lines, 'XvisualStartsBeforeSkipcol', 'D')
1030  let buf = RunVimInTerminal('-S XvisualStartsBeforeSkipcol', #{rows: 6})
1031
1032  call term_sendkeys(buf, "v$")
1033  call WaitForAssert({-> assert_match('VISUAL.*\d', term_getline(buf, 6))}, 1000)
1034  call VerifyScreenDump(buf, 'Test_visual_starts_before_skipcol_1', {})
1035  call term_sendkeys(buf, "\<Esc>:setlocal showbreak=+++\<CR>gv")
1036  call VerifyScreenDump(buf, 'Test_visual_starts_before_skipcol_2', {})
1037  call term_sendkeys(buf, "\<Esc>:setlocal breakindentopt+=sbr\<CR>gv")
1038  call VerifyScreenDump(buf, 'Test_visual_starts_before_skipcol_3', {})
1039  call term_sendkeys(buf, "\<Esc>:setlocal nobreakindent\<CR>gv")
1040  call VerifyScreenDump(buf, 'Test_visual_starts_before_skipcol_4', {})
1041
1042  call StopVimInTerminal(buf)
1043endfunc
1044
1045func Test_no_spurious_match()
1046  let s:input = printf('- y %s y %s', repeat('x', 50), repeat('x', 50))
1047  call s:test_windows('setl breakindent breakindentopt=list:-1 formatlistpat=^- hls')
1048  let @/ = '\%>3v[y]'
1049  redraw!
1050  call searchcount().total->assert_equal(1)
1051
1052  " cleanup
1053  set hls&vim
1054  bwipeout!
1055endfunc
1056
1057func Test_no_extra_indent()
1058  call s:test_windows('setl breakindent breakindentopt=list:-1,min:10')
1059  %d
1060  let &l:formatlistpat='^\s*\d\+\.\s\+'
1061  let text = 'word '
1062  let len = text->strcharlen()
1063  let line1 = text->repeat((winwidth(0) / len) * 2)
1064  let line2 = repeat(' ', 2) .. '1. ' .. line1
1065  call setline(1, [line2])
1066  redraw!
1067  " 1) matches formatlist pattern, so indent
1068  let expect = [
1069  \ "  1. word word word ",
1070  \ "     word word word ",
1071  \ "     word word      ",
1072  \ "~                   ",
1073  \ ]
1074  let lines = s:screen_lines2(1, 4, 20)
1075  call s:compare_lines(expect, lines)
1076  " 2) change formatlist pattern
1077  " -> indent adjusted
1078  let &l:formatlistpat='^\s*\d\+\.'
1079  let expect = [
1080  \ "  1. word word word ",
1081  \ "    word word word  ",
1082  \ "    word word       ",
1083  \ "~                   ",
1084  \ ]
1085  let lines = s:screen_lines2(1, 4, 20)
1086  " 3) no local formatlist pattern,
1087  " so use global one -> indent
1088  let g_flp = &g:flp
1089  let &g:formatlistpat='^\s*\d\+\.\s\+'
1090  let &l:formatlistpat=''
1091  let expect = [
1092  \ "  1. word word word ",
1093  \ "     word word word ",
1094  \ "     word word      ",
1095  \ "~                   ",
1096  \ ]
1097  let lines = s:screen_lines2(1, 4, 20)
1098  call s:compare_lines(expect, lines)
1099  let &g:flp = g_flp
1100  let &l:formatlistpat='^\s*\d\+\.'
1101  " 4) add something in front, no additional indent
1102  norm! gg0
1103  exe ":norm! 5iword \<esc>"
1104  redraw!
1105  let expect = [
1106  \ "word word word word ",
1107  \ "word   1. word word ",
1108  \ "word word word word ",
1109  \ "word word           ",
1110  \ "~                   ",
1111  \ ]
1112  let lines = s:screen_lines2(1, 5, 20)
1113  call s:compare_lines(expect, lines)
1114  bwipeout!
1115endfunc
1116
1117func Test_breakindent_column()
1118  call s:test_windows('setl breakindent breakindentopt=column:10')
1119  redraw!
1120  " 1) default: does not indent, too wide :(
1121  let expect = [
1122  \ "                    ",
1123  \ "    abcdefghijklmnop",
1124  \ "qrstuvwxyzABCDEFGHIJ",
1125  \ "KLMNOP              "
1126  \ ]
1127  let lines = s:screen_lines2(1, 4, 20)
1128  call s:compare_lines(expect, lines)
1129  " 2) lower min value, so that breakindent works
1130  setl breakindentopt+=min:5
1131  redraw!
1132  let expect = [
1133  \ "                    ",
1134  \ "    abcdefghijklmnop",
1135  \ "          qrstuvwxyz",
1136  \ "          ABCDEFGHIJ",
1137  \ "          KLMNOP    "
1138  \ ]
1139  let lines = s:screen_lines2(1, 5, 20)
1140  " 3) set shift option -> no influence
1141  setl breakindentopt+=shift:5
1142  redraw!
1143  let expect = [
1144  \ "                    ",
1145  \ "    abcdefghijklmnop",
1146  \ "          qrstuvwxyz",
1147  \ "          ABCDEFGHIJ",
1148  \ "          KLMNOP    "
1149  \ ]
1150  let lines = s:screen_lines2(1, 5, 20)
1151  call s:compare_lines(expect, lines)
1152  " 4) add showbreak value
1153  setl showbreak=++
1154  redraw!
1155  let expect = [
1156  \ "                    ",
1157  \ "    abcdefghijklmnop",
1158  \ "          ++qrstuvwx",
1159  \ "          ++yzABCDEF",
1160  \ "          ++GHIJKLMN",
1161  \ "          ++OP      "
1162  \ ]
1163  let lines = s:screen_lines2(1, 6, 20)
1164  call s:compare_lines(expect, lines)
1165  bwipeout!
1166endfunc
1167
1168func Test_linebreak_list()
1169  " This was setting wlv.c_extra to NUL while wlv.p_extra is NULL
1170  filetype plugin on
1171  syntax enable
1172  edit! $VIMRUNTIME/doc/index.txt
1173  /v_P
1174
1175  setlocal list
1176  setlocal listchars=tab:>-
1177  setlocal linebreak
1178  setlocal nowrap
1179  setlocal filetype=help
1180  redraw!
1181
1182  bwipe!
1183endfunc
1184
1185func Test_breakindent_change_display_uhex()
1186  call s:test_windows('setl briopt=min:0 list listchars=eol:$')
1187  redraw!
1188  let lines = s:screen_lines(line('.'), 20)
1189  let expect = [
1190        \ "^Iabcdefghijklmnopqr",
1191        \ "  stuvwxyzABCDEFGHIJ",
1192        \ "  KLMNOP$           "
1193        \ ]
1194  call s:compare_lines(expect, lines)
1195  set display+=uhex
1196  redraw!
1197  let lines = s:screen_lines(line('.'), 20)
1198  let expect = [
1199        \ "<09>abcdefghijklmnop",
1200        \ "    qrstuvwxyzABCDEF",
1201        \ "    GHIJKLMNOP$     "
1202        \ ]
1203  call s:compare_lines(expect, lines)
1204  set display&
1205
1206  call s:close_windows()
1207endfunc
1208
1209func Test_breakindent_list_split()
1210  10new
1211  61vsplit
1212  setlocal tabstop=8 breakindent list listchars=tab:<->,eol:$
1213  put =s:input
1214  30vsplit
1215  setlocal listchars=eol:$
1216  let expect = [
1217      \ "^IabcdefghijklmnopqrstuvwxyzAB|<------>abcdefghijklmnopqrstuv",
1218      \ "  CDEFGHIJKLMNOP$             |        wxyzABCDEFGHIJKLMNOP$ ",
1219      \ "~                             |~                             "
1220      \ ]
1221  redraw!
1222  let lines = s:screen_lines(line('.'), 61)
1223  call s:compare_lines(expect, lines)
1224  wincmd p
1225  redraw!
1226  let lines = s:screen_lines(line('.'), 61)
1227  call s:compare_lines(expect, lines)
1228
1229  bwipe!
1230endfunc
1231
1232func Test_breakindent_min_with_signcol()
1233  call s:test_windows('setl briopt=min:15 signcolumn=yes')
1234  redraw!
1235  let expect = [
1236        \ "      abcdefghijklmn",
1237        \ "     opqrstuvwxyzABC",
1238        \ "     DEFGHIJKLMNOP  "
1239        \ ]
1240  let lines = s:screen_lines(line('.'), 20)
1241  call s:compare_lines(expect, lines)
1242  setl briopt=min:17
1243  redraw!
1244  let expect = [
1245        \ "      abcdefghijklmn",
1246        \ "   opqrstuvwxyzABCDE",
1247        \ "   FGHIJKLMNOP      "
1248        \ ]
1249  let lines = s:screen_lines(line('.'), 20)
1250  call s:compare_lines(expect, lines)
1251  setl briopt=min:19
1252  redraw!
1253  let expect = [
1254        \ "      abcdefghijklmn",
1255        \ "  opqrstuvwxyzABCDEF",
1256        \ "  GHIJKLMNOP        "
1257        \ ]
1258  let lines = s:screen_lines(line('.'), 20)
1259  call s:compare_lines(expect, lines)
1260
1261  call s:close_windows()
1262endfunc
1263
1264func Test_breakindent_with_double_width_wrap()
1265  50vnew
1266  setlocal tabstop=8 breakindent nolist
1267  call setline(1, "\t" .. repeat('a', winwidth(0) - 9) .. '口口口')
1268  normal! $g0
1269  call assert_equal(2, winline())
1270  call assert_equal(9, wincol())
1271
1272  bwipe!
1273endfunc
1274
1275" vim: shiftwidth=2 sts=2 expandtab