robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
dab5fab948
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear =n . clear 7local eq =t . eq 8local exec =n . exec 9local exec_lua =n . exec_lua 10local command =n . command 11local feed =n . feed 12local fn =n . fn 13 14-- oldtest: Test_window_cmd_ls0_split_scrolling() 15it ( 'scrolling with laststatus=0 and :botright split' , function () 16clear ( '--cmd' , 'set ruler' ) 17local screen =Screen . new ( 40 , 10 ) 18exec ( [[ 19set laststatus=0 20call setline(1, range(1, 100)) 21normal! G 22]] ) 23command ( 'botright split' ) 24screen : expect ( [[ 2597 | 2698 | 2799 | 28100 | 29{2:[No Name] [+] 100,1 Bot}| 3097 | 3198 | 3299 | 33^100 | 34100,1 Bot| 35]] ) 36end ) 37 38describe ( 'splitkeep' , function () 39local screen 40 41before_each ( function () 42clear ( '--cmd' , 'set splitkeep=screen' ) 43screen =Screen . new () 44end ) 45 46-- oldtest: Test_splitkeep_cursor() 47it ( 'does not adjust cursor in window that did not change size' , function () 48screen : try_resize ( 75 , 8 ) 49-- FIXME: bottom window is different without the "vsplit | close" 50exec ( [[ 51vsplit | close 52set scrolloff=5 53set splitkeep=screen 54autocmd CursorMoved * wincmd p | wincmd p 55call setline(1, range(1, 200)) 56func CursorEqualize() 57call cursor(100, 1) 58wincmd = 59endfunc 60wincmd s 61call CursorEqualize() 62]] ) 63 64screen : expect ( [[ 6599 | 66^100 | 67101 | 68{3:[No Name] [+] }| 695 | 706 | 71{2:[No Name] [+] }| 72| 73]] ) 74 75feed ( 'j' ) 76screen : expect ( [[ 77100 | 78^101 | 79102 | 80{3:[No Name] [+] }| 815 | 826 | 83{2:[No Name] [+] }| 84| 85]] ) 86 87command ( 'set scrolloff=0' ) 88feed ( 'G' ) 89screen : expect ( [[ 90198 | 91199 | 92^200 | 93{3:[No Name] [+] }| 945 | 956 | 96{2:[No Name] [+] }| 97| 98]] ) 99end ) 100 101-- oldtest: Test_splitkeep_callback() 102it ( 'does not scroll when split in callback' , function () 103exec ( [[ 104call setline(1, range(&lines)) 105function C1(a, b, c) 106split | wincmd p 107endfunction 108function C2(a, b, c) 109close | split 110endfunction 111]] ) 112exec_lua ( [[ 113vim.api.nvim_set_keymap("n", "j", "", { callback = function() 114vim.cmd("call jobstart([&sh, &shcf, 'true'], { 'on_exit': 'C1' })") 115end 116})]] ) 117exec_lua ( [[ 118vim.api.nvim_set_keymap("n", "t", "", { callback = function() 119vim.api.nvim_set_current_win( 120vim.api.nvim_open_win(vim.api.nvim_create_buf(false, {}), false, { 121width = 10, 122relative = "cursor", 123height = 4, 124row = 0, 125col = 0, 126})) 127vim.cmd("call jobstart([&sh, &shcf, 'true'], { 'term': v:true, 'on_exit': 'C2' })") 128end 129})]] ) 130feed ( 'j' ) 131screen : expect ( [[ 1320 | 1331 | 1342 | 1353 | 1364 | 1375 | 138{2:[No Name] [+] }| 139^7 | 1408 | 1419 | 14210 | 14311 | 144{3:[No Name] [+] }| 145| 146]] ) 147feed ( ':quit<CR>Ht' ) 148screen : expect ( [[ 149^0 | 1501 | 1512 | 1523 | 1534 | 1545 | 155{3:[No Name] [+] }| 1567 | 1578 | 1589 | 15910 | 16011 | 161{2:[No Name] [+] }| 162:quit | 163]] ) 164feed ( ':set sb<CR>:quit<CR>Gj' ) 165screen : expect ( [[ 1661 | 1672 | 1683 | 1694 | 170^5 | 171{3:[No Name] [+] }| 1727 | 1738 | 1749 | 17510 | 17611 | 17712 | 178{2:[No Name] [+] }| 179:quit | 180]] ) 181feed ( ':quit<CR>Gt' ) 182screen : expect ( [[ 1831 | 1842 | 1853 | 1864 | 1875 | 188{2:[No Name] [+] }| 1897 | 1908 | 1919 | 19210 | 19311 | 194^12 | 195{3:[No Name] [+] }| 196:quit | 197]] ) 198end ) 199 200-- oldtest: Test_splitkeep_fold() 201it ( 'does not scroll when window has closed folds' , function () 202exec ( [[ 203set commentstring=/*%s*/ 204set splitkeep=screen 205set foldmethod=marker 206set number 207let line = 1 208for n in range(1, &lines) 209call setline(line, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/', 210\ 'after fold']) 211let line += 8 212endfor 213]] ) 214feed ( 'L:wincmd s<CR>' ) 215screen : expect ( [[ 216{8: 1 }{13:+-- 7 lines: int FuncName() {···················}| 217{8: 8 }after fold | 218{8: 9 }{13:+-- 7 lines: int FuncName() {···················}| 219{8: 16 }after fold | 220{8: 17 }{13:+-- 7 lines: int FuncName() {···················}| 221{8: 24 }^after fold | 222{3:[No Name] [+] }| 223{8: 32 }after fold | 224{8: 33 }{13:+-- 7 lines: int FuncName() {···················}| 225{8: 40 }after fold | 226{8: 41 }{13:+-- 7 lines: int FuncName() {···················}| 227{8: 48 }after fold | 228{2:[No Name] [+] }| 229:wincmd s | 230]] ) 231feed ( ':quit<CR>' ) 232screen : expect ( [[ 233{8: 1 }{13:+-- 7 lines: int FuncName() {···················}| 234{8: 8 }after fold | 235{8: 9 }{13:+-- 7 lines: int FuncName() {···················}| 236{8: 16 }after fold | 237{8: 17 }{13:+-- 7 lines: int FuncName() {···················}| 238{8: 24 }after fold | 239{8: 25 }{13:+-- 7 lines: int FuncName() {···················}| 240{8: 32 }after fold | 241{8: 33 }{13:+-- 7 lines: int FuncName() {···················}| 242{8: 40 }after fold | 243{8: 41 }{13:+-- 7 lines: int FuncName() {···················}| 244{8: 48 }after fold | 245{8: 49 }{13:^+-- 7 lines: int FuncName() {···················}| 246:quit | 247]] ) 248feed ( 'H:below split<CR>' ) 249screen : expect ( [[ 250{8: 1 }{13:+-- 7 lines: int FuncName() {···················}| 251{8: 8 }after fold | 252{8: 9 }{13:+-- 7 lines: int FuncName() {···················}| 253{8: 16 }after fold | 254{8: 17 }{13:+-- 7 lines: int FuncName() {···················}| 255{2:[No Name] [+] }| 256{8: 25 }{13:^+-- 7 lines: int FuncName() {···················}| 257{8: 32 }after fold | 258{8: 33 }{13:+-- 7 lines: int FuncName() {···················}| 259{8: 40 }after fold | 260{8: 41 }{13:+-- 7 lines: int FuncName() {···················}| 261{8: 48 }after fold | 262{3:[No Name] [+] }| 263:below split | 264]] ) 265feed ( ':wincmd k<CR>:quit<CR>' ) 266screen : expect ( [[ 267{8: 1 }{13:+-- 7 lines: int FuncName() {···················}| 268{8: 8 }after fold | 269{8: 9 }{13:+-- 7 lines: int FuncName() {···················}| 270{8: 16 }after fold | 271{8: 17 }{13:+-- 7 lines: int FuncName() {···················}| 272{8: 24 }after fold | 273{8: 25 }{13:^+-- 7 lines: int FuncName() {···················}| 274{8: 32 }after fold | 275{8: 33 }{13:+-- 7 lines: int FuncName() {···················}| 276{8: 40 }after fold | 277{8: 41 }{13:+-- 7 lines: int FuncName() {···················}| 278{8: 48 }after fold | 279{8: 49 }{13:+-- 7 lines: int FuncName() {···················}| 280:quit | 281]] ) 282end ) 283 284-- oldtest: Test_splitkeep_status() 285it ( 'does not scroll when split in callback' , function () 286exec ( [[ 287call setline(1, ['a', 'b', 'c']) 288set nomodified 289set splitkeep=screen 290let win = winnr() 291wincmd s 292wincmd j 293]] ) 294feed ( ':call win_move_statusline(win, 1)<CR>' ) 295screen : expect ( [[ 296a | 297b | 298c | 299{1:~ }|*4 300{2:[No Name] }| 301^a | 302b | 303c | 304{1:~ }| 305{3:[No Name] }| 306:call win_move_statusline(win, 1) | 307]] ) 308end ) 309 310-- oldtest: Test_splitkeep_skipcol() 311it ( 'skipcol is not reset unnecessarily and is copied to new window' , function () 312screen : try_resize ( 40 , 12 ) 313exec ( [[ 314set splitkeep=topline smoothscroll splitbelow scrolloff=0 315call setline(1, 'with lots of text in one line '->repeat(6)) 316norm 2 317wincmd s 318]] ) 319screen : expect ( [[ 320{1:<<<}e line with lots of text in one line | 321with lots of text in one line with lots | 322of text in one line | 323{1:~ }| 324{2:[No Name] [+] }| 325{1:<<<}e line with lots of text in one line | 326^with lots of text in one line with lots | 327of text in one line | 328{1:~ }|*2 329{3:[No Name] [+] }| 330| 331]] ) 332end ) 333 334-- oldtest: Test_splitkeep_line() 335it ( "no scrolling with 'splitkeep' and line()" , function () 336screen : try_resize ( 40 , 6 ) 337exec ( [[ 338set splitkeep=screen nosplitbelow 339autocmd WinResized * call line('w0', 1000) 340call setline(1, range(1000)) 341]] ) 342screen : expect ( [[ 343^0 | 3441 | 3452 | 3463 | 3474 | 348| 349]] ) 350feed ( ':wincmd s<CR>' ) 351screen : expect ( [[ 352^0 | 3531 | 354{3:[No Name] [+] }| 3553 | 356{2:[No Name] [+] }| 357:wincmd s | 358]] ) 359end ) 360end ) 361 362-- oldtest: Test_winfixsize_vsep_statusline() 363it ( "'winfixwidth/height' does not leave stray vseps/statuslines" , function () 364clear () 365local screen =Screen . new ( 75 , 8 ) 366exec ( [[ 367set noequalalways splitbelow splitright 368vsplit 369setlocal winfixwidth 370vsplit 371]] ) 372eq ( 16 , fn . winwidth ( 1 )) 373eq ( 37 , fn . winwidth ( 2 )) 374eq ( 20 , fn . winwidth ( 3 )) 375 376command ( 'quit' ) 377screen : expect ( [[ 378^ │ | 379{1:~ }│{1:~ }|*5 380{3:[No Name] }{2:[No Name] }| 381| 382]] ) 383-- Checks w_view_width in Nvim; especially important as the screen test may still pass if only 384-- w_width changed to make room for the vsep. 385eq ( 36 , fn . winwidth ( 1 )) 386eq ( 38 , fn . winwidth ( 2 )) 387 388exec ( [[ 389set laststatus=0 390only 391split 392set winfixheight 393split 394]] ) 395eq ( 1 , fn . winheight ( 1 )) 396eq ( 3 , fn . winheight ( 2 )) 397eq ( 1 , fn . winheight ( 3 )) 398 399command ( 'quit' ) 400screen : expect ( [[ 401^ | 402{1:~ }| 403{3:[No Name] }| 404| 405{1:~ }|*3 406| 407]] ) 408eq ( 2 , fn . winheight ( 1 )) 409eq ( 4 , fn . winheight ( 2 )) 410end ) 411 412-- oldtest: Test_resize_from_another_tabpage() 413it ( 'resizing window from another tabpage' , function () 414clear () 415local screen =Screen . new ( 75 , 8 ) 416screen : add_extra_attr_ids ( { 417[ 100 ] ={ foreground =Screen . colors . Magenta1 , bold =true } , 418} ) 419exec ( [[ 420set laststatus=2 421vnew 422let w = win_getid() 423tabnew 424call win_execute(w, 'vertical resize 20') 425tabprev 426]] ) 427screen : expect ( [[ 428{5: }{100:2}{5: [No Name] }{24: [No Name] }{2: }{24:X}| 429^ │ | 430{1:~ }│{1:~ }|*4 431{3:[No Name] }{2:[No Name] }| 432| 433]] ) 434end )