robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- ShaDa compatibility 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 reset , clear , get_shada_rw =t_shada . reset , t_shada . clear , t_shada . get_shada_rw 9local read_shada_file =t_shada . read_shada_file 10 11local wshada , sdrcmd , shada_fname =get_shada_rw ( 'Xtest-functional-shada-compatibility.shada' ) 12 13local mock_file_path ='/a/b/' 14local mock_file_path2 ='/d/e/' 15if t . is_os ( 'win' ) then 16mock_file_path ='C:/a/' 17mock_file_path2 ='C:/d/' 18end 19 20describe ( 'ShaDa forward compatibility support code' , function () 21before_each ( reset ) 22after_each ( function () 23clear () 24os . remove ( shada_fname ) 25end ) 26 27it ( 'works with search pattern item with BOOL unknown (sX) key value' , function () 28wshada ( '\002\001\011\130\162sX\194\162sp\196\001-' ) 29nvim_command ( sdrcmd ()) 30os . remove ( shada_fname ) 31nvim_command ( 'wshada ' .. shada_fname ) 32local found =false 33for _ , v in ipairs ( read_shada_file ( shada_fname )) do 34if v . type == 2 and not v . value . ss then 35eq ( false , v . value . sX ) 36found =true 37end 38end 39eq ( true , found ) 40nvim_command ( sdrcmd ()) 41os . remove ( shada_fname ) 42nvim_command ( 'silent! /---/' ) 43nvim_command ( 'wshada ' .. shada_fname ) 44found =false 45for _ , v in ipairs ( read_shada_file ( shada_fname )) do 46if v . type == 2 and not v . value . ss then 47eq ( nil , v . value . sX ) 48found =true 49end 50end 51eq ( true , found ) 52fn . garbagecollect ( 1 ) 53fn . garbagecollect ( 1 ) 54nvim_command ( 'rshada! ' .. shada_fname ) 55fn . garbagecollect ( 1 ) 56fn . garbagecollect ( 1 ) 57end ) 58 59it ( 'works with s/search pattern item with BOOL unknown (sX) key value' , function () 60wshada ( '\002\001\015\131\162sX\194\162ss\195\162sp\196\001-' ) 61nvim_command ( sdrcmd ()) 62os . remove ( shada_fname ) 63nvim_command ( 'wshada ' .. shada_fname ) 64local found =false 65for _ , v in ipairs ( read_shada_file ( shada_fname )) do 66if v . type == 2 and v . value . ss then 67eq ( false , v . value . sX ) 68found =true 69end 70end 71eq ( true , found ) 72nvim_command ( sdrcmd ()) 73os . remove ( shada_fname ) 74nvim_command ( 'silent! s/--/---/ge' ) 75nvim_command ( 'wshada ' .. shada_fname ) 76found =false 77for _ , v in ipairs ( read_shada_file ( shada_fname )) do 78if v . type == 2 and v . value . ss then 79eq ( nil , v . value . sX ) 80found =true 81end 82end 83eq ( true , found ) 84fn . garbagecollect ( 1 ) 85fn . garbagecollect ( 1 ) 86nvim_command ( 'rshada!' .. shada_fname ) 87fn . garbagecollect ( 1 ) 88fn . garbagecollect ( 1 ) 89end ) 90 91it ( 'works with replacement item with BOOL additional value in list' , function () 92wshada ( '\003\000\005\146\196\001-\194' ) 93nvim_command ( sdrcmd ()) 94os . remove ( shada_fname ) 95nvim_command ( 'wshada ' .. shada_fname ) 96local found =false 97for _ , v in ipairs ( read_shada_file ( shada_fname )) do 98if v . type == 3 then 99eq ( 2 , # v . value ) 100eq ( false , v . value [ 2 ]) 101found =true 102end 103end 104eq ( true , found ) 105nvim_command ( sdrcmd ()) 106os . remove ( shada_fname ) 107nvim_command ( 'silent! s/--/---/ge' ) 108nvim_command ( 'wshada ' .. shada_fname ) 109found =false 110for _ , v in ipairs ( read_shada_file ( shada_fname )) do 111if v . type == 3 then 112eq ( 1 , # v . value ) 113found =true 114end 115end 116eq ( true , found ) 117fn . garbagecollect ( 1 ) 118fn . garbagecollect ( 1 ) 119nvim_command ( 'rshada!' .. shada_fname ) 120fn . garbagecollect ( 1 ) 121fn . garbagecollect ( 1 ) 122end ) 123 124for _ , v in ipairs ( { 125{ 126name ='global mark' , 127mpack ='\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161nA' , 128} , 129{ 130name ='jump' , 131mpack ='\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002' , 132} , 133{ 134name ='local mark' , 135mpack ='\010\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161na' , 136} , 137{ name ='change' , mpack ='\011\001\015\130\162mX\195\161f\196\006' .. mock_file_path .. 'c' } , 138} ) do 139it ( 'works with ' .. v . name .. ' item with BOOL unknown (mX) key value' , function () 140nvim_command ( 'silent noautocmd edit ' .. mock_file_path .. 'c' ) 141eq ( '' .. mock_file_path .. 'c' , fn . bufname ( '%' )) 142fn . setline ( '.' , { '1' , '2' , '3' } ) 143wshada ( v . mpack ) 144nvim_command ( sdrcmd ( true )) 145os . remove ( shada_fname ) 146nvim_command ( 'wshada ' .. shada_fname ) 147local found =false 148for _ , subv in ipairs ( read_shada_file ( shada_fname )) do 149if subv . type == v . mpack : byte () then 150if subv . value . mX == true then 151found =true 152end 153end 154end 155eq ( true , found ) 156nvim_command ( sdrcmd ()) 157nvim_command ( 'bwipeout!' ) 158fn . setpos ( "'A" , { 0 , 1 , 1 , 0 } ) 159os . remove ( shada_fname ) 160nvim_command ( 'wshada ' .. shada_fname ) 161found =false 162for _ , subv in ipairs ( read_shada_file ( shada_fname )) do 163if subv . type == v . mpack : byte () then 164if subv . value . mX == true then 165found =true 166end 167end 168end 169eq ( false , found ) 170fn . garbagecollect ( 1 ) 171fn . garbagecollect ( 1 ) 172nvim_command ( 'rshada!' .. shada_fname ) 173fn . garbagecollect ( 1 ) 174fn . garbagecollect ( 1 ) 175end ) 176 177if v . name == 'global mark' or v . name == 'local mark' then 178it ( 'works with ' .. v . name .. ' item with <C-a> name' , function () 179nvim_command ( 'silent noautocmd edit ' .. mock_file_path .. 'c' ) 180eq ( '' .. mock_file_path .. 'c' , fn . bufname ( '%' )) 181fn . setline ( '.' , { '1' , '2' , '3' } ) 182wshada ( 183v . mpack : gsub ( 'n.$' , 'n\001' ) 184.. v . mpack : gsub ( 'n.$' , 'n\002' ) 185.. v . mpack 186: gsub ( 'n.$' , 'n\003' ) 187: gsub ( '' .. mock_file_path .. 'c' , '' .. mock_file_path2 .. 'f' ) 188) 189nvim_command ( sdrcmd ( true )) 190nvim_command ( 'wshada ' .. shada_fname ) 191local found =0 192for i , subv in ipairs ( read_shada_file ( shada_fname )) do 193if i == 1 then 194eq ( 1 , subv . type ) 195end 196if subv . type == v . mpack : byte () then 197if subv . value . mX == true and subv . value . n <= 3 then 198found =found + 1 199end 200end 201end 202eq ( 3 , found ) 203nvim_command ( 'wshada! ' .. shada_fname ) 204found =0 205for i , subv in ipairs ( read_shada_file ( shada_fname )) do 206if i == 1 then 207eq ( 1 , subv . type ) 208end 209if subv . type == v . mpack : byte () then 210if subv . value . mX == true and subv . value . n <= 3 then 211found =found + 1 212end 213end 214end 215eq ( 0 , found ) 216fn . garbagecollect ( 1 ) 217fn . garbagecollect ( 1 ) 218nvim_command ( 'rshada!' .. shada_fname ) 219fn . garbagecollect ( 1 ) 220fn . garbagecollect ( 1 ) 221end ) 222end 223end 224 225it ( 'works with register item with BOOL unknown (rX) key' , function () 226wshada ( '\005\001\015\131\161na\162rX\194\162rc\145\196\001-' ) 227nvim_command ( sdrcmd ()) 228os . remove ( shada_fname ) 229nvim_command ( 'wshada ' .. shada_fname ) 230local found =false 231for _ , v in ipairs ( read_shada_file ( shada_fname )) do 232if v . type == 5 and v . value . rX == false then 233found =true 234end 235end 236eq ( true , found ) 237nvim_command ( sdrcmd ()) 238os . remove ( shada_fname ) 239nvim_command ( 'let @a = "Test"' ) 240nvim_command ( 'wshada ' .. shada_fname ) 241found =false 242for _ , v in ipairs ( read_shada_file ( shada_fname )) do 243if v . type == 5 and v . value . rX == false then 244found =true 245end 246end 247eq ( false , found ) 248fn . garbagecollect ( 1 ) 249fn . garbagecollect ( 1 ) 250nvim_command ( 'rshada!' .. shada_fname ) 251fn . garbagecollect ( 1 ) 252fn . garbagecollect ( 1 ) 253end ) 254 255it ( 'works with register item with <C-a> name' , function () 256wshada ( '\005\001\015\131\161n\001\162rX\194\162rc\145\196\001-' ) 257nvim_command ( sdrcmd ( true )) 258nvim_command ( 'wshada ' .. shada_fname ) 259local found =0 260for i , v in ipairs ( read_shada_file ( shada_fname )) do 261if i == 1 then 262eq ( 1 , v . type ) 263end 264if v . type == 5 then 265if v . value . rX == false and v . value . n == 1 then 266found =found + 1 267end 268end 269end 270eq ( 1 , found ) 271nvim_command ( 'wshada! ' .. shada_fname ) 272found =0 273for i , v in ipairs ( read_shada_file ( shada_fname )) do 274if i == 1 then 275eq ( 1 , v . type ) 276end 277if v . type == 5 then 278if v . value . rX == false and v . value . n == 1 then 279found =found + 1 280end 281end 282end 283eq ( 0 , found ) 284fn . garbagecollect ( 1 ) 285fn . garbagecollect ( 1 ) 286nvim_command ( 'rshada!' .. shada_fname ) 287fn . garbagecollect ( 1 ) 288fn . garbagecollect ( 1 ) 289end ) 290 291it ( 'works with register item with type 10' , function () 292wshada ( '\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010' ) 293nvim_command ( sdrcmd ( true )) 294eq ( {} , fn . getreg ( 'a' , 1 , 1 )) 295eq ( '' , fn . getregtype ( 'a' )) 296nvim_command ( 'wshada ' .. shada_fname ) 297local found =0 298for i , v in ipairs ( read_shada_file ( shada_fname )) do 299if i == 1 then 300eq ( 1 , v . type ) 301end 302if v . type == 5 then 303if v . value . rX == false and v . value . rt == 10 then 304found =found + 1 305end 306end 307end 308eq ( 1 , found ) 309nvim_command ( 'wshada! ' .. shada_fname ) 310found =0 311for i , v in ipairs ( read_shada_file ( shada_fname )) do 312if i == 1 then 313eq ( 1 , v . type ) 314end 315if v . type == 5 then 316if v . value . rX == false and v . value . rt == 10 then 317found =found + 1 318end 319end 320end 321eq ( 0 , found ) 322fn . garbagecollect ( 1 ) 323fn . garbagecollect ( 1 ) 324nvim_command ( 'rshada!' .. shada_fname ) 325fn . garbagecollect ( 1 ) 326fn . garbagecollect ( 1 ) 327end ) 328 329it ( 'works with buffer list item with BOOL unknown (bX) key' , function () 330nvim_command ( 'set shada+=%' ) 331wshada ( '\009\000\016\145\130\161f\196\006' .. mock_file_path .. 'c\162bX\195' ) 332nvim_command ( sdrcmd ()) 333eq ( 2 , fn . bufnr ( '$' )) 334eq ( '' .. mock_file_path .. 'c' , fn . bufname ( 2 )) 335os . remove ( shada_fname ) 336nvim_command ( 'wshada ' .. shada_fname ) 337local found =false 338for _ , v in ipairs ( read_shada_file ( shada_fname )) do 339if v . type == 9 and # v . value == 1 and v . value [ 1 ]. bX == true then 340found =true 341end 342end 343eq ( true , found ) 344nvim_command ( sdrcmd ()) 345os . remove ( shada_fname ) 346nvim_command ( 'buffer 2' ) 347nvim_command ( 'edit!' ) 348nvim_command ( 'wshada ' .. shada_fname ) 349found =false 350for _ , v in ipairs ( read_shada_file ( shada_fname )) do 351if v . type == 5 and v . value . rX == false then 352found =true 353end 354end 355eq ( false , found ) 356nvim_command ( 'bwipeout!' ) 357fn . garbagecollect ( 1 ) 358fn . garbagecollect ( 1 ) 359nvim_command ( 'rshada!' .. shada_fname ) 360fn . garbagecollect ( 1 ) 361fn . garbagecollect ( 1 ) 362end ) 363 364it ( 'works with history item with BOOL additional value in list' , function () 365wshada ( '\004\000\006\147\000\196\001-\194' ) 366nvim_command ( sdrcmd ()) 367os . remove ( shada_fname ) 368nvim_command ( 'wshada ' .. shada_fname ) 369local found =false 370for _ , v in ipairs ( read_shada_file ( shada_fname )) do 371if v . type == 4 and v . value [ 1 ] == 0 and v . value [ 2 ] == '-' then 372eq ( false , v . value [ 3 ]) 373eq ( 3 , # v . value ) 374found =true 375end 376end 377eq ( true , found ) 378nvim_command ( sdrcmd ()) 379os . remove ( shada_fname ) 380fn . histadd ( ':' , '--' ) 381fn . histadd ( ':' , '-' ) 382nvim_command ( 'wshada ' .. shada_fname ) 383found =false 384for _ , v in ipairs ( read_shada_file ( shada_fname )) do 385if v . type == 4 and v . value [ 1 ] == 0 and v . value [ 2 ] == '-' then 386eq ( 2 , # v . value ) 387found =true 388end 389end 390eq ( true , found ) 391fn . garbagecollect ( 1 ) 392fn . garbagecollect ( 1 ) 393nvim_command ( 'rshada!' .. shada_fname ) 394fn . garbagecollect ( 1 ) 395fn . garbagecollect ( 1 ) 396end ) 397 398it ( 'works with history item with type 10' , function () 399wshada ( '\004\000\006\147\010\196\001-\194' ) 400nvim_command ( sdrcmd ()) 401nvim_command ( 'wshada ' .. shada_fname ) 402nvim_command ( sdrcmd ()) 403local found =0 404for i , v in ipairs ( read_shada_file ( shada_fname )) do 405if i == 1 then 406eq ( 1 , v . type ) 407end 408if v . type == 4 then 409if v . value [ 1 ] == 10 and # v . value == 3 and v . value [ 3 ] == false then 410found =found + 1 411end 412end 413end 414eq ( 1 , found ) 415nvim_command ( 'wshada! ' .. shada_fname ) 416found =0 417for i , v in ipairs ( read_shada_file ( shada_fname )) do 418if i == 1 then 419eq ( 1 , v . type ) 420end 421if v . type == 4 then 422if v . value [ 1 ] == 10 and # v . value == 3 and v . value [ 3 ] == false then 423found =found + 1 424end 425end 426end 427eq ( 0 , found ) 428fn . garbagecollect ( 1 ) 429fn . garbagecollect ( 1 ) 430nvim_command ( 'rshada!' .. shada_fname ) 431fn . garbagecollect ( 1 ) 432fn . garbagecollect ( 1 ) 433end ) 434 435it ( 'works with item with 100 type' , function () 436wshada ( '\100\000\006\147\010\196\001-\194' ) 437nvim_command ( sdrcmd ()) 438nvim_command ( 'wshada ' .. shada_fname ) 439nvim_command ( sdrcmd ()) 440local found =0 441for i , v in ipairs ( read_shada_file ( shada_fname )) do 442if i == 1 then 443eq ( 1 , v . type ) 444end 445if v . type == 100 then 446if v . value [ 1 ] == 10 and # v . value == 3 and v . value [ 3 ] == false then 447found =found + 1 448end 449end 450end 451eq ( 1 , found ) 452nvim_command ( 'wshada! ' .. shada_fname ) 453found =0 454for i , v in ipairs ( read_shada_file ( shada_fname )) do 455if i == 1 then 456eq ( 1 , v . type ) 457end 458if v . type == 100 then 459if v . value [ 1 ] == 10 and # v . value == 3 and v . value [ 3 ] == false then 460found =found + 1 461end 462end 463end 464eq ( 0 , found ) 465fn . garbagecollect ( 1 ) 466fn . garbagecollect ( 1 ) 467nvim_command ( 'rshada!' .. shada_fname ) 468fn . garbagecollect ( 1 ) 469fn . garbagecollect ( 1 ) 470end ) 471end )