robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
8b21fe83da
master
1" Test for 'number' and 'relativenumber' 2 3source check.vim 4source view_util.vim 5 6source screendump.vim 7 8func s: screen_lines ( start , end ) abort 9return ScreenLines ([ a: start , a: end ], 8 ) 10endfunc 11 12func s: compare_lines ( expect , actual ) 13call assert_equal ( a: expect , a: actual ) 14endfunc 15 16func s: test_windows ( h , w ) abort 17call NewWindow ( a: h , a: w ) 18endfunc 19 20func s: close_windows () abort 21call CloseWindow () 22endfunc 23 24func s: validate_cursor () abort 25" update skipcol. 26" wincol(): 27" f_wincol 28" -> validate_cursor 29" -> curs_columns 30call wincol () 31endfunc 32 33func Test_set_options () 34set nu rnu 35call assert_equal ( 1 , & nu ) 36call assert_equal ( 1 , & rnu ) 37 38call s: test_windows ( 10 , 20 ) 39call assert_equal ( 1 , & nu ) 40call assert_equal ( 1 , & rnu ) 41call s: close_windows () 42 43set nu & rnu & 44endfunc 45 46func Test_set_global_and_local () 47" setlocal must NOT reset the other global value 48set nonu nornu 49setglobal nu 50setlocal rnu 51call assert_equal ( 1 , & g: nu ) 52 53set nonu nornu 54setglobal rnu 55setlocal nu 56call assert_equal ( 1 , & g: rnu ) 57 58" setglobal MUST reset the other global value 59set nonu nornu 60setglobal nu 61setglobal rnu 62call assert_equal ( 1 , & g: nu ) 63 64set nonu nornu 65setglobal rnu 66setglobal nu 67call assert_equal ( 1 , & g: rnu ) 68 69" set MUST reset the other global value 70set nonu nornu 71set nu 72set rnu 73call assert_equal ( 1 , & g: nu ) 74 75set nonu nornu 76set rnu 77set nu 78call assert_equal ( 1 , & g: rnu ) 79 80set nu & rnu & 81endfunc 82 83func Test_number () 84call s: test_windows ( 10 , 20 ) 85call setline ( 1 , [ "abcdefghij" , "klmnopqrst" , "uvwxyzABCD" , "EFGHIJKLMN" , "OPQRSTUVWX" , "YZ" ]) 86setl number 87let lines = s: screen_lines ( 1 , 4 ) 88let expect = [ 89\" 1 abcd" , 90\" 2 klmn" , 91\" 3 uvwx" , 92\" 4 EFGH" , 93\] 94call s: compare_lines ( expect , lines ) 95call s: close_windows () 96endfunc 97 98func Test_relativenumber () 99call s: test_windows ( 10 , 20 ) 100call setline ( 1 , [ "abcdefghij" , "klmnopqrst" , "uvwxyzABCD" , "EFGHIJKLMN" , "OPQRSTUVWX" , "YZ" ]) 1013 102setl relativenumber 103let lines = s: screen_lines ( 1 , 6 ) 104let expect = [ 105\" 2 abcd" , 106\" 1 klmn" , 107\" 0 uvwx" , 108\" 1 EFGH" , 109\" 2 OPQR" , 110\" 3 YZ " , 111\] 112call s: compare_lines ( expect , lines ) 113call s: close_windows () 114endfunc 115 116func Test_number_with_relativenumber () 117call s: test_windows ( 10 , 20 ) 118call setline ( 1 , [ "abcdefghij" , "klmnopqrst" , "uvwxyzABCD" , "EFGHIJKLMN" , "OPQRSTUVWX" , "YZ" ]) 1194 120setl number relativenumber 121let lines = s: screen_lines ( 1 , 6 ) 122let expect = [ 123\" 3 abcd" , 124\" 2 klmn" , 125\" 1 uvwx" , 126\"4 EFGH" , 127\" 1 OPQR" , 128\" 2 YZ " , 129\] 130call s: compare_lines ( expect , lines ) 131call s: close_windows () 132endfunc 133 134func Test_number_with_linewrap1 () 135call s: test_windows ( 3 , 20 ) 136normal ! 61ia 137setl number wrap 138call s: validate_cursor () 139let lines = s: screen_lines ( 1 , 3 ) 140let expect = [ 141\"<<< aaaa" , 142\" aaaa" , 143\" aaaa" , 144\] 145call s: compare_lines ( expect , lines ) 146call s: close_windows () 147endfunc 148 149func Test_number_with_linewrap2 () 150call s: test_windows ( 3 , 20 ) 151normal ! 61ia 152setl number wrap 153call s: validate_cursor () 1540 155call s: validate_cursor () 156let lines = s: screen_lines ( 1 , 3 ) 157let expect = [ 158\" 1 aaaa" , 159\" aaaa" , 160\" aaaa" , 161\] 162call s: compare_lines ( expect , lines ) 163call s: close_windows () 164endfunc 165 166func Test_number_with_linewrap3 () 167call s: test_windows ( 4 , 20 ) 168normal ! 81ia 169setl number wrap 170call s: validate_cursor () 171setl nonumber 172call s: validate_cursor () 173let lines = s: screen_lines ( 1 , 4 ) 174let expect = [ 175\"<<<aaaaa" , 176\"aaaaaaaa" , 177\"aaaaaaaa" , 178\"a " , 179\] 180call s: compare_lines ( expect , lines ) 181call s: close_windows () 182endfunc 183 184func Test_numberwidth () 185call s: test_windows ( 10 , 20 ) 186call setline ( 1 , repeat ([ 'aaaa' ], 10 )) 187setl number numberwidth = 6 188let lines = s: screen_lines ( 1 , 3 ) 189let expect = [ 190\" 1 aa" , 191\" 2 aa" , 192\" 3 aa" , 193\] 194call s: compare_lines ( expect , lines ) 195 196set relativenumber 197let lines = s: screen_lines ( 1 , 3 ) 198let expect = [ 199\"1 aa" , 200\" 1 aa" , 201\" 2 aa" , 202\] 203call s: compare_lines ( expect , lines ) 204 205set nonumber 206let lines = s: screen_lines ( 1 , 3 ) 207let expect = [ 208\" 0 aa" , 209\" 1 aa" , 210\" 2 aa" , 211\] 212call s: compare_lines ( expect , lines ) 213call s: close_windows () 214endfunc 215 216func Test_numberwidth_adjusted () 217call s: test_windows ( 10 , 20 ) 218call setline ( 1 , repeat ([ 'aaaa' ], 10000 )) 219setl number numberwidth = 4 220let lines = s: screen_lines ( 1 , 3 ) 221let expect = [ 222\" 1 aa" , 223\" 2 aa" , 224\" 3 aa" , 225\] 226call s: compare_lines ( expect , lines ) 227 228$ 229let lines = s: screen_lines ( 8 , 10 ) 230let expect = [ 231\" 9998 aa" , 232\" 9999 aa" , 233\"10000 aa" , 234\] 235call s: compare_lines ( expect , lines ) 236 237setl relativenumber 238let lines = s: screen_lines ( 8 , 10 ) 239let expect = [ 240\" 2 aa" , 241\" 1 aa" , 242\"10000 aa" , 243\] 244call s: compare_lines ( expect , lines ) 245 246setl nonumber 247let lines = s: screen_lines ( 8 , 10 ) 248let expect = [ 249\" 2 aaaa" , 250\" 1 aaaa" , 251\" 0 aaaa" , 252\] 253call s: compare_lines ( expect , lines ) 254call s: close_windows () 255endfunc 256 257" This was causing a memcheck error 258func Test_relativenumber_uninitialised () 259new 260set rnu 261call setline ( 1 , [ "a" , "b" ]) 262redraw 263call feedkeys ( "j" , 'xt' ) 264redraw 265bwipe ! 266endfunc 267 268func Test_relativenumber_colors () 269CheckScreendump 270 271let lines =<< trim [CODE] 272call setline(1, range(200)) 273111 274set number relativenumber 275hi LineNr ctermfg=red 276[CODE] 277call writefile ( lines , 'XTest_relnr' , 'D' ) 278 279let buf = RunVimInTerminal ( '-S XTest_relnr' , { 'rows' : 10 , 'cols' : 50 }) 280" Default colors 281call VerifyScreenDump ( buf , 'Test_relnr_colors_1' , {}) 282 283call term_sendkeys ( buf , ":hi LineNrAbove ctermfg=blue\<CR>:\<CR>" ) 284call VerifyScreenDump ( buf , 'Test_relnr_colors_2' , {}) 285 286call term_sendkeys ( buf , ":hi LineNrBelow ctermfg=green\<CR>:\<CR>" ) 287call VerifyScreenDump ( buf , 'Test_relnr_colors_3' , {}) 288 289call term_sendkeys ( buf , ":hi clear LineNrAbove\<CR>" ) 290call VerifyScreenDump ( buf , 'Test_relnr_colors_4' , {}) 291 292" clean up 293call StopVimInTerminal ( buf ) 294endfunc 295 296func Test_relativenumber_colors_wrapped () 297CheckScreendump 298 299let lines =<< trim [CODE] 300set display=lastline scrolloff=0 301call setline(1, range(200)->map('v:val->string()->repeat(40)')) 302111 303set number relativenumber 304hi LineNr ctermbg=red ctermfg=black 305hi LineNrAbove ctermbg=blue ctermfg=black 306hi LineNrBelow ctermbg=green ctermfg=black 307[CODE] 308call writefile ( lines , 'XTest_relnr_wrap' , 'D' ) 309 310let buf = RunVimInTerminal ( '-S XTest_relnr_wrap' , { 'rows' : 20 , 'cols' : 50 }) 311 312call VerifyScreenDump ( buf , 'Test_relnr_colors_wrapped_1' , {}) 313call term_sendkeys ( buf , "k" ) 314call VerifyScreenDump ( buf , 'Test_relnr_colors_wrapped_2' , {}) 315call term_sendkeys ( buf , "2j" ) 316call VerifyScreenDump ( buf , 'Test_relnr_colors_wrapped_3' , {}) 317call term_sendkeys ( buf , "2j" ) 318call VerifyScreenDump ( buf , 'Test_relnr_colors_wrapped_4' , {}) 319call term_sendkeys ( buf , "k" ) 320call VerifyScreenDump ( buf , 'Test_relnr_colors_wrapped_5' , {}) 321 322" clean up 323call StopVimInTerminal ( buf ) 324endfunc 325 326func Test_relativenumber_callback () 327CheckScreendump 328CheckFeature timers 329 330let lines =<< trim END 331call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd']) 332set relativenumber 333call cursor(4, 1) 334 335func Func(timer) 336call cursor(1, 1) 337endfunc 338 339call timer_start(300, 'Func') 340END 341call writefile ( lines , 'Xrnu_timer' , 'D' ) 342 343let buf = RunVimInTerminal ( '-S Xrnu_timer' , #{ rows : 8 }) 344call TermWait ( buf , 310 ) 345call VerifyScreenDump ( buf , 'Test_relativenumber_callback_1' , {}) 346 347call StopVimInTerminal ( buf ) 348endfunc 349 350" Test that line numbers below inserted/deleted lines are updated. 351func Test_number_insert_delete_lines () 352CheckScreendump 353 354let lines =<< trim END 355call setline(1, range(1, 7)) 356set number 357call cursor(2, 1) 358END 359call writefile ( lines , 'Xnumber_insert_delete_lines' , 'D' ) 360 361let buf = RunVimInTerminal ( '-S Xnumber_insert_delete_lines' , #{ rows : 8 }) 362call VerifyScreenDump ( buf , 'Test_number_insert_delete_lines_1' , {}) 363call term_sendkeys ( buf , "dd" ) 364call VerifyScreenDump ( buf , 'Test_number_insert_delete_lines_2' , {}) 365call term_sendkeys ( buf , "P" ) 366call VerifyScreenDump ( buf , 'Test_number_insert_delete_lines_1' , {}) 367call term_sendkeys ( buf , "2dd" ) 368call VerifyScreenDump ( buf , 'Test_number_insert_delete_lines_3' , {}) 369call term_sendkeys ( buf , "P" ) 370call VerifyScreenDump ( buf , 'Test_number_insert_delete_lines_1' , {}) 371 372call StopVimInTerminal ( buf ) 373endfunc 374 375" Test for displaying line numbers with 'rightleft' 376func Test_number_rightleft () 377CheckFeature rightleft 378new 379setlocal number 380setlocal rightleft 381call setline ( 1 , range ( 1 , 1000 )) 382normal ! 9Gzt 383redraw ! 384call assert_match ( '^\s\+9 9$' , Screenline ( 1 )) 385normal ! 10Gzt 386redraw ! 387call assert_match ( '^\s\+01 10$' , Screenline ( 1 )) 388normal ! 100Gzt 389redraw ! 390call assert_match ( '^\s\+001 100$' , Screenline ( 1 )) 391normal ! 1000Gzt 392redraw ! 393call assert_match ( '^\s\+0001 1000$' , Screenline ( 1 )) 394bw ! 395endfunc 396 397" This used to cause a divide by zero 398func Test_number_no_text_virtual_edit () 399vnew 400call setline ( 1 , [ 'line one' , 'line two' ]) 401set number virtualedit = all 402normal w 4034 wincmd | 404normal j 405bwipe ! 406endfunc 407 408" vim: shiftwidth=2 sts=2 expandtab