robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local describe , it , before_each =t . describe , t . it , t . before_each 4local clear =n . clear 5local Screen =require ( 'test.functional.ui.screen' ) 6 7before_each ( clear ) 8 9describe ( 'Scrollbind' , function () 10local screen --- @type test.functional.ui.screen 11 12before_each ( function () 13screen =Screen . new ( 40 , 12 ) 14end ) 15 16it ( 'works with one buffer with virtual lines' , function () 17n . exec_lua ( function () 18local lines ={} --- @type string[] 19 20for i =1 , 20 do 21lines [ i ] =tostring ( i * 2 - 1 ) 22end 23 24local ns =vim . api . nvim_create_namespace ( 'test' ) 25 26vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , lines ) 27vim . bo . buftype ='nofile' 28 29for i in ipairs ( lines ) do 30vim . api . nvim_buf_set_extmark ( 0 , ns , i - 1 , 0 , { 31virt_lines ={ { { tostring ( 2 * i ) .. ' v' } } } , 32} ) 33end 34 35vim . wo . scrollbind =true 36vim . cmd . vsplit () 37vim . wo . scrollbind =true 38end ) 39 40n . feed ( '<C-d>' ) 41 42t . eq ( 5 , n . api . nvim_get_option_value ( 'scroll' , {} )) 43 44screen : expect ( { 45grid =[[ 466 v │6 v | 477 │7 | 488 v │8 v | 499 │9 | 5010 v │10 v | 51^11 │11 | 5212 v │12 v | 5313 │13 | 5414 v │14 v | 5515 │15 | 56{3:[Scratch] }{2:[Scratch] }| 57| 58]] , 59} ) 60 61n . feed ( '<C-u>' ) 62 63local line1_grid =[[ 64^1 │1 | 652 v │2 v | 663 │3 | 674 v │4 v | 685 │5 | 696 v │6 v | 707 │7 | 718 v │8 v | 729 │9 | 7310 v │10 v | 74{3:[Scratch] }{2:[Scratch] }| 75| 76]] 77 78screen : expect ( { grid =line1_grid } ) 79 80n . api . nvim_set_option_value ( 'scroll' , 6 , {} ) 81 82n . feed ( '<C-d>' ) 83 84screen : expect ( { 85grid =[[ 867 │7 | 878 v │8 v | 889 │9 | 8910 v │10 v | 9011 │11 | 9112 v │12 v | 92^13 │13 | 9314 v │14 v | 9415 │15 | 9516 v │16 v | 96{3:[Scratch] }{2:[Scratch] }| 97| 98]] , 99} ) 100 101n . feed ( '<C-u>' ) 102 103screen : expect ( { grid =line1_grid } ) 104end ) 105 106it ( 'works with two buffers with virtual lines on one side' , function () 107n . exec_lua ( function () 108local lines ={} --- @type string[] 109 110for i =1 , 20 do 111lines [ i ] =tostring ( i ) 112end 113 114local ns =vim . api . nvim_create_namespace ( 'test' ) 115 116vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , lines ) 117vim . bo . buftype ='nofile' 118 119vim . wo . scrollbind =true 120vim . cmd . vnew () 121 122lines ={} --- @type string[] 123 124for i =1 , 20 do 125lines [ i ] =tostring ( i + ( i > 3 and 4 or 0 )) 126end 127vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , lines ) 128vim . bo . buftype ='nofile' 129 130vim . api . nvim_buf_set_extmark ( 0 , ns , 2 , 0 , { 131virt_lines ={ 132{ { '4 v' } } , 133{ { '5 v' } } , 134{ { '6 v' } } , 135{ { '7 v' } } , 136} , 137} ) 138 139vim . wo . scrollbind =true 140end ) 141 142n . feed ( '<C-d>' ) 143 144t . eq ( 5 , n . api . nvim_get_option_value ( 'scroll' , {} )) 145 146screen : expect ( { 147grid =[[ 1486 v │6 | 1497 v │7 | 1508 │8 | 1519 │9 | 152^10 │10 | 15311 │11 | 15412 │12 | 15513 │13 | 15614 │14 | 15715 │15 | 158{3:[Scratch] }{2:[Scratch] }| 159| 160]] , 161} ) 162 163n . feed ( '<C-u>' ) 164 165local line1_grid =[[ 166^1 │1 | 1672 │2 | 1683 │3 | 1694 v │4 | 1705 v │5 | 1716 v │6 | 1727 v │7 | 1738 │8 | 1749 │9 | 17510 │10 | 176{3:[Scratch] }{2:[Scratch] }| 177| 178]] 179 180screen : expect ( { grid =line1_grid } ) 181 182n . api . nvim_set_option_value ( 'scroll' , 6 , {} ) 183 184n . feed ( '<C-d>' ) 185 186screen : expect ( { 187grid =[[ 1887 v │7 | 1898 │8 | 1909 │9 | 19110 │10 | 192^11 │11 | 19312 │12 | 19413 │13 | 19514 │14 | 19615 │15 | 19716 │16 | 198{3:[Scratch] }{2:[Scratch] }| 199| 200]] , 201} ) 202 203n . feed ( '<C-u>' ) 204 205screen : expect ( { grid =line1_grid } ) 206 207-- Note: not the same as n.feed('4<C-e>') 208n . feed ( '<C-e>' ) 209n . feed ( '<C-e>' ) 210n . feed ( '<C-e>' ) 211n . feed ( '<C-e>' ) 212 213screen : expect ( { 214grid =[[ 2155 v │5 | 2166 v │6 | 2177 v │7 | 218^8 │8 | 2199 │9 | 22010 │10 | 22111 │11 | 22212 │12 | 22313 │13 | 22414 │14 | 225{3:[Scratch] }{2:[Scratch] }| 226| 227]] , 228} ) 229 230n . feed ( '<C-e>' ) 231 232screen : expect ( { 233grid =[[ 2346 v │6 | 2357 v │7 | 236^8 │8 | 2379 │9 | 23810 │10 | 23911 │11 | 24012 │12 | 24113 │13 | 24214 │14 | 24315 │15 | 244{3:[Scratch] }{2:[Scratch] }| 245| 246]] , 247} ) 248 249n . feed ( '<C-y>' ) 250n . feed ( '<C-y>' ) 251 252screen : expect ( { 253grid =[[ 2544 v │4 | 2555 v │5 | 2566 v │6 | 2577 v │7 | 258^8 │8 | 2599 │9 | 26010 │10 | 26111 │11 | 26212 │12 | 26313 │13 | 264{3:[Scratch] }{2:[Scratch] }| 265| 266]] , 267} ) 268end ) 269 270it ( 'works with buffers of different lengths' , function () 271n . exec_lua ( function () 272vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , { '1' , '2' , '3' } ) 273vim . bo . buftype ='nofile' 274 275vim . wo . scrollbind =true 276vim . cmd . vnew () 277 278local lines ={} --- @type string[] 279 280for i =1 , 50 do 281lines [ i ] =tostring ( i ) 282end 283 284vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , lines ) 285vim . bo . buftype ='nofile' 286vim . wo . scrollbind =true 287end ) 288 289n . feed ( '10<C-e>' ) 290 291screen : expect ( { 292grid =[[ 293^11 │3 | 29412 │{1:~ }| 29513 │{1:~ }| 29614 │{1:~ }| 29715 │{1:~ }| 29816 │{1:~ }| 29917 │{1:~ }| 30018 │{1:~ }| 30119 │{1:~ }| 30220 │{1:~ }| 303{3:[Scratch] }{2:[Scratch] }| 304| 305]] , 306} ) 307 308n . feed ( '<C-y>' ) 309 310screen : expect ( { 311grid =[[ 31210 │3 | 313^11 │{1:~ }| 31412 │{1:~ }| 31513 │{1:~ }| 31614 │{1:~ }| 31715 │{1:~ }| 31816 │{1:~ }| 31917 │{1:~ }| 32018 │{1:~ }| 32119 │{1:~ }| 322{3:[Scratch] }{2:[Scratch] }| 323| 324]] , 325} ) 326end ) 327 328it ( 'works with buffers of different lengths and virtual lines' , function () 329n . exec_lua ( function () 330vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , { '1' , '5' , '6' } ) 331 332local ns =vim . api . nvim_create_namespace ( 'test' ) 333vim . api . nvim_buf_set_extmark ( 0 , ns , 0 , 0 , { 334virt_lines ={ 335{ { '2 v' } } , 336{ { '3 v' } } , 337{ { '4 v' } } , 338} , 339} ) 340 341vim . bo . buftype ='nofile' 342 343vim . wo . scrollbind =true 344vim . cmd . vnew () 345 346local lines ={} --- @type string[] 347 348for i =1 , 50 do 349lines [ i ] =tostring ( i ) 350end 351 352vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , false , lines ) 353vim . bo . buftype ='nofile' 354vim . wo . scrollbind =true 355end ) 356 357n . feed ( '<C-e>' ) 358n . feed ( '<C-e>' ) 359screen : expect ( { 360grid =[[ 361^3 │3 v | 3624 │4 v | 3635 │5 | 3646 │6 | 3657 │{1:~ }| 3668 │{1:~ }| 3679 │{1:~ }| 36810 │{1:~ }| 36911 │{1:~ }| 37012 │{1:~ }| 371{3:[Scratch] }{2:[Scratch] }| 372| 373]] , 374} ) 375 376n . feed ( '8<C-e>' ) 377 378screen : expect ( { 379grid =[[ 380^11 │6 | 38112 │{1:~ }| 38213 │{1:~ }| 38314 │{1:~ }| 38415 │{1:~ }| 38516 │{1:~ }| 38617 │{1:~ }| 38718 │{1:~ }| 38819 │{1:~ }| 38920 │{1:~ }| 390{3:[Scratch] }{2:[Scratch] }| 391| 392]] , 393} ) 394 395n . feed ( '<C-y>' ) 396n . feed ( '<C-y>' ) 397n . feed ( '<C-y>' ) 398n . feed ( '<C-y>' ) 399n . feed ( '<C-y>' ) 400 401t . eq ( 6 , n . exec_lua [[return vim.fn.line('w0', 1001)]] ) 402t . eq ( 3 , n . exec_lua [[return vim.fn.line('w0', 1000)]] ) 403 404screen : expect ( { 405grid =[[ 4066 │6 | 4077 │{1:~ }| 4088 │{1:~ }| 4099 │{1:~ }| 41010 │{1:~ }| 411^11 │{1:~ }| 41212 │{1:~ }| 41313 │{1:~ }| 41414 │{1:~ }| 41515 │{1:~ }| 416{3:[Scratch] }{2:[Scratch] }| 417| 418]] , 419} ) 420 421n . feed ( '<C-y>' ) 422n . feed ( '<C-y>' ) 423n . feed ( '<C-y>' ) 424 425screen : expect ( { 426grid =[[ 4273 │3 v | 4284 │4 v | 4295 │5 | 4306 │6 | 4317 │{1:~ }| 4328 │{1:~ }| 4339 │{1:~ }| 43410 │{1:~ }| 435^11 │{1:~ }| 43612 │{1:~ }| 437{3:[Scratch] }{2:[Scratch] }| 438| 439]] , 440} ) 441end ) 442end )