robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1-- Test for linebreak and list option in utf-8 mode 2 3local n =require ( 'test.functional.testnvim' )() 4local t =require ( 'test.testutil' ) 5local Screen =require ( 'test.functional.ui.screen' ) 6 7local describe , it , before_each =t . describe , t . it , t . before_each 8local source =n . source 9local feed =n . feed 10local exec =n . exec 11local clear , expect =n . clear , n . expect 12 13describe ( 'linebreak' , function () 14before_each ( clear ) 15 16-- luacheck: ignore 621 (Indentation) 17-- luacheck: ignore 613 (Trailing whitespaces in a string) 18it ( 'is working' , function () 19source ( [[ 20set wildchar=^E 2110new 22vsp 23vert resize 20 24put =\"\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP \" 25norm! zt 26set ts=4 sw=4 sts=4 linebreak sbr=+ wrap 27fu! ScreenChar(width, lines) 28let c='' 29for j in range(1,a:lines) 30for i in range(1,a:width) 31let c.=nr2char(screenchar(j, i)) 32endfor 33let c.="\n" 34endfor 35return c 36endfu 37fu! DoRecordScreen() 38wincmd l 39$put =printf(\"\n%s\", g:test) 40$put =g:line 41wincmd p 42endfu 43" 44let g:test ="Test 1: set linebreak + set list + fancy listchars" 45exe "set linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6" 46redraw! 47let line=ScreenChar(winwidth(0),4) 48call DoRecordScreen() 49" 50let g:test ="Test 2: set nolinebreak list" 51set list nolinebreak 52redraw! 53let line=ScreenChar(winwidth(0),4) 54call DoRecordScreen() 55" 56let g:test ="Test 3: set linebreak nolist" 57$put =\"\t*mask = nil;\" 58$ 59norm! zt 60set nolist linebreak 61redraw! 62let line=ScreenChar(winwidth(0),4) 63call DoRecordScreen() 64" 65let g:test ="Test 4: set linebreak list listchars and concealing" 66let c_defines=['#define ABCDE 1','#define ABCDEF 1','#define ABCDEFG 1','#define ABCDEFGH 1', '#define MSG_MODE_FILE 1','#define MSG_MODE_CONSOLE 2','#define MSG_MODE_FILE_AND_CONSOLE 3','#define MSG_MODE_FILE_THEN_CONSOLE 4'] 67call append('$', c_defines) 68vert resize 40 69$-7 70norm! zt 71set list linebreak listchars=tab:>- cole=1 72syn match Conceal conceal cchar=>'AB\|MSG_MODE' 73redraw! 74let line=ScreenChar(winwidth(0),7) 75call DoRecordScreen() 76" 77let g:test ="Test 5: set linebreak list listchars and concealing part2" 78let c_defines=['bbeeeeee ; some text'] 79call append('$', c_defines) 80$ 81norm! zt 82set nowrap ts=2 list linebreak listchars=tab:>- cole=2 concealcursor=n 83syn clear 84syn match meaning /;\s*\zs.*/ 85syn match hasword /^\x\{8}/ contains=word 86syn match word /\<\x\{8}\>/ contains=beginword,endword contained 87syn match beginword /\<\x\x/ contained conceal 88syn match endword /\x\{6}\>/ contained 89hi meaning guibg=blue 90hi beginword guibg=green 91hi endword guibg=red 92redraw! 93let line=ScreenChar(winwidth(0),1) 94call DoRecordScreen() 95" 96let g:test ="Test 6: Screenattributes for comment" 97$put =g:test 98call append('$', ' /* and some more */') 99exe "set ft=c ts=7 linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6" 100syntax on 101hi SpecialKey term=underline ctermfg=red guifg=red 102let attr=[] 103nnoremap <expr> GG ":let attr += ['".screenattr(screenrow(),screencol())."']\n" 104$ 105norm! zt0 106]] ) 107feed ( 'GGlGGlGGlGGlGGlGGlGGlGGlGGlGGl' ) 108source ( [[ 109call append('$', ['ScreenAttributes for test6:']) 110if attr[0] != attr[1] && attr[1] != attr[3] && attr[3] != attr[5] 111call append('$', "Attribut 0 and 1 and 3 and 5 are different!") 112else 113call append('$', "Not all attributes are different") 114endif 115set cpo&vim linebreak selection=exclusive 116let g:test ="Test 8: set linebreak with visual block mode and v_b_A and selection=exclusive and multibyte char" 117$put =g:test 118]] ) 119feed ( "Golong line: <Esc>40afoobar <Esc>aTARGETÃ' at end<Esc>" ) 120source ( [[ 121exe "norm! $3B\<C-v>eAx\<Esc>" 122" 123let g:test ="Test 9: a multibyte sign and colorcolumn" 124let attr=[] 125let attr2=[] 126$put ='' 127$put ='a b c' 128$put ='a b c' 129set list nolinebreak cc=3 130]] ) 131feed ( ':sign define foo text=<C-v>uff0b<CR>' ) 132source ( [[ 133sign place 1 name=foo line=50 buffer=2 134norm! 2kztj 135let line1=line('.') 136]] ) 137feed ( '0GGlGGlGGlGGl' ) 138source ( [[ 139let line2=line('.') 140let attr2=attr 141let attr=[] 142]] ) 143feed ( '0GGlGGlGGlGGl' ) 144source ( [[ 145redraw! 146let line=ScreenChar(winwidth(0),3) 147call DoRecordScreen() 148" expected: attr[2] is different because of colorcolumn 149if attr[0] != attr2[0] || attr[1] != attr2[1] || attr[2] != attr2[2] 150call append('$', "Screen attributes are different!") 151else 152call append('$', "Screen attributes are the same!") 153endif 154]] ) 155 156-- Assert buffer contents. 157expect ( [[ 158 159abcdef hijklmn pqrstuvwxyz 1060ABCDEFGHIJKLMNOP 160 161Test 1: set linebreak + set list + fancy listchars 162▕———abcdef 163+hijklmn▕——— 164+pqrstuvwxyz␣1060ABC 165+DEFGHIJKLMNOPˑ¶ 166 167Test 2: set nolinebreak list 168▕———abcdef hijklmn▕— 169+pqrstuvwxyz␣1060ABC 170+DEFGHIJKLMNOPˑ¶ 171¶ 172*mask = nil; 173 174Test 3: set linebreak nolist 175*mask = nil; 176~ 177~ 178~ 179#define ABCDE 1 180#define ABCDEF 1 181#define ABCDEFG 1 182#define ABCDEFGH 1 183#define MSG_MODE_FILE 1 184#define MSG_MODE_CONSOLE 2 185#define MSG_MODE_FILE_AND_CONSOLE 3 186#define MSG_MODE_FILE_THEN_CONSOLE 4 187 188Test 4: set linebreak list listchars and concealing 189#define ABCDE>-->---1 190#define >CDEF>-->---1 191#define >CDEFG>->---1 192#define >CDEFGH>----1 193#define >_FILE>--------->--->---1 194#define >_CONSOLE>---------->---2 195#define >_FILE_AND_CONSOLE>---------3 196bbeeeeee ; some text 197 198Test 5: set linebreak list listchars and concealing part2 199eeeeee>--->-;>some text 200Test 6: Screenattributes for comment 201/* and some more */ 202ScreenAttributes for test6: 203Attribut 0 and 1 and 3 and 5 are different! 204Test 8: set linebreak with visual block mode and v_b_A and selection=exclusive and multibyte char 205long line: foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar TARGETÃx' at end 206 207a b c 208a b c 209 210Test 9: a multibyte sign and colorcolumn 211¶ 212+a b c¶ 213a b c¶ 214Screen attributes are the same!]] ) 215end ) 216 217-- oldtest: Test_visual_ends_before_showbreak() 218it ( "Visual area is correct when it ends before multibyte 'showbreak'" , function () 219local screen =Screen . new ( 60 , 6 ) 220exec ( [[ 221let &wrap = v:true 222let &linebreak = v:true 223let &showbreak = '↪ ' 224eval ['xxxxx ' .. 'y'->repeat(&columns - 6) .. ' zzzz']->setline(1) 225normal! wvel 226]] ) 227screen : expect ( [[ 228xxxxx | 229{1:↪ }{17:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy^ }| 230{1:↪ }zzzz | 231{1:~ }|*2 232{5:-- VISUAL --} | 233]] ) 234end ) 235 236it ( "Visual block highlight is correct with 'linebreak'" , function () 237local screen =Screen . new ( 60 , 6 ) 238exec ( 'set laststatus=0 showcmd ruler' ) 239 240-- 'linebreak' after end char (initially fixed by patch 7.4.467) 241exec ( [[ 24220vnew 243setlocal linebreak 244call setline(1, ['foo ' .. repeat('x', 10), 'foo ' .. repeat('x', 20)]) 245exe "normal! gg0\<C-V>3lj" 246]] ) 247screen : expect ( [[ 248{17:foo }xxxxxxxxxx │ | 249{17:foo^ } │{1:~ }| 250xxxxxxxxxxxxxxxxxxxx│{1:~ }| 251{1:~ }│{1:~ }|*2 252{5:-- VISUAL BLOCK --} 2x4 2,4 All| 253]] ) 254 255-- TAB as end char: 'linebreak' shouldn't break Visual block hl 256exec ( [[ 257bwipe! 258setlocal nolinebreak 259call setline(1, ["foo\tbar", 'foo12345bar', "foo\tbar"]) 260exe "normal! gg03l\<C-V>2j2h" 261]] ) 262screen : expect ( [[ 263f{17:oo }bar | 264f{17:oo12345}bar | 265f{17:^oo }bar | 266{1:~ }|*2 267{5:-- VISUAL BLOCK --} 3x7 3,2 All| 268]] ) 269feed ( '<Esc>:setlocal linebreak<CR>gv' ) 270screen : expect_unchanged ( true ) 271 272-- Unprintable end char: 'linebreak' shouldn't break Visual block hl 273exec ( [[ 274bwipe! 275setlocal nolinebreak 276call setline(1, ["foo\uffffbar", 'foo123456bar', "foo\uffffbar"]) 277exe "normal! gg03l\<C-V>2j2h" 278]] ) 279screen : expect ( [[ 280f{17:oo<ffff>}bar | 281f{17:oo123456}bar | 282f{17:^oo<ffff>}bar | 283{1:~ }|*2 284{5:-- VISUAL BLOCK --} 3x8 3,2 All| 285]] ) 286feed ( '<Esc>:setlocal linebreak<CR>gv' ) 287screen : expect_unchanged ( true ) 288 289-- Virtual text before end char: 'linebreak' shouldn't break Visual block hl 290exec ( [=[ 291bwipe! 292setlocal nolinebreak 293call setline(1, [repeat('x', 15), repeat('x', 10), repeat('x', 10)]) 294let s:ns = nvim_create_namespace('test') 295call nvim_buf_set_extmark(0, s:ns, 1, 4, #{virt_text: [['foo: ']], 296\ virt_text_pos: 'inline'}) 297call nvim_buf_set_extmark(0, s:ns, 2, 4, #{virt_text: [['bar: ']], 298\ virt_text_pos: 'inline'}) 299exe "normal! gg02l\<C-V>2j2l" 300]=] ) 301screen : expect ( [[ 302xx{17:xxxxxxxx}xxxxx | 303xx{17:xx}foo: {17:x}xxxxx | 304xx{17:xx}bar: {17:^x}xxxxx | 305{1:~ }|*2 306{5:-- VISUAL BLOCK --} 3x8 3,5-10 All| 307]] ) 308feed ( '<Esc>:setlocal linebreak<CR>gv' ) 309screen : expect_unchanged ( true ) 310end ) 311end )