-- ShaDa marks saving/reading support local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq local shada_helpers = require('test.functional.shada.helpers') local reset, set_additional_cmd, clear, exc_exec = shada_helpers.reset, shada_helpers.set_additional_cmd, shada_helpers.clear, shada_helpers.exc_exec local nvim_current_line = function() return nvim_window('get_cursor', nvim_curwin())[1] end describe('ShaDa support code', function() testfilename = 'Xtestfile-functional-shada-marks' testfilename_2 = 'Xtestfile-functional-shada-marks-2' before_each(function() reset() local fd = io.open(testfilename, 'w') fd:write('test\n') fd:write('test2\n') fd:close() local fd = io.open(testfilename_2, 'w') fd:write('test3\n') fd:write('test4\n') fd:close() end) after_each(function() clear() os.remove(testfilename) os.remove(testfilename_2) end) it('is able to dump and read back global mark', function() nvim_command('edit ' .. testfilename) nvim_command('mark A') nvim_command('2') nvim_command('kB') nvim_command('wshada') reset() nvim_command('rshada') nvim_command('normal! `A') eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) eq(1, nvim_current_line()) nvim_command('normal! `B') eq(2, nvim_current_line()) end) it('does not dump global mark with `f0` in shada', function() nvim_command('set shada+=f0') nvim_command('edit ' .. testfilename) nvim_command('mark A') nvim_command('2') nvim_command('kB') nvim_command('wshada') reset() nvim_command('language C') eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A')) end) it('does read back global mark even with `\'0` and `f0` in shada', function() nvim_command('edit ' .. testfilename) nvim_command('mark A') nvim_command('2') nvim_command('kB') nvim_command('wshada') set_additional_cmd('set shada=\'0,f0') reset() nvim_command('language C') nvim_command('normal! `A') eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) eq(1, nvim_current_line()) end) it('is able to dump and read back local mark', function() nvim_command('edit ' .. testfilename) nvim_command('mark a') nvim_command('2') nvim_command('kb') nvim_command('qall') reset() nvim_command('edit ' .. testfilename) nvim_command('normal! `a') eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) eq(1, nvim_current_line()) nvim_command('normal! `b') eq(2, nvim_current_line()) end) it('is able to populate v:oldfiles', function() nvim_command('edit ' .. testfilename) local tf_full = nvim_eval('fnamemodify(bufname("%"), ":p")') nvim_command('edit ' .. testfilename_2) local tf_full_2 = nvim_eval('fnamemodify(bufname("%"), ":p")') nvim_command('qall') reset() local oldfiles = nvim('get_vvar', 'oldfiles') eq(2, #oldfiles) eq(testfilename, oldfiles[1]:sub(-#testfilename)) eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2)) eq(tf_full, oldfiles[1]) eq(tf_full_2, oldfiles[2]) end) it('is able to dump and restore jump list', function() nvim_command('edit ' .. testfilename_2) nvim_feed('G') nvim_feed('gg') nvim_command('edit ' .. testfilename) nvim_feed('G') nvim_feed('gg') -- nvim_command('redir! >/tmp/jumps.last | jumps | redir END') -- nvim_command('wshada /tmp/foo') nvim_command('qall') reset() nvim_command('redraw') -- nvim_command('redir! >/tmp/jumps.init | jumps | redir END') nvim_command('edit ' .. testfilename) -- nvim_command('redir! >/tmp/jumps | jumps | redir END') eq(testfilename, nvim_eval('bufname("%")')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') eq(testfilename, nvim_eval('bufname("%")')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') eq(testfilename, nvim_eval('bufname("%")')) eq(2, nvim_current_line()) nvim_command('execute "normal! \\"') eq(testfilename_2, nvim_eval('bufname("%")')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') eq(testfilename_2, nvim_eval('bufname("%")')) eq(2, nvim_current_line()) end) it('is able to dump and restore jump list with different times (slow!)', function() nvim_command('edit ' .. testfilename_2) nvim_command('sleep 2') nvim_feed('G') nvim_command('sleep 2') nvim_feed('gg') nvim_command('sleep 2') nvim_command('edit ' .. testfilename) nvim_command('sleep 2') nvim_feed('G') nvim_command('sleep 2') nvim_feed('gg') -- nvim_command('redir! >/tmp/jumps.last | jumps | redir END') -- nvim_command('wshada /tmp/foo') nvim_command('qall') reset() nvim_command('redraw') -- nvim_command('redir! >/tmp/jumps.init | jumps | redir END') nvim_command('edit ' .. testfilename) -- nvim_command('redir! >/tmp/jumps | jumps | redir END') eq(testfilename, nvim_eval('bufname("%")')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') eq(testfilename, nvim_eval('bufname("%")')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') eq(testfilename, nvim_eval('bufname("%")')) eq(2, nvim_current_line()) nvim_command('execute "normal! \\"') eq(testfilename_2, nvim_eval('bufname("%")')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') eq(testfilename_2, nvim_eval('bufname("%")')) eq(2, nvim_current_line()) end) it('is able to dump and restore change list', function() nvim_command('edit ' .. testfilename) nvim_feed('Gra') nvim_feed('ggrb') nvim_command('qall!') reset() nvim_command('edit ' .. testfilename) -- nvim_command('rshada') -- nvim_command('redir! >/tmp/changes | changes | redir END') nvim_feed('Gg;') -- Note: without “sync” “commands” test has good changes to fail for unknown -- reason (in first eq expected 1 is compared with 2). Any command inserted -- causes this to work properly. nvim_command('" sync') eq(1, nvim_current_line()) nvim_feed('g;') nvim_command('" sync 2') eq(2, nvim_current_line()) end) end)