neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

compatibility_spec.lua (13954B)


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