robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- ShaDa merging data support 2local t =require ( 'test.testutil' ) 3local n =require ( 'test.functional.testnvim' )() 4local t_shada =require ( 'test.functional.shada.testutil' ) 5 6local describe , it , before_each , after_each =t . describe , t . it , t . before_each , t . after_each 7local nvim_command , fn , eq =n . command , n . fn , t . eq 8local exec_capture =n . exec_capture 9local api =n . api 10local command =n . command 11 12local reset , clear , get_shada_rw =t_shada . reset , t_shada . clear , t_shada . get_shada_rw 13local read_shada_file =t_shada . read_shada_file 14 15local wshada , sdrcmd , shada_fname =get_shada_rw ( 'Xtest-functional-shada-merging.shada' ) 16 17local mock_file_path ='/a/b/' 18if t . is_os ( 'win' ) then 19mock_file_path ='C:/a/' 20end 21 22describe ( 'ShaDa history merging code' , function () 23before_each ( reset ) 24after_each ( function () 25clear () 26os . remove ( shada_fname ) 27end ) 28 29it ( 'takes item with greater timestamp from Neovim instance when reading' , function () 30wshada ( '\004\001\009\147\000\196\002ab\196\001a' ) 31command ( sdrcmd ()) 32wshada ( '\004\000\009\147\000\196\002ab\196\001b' ) 33command ( sdrcmd ()) 34os . remove ( shada_fname ) 35command ( 'wshada! ' .. shada_fname ) 36local found =0 37for _ , v in ipairs ( read_shada_file ( shada_fname )) do 38if v . type == 4 and v . value [ 1 ] == 0 and v . value [ 2 ] == 'ab' then 39eq ( 1 , v . timestamp ) 40eq ( 'a' , v . value [ 3 ]) 41found =found + 1 42end 43end 44eq ( 1 , found ) 45end ) 46 47it ( 'takes item with equal timestamp from Neovim instance when reading' , function () 48wshada ( '\004\000\009\147\000\196\002ab\196\001a' ) 49command ( sdrcmd ()) 50wshada ( '\004\000\009\147\000\196\002ab\196\001b' ) 51command ( sdrcmd ()) 52os . remove ( shada_fname ) 53command ( 'wshada! ' .. shada_fname ) 54local found =0 55for _ , v in ipairs ( read_shada_file ( shada_fname )) do 56if v . type == 4 and v . value [ 1 ] == 0 and v . value [ 2 ] == 'ab' then 57eq ( 0 , v . timestamp ) 58eq ( 'a' , v . value [ 3 ]) 59found =found + 1 60end 61end 62eq ( 1 , found ) 63end ) 64 65it ( 'takes item with greater timestamp from ShaDa when reading' , function () 66wshada ( '\004\000\009\147\000\196\002ab\196\001a' ) 67command ( sdrcmd ()) 68wshada ( '\004\001\009\147\000\196\002ab\196\001b' ) 69command ( sdrcmd ()) 70os . remove ( shada_fname ) 71command ( 'wshada! ' .. shada_fname ) 72local found =0 73for _ , v in ipairs ( read_shada_file ( shada_fname )) do 74if v . type == 4 and v . value [ 1 ] == 0 and v . value [ 2 ] == 'ab' then 75eq ( 1 , v . timestamp ) 76eq ( 'b' , v . value [ 3 ]) 77found =found + 1 78end 79end 80eq ( 1 , found ) 81end ) 82 83it ( 'takes item with greater timestamp from Neovim instance when writing' , function () 84wshada ( '\004\001\009\147\000\196\002ab\196\001a' ) 85command ( sdrcmd ()) 86wshada ( '\004\000\009\147\000\196\002ab\196\001b' ) 87command ( 'wshada ' .. shada_fname ) 88local found =0 89for _ , v in ipairs ( read_shada_file ( shada_fname )) do 90if v . type == 4 and v . value [ 1 ] == 0 and v . value [ 2 ] == 'ab' then 91eq ( 1 , v . timestamp ) 92eq ( 'a' , v . value [ 3 ]) 93found =found + 1 94end 95end 96eq ( 1 , found ) 97end ) 98 99it ( 'takes item with equal timestamp from Neovim instance when writing' , function () 100wshada ( '\004\000\009\147\000\196\002ab\196\001a' ) 101command ( sdrcmd ()) 102wshada ( '\004\000\009\147\000\196\002ab\196\001b' ) 103command ( 'wshada ' .. shada_fname ) 104local found =0 105for _ , v in ipairs ( read_shada_file ( shada_fname )) do 106if v . type == 4 and v . value [ 1 ] == 0 and v . value [ 2 ] == 'ab' then 107eq ( 0 , v . timestamp ) 108eq ( 'a' , v . value [ 3 ]) 109found =found + 1 110end 111end 112eq ( 1 , found ) 113end ) 114 115it ( 'takes item with greater timestamp from ShaDa when writing' , function () 116wshada ( '\004\000\009\147\000\196\002ab\196\001a' ) 117command ( sdrcmd ()) 118wshada ( '\004\001\009\147\000\196\002ab\196\001b' ) 119command ( 'wshada ' .. shada_fname ) 120local found =0 121for _ , v in ipairs ( read_shada_file ( shada_fname )) do 122if v . type == 4 and v . value [ 1 ] == 0 and v . value [ 2 ] == 'ab' then 123eq ( 1 , v . timestamp ) 124eq ( 'b' , v . value [ 3 ]) 125found =found + 1 126end 127end 128eq ( 1 , found ) 129end ) 130 131it ( 'correctly reads history items with messed up timestamps' , function () 132wshada ( 133'\004\010\009\147\000\196\002ab\196\001a' 134.. '\004\010\009\147\000\196\002ac\196\001a' 135.. '\004\005\009\147\000\196\002ad\196\001a' 136.. '\004\100\009\147\000\196\002ae\196\001a' 137.. '\004\090\009\147\000\196\002af\196\001a' 138) 139command ( sdrcmd ()) 140os . remove ( shada_fname ) 141command ( 'wshada! ' .. shada_fname ) 142local items ={ 'ad' , 'ab' , 'ac' , 'af' , 'ae' } 143for i , v in ipairs ( items ) do 144eq ( v , fn . histget ( ':' , i )) 145end 146local found =0 147for _ , v in ipairs ( read_shada_file ( shada_fname )) do 148if v . type == 4 and v . value [ 1 ] == 0 then 149found =found + 1 150eq ( items [ found ], v . value [ 2 ]) 151eq ( 'a' , v . value [ 3 ]) 152end 153end 154eq ( # items , found ) 155end ) 156 157it ( 'correctly reorders history items with messed up timestamps when writing' , function () 158wshada ( 159'\004\010\009\147\000\196\002ab\196\001a' 160.. '\004\010\009\147\000\196\002ac\196\001a' 161.. '\004\005\009\147\000\196\002ad\196\001a' 162.. '\004\100\009\147\000\196\002ae\196\001a' 163.. '\004\090\009\147\000\196\002af\196\001a' 164) 165command ( 'wshada ' .. shada_fname ) 166local items ={ 'ad' , 'ab' , 'ac' , 'af' , 'ae' } 167local found =0 168for _ , v in ipairs ( read_shada_file ( shada_fname )) do 169if v . type == 4 and v . value [ 1 ] == 0 then 170found =found + 1 171eq ( items [ found ], v . value [ 2 ]) 172eq ( 'a' , v . value [ 3 ]) 173end 174end 175eq ( # items , found ) 176end ) 177 178it ( 'correctly merges history items with duplicate mid entry when writing' , function () 179-- Regression test: ShaDa code used to crash here. 180-- Conditions: 181-- 1. Entry which is duplicate to non-last entry. 182-- 2. At least one more non-duplicate entry. 183wshada ( 184'\004\000\009\147\000\196\002ab\196\001a' 185.. '\004\001\009\147\000\196\002ac\196\001a' 186.. '\004\002\009\147\000\196\002ad\196\001a' 187.. '\004\003\009\147\000\196\002ac\196\001a' 188.. '\004\004\009\147\000\196\002af\196\001a' 189.. '\004\005\009\147\000\196\002ae\196\001a' 190.. '\004\006\009\147\000\196\002ag\196\001a' 191.. '\004\007\009\147\000\196\002ah\196\001a' 192.. '\004\008\009\147\000\196\002ai\196\001a' 193) 194command ( 'wshada ' .. shada_fname ) 195local items ={ 'ab' , 'ad' , 'ac' , 'af' , 'ae' , 'ag' , 'ah' , 'ai' } 196local found =0 197for _ , v in ipairs ( read_shada_file ( shada_fname )) do 198if v . type == 4 and v . value [ 1 ] == 0 then 199found =found + 1 200eq ( items [ found ], v . value [ 2 ]) 201eq ( 'a' , v . value [ 3 ]) 202end 203end 204eq ( # items , found ) 205end ) 206 207it ( 'correctly merges history items with duplicate adj entry when writing' , function () 208wshada ( 209'\004\000\009\147\000\196\002ab\196\001a' 210.. '\004\001\009\147\000\196\002ac\196\001a' 211.. '\004\002\009\147\000\196\002ad\196\001a' 212.. '\004\003\009\147\000\196\002ad\196\001a' 213.. '\004\004\009\147\000\196\002af\196\001a' 214.. '\004\005\009\147\000\196\002ae\196\001a' 215.. '\004\006\009\147\000\196\002ag\196\001a' 216.. '\004\007\009\147\000\196\002ah\196\001a' 217.. '\004\008\009\147\000\196\002ai\196\001a' 218) 219command ( 'wshada ' .. shada_fname ) 220local items ={ 'ab' , 'ac' , 'ad' , 'af' , 'ae' , 'ag' , 'ah' , 'ai' } 221local found =0 222for _ , v in ipairs ( read_shada_file ( shada_fname )) do 223if v . type == 4 and v . value [ 1 ] == 0 then 224found =found + 1 225eq ( items [ found ], v . value [ 2 ]) 226eq ( 'a' , v . value [ 3 ]) 227end 228end 229eq ( # items , found ) 230end ) 231end ) 232 233describe ( 'ShaDa search pattern support code' , function () 234before_each ( reset ) 235after_each ( function () 236clear () 237os . remove ( shada_fname ) 238end ) 239 240it ( 'uses last search pattern with gt timestamp from instance when reading' , function () 241wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 242command ( sdrcmd ()) 243wshada ( '\002\000\011\130\162sX\194\162sp\196\001?' ) 244command ( sdrcmd ()) 245eq ( '-' , fn . getreg ( '/' )) 246end ) 247 248it ( 'uses last search pattern with gt tstamp from file when reading with bang' , function () 249wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 250command ( sdrcmd ()) 251wshada ( '\002\000\011\130\162sX\194\162sp\196\001?' ) 252command ( sdrcmd ( true )) 253eq ( '?' , fn . getreg ( '/' )) 254end ) 255 256it ( 'uses last search pattern with eq timestamp from instance when reading' , function () 257wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 258command ( sdrcmd ()) 259wshada ( '\002\001\011\130\162sX\194\162sp\196\001?' ) 260command ( sdrcmd ()) 261eq ( '-' , fn . getreg ( '/' )) 262end ) 263 264it ( 'uses last search pattern with gt timestamp from file when reading' , function () 265wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 266command ( sdrcmd ()) 267wshada ( '\002\002\011\130\162sX\194\162sp\196\001?' ) 268command ( sdrcmd ()) 269eq ( '?' , fn . getreg ( '/' )) 270end ) 271 272it ( 'uses last search pattern with gt timestamp from instance when writing' , function () 273wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 274command ( sdrcmd ()) 275wshada ( '\002\000\011\130\162sX\194\162sp\196\001?' ) 276eq ( '-' , fn . getreg ( '/' )) 277command ( 'wshada ' .. shada_fname ) 278local found =0 279for _ , v in ipairs ( read_shada_file ( shada_fname )) do 280if v . type == 2 and v . value . sp == '-' then 281found =found + 1 282end 283end 284eq ( 1 , found ) 285end ) 286 287it ( 'uses last search pattern with eq timestamp from instance when writing' , function () 288wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 289command ( sdrcmd ()) 290wshada ( '\002\001\011\130\162sX\194\162sp\196\001?' ) 291eq ( '-' , fn . getreg ( '/' )) 292command ( 'wshada ' .. shada_fname ) 293local found =0 294for _ , v in ipairs ( read_shada_file ( shada_fname )) do 295if v . type == 2 and v . value . sp == '-' then 296found =found + 1 297end 298end 299eq ( 1 , found ) 300end ) 301 302it ( 'uses last search pattern with gt timestamp from file when writing' , function () 303wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 304command ( sdrcmd ()) 305wshada ( '\002\002\011\130\162sX\194\162sp\196\001?' ) 306eq ( '-' , fn . getreg ( '/' )) 307command ( 'wshada ' .. shada_fname ) 308local found =0 309for _ , v in ipairs ( read_shada_file ( shada_fname )) do 310if v . type == 2 and v . value . sp == '?' then 311found =found + 1 312end 313end 314eq ( 1 , found ) 315end ) 316 317it ( 'does not restore a search pattern cleared with :let @/ = ""' , function () 318command ( 'let @/ = "foobar"' ) 319command ( 'wshada ' .. shada_fname ) 320 321reset ( { shadafile =shada_fname } ) 322eq ( 'foobar' , fn . getreg ( '/' )) 323command ( 'let @/ = ""' ) 324command ( 'wshada ' .. shada_fname ) 325 326local found =0 327for _ , v in ipairs ( read_shada_file ( shada_fname )) do 328if v . type == 2 and v . value . sp == 'foobar' then 329found =found + 1 330end 331end 332eq ( 0 , found ) 333 334reset ( { shadafile =shada_fname } ) 335eq ( '' , fn . getreg ( '/' )) 336end ) 337 338it ( 'keeps an on-disk search pattern that the instance never set' , function () 339wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 340command ( 'wshada ' .. shada_fname ) 341local found =0 342for _ , v in ipairs ( read_shada_file ( shada_fname )) do 343if v . type == 2 and v . value . sp == '-' then 344found =found + 1 345end 346end 347eq ( 1 , found ) 348end ) 349 350it ( 'uses last s/ pattern with gt timestamp from instance when reading' , function () 351wshada ( '\002\001\011\130\162ss\195\162sp\196\001-' ) 352command ( sdrcmd ()) 353wshada ( '\002\000\011\130\162ss\195\162sp\196\001?' ) 354command ( sdrcmd ()) 355eq ( '-' , fn . getreg ( '/' )) 356end ) 357 358it ( 'uses last s/ pattern with gt timestamp from file when reading with !' , function () 359wshada ( '\002\001\011\130\162ss\195\162sp\196\001-' ) 360command ( sdrcmd ()) 361wshada ( '\002\000\011\130\162ss\195\162sp\196\001?' ) 362command ( sdrcmd ( true )) 363eq ( '?' , fn . getreg ( '/' )) 364end ) 365 366it ( 'uses last s/ pattern with eq timestamp from instance when reading' , function () 367wshada ( '\002\001\011\130\162ss\195\162sp\196\001-' ) 368command ( sdrcmd ()) 369wshada ( '\002\001\011\130\162ss\195\162sp\196\001?' ) 370command ( sdrcmd ()) 371eq ( '-' , fn . getreg ( '/' )) 372end ) 373 374it ( 'uses last s/ pattern with gt timestamp from file when reading' , function () 375wshada ( '\002\001\011\130\162ss\195\162sp\196\001-' ) 376command ( sdrcmd ()) 377wshada ( '\002\002\011\130\162ss\195\162sp\196\001?' ) 378command ( sdrcmd ()) 379eq ( '?' , fn . getreg ( '/' )) 380end ) 381 382it ( 'uses last s/ pattern with gt timestamp from instance when writing' , function () 383wshada ( '\002\001\011\130\162ss\195\162sp\196\001-' ) 384command ( sdrcmd ()) 385wshada ( '\002\000\011\130\162ss\195\162sp\196\001?' ) 386eq ( '-' , fn . getreg ( '/' )) 387command ( 'wshada ' .. shada_fname ) 388local found =0 389for _ , v in ipairs ( read_shada_file ( shada_fname )) do 390if v . type == 2 and v . value . sp == '-' then 391found =found + 1 392end 393end 394eq ( 1 , found ) 395end ) 396 397it ( 'uses last s/ pattern with eq timestamp from instance when writing' , function () 398wshada ( '\002\001\011\130\162ss\195\162sp\196\001-' ) 399command ( sdrcmd ()) 400wshada ( '\002\001\011\130\162ss\195\162sp\196\001?' ) 401eq ( '-' , fn . getreg ( '/' )) 402command ( 'wshada ' .. shada_fname ) 403local found =0 404for _ , v in ipairs ( read_shada_file ( shada_fname )) do 405if v . type == 2 and v . value . sp == '-' then 406found =found + 1 407end 408end 409eq ( 1 , found ) 410end ) 411 412it ( 'uses last s/ pattern with gt timestamp from file when writing' , function () 413wshada ( '\002\001\011\130\162ss\195\162sp\196\001-' ) 414command ( sdrcmd ()) 415wshada ( '\002\002\011\130\162ss\195\162sp\196\001?' ) 416eq ( '-' , fn . getreg ( '/' )) 417command ( 'wshada ' .. shada_fname ) 418local found =0 419for _ , v in ipairs ( read_shada_file ( shada_fname )) do 420if v . type == 2 and v . value . sp == '?' then 421found =found + 1 422end 423end 424eq ( 1 , found ) 425end ) 426end ) 427 428describe ( 'ShaDa replacement string support code' , function () 429before_each ( reset ) 430after_each ( function () 431clear () 432os . remove ( shada_fname ) 433end ) 434 435it ( 'uses last replacement with gt timestamp from instance when reading' , function () 436wshada ( '\003\001\004\145\196\001-' ) 437command ( sdrcmd ()) 438wshada ( '\003\000\004\145\196\001?' ) 439command ( sdrcmd ()) 440nvim_command ( 's/.*/~' ) 441eq ( '-' , fn . getline ( '.' )) 442nvim_command ( 'bwipeout!' ) 443end ) 444 445it ( 'uses last replacement with gt timestamp from file when reading with bang' , function () 446wshada ( '\003\001\004\145\196\001-' ) 447command ( sdrcmd ()) 448wshada ( '\003\000\004\145\196\001?' ) 449command ( sdrcmd ( true )) 450nvim_command ( 's/.*/~' ) 451eq ( '?' , fn . getline ( '.' )) 452nvim_command ( 'bwipeout!' ) 453end ) 454 455it ( 'uses last replacement with eq timestamp from instance when reading' , function () 456wshada ( '\003\001\004\145\196\001-' ) 457command ( sdrcmd ()) 458wshada ( '\003\001\004\145\196\001?' ) 459command ( sdrcmd ()) 460nvim_command ( 's/.*/~' ) 461eq ( '-' , fn . getline ( '.' )) 462nvim_command ( 'bwipeout!' ) 463end ) 464 465it ( 'uses last replacement with gt timestamp from file when reading' , function () 466wshada ( '\003\001\004\145\196\001-' ) 467command ( sdrcmd ()) 468wshada ( '\003\002\004\145\196\001?' ) 469command ( sdrcmd ()) 470nvim_command ( 's/.*/~' ) 471eq ( '?' , fn . getline ( '.' )) 472nvim_command ( 'bwipeout!' ) 473end ) 474 475it ( 'uses last replacement with gt timestamp from instance when writing' , function () 476wshada ( '\003\001\004\145\196\001-' ) 477command ( sdrcmd ()) 478wshada ( '\003\000\004\145\196\001?' ) 479command ( 'wshada ' .. shada_fname ) 480local found =0 481for _ , v in ipairs ( read_shada_file ( shada_fname )) do 482if v . type == 3 and v . value [ 1 ] == '-' then 483found =found + 1 484end 485end 486eq ( 1 , found ) 487end ) 488 489it ( 'uses last replacement with eq timestamp from instance when writing' , function () 490wshada ( '\003\001\004\145\196\001-' ) 491command ( sdrcmd ()) 492wshada ( '\003\001\004\145\196\001?' ) 493command ( 'wshada ' .. shada_fname ) 494local found =0 495for _ , v in ipairs ( read_shada_file ( shada_fname )) do 496if v . type == 3 and v . value [ 1 ] == '-' then 497found =found + 1 498end 499end 500eq ( 1 , found ) 501end ) 502 503it ( 'uses last replacement with gt timestamp from file when writing' , function () 504wshada ( '\003\001\004\145\196\001-' ) 505command ( sdrcmd ()) 506wshada ( '\003\002\004\145\196\001?' ) 507command ( 'wshada ' .. shada_fname ) 508local found =0 509for _ , v in ipairs ( read_shada_file ( shada_fname )) do 510if v . type == 3 and v . value [ 1 ] == '?' then 511found =found + 1 512end 513end 514eq ( 1 , found ) 515end ) 516end ) 517 518describe ( 'ShaDa marks support code' , function () 519before_each ( reset ) 520after_each ( function () 521clear () 522os . remove ( shada_fname ) 523end ) 524 525it ( 'uses last A mark with gt timestamp from instance when reading' , function () 526wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA' ) 527command ( sdrcmd ()) 528wshada ( '\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA' ) 529command ( sdrcmd ()) 530nvim_command ( 'normal! `A' ) 531eq ( '-' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 532end ) 533 534it ( 'can merge with file with mark 9 as the only numeric mark' , function () 535wshada ( '\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9' ) 536command ( sdrcmd ()) 537nvim_command ( 'normal! `9oabc' ) 538eq ( '-' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 539command ( 'wshada ' .. shada_fname ) 540local found ={} 541for _ , v in ipairs ( read_shada_file ( shada_fname )) do 542if v . type == 7 and v . value . f == mock_file_path .. '-' then 543local name =( '%c' ): format ( v . value . n ) 544found [ name ] =( found [ name ] or 0 ) + 1 545end 546end 547eq ( { [ '0' ] =1 , [ '1' ] =1 } , found ) 548end ) 549 550it ( 'removes duplicates while merging' , function () 551wshada ( 552'\007\001\014\130\161f\196\006' 553.. mock_file_path 554.. '-\161n9' 555.. '\007\001\014\130\161f\196\006' 556.. mock_file_path 557.. '-\161n9' 558) 559command ( sdrcmd ()) 560command ( 'wshada ' .. shada_fname ) 561local found =0 562for _ , v in ipairs ( read_shada_file ( shada_fname )) do 563if v . type == 7 and v . value . f == mock_file_path .. '-' then 564( require ( 'test.format_string' ). format_luav ( v )) 565found =found + 1 566end 567end 568eq ( 1 , found ) 569end ) 570 571it ( 'does not leak when no append is performed due to too many marks' , function () 572wshada ( 573'\007\002\018\131\162mX\195\161f\196\006' 574.. mock_file_path 575.. 'a\161n0' 576.. '\007\002\018\131\162mX\195\161f\196\006' 577.. mock_file_path 578.. 'b\161n1' 579.. '\007\002\018\131\162mX\195\161f\196\006' 580.. mock_file_path 581.. 'c\161n2' 582.. '\007\002\018\131\162mX\195\161f\196\006' 583.. mock_file_path 584.. 'd\161n3' 585.. '\007\002\018\131\162mX\195\161f\196\006' 586.. mock_file_path 587.. 'e\161n4' 588.. '\007\002\018\131\162mX\195\161f\196\006' 589.. mock_file_path 590.. 'f\161n5' 591.. '\007\002\018\131\162mX\195\161f\196\006' 592.. mock_file_path 593.. 'g\161n6' 594.. '\007\002\018\131\162mX\195\161f\196\006' 595.. mock_file_path 596.. 'h\161n7' 597.. '\007\002\018\131\162mX\195\161f\196\006' 598.. mock_file_path 599.. 'i\161n8' 600.. '\007\002\018\131\162mX\195\161f\196\006' 601.. mock_file_path 602.. 'j\161n9' 603.. '\007\001\018\131\162mX\195\161f\196\006' 604.. mock_file_path 605.. 'k\161n9' 606) 607command ( sdrcmd ()) 608command ( 'wshada ' .. shada_fname ) 609local found ={} 610for _ , v in ipairs ( read_shada_file ( shada_fname )) do 611if v . type == 7 and v . value . f : sub ( 1 , # mock_file_path ) == mock_file_path then 612found [ # found + 1 ] =v . value . f : sub ( # v . value . f ) 613end 614end 615eq ( { 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' } , found ) 616end ) 617 618it ( 'does not leak when last mark in file removes some of the earlier ones' , function () 619wshada ( 620'\007\002\018\131\162mX\195\161f\196\006' 621.. mock_file_path 622.. 'a\161n0' 623.. '\007\002\018\131\162mX\195\161f\196\006' 624.. mock_file_path 625.. 'b\161n1' 626.. '\007\002\018\131\162mX\195\161f\196\006' 627.. mock_file_path 628.. 'c\161n2' 629.. '\007\002\018\131\162mX\195\161f\196\006' 630.. mock_file_path 631.. 'd\161n3' 632.. '\007\002\018\131\162mX\195\161f\196\006' 633.. mock_file_path 634.. 'e\161n4' 635.. '\007\002\018\131\162mX\195\161f\196\006' 636.. mock_file_path 637.. 'f\161n5' 638.. '\007\002\018\131\162mX\195\161f\196\006' 639.. mock_file_path 640.. 'g\161n6' 641.. '\007\002\018\131\162mX\195\161f\196\006' 642.. mock_file_path 643.. 'h\161n7' 644.. '\007\002\018\131\162mX\195\161f\196\006' 645.. mock_file_path 646.. 'i\161n8' 647.. '\007\002\018\131\162mX\195\161f\196\006' 648.. mock_file_path 649.. 'j\161n9' 650.. '\007\003\018\131\162mX\195\161f\196\006' 651.. mock_file_path 652.. 'k\161n9' 653) 654command ( sdrcmd ()) 655command ( 'wshada ' .. shada_fname ) 656local found ={} 657for _ , v in ipairs ( read_shada_file ( shada_fname )) do 658if v . type == 7 and v . value . f : sub ( 1 , # mock_file_path ) == mock_file_path then 659found [ # found + 1 ] =v . value . f : sub ( # v . value . f ) 660end 661end 662eq ( { 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'k' } , found ) 663end ) 664 665it ( 'uses last A mark with gt timestamp from file when reading with !' , function () 666wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA' ) 667command ( sdrcmd ()) 668wshada ( '\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA' ) 669command ( sdrcmd ( true )) 670nvim_command ( 'normal! `A' ) 671eq ( '?' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 672end ) 673 674it ( 'uses last A mark with eq timestamp from instance when reading' , function () 675wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA' ) 676command ( sdrcmd ()) 677wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA' ) 678command ( sdrcmd ()) 679nvim_command ( 'normal! `A' ) 680eq ( '-' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 681end ) 682 683it ( 'uses last A mark with gt timestamp from file when reading' , function () 684wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA' ) 685command ( sdrcmd ()) 686wshada ( '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA' ) 687command ( sdrcmd ()) 688nvim_command ( 'normal! `A' ) 689eq ( '?' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 690end ) 691 692it ( 'uses last A mark with gt timestamp from instance when writing' , function () 693wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA' ) 694command ( sdrcmd ()) 695wshada ( '\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA' ) 696nvim_command ( 'normal! `A' ) 697eq ( '-' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 698command ( 'wshada ' .. shada_fname ) 699local found ={} 700for _ , v in ipairs ( read_shada_file ( shada_fname )) do 701if v . type == 7 and v . value . f == mock_file_path .. '-' then 702local name =( '%c' ): format ( v . value . n ) 703found [ name ] =( found [ name ] or 0 ) + 1 704end 705end 706eq ( { [ '0' ] =1 , A =1 } , found ) 707end ) 708 709it ( 'uses last A mark with eq timestamp from instance when writing' , function () 710wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA' ) 711command ( sdrcmd ()) 712wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA' ) 713nvim_command ( 'normal! `A' ) 714eq ( '-' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 715command ( 'wshada ' .. shada_fname ) 716local found ={} 717for _ , v in ipairs ( read_shada_file ( shada_fname )) do 718if v . type == 7 and v . value . f == mock_file_path .. '-' then 719local name =( '%c' ): format ( v . value . n ) 720found [ name ] =( found [ name ] or 0 ) + 1 721end 722end 723eq ( { [ '0' ] =1 , A =1 } , found ) 724end ) 725 726it ( 'uses last A mark with gt timestamp from file when writing' , function () 727wshada ( '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA' ) 728command ( sdrcmd ()) 729wshada ( '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA' ) 730nvim_command ( 'normal! `A' ) 731eq ( '-' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 732command ( 'wshada ' .. shada_fname ) 733local found ={} 734for _ , v in ipairs ( read_shada_file ( shada_fname )) do 735if v . type == 7 then 736local name =( '%c' ): format ( v . value . n ) 737local _t =found [ name ] or {} 738_t [ v . value . f ] =( _t [ v . value . f ] or 0 ) + 1 739found [ name ] =_t 740end 741end 742eq ( { [ '0' ] ={ [ mock_file_path .. '-' ] =1 } , A ={ [ mock_file_path .. '?' ] =1 } } , found ) 743end ) 744 745it ( 'uses last a mark with gt timestamp from instance when reading' , function () 746nvim_command ( 'edit ' .. mock_file_path .. '-' ) 747fn . setline ( 1 , { '-' , '?' } ) 748wshada ( '\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na' ) 749command ( sdrcmd ()) 750wshada ( '\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na' ) 751command ( sdrcmd ()) 752nvim_command ( 'normal! `a' ) 753eq ( '-' , fn . getline ( '.' )) 754end ) 755 756it ( 'uses last a mark with gt timestamp from file when reading with !' , function () 757nvim_command ( 'edit ' .. mock_file_path .. '-' ) 758fn . setline ( 1 , { '-' , '?' } ) 759wshada ( '\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na' ) 760command ( sdrcmd ()) 761wshada ( '\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na' ) 762command ( sdrcmd ( true )) 763nvim_command ( 'normal! `a' ) 764eq ( '?' , fn . getline ( '.' )) 765end ) 766 767it ( 'uses last a mark with eq timestamp from instance when reading' , function () 768nvim_command ( 'edit ' .. mock_file_path .. '-' ) 769fn . setline ( 1 , { '-' , '?' } ) 770wshada ( '\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na' ) 771command ( sdrcmd ()) 772wshada ( '\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na' ) 773command ( sdrcmd ()) 774nvim_command ( 'normal! `a' ) 775eq ( '-' , fn . getline ( '.' )) 776end ) 777 778it ( 'uses last a mark with gt timestamp from file when reading' , function () 779nvim_command ( 'edit ' .. mock_file_path .. '-' ) 780fn . setline ( 1 , { '-' , '?' } ) 781wshada ( '\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na' ) 782command ( sdrcmd ()) 783wshada ( '\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na' ) 784command ( sdrcmd ()) 785nvim_command ( 'normal! `a' ) 786eq ( '?' , fn . getline ( '.' )) 787end ) 788 789it ( 'uses last a mark with gt timestamp from instance when writing' , function () 790nvim_command ( 'edit ' .. mock_file_path .. '-' ) 791fn . setline ( 1 , { '-' , '?' } ) 792wshada ( '\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na' ) 793command ( sdrcmd ()) 794wshada ( '\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na' ) 795nvim_command ( 'normal! `a' ) 796eq ( '-' , fn . getline ( '.' )) 797command ( 'wshada ' .. shada_fname ) 798local found =0 799for _ , v in ipairs ( read_shada_file ( shada_fname )) do 800if 801v . type == 10 802and v . value . f == '' .. mock_file_path .. '-' 803and v . value . n == ( 'a' ): byte () 804then 805eq ( true , v . value . l == 1 or v . value . l == nil ) 806found =found + 1 807end 808end 809eq ( 1 , found ) 810end ) 811 812it ( 'uses last a mark with eq timestamp from instance when writing' , function () 813nvim_command ( 'edit ' .. mock_file_path .. '-' ) 814fn . setline ( 1 , { '-' , '?' } ) 815wshada ( '\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na' ) 816command ( sdrcmd ()) 817wshada ( '\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na' ) 818nvim_command ( 'normal! `a' ) 819eq ( '-' , fn . getline ( '.' )) 820command ( 'wshada ' .. shada_fname ) 821local found =0 822for _ , v in ipairs ( read_shada_file ( shada_fname )) do 823if 824v . type == 10 825and v . value . f == '' .. mock_file_path .. '-' 826and v . value . n == ( 'a' ): byte () 827then 828eq ( true , v . value . l == 1 or v . value . l == nil ) 829found =found + 1 830end 831end 832eq ( 1 , found ) 833end ) 834 835it ( 'uses last a mark with gt timestamp from file when writing' , function () 836nvim_command ( 'edit ' .. mock_file_path .. '-' ) 837fn . setline ( 1 , { '-' , '?' } ) 838wshada ( '\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na' ) 839command ( sdrcmd ()) 840wshada ( '\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na' ) 841nvim_command ( 'normal! `a' ) 842eq ( '-' , fn . fnamemodify ( api . nvim_buf_get_name ( 0 ), ':t' )) 843command ( 'wshada ' .. shada_fname ) 844local found =0 845for _ , v in ipairs ( read_shada_file ( shada_fname )) do 846if 847v . type == 10 848and v . value . f == '' .. mock_file_path .. '-' 849and v . value . n == ( 'a' ): byte () 850then 851eq ( 2 , v . value . l ) 852found =found + 1 853end 854end 855eq ( 1 , found ) 856end ) 857end ) 858 859describe ( 'ShaDa registers support code' , function () 860before_each ( reset ) 861after_each ( function () 862clear () 863os . remove ( shada_fname ) 864end ) 865 866it ( 'uses last a register with gt timestamp from instance when reading' , function () 867wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 868command ( sdrcmd ()) 869wshada ( '\005\000\015\131\161na\162rX\194\162rc\145\196\001?' ) 870command ( sdrcmd ()) 871eq ( '-' , fn . getreg ( 'a' )) 872end ) 873 874it ( 'uses last a register with gt timestamp from file when reading with !' , function () 875wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 876command ( sdrcmd ()) 877wshada ( '\005\000\015\131\161na\162rX\194\162rc\145\196\001?' ) 878command ( sdrcmd ( true )) 879eq ( '?' , fn . getreg ( 'a' )) 880end ) 881 882it ( 'uses last a register with eq timestamp from instance when reading' , function () 883wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 884command ( sdrcmd ()) 885wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001?' ) 886command ( sdrcmd ()) 887eq ( '-' , fn . getreg ( 'a' )) 888end ) 889 890it ( 'uses last a register with gt timestamp from file when reading' , function () 891wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 892command ( sdrcmd ()) 893wshada ( '\005\002\015\131\161na\162rX\194\162rc\145\196\001?' ) 894command ( sdrcmd ()) 895eq ( '?' , fn . getreg ( 'a' )) 896end ) 897 898it ( 'uses last a register with gt timestamp from instance when writing' , function () 899wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 900command ( sdrcmd ()) 901wshada ( '\005\000\015\131\161na\162rX\194\162rc\145\196\001?' ) 902eq ( '-' , fn . getreg ( 'a' )) 903command ( 'wshada ' .. shada_fname ) 904local found =0 905for _ , v in ipairs ( read_shada_file ( shada_fname )) do 906if v . type == 5 and v . value . n == ( 'a' ): byte () then 907eq ( { '-' } , v . value . rc ) 908found =found + 1 909end 910end 911eq ( 1 , found ) 912end ) 913 914it ( 'uses last a register with eq timestamp from instance when writing' , function () 915wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 916command ( sdrcmd ()) 917wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001?' ) 918eq ( '-' , fn . getreg ( 'a' )) 919command ( 'wshada ' .. shada_fname ) 920local found =0 921for _ , v in ipairs ( read_shada_file ( shada_fname )) do 922if v . type == 5 and v . value . n == ( 'a' ): byte () then 923eq ( { '-' } , v . value . rc ) 924found =found + 1 925end 926end 927eq ( 1 , found ) 928end ) 929 930it ( 'uses last a register with gt timestamp from file when writing' , function () 931wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 932command ( sdrcmd ()) 933wshada ( '\005\002\015\131\161na\162rX\194\162rc\145\196\001?' ) 934eq ( '-' , fn . getreg ( 'a' )) 935command ( 'wshada ' .. shada_fname ) 936local found =0 937for _ , v in ipairs ( read_shada_file ( shada_fname )) do 938if v . type == 5 and v . value . n == ( 'a' ): byte () then 939eq ( { '?' } , v . value . rc ) 940found =found + 1 941end 942end 943eq ( 1 , found ) 944end ) 945 946it ( 'does not restore a register cleared with :let @a = ""' , function () 947command ( 'let @a = "hello"' ) 948command ( 'wshada ' .. shada_fname ) 949 950reset ( { shadafile =shada_fname } ) 951eq ( 'hello' , fn . getreg ( 'a' )) 952command ( 'let @a = ""' ) 953command ( 'wshada ' .. shada_fname ) 954 955local found =0 956for _ , v in ipairs ( read_shada_file ( shada_fname )) do 957if v . type == 5 and v . value . n == ( 'a' ): byte () then 958found =found + 1 959end 960end 961eq ( 0 , found ) 962 963reset ( { shadafile =shada_fname } ) 964eq ( '' , fn . getreg ( 'a' )) 965end ) 966 967it ( 'keeps an on-disk register that the instance never set' , function () 968wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 969command ( 'wshada ' .. shada_fname ) 970local found =0 971for _ , v in ipairs ( read_shada_file ( shada_fname )) do 972if v . type == 5 and v . value . n == ( 'a' ): byte () then 973found =found + 1 974end 975end 976eq ( 1 , found ) 977end ) 978end ) 979 980describe ( 'ShaDa jumps support code' , function () 981before_each ( reset ) 982after_each ( function () 983clear () 984os . remove ( shada_fname ) 985end ) 986 987it ( 'merges jumps when reading' , function () 988wshada ( 989'\008\001\018\131\162mX\195\161f\196\006' 990.. mock_file_path 991.. 'c\161l\002' 992.. '\008\004\018\131\162mX\195\161f\196\006' 993.. mock_file_path 994.. 'd\161l\002' 995.. '\008\007\018\131\162mX\195\161f\196\006' 996.. mock_file_path 997.. 'e\161l\002' 998) 999command ( sdrcmd ()) 1000wshada ( 1001'\008\001\018\131\162mX\195\161f\196\006' 1002.. mock_file_path 1003.. 'c\161l\002' 1004.. '\008\004\018\131\162mX\195\161f\196\006' 1005.. mock_file_path 1006.. 'd\161l\003' 1007.. '\008\007\018\131\162mX\195\161f\196\006' 1008.. mock_file_path 1009.. 'f\161l\002' 1010) 1011command ( sdrcmd ()) 1012eq ( '' , api . nvim_buf_get_name ( 0 )) 1013eq ( 1014' jump line col file/text\n' 1015.. ' 5 2 0 ' 1016.. mock_file_path 1017.. 'c\n' 1018.. ' 4 2 0 ' 1019.. mock_file_path 1020.. 'd\n' 1021.. ' 3 3 0 ' 1022.. mock_file_path 1023.. 'd\n' 1024.. ' 2 2 0 ' 1025.. mock_file_path 1026.. 'e\n' 1027.. ' 1 2 0 ' 1028.. mock_file_path 1029.. 'f\n' 1030.. '>' , 1031exec_capture ( 'jumps' ) 1032) 1033end ) 1034 1035it ( 'merges jumps when writing' , function () 1036wshada ( 1037'\008\001\018\131\162mX\195\161f\196\006' 1038.. mock_file_path 1039.. 'c\161l\002' 1040.. '\008\004\018\131\162mX\195\161f\196\006' 1041.. mock_file_path 1042.. 'd\161l\002' 1043.. '\008\007\018\131\162mX\195\161f\196\006' 1044.. mock_file_path 1045.. 'e\161l\002' 1046) 1047command ( sdrcmd ()) 1048wshada ( 1049'\008\001\018\131\162mX\195\161f\196\006' 1050.. mock_file_path 1051.. 'c\161l\002' 1052.. '\008\004\018\131\162mX\195\161f\196\006' 1053.. mock_file_path 1054.. 'd\161l\003' 1055.. '\008\007\018\131\162mX\195\161f\196\006' 1056.. mock_file_path 1057.. 'f\161l\002' 1058) 1059command ( 'wshada ' .. shada_fname ) 1060local jumps ={ 1061{ file ='' .. mock_file_path .. 'c' , line =2 } , 1062{ file ='' .. mock_file_path .. 'd' , line =2 } , 1063{ file ='' .. mock_file_path .. 'd' , line =3 } , 1064{ file ='' .. mock_file_path .. 'e' , line =2 } , 1065{ file ='' .. mock_file_path .. 'f' , line =2 } , 1066} 1067local found =0 1068for _ , v in ipairs ( read_shada_file ( shada_fname )) do 1069if v . type == 8 then 1070found =found + 1 1071eq ( jumps [ found ]. file , v . value . f ) 1072eq ( jumps [ found ]. line , v . value . l ) 1073end 1074end 1075eq ( # jumps , found ) 1076end ) 1077 1078it ( 'merges JUMPLISTSIZE jumps when writing' , function () 1079local jumps ={} 1080local shada ='' 1081for i =1 , 100 do 1082shada =shada 1083.. ( '\008%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c' ): format ( i , i ) 1084jumps [ i ] ={ file ='' .. mock_file_path .. 'c' , line =i } 1085end 1086wshada ( shada ) 1087command ( sdrcmd ()) 1088shada ='' 1089for i =1 , 101 do 1090local _t =i * 2 1091shada =shada 1092.. ( '\008\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c' ): format ( 1093_t , 1094_t 1095) 1096jumps [( _t > # jumps + 1 ) and ( # jumps + 1 ) or _t ] = 1097{ file ='' .. mock_file_path .. 'c' , line =_t } 1098end 1099wshada ( shada ) 1100command ( 'wshada ' .. shada_fname ) 1101local shift =# jumps - 100 1102for i =1 , 100 do 1103jumps [ i ] =jumps [ i + shift ] 1104end 1105local found =0 1106for _ , v in ipairs ( read_shada_file ( shada_fname )) do 1107if v . type == 8 then 1108found =found + 1 1109eq ( jumps [ found ]. file , v . value . f ) 1110eq ( jumps [ found ]. line , v . value . l ) 1111end 1112end 1113eq ( 100 , found ) 1114end ) 1115end ) 1116 1117describe ( 'ShaDa changes support code' , function () 1118before_each ( reset ) 1119after_each ( function () 1120clear () 1121os . remove ( shada_fname ) 1122end ) 1123 1124it ( 'merges changes when reading' , function () 1125nvim_command ( 'edit ' .. mock_file_path .. 'c' ) 1126nvim_command ( 'keepjumps call setline(1, range(7))' ) 1127wshada ( 1128'\011\001\018\131\162mX\195\161f\196\006' 1129.. mock_file_path 1130.. 'c\161l\001' 1131.. '\011\004\018\131\162mX\195\161f\196\006' 1132.. mock_file_path 1133.. 'c\161l\002' 1134.. '\011\007\018\131\162mX\195\161f\196\006' 1135.. mock_file_path 1136.. 'c\161l\003' 1137) 1138command ( sdrcmd ()) 1139wshada ( 1140'\011\001\018\131\162mX\194\161f\196\006' 1141.. mock_file_path 1142.. 'c\161l\001' 1143.. '\011\004\018\131\162mX\195\161f\196\006' 1144.. mock_file_path 1145.. 'c\161l\005' 1146.. '\011\008\018\131\162mX\195\161f\196\006' 1147.. mock_file_path 1148.. 'c\161l\004' 1149) 1150command ( sdrcmd ()) 1151eq ( 1152'change line col text\n' 1153.. ' 5 1 0 0\n' 1154.. ' 4 2 0 1\n' 1155.. ' 3 5 0 4\n' 1156.. ' 2 3 0 2\n' 1157.. ' 1 4 0 3\n' 1158.. '>' , 1159exec_capture ( 'changes' ) 1160) 1161end ) 1162 1163it ( 'merges changes when writing' , function () 1164nvim_command ( 'edit ' .. mock_file_path .. 'c' ) 1165nvim_command ( 'keepjumps call setline(1, range(7))' ) 1166wshada ( 1167'\011\001\018\131\162mX\195\161f\196\006' 1168.. mock_file_path 1169.. 'c\161l\001' 1170.. '\011\004\018\131\162mX\195\161f\196\006' 1171.. mock_file_path 1172.. 'c\161l\002' 1173.. '\011\007\018\131\162mX\195\161f\196\006' 1174.. mock_file_path 1175.. 'c\161l\003' 1176) 1177command ( sdrcmd ()) 1178wshada ( 1179'\011\001\018\131\162mX\194\161f\196\006' 1180.. mock_file_path 1181.. 'c\161l\001' 1182.. '\011\004\018\131\162mX\195\161f\196\006' 1183.. mock_file_path 1184.. 'c\161l\005' 1185.. '\011\008\018\131\162mX\195\161f\196\006' 1186.. mock_file_path 1187.. 'c\161l\004' 1188) 1189command ( 'wshada ' .. shada_fname ) 1190local changes ={ 1191{ line =1 } , 1192{ line =2 } , 1193{ line =5 } , 1194{ line =3 } , 1195{ line =4 } , 1196} 1197local found =0 1198for _ , v in ipairs ( read_shada_file ( shada_fname )) do 1199if v . type == 11 and v . value . f == '' .. mock_file_path .. 'c' then 1200found =found + 1 1201eq ( changes [ found ]. line , v . value . l or 1 ) 1202end 1203end 1204eq ( # changes , found ) 1205end ) 1206 1207it ( 'merges JUMPLISTSIZE changes when writing' , function () 1208nvim_command ( 'edit ' .. mock_file_path .. 'c' ) 1209nvim_command ( 'keepjumps call setline(1, range(202))' ) 1210local changes ={} 1211local shada ='' 1212for i =1 , 100 do 1213shada =shada 1214.. ( '\011%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c' ): format ( i , i ) 1215changes [ i ] ={ line =i } 1216end 1217wshada ( shada ) 1218command ( sdrcmd ()) 1219shada ='' 1220for i =1 , 101 do 1221local _t =i * 2 1222shada =shada 1223.. ( '\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c' ): format ( 1224_t , 1225_t 1226) 1227changes [( _t > # changes + 1 ) and ( # changes + 1 ) or _t ] ={ line =_t } 1228end 1229wshada ( shada ) 1230command ( 'wshada ' .. shada_fname ) 1231local shift =# changes - 100 1232for i =1 , 100 do 1233changes [ i ] =changes [ i + shift ] 1234end 1235local found =0 1236for _ , v in ipairs ( read_shada_file ( shada_fname )) do 1237if v . type == 11 and v . value . f == '' .. mock_file_path .. 'c' then 1238found =found + 1 1239eq ( changes [ found ]. line , v . value . l ) 1240end 1241end 1242eq ( 100 , found ) 1243end ) 1244 1245it ( 'merges JUMPLISTSIZE changes when writing, with new items between old' , function () 1246nvim_command ( 'edit ' .. mock_file_path .. 'c' ) 1247nvim_command ( 'keepjumps call setline(1, range(202))' ) 1248local shada ='' 1249for i =1 , 101 do 1250local _t =i * 2 1251shada =shada 1252.. ( '\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c' ): format ( 1253_t , 1254_t 1255) 1256end 1257wshada ( shada ) 1258command ( sdrcmd ()) 1259shada ='' 1260for i =1 , 100 do 1261shada =shada 1262.. ( '\011%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c' ): format ( i , i ) 1263end 1264local changes ={} 1265for i =1 , 100 do 1266changes [ i ] ={ line =i } 1267end 1268for i =1 , 101 do 1269local _t =i * 2 1270changes [( _t > # changes + 1 ) and ( # changes + 1 ) or _t ] ={ line =_t } 1271end 1272wshada ( shada ) 1273command ( 'wshada ' .. shada_fname ) 1274local shift =# changes - 100 1275for i =1 , 100 do 1276changes [ i ] =changes [ i + shift ] 1277end 1278local found =0 1279for _ , v in ipairs ( read_shada_file ( shada_fname )) do 1280if v . type == 11 and v . value . f == '' .. mock_file_path .. 'c' then 1281found =found + 1 1282eq ( changes [ found ]. line , v . value . l ) 1283end 1284end 1285eq ( 100 , found ) 1286end ) 1287end )