robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
d10dda8a47
master
1" Test for linebreak and list option in utf-8 mode 2 3set encoding = utf-8 4scriptencoding utf-8 5 6source check.vim 7CheckOption linebreak 8CheckFeature conceal 9CheckFeature signs 10 11source view_util.vim 12source screendump.vim 13 14func s: screen_lines ( lnum , width ) abort 15return ScreenLines ( a: lnum , a: width ) 16endfunc 17 18func s: compare_lines ( expect , actual ) 19call assert_equal ( a: expect , a: actual ) 20endfunc 21 22func s: screen_attr ( lnum , chars , ...) abort 23let line = getline ( a: lnum ) 24let attr = [] 25let prefix = get ( a: 000 , 0 , 0 ) 26for i in range ( a: chars [ 0 ], a: chars [ 1 ]) 27let scol = strdisplaywidth ( strcharpart ( line , 0 , i - 1 )) + 1 28let attr += [ screenattr ( a: lnum , scol + prefix )] 29endfor 30return attr 31endfunc 32 33func s: test_windows (...) 34call NewWindow ( 10 , 20 ) 35setl ts = 4 sw = 4 sts = 4 linebreak sbr = +wrap 36exe get ( a: 000 , 0 , '' ) 37endfunc 38 39func s: close_windows (...) 40call CloseWindow () 41exe get ( a: 000 , 0 , '' ) 42endfunc 43 44func Test_linebreak_with_fancy_listchars () 45call s: test_windows ( "setl list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6" ) 46call setline ( 1 , "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP " ) 47redraw ! 48let lines = s: screen_lines ([ 1 , 4 ], winwidth ( 0 )) 49let expect = [ 50\"▕———abcdef " , 51\"+hijklmn▕——— " , 52\"+pqrstuvwxyz␣1060ABC" , 53\"+DEFGHIJKLMNOPˑ¶ " , 54\] 55call s: compare_lines ( expect , lines ) 56call s: close_windows () 57endfunc 58 59func Test_nolinebreak_with_list () 60call s: test_windows ( "setl nolinebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6" ) 61call setline ( 1 , "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP " ) 62redraw ! 63let lines = s: screen_lines ([ 1 , 4 ], winwidth ( 0 )) 64let expect = [ 65\"▕———abcdef hijklmn▕—" , 66\"+pqrstuvwxyz␣1060ABC" , 67\"+DEFGHIJKLMNOPˑ¶ " , 68\"~ " , 69\] 70call s: compare_lines ( expect , lines ) 71call s: close_windows () 72endfunc 73 74" this was causing a crash 75func Test_linebreak_with_list_and_tabs () 76set linebreak list listchars = tab:⇤\ ⇥tabstop = 100 77new 78call setline ( 1 , "\t\t\ttext" ) 79redraw 80bwipe ! 81set nolinebreak nolist listchars & vim tabstop = 8 82endfunc 83 84func Test_linebreak_with_nolist () 85call s: test_windows ( 'setl nolist' ) 86call setline ( 1 , "\t*mask = nil;" ) 87redraw ! 88let lines = s: screen_lines ([ 1 , 4 ], winwidth ( 0 )) 89let expect = [ 90\" *mask = nil; " , 91\"~ " , 92\"~ " , 93\"~ " , 94\] 95call s: compare_lines ( expect , lines ) 96call s: close_windows () 97endfunc 98 99func Test_list_and_concealing1 () 100call s: test_windows ( 'setl list listchars=tab:>- cole=1' ) 101call setline ( 1 , [ 102\"#define ABCDE\t\t1" , 103\"#define ABCDEF\t\t1" , 104\"#define ABCDEFG\t\t1" , 105\"#define ABCDEFGH\t1" , 106\"#define MSG_MODE_FILE\t\t\t1" , 107\"#define MSG_MODE_CONSOLE\t\t2" , 108\"#define MSG_MODE_FILE_AND_CONSOLE\t3" , 109\"#define MSG_MODE_FILE_THEN_CONSOLE\t4" , 110\]) 111vert resize 40 112syn match Conceal conceal cchar = >'AB\|MSG_MODE ' 113redraw ! 114let lines = s: screen_lines ([ 1 , 7 ], winwidth ( 0 )) 115let expect = [ 116\"#define ABCDE>-->---1 " , 117\"#define >CDEF>-->---1 " , 118\"#define >CDEFG>->---1 " , 119\"#define >CDEFGH>----1 " , 120\"#define >_FILE>--------->--->---1 " , 121\"#define >_CONSOLE>---------->---2 " , 122\"#define >_FILE_AND_CONSOLE>---------3 " , 123\] 124call s: compare_lines ( expect , lines ) 125call s: close_windows () 126endfunc 127 128func Test_list_and_concealing2 () 129call s: test_windows ( 'setl nowrap ts=2 list listchars=tab:>- cole=2 concealcursor=n' ) 130call setline ( 1 , "bbeeeeee\t\t;\tsome text" ) 131vert resize 40 132syn clear 133syn match meaning /;\s * \zs. * / 134syn match hasword /^\x\{8} /contains = word 135syn match word /\<\x\{8}\> /contains = beginword , endword contained 136syn match beginword /\<\x\x /contained conceal 137syn match endword /\x\{6}\> /contained 138hi meaning guibg = blue 139hi beginword guibg = green 140hi endword guibg = red 141redraw ! 142let lines = s: screen_lines ([ 1 , 1 ], winwidth ( 0 )) 143let expect = [ 144\"eeeeee>--->-;>some text " , 145\] 146call s: compare_lines ( expect , lines ) 147call s: close_windows () 148endfunc 149 150func Test_screenattr_for_comment () 151call s: test_windows ( "setl ft=c ts=7 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6" ) 152call setline ( 1 , " /*\t\t and some more */" ) 153norm ! gg0 154syntax on 155hi SpecialKey term = underline ctermfg = red guifg = red 156redraw ! 157let line = getline ( 1 ) 158let attr = s: screen_attr ( 1 , [ 1 , 6 ]) 159call assert_notequal ( attr [ 0 ], attr [ 1 ]) 160call assert_notequal ( attr [ 1 ], attr [ 3 ]) 161call assert_notequal ( attr [ 3 ], attr [ 5 ]) 162call s: close_windows () 163endfunc 164 165func Test_visual_block_and_selection_exclusive () 166call s: test_windows ( 'setl selection=exclusive' ) 167call setline ( 1 , "long line: " . repeat ( "foobar " , 40 ) . "TARGETÃ' at end" ) 168exe "norm! $3B\<C-v>eAx\<Esc>" 169let lines = s: screen_lines ([ 1 , 10 ], winwidth ( 0 )) 170let expect = [ 171\"+foobar foobar " , 172\"+foobar foobar " , 173\"+foobar foobar " , 174\"+foobar foobar " , 175\"+foobar foobar " , 176\"+foobar foobar " , 177\"+foobar foobar " , 178\"+foobar foobar " , 179\"+foobar foobar " , 180\"+foobar TARGETÃx' " , 181\] 182call s: compare_lines ( expect , lines ) 183call s: close_windows () 184endfunc 185 186func Test_multibyte_sign_and_colorcolumn () 187call s: test_windows ( "setl nolinebreak cc=3 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6" ) 188call setline ( 1 , [ "" , "a b c" , "a b c" ]) 189exe "sign define foo text=\uff0b" 190exe "sign place 1 name=foo line=2 buffer=" . bufnr ( '%' ) 191redraw ! 192norm ! ggj0 193let signwidth = strdisplaywidth ( "\uff0b" ) 194let attr1 = s: screen_attr ( 2 , [ 1 , 3 ], signwidth ) 195let attr2 = s: screen_attr ( 3 , [ 1 , 3 ], signwidth ) 196call assert_equal ( attr1 [ 0 ], attr2 [ 0 ]) 197call assert_equal ( attr1 [ 1 ], attr2 [ 1 ]) 198call assert_equal ( attr1 [ 2 ], attr2 [ 2 ]) 199let lines = s: screen_lines ([ 1 , 3 ], winwidth ( 0 )) 200let expect = [ 201\" ¶ " , 202\"+a b c¶ " , 203\" a b c¶ " , 204\] 205call s: compare_lines ( expect , lines ) 206call s: close_windows () 207endfunc 208 209func Test_colorcolumn_priority () 210call s: test_windows ( 'setl cc=4 cuc hls' ) 211call setline ( 1 , [ "xxyy" , "" ]) 212norm ! gg 213exe "normal! /xxyy\<CR>" 214norm ! G 215redraw ! 216let line_attr = s: screen_attr ( 1 , [ 1 , & cc ]) 217" Search wins over CursorColumn 218call assert_equal ( line_attr [ 1 ], line_attr [ 0 ]) 219" Search wins over Colorcolumn 220call assert_equal ( line_attr [ 2 ], line_attr [ 3 ]) 221call s: close_windows ( 'setl hls&vim' ) 222endfunc 223 224func Test_illegal_byte_and_breakat () 225call s: test_windows ( "setl sbr= brk+=<" ) 226vert resize 18 227call setline ( 1 , repeat ( "\x80" , 6 )) 228redraw ! 229let lines = s: screen_lines ([ 1 , 2 ], winwidth ( 0 )) 230let expect = [ 231\"<80><80><80><80><8" , 232\"0><80> " , 233\] 234call s: compare_lines ( expect , lines ) 235call s: close_windows ( 'setl brk&vim' ) 236endfunc 237 238func Test_multibyte_wrap_and_breakat () 239call s: test_windows ( "setl sbr= brk+=>" ) 240call setline ( 1 , repeat ( 'a' , 17 ) . repeat ( 'あ' , 2 )) 241redraw ! 242let lines = s: screen_lines ([ 1 , 2 ], winwidth ( 0 )) 243let expect = [ 244\"aaaaaaaaaaaaaaaaaあ>" , 245\"あ " , 246\] 247call s: compare_lines ( expect , lines ) 248call s: close_windows ( 'setl brk&vim' ) 249endfunc 250 251func Test_chinese_char_on_wrap_column () 252call s: test_windows ( "setl nolbr wrap sbr=" ) 253call setline ( 1 , [ 254\'aaaaaaaaaaaaaaaaaaa中' . 255\'aaaaaaaaaaaaaaaaa中' . 256\'aaaaaaaaaaaaaaaaa中' . 257\'aaaaaaaaaaaaaaaaa中' . 258\'aaaaaaaaaaaaaaaaa中' . 259\'aaaaaaaaaaaaaaaaa中' . 260\'aaaaaaaaaaaaaaaaa中' . 261\'aaaaaaaaaaaaaaaaa中' . 262\'aaaaaaaaaaaaaaaaa中' . 263\'aaaaaaaaaaaaaaaaa中' . 264\'hello' ]) 265call cursor ( 1 , 1 ) 266norm ! $ 267redraw ! 268let expect = [ 269\'<<<aaaaaaaaaaaaaaaa>' , 270\'中aaaaaaaaaaaaaaaaa>' , 271\'中aaaaaaaaaaaaaaaaa>' , 272\'中aaaaaaaaaaaaaaaaa>' , 273\'中aaaaaaaaaaaaaaaaa>' , 274\'中aaaaaaaaaaaaaaaaa>' , 275\'中aaaaaaaaaaaaaaaaa>' , 276\'中aaaaaaaaaaaaaaaaa>' , 277\'中aaaaaaaaaaaaaaaaa>' , 278\'中hello ' ] 279let lines = s: screen_lines ([ 1 , 10 ], winwidth ( 0 )) 280call s: compare_lines ( expect , lines ) 281call assert_equal ( len ( expect ), winline ()) 282call assert_equal ( strwidth ( trim ( expect [ -1 ], ' ' , 2 )), wincol ()) 283norm ! g0 284call assert_equal ( len ( expect ), winline ()) 285call assert_equal ( 1 , wincol ()) 286call s: close_windows () 287endfunc 288 289func Test_chinese_char_on_wrap_column_sbr () 290call s: test_windows ( "setl nolbr wrap sbr=!!!" ) 291call setline ( 1 , [ 292\'aaaaaaaaaaaaaaaaaaa中' . 293\'aaaaaaaaaaaaaa中' . 294\'aaaaaaaaaaaaaa中' . 295\'aaaaaaaaaaaaaa中' . 296\'aaaaaaaaaaaaaa中' . 297\'aaaaaaaaaaaaaa中' . 298\'aaaaaaaaaaaaaa中' . 299\'aaaaaaaaaaaaaa中' . 300\'aaaaaaaaaaaaaa中' . 301\'aaaaaaaaaaaaaa中' . 302\'hello' ]) 303call cursor ( 1 , 1 ) 304norm ! $ 305redraw ! 306let expect = [ 307\'!!!中aaaaaaaaaaaaaa>' , 308\'!!!中aaaaaaaaaaaaaa>' , 309\'!!!中aaaaaaaaaaaaaa>' , 310\'!!!中aaaaaaaaaaaaaa>' , 311\'!!!中aaaaaaaaaaaaaa>' , 312\'!!!中aaaaaaaaaaaaaa>' , 313\'!!!中aaaaaaaaaaaaaa>' , 314\'!!!中aaaaaaaaaaaaaa>' , 315\'!!!中aaaaaaaaaaaaaa>' , 316\'!!!中hello ' ] 317let lines = s: screen_lines ([ 1 , 10 ], winwidth ( 0 )) 318call s: compare_lines ( expect , lines ) 319call assert_equal ( len ( expect ), winline ()) 320call assert_equal ( strwidth ( trim ( expect [ -1 ], ' ' , 2 )), wincol ()) 321norm ! g0 322call assert_equal ( len ( expect ), winline ()) 323call assert_equal ( 4 , wincol ()) 324call s: close_windows () 325endfunc 326 327func Test_unprintable_char_on_wrap_column () 328call s: test_windows ( "setl nolbr wrap sbr=" ) 329call setline ( 1 , 'aaa' .. repeat ( "\uFEFF" , 50 ) .. 'bbb' ) 330call cursor ( 1 , 1 ) 331norm ! $ 332redraw ! 333let expect = [ 334\'<<<<feff><feff><feff' , 335\'><feff><feff><feff><' , 336\'feff><feff><feff><fe' , 337\'ff><feff><feff><feff' , 338\'><feff><feff><feff><' , 339\'feff><feff><feff><fe' , 340\'ff><feff><feff><feff' , 341\'><feff><feff><feff><' , 342\'feff><feff><feff><fe' , 343\'ff>bbb ' ] 344let lines = s: screen_lines ([ 1 , 10 ], winwidth ( 0 )) 345call s: compare_lines ( expect , lines ) 346call assert_equal ( len ( expect ), winline ()) 347call assert_equal ( strwidth ( trim ( expect [ -1 ], ' ' , 2 )), wincol ()) 348setl sbr = !! 349redraw ! 350let expect = [ 351\'!!><feff><feff><feff' , 352\'!!><feff><feff><feff' , 353\'!!><feff><feff><feff' , 354\'!!><feff><feff><feff' , 355\'!!><feff><feff><feff' , 356\'!!><feff><feff><feff' , 357\'!!><feff><feff><feff' , 358\'!!><feff><feff><feff' , 359\'!!><feff><feff><feff' , 360\'!!><feff><feff>bbb ' ] 361let lines = s: screen_lines ([ 1 , 10 ], winwidth ( 0 )) 362call s: compare_lines ( expect , lines ) 363call assert_equal ( len ( expect ), winline ()) 364call assert_equal ( strwidth ( trim ( expect [ -1 ], ' ' , 2 )), wincol ()) 365call s: close_windows () 366endfunc 367 368" Test that Visual selection is drawn correctly when 'linebreak' is set and 369" selection ends before multibyte 'showbreak'. 370func Test_visual_ends_before_showbreak () 371CheckScreendump 372 373let lines =<< trim END 374vim9script 375&wrap = true 376&linebreak = true 377&showbreak = '↪ ' 378['xxxxx ' .. 'y'->repeat(&columns - 6) .. ' zzzz']->setline(1) 379normal! wvel 380END 381call writefile ( lines , 'XvisualEndsBeforeShowbreak' , 'D' ) 382let buf = RunVimInTerminal ( '-S XvisualEndsBeforeShowbreak' , #{ rows : 6 }) 383call VerifyScreenDump ( buf , 'Test_visual_ends_before_showbreak' , {}) 384 385call StopVimInTerminal ( buf ) 386endfunc 387 388func Test_visual_block_hl_with_linebreak () 389CheckScreendump 390 391let lines =<< trim END 392func Case1() 39320vnew 394setlocal linebreak 395call setline(1, ['foo ' .. repeat('x', 10), 'foo ' .. repeat('x', 20)]) 396exe "normal! gg0\<C-V>3lj" 397endfunc 398 399func Case2() 400setlocal nolinebreak 401call setline(1, ["foo\tbar", 'foo12345bar', "foo\tbar"]) 402exe "normal! gg03l\<C-V>2j2h" 403endfunc 404 405func Case3() 406setlocal nolinebreak 407call setline(1, ["foo\uffffbar", 'foo123456bar', "foo\uffffbar"]) 408exe "normal! gg03l\<C-V>2j2h" 409endfunc 410 411func Case4() 412setlocal nolinebreak 413call setline(1, [repeat('x', 15), repeat('x', 10), repeat('x', 10)]) 414call prop_type_add('test', {}) 415call prop_add(2, 5, #{text: "foo: ", type: "test"}) 416call prop_add(3, 5, #{text: "bar: ", type: "test"}) 417exe "normal! gg02l\<C-V>2j2l" 418endfunc 419 420set laststatus=0 showcmd ruler 421" FIXME: clipboard=autoselect sometimes changes Visual highlight 422set clipboard= 423END 424call writefile ( lines , 'XvisualBlockHlWithLinebreak' , 'D' ) 425let buf = RunVimInTerminal ( '-S XvisualBlockHlWithLinebreak' , #{ rows : 6 }) 426 427" 'linebreak' after end char (initially fixed by patch 7.4.467) 428call term_sendkeys ( buf , ":call Case1()\r" ) 429call VerifyScreenDump ( buf , 'Test_visual_block_hl_with_linebreak_1' , {}) 430 431" TAB as end char: 'linebreak' shouldn't break Visual block hl 432call term_sendkeys ( buf , "\<Esc>:bwipe! | call Case2()\r" ) 433call VerifyScreenDump ( buf , 'Test_visual_block_hl_with_linebreak_2' , {}) 434call term_sendkeys ( buf , "\<Esc>:setlocal linebreak\rgv" ) 435call term_wait ( buf , 50 ) 436call VerifyScreenDump ( buf , 'Test_visual_block_hl_with_linebreak_2' , {}) 437 438" Unprintable end char: 'linebreak' shouldn't break Visual block hl 439call term_sendkeys ( buf , "\<Esc>:bwipe! | call Case3()\r" ) 440call VerifyScreenDump ( buf , 'Test_visual_block_hl_with_linebreak_3' , {}) 441call term_sendkeys ( buf , "\<Esc>:setlocal linebreak\rgv" ) 442call term_wait ( buf , 50 ) 443call VerifyScreenDump ( buf , 'Test_visual_block_hl_with_linebreak_3' , {}) 444 445" Virtual text before end char: 'linebreak' shouldn't break Visual block hl 446call term_sendkeys ( buf , "\<Esc>:bwipe! | call Case4()\r" ) 447call VerifyScreenDump ( buf , 'Test_visual_block_hl_with_linebreak_4' , {}) 448call term_sendkeys ( buf , "\<Esc>:setlocal linebreak\rgv" ) 449call term_wait ( buf , 50 ) 450call VerifyScreenDump ( buf , 'Test_visual_block_hl_with_linebreak_4' , {}) 451 452call term_sendkeys ( buf , "\<Esc>" ) 453call StopVimInTerminal ( buf ) 454endfunc 455 456" vim: shiftwidth=2 sts=2 expandtab