2015-07-11 17:29:31 -07:00
|
|
|
-- ShaDa marks saving/reading support
|
2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-09-26 16:49:48 -07:00
|
|
|
local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq =
|
|
|
|
helpers.meths, helpers.curwinmeths, helpers.curbufmeths, helpers.command,
|
|
|
|
helpers.funcs, helpers.eq
|
2023-08-30 19:15:49 -07:00
|
|
|
local feed = helpers.feed
|
2021-09-19 02:29:37 -07:00
|
|
|
local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture
|
2022-06-08 14:22:50 -07:00
|
|
|
local expect_exit = helpers.expect_exit
|
2015-07-11 17:29:31 -07:00
|
|
|
|
|
|
|
local shada_helpers = require('test.functional.shada.helpers')
|
2019-08-09 01:23:57 -07:00
|
|
|
local reset, clear = shada_helpers.reset, shada_helpers.clear
|
2015-07-11 17:29:31 -07:00
|
|
|
|
|
|
|
local nvim_current_line = function()
|
2015-09-26 16:49:48 -07:00
|
|
|
return curwinmeths.get_cursor()[1]
|
2015-07-11 17:29:31 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe('ShaDa support code', function()
|
2015-11-17 14:44:00 -07:00
|
|
|
local testfilename = 'Xtestfile-functional-shada-marks'
|
|
|
|
local testfilename_2 = 'Xtestfile-functional-shada-marks-2'
|
2017-12-23 14:29:38 -07:00
|
|
|
local non_existent_testfilename = testfilename .. '.nonexistent'
|
2015-07-11 17:29:31 -07:00
|
|
|
before_each(function()
|
|
|
|
reset()
|
2017-12-23 14:29:38 -07:00
|
|
|
os.remove(non_existent_testfilename)
|
2015-07-11 17:29:31 -07:00
|
|
|
local fd = io.open(testfilename, 'w')
|
|
|
|
fd:write('test\n')
|
|
|
|
fd:write('test2\n')
|
|
|
|
fd:close()
|
2015-11-17 14:44:00 -07:00
|
|
|
fd = io.open(testfilename_2, 'w')
|
2015-06-27 22:06:16 -07:00
|
|
|
fd:write('test3\n')
|
|
|
|
fd:write('test4\n')
|
|
|
|
fd:close()
|
2015-07-11 17:29:31 -07:00
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
clear()
|
|
|
|
os.remove(testfilename)
|
2015-06-27 22:06:16 -07:00
|
|
|
os.remove(testfilename_2)
|
2015-07-11 17:29:31 -07:00
|
|
|
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')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-07-11 17:29:31 -07:00
|
|
|
reset()
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('rshada')
|
2015-07-11 17:29:31 -07:00
|
|
|
nvim_command('normal! `A')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t'))
|
2015-07-11 17:29:31 -07:00
|
|
|
eq(1, nvim_current_line())
|
|
|
|
nvim_command('normal! `B')
|
|
|
|
eq(2, nvim_current_line())
|
|
|
|
end)
|
|
|
|
|
2015-07-05 16:26:44 -07:00
|
|
|
it('does not dump global mark with `f0` in shada', function()
|
|
|
|
nvim_command('set shada+=f0')
|
2015-07-11 17:29:31 -07:00
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('mark A')
|
|
|
|
nvim_command('2')
|
|
|
|
nvim_command('kB')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2015-07-11 17:29:31 -07:00
|
|
|
reset()
|
|
|
|
nvim_command('language C')
|
2015-07-25 15:52:50 -07:00
|
|
|
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A'))
|
2015-07-11 17:29:31 -07:00
|
|
|
end)
|
|
|
|
|
2015-07-05 16:26:44 -07:00
|
|
|
it('does read back global mark even with `\'0` and `f0` in shada', function()
|
2015-07-04 17:13:00 -07:00
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('mark A')
|
|
|
|
nvim_command('2')
|
|
|
|
nvim_command('kB')
|
2015-07-05 16:26:44 -07:00
|
|
|
nvim_command('wshada')
|
2019-08-09 01:23:57 -07:00
|
|
|
reset('set shada=\'0,f0')
|
2015-07-04 17:13:00 -07:00
|
|
|
nvim_command('language C')
|
|
|
|
nvim_command('normal! `A')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t'))
|
2015-07-04 17:13:00 -07:00
|
|
|
eq(1, nvim_current_line())
|
|
|
|
end)
|
|
|
|
|
2015-07-11 17:29:31 -07:00
|
|
|
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')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-07-11 17:29:31 -07:00
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('normal! `a')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t'))
|
2015-07-11 17:29:31 -07:00
|
|
|
eq(1, nvim_current_line())
|
|
|
|
nvim_command('normal! `b')
|
|
|
|
eq(2, nvim_current_line())
|
|
|
|
end)
|
2015-06-27 22:06:16 -07:00
|
|
|
|
2015-10-23 03:35:19 -07:00
|
|
|
it('is able to dump and read back mark "', function()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('2')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-10-23 03:35:19 -07:00
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('normal! `"')
|
2016-10-18 12:04:57 -07:00
|
|
|
eq(2, nvim_current_line())
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('is able to dump and read back mark " from a closed tab', function()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
2016-10-28 19:32:14 -07:00
|
|
|
nvim_command('tabedit ' .. testfilename_2)
|
2016-10-18 12:04:57 -07:00
|
|
|
nvim_command('2')
|
|
|
|
nvim_command('q!')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2016-10-18 12:04:57 -07:00
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename_2)
|
|
|
|
nvim_command('normal! `"')
|
2015-10-23 03:35:19 -07:00
|
|
|
eq(2, nvim_current_line())
|
|
|
|
end)
|
|
|
|
|
2015-07-07 13:49:22 -07:00
|
|
|
it('is able to populate v:oldfiles', function()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
2015-09-26 16:49:48 -07:00
|
|
|
local tf_full = curbufmeths.get_name()
|
2015-07-07 13:49:22 -07:00
|
|
|
nvim_command('edit ' .. testfilename_2)
|
2015-09-26 16:49:48 -07:00
|
|
|
local tf_full_2 = curbufmeths.get_name()
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-07-07 13:49:22 -07:00
|
|
|
reset()
|
2015-09-26 16:49:48 -07:00
|
|
|
local oldfiles = meths.get_vvar('oldfiles')
|
2015-11-06 04:02:41 -07:00
|
|
|
table.sort(oldfiles)
|
2015-07-07 13:49:22 -07:00
|
|
|
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])
|
2015-08-09 15:39:50 -07:00
|
|
|
nvim_command('rshada!')
|
2015-11-17 14:44:00 -07:00
|
|
|
oldfiles = meths.get_vvar('oldfiles')
|
2015-11-06 04:02:41 -07:00
|
|
|
table.sort(oldfiles)
|
2015-08-09 15:39:50 -07:00
|
|
|
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])
|
2015-07-07 13:49:22 -07:00
|
|
|
end)
|
|
|
|
|
2015-06-27 22:06:16 -07:00
|
|
|
it('is able to dump and restore jump list', function()
|
|
|
|
nvim_command('edit ' .. testfilename_2)
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! G')
|
|
|
|
nvim_command('normal! gg')
|
2015-06-27 22:06:16 -07:00
|
|
|
nvim_command('edit ' .. testfilename)
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! G')
|
|
|
|
nvim_command('normal! gg')
|
2015-08-12 11:01:45 -07:00
|
|
|
nvim_command('enew')
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! gg')
|
2021-09-19 02:29:37 -07:00
|
|
|
local saved = exec_capture('jumps')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-06-27 22:06:16 -07:00
|
|
|
reset()
|
2021-09-19 02:29:37 -07:00
|
|
|
eq(saved, exec_capture('jumps'))
|
2015-06-27 22:06:16 -07:00
|
|
|
end)
|
|
|
|
|
2016-07-17 05:28:14 -07:00
|
|
|
it('when dumping jump list also dumps current position', function()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('normal! G')
|
|
|
|
nvim_command('split ' .. testfilename_2)
|
|
|
|
nvim_command('normal! G')
|
|
|
|
nvim_command('wshada')
|
|
|
|
nvim_command('quit')
|
|
|
|
nvim_command('rshada')
|
|
|
|
nvim_command('normal! \15') -- <C-o>
|
|
|
|
eq(testfilename_2, funcs.bufname('%'))
|
|
|
|
eq({2, 0}, curwinmeths.get_cursor())
|
|
|
|
end)
|
|
|
|
|
2015-06-27 22:06:16 -07:00
|
|
|
it('is able to dump and restore jump list with different times (slow!)',
|
|
|
|
function()
|
|
|
|
nvim_command('edit ' .. testfilename_2)
|
|
|
|
nvim_command('sleep 2')
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! G')
|
2015-06-27 22:06:16 -07:00
|
|
|
nvim_command('sleep 2')
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! gg')
|
2015-06-27 22:06:16 -07:00
|
|
|
nvim_command('sleep 2')
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('sleep 2')
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! G')
|
2015-06-27 22:06:16 -07:00
|
|
|
nvim_command('sleep 2')
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! gg')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-06-27 22:06:16 -07:00
|
|
|
reset()
|
|
|
|
nvim_command('redraw')
|
|
|
|
nvim_command('edit ' .. testfilename)
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(testfilename, funcs.bufname('%'))
|
2015-06-27 22:06:16 -07:00
|
|
|
eq(1, nvim_current_line())
|
|
|
|
nvim_command('execute "normal! \\<C-o>"')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(testfilename, funcs.bufname('%'))
|
2015-06-27 22:06:16 -07:00
|
|
|
eq(2, nvim_current_line())
|
|
|
|
nvim_command('execute "normal! \\<C-o>"')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(testfilename_2, funcs.bufname('%'))
|
2015-06-27 22:06:16 -07:00
|
|
|
eq(1, nvim_current_line())
|
|
|
|
nvim_command('execute "normal! \\<C-o>"')
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(testfilename_2, funcs.bufname('%'))
|
2015-06-27 22:06:16 -07:00
|
|
|
eq(2, nvim_current_line())
|
2019-04-01 15:50:28 -07:00
|
|
|
nvim_command('execute "normal! \\<C-o>"')
|
|
|
|
eq(testfilename_2, funcs.bufname('%'))
|
|
|
|
eq(2, nvim_current_line())
|
2015-06-27 22:06:16 -07:00
|
|
|
end)
|
2015-07-04 16:38:41 -07:00
|
|
|
|
|
|
|
it('is able to dump and restore change list', function()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! Gra')
|
|
|
|
nvim_command('normal! ggrb')
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall!')
|
2015-07-04 16:38:41 -07:00
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! Gg;')
|
2016-11-16 16:33:45 -07:00
|
|
|
-- 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
|
2015-07-05 15:20:43 -07:00
|
|
|
-- causes this to work properly.
|
|
|
|
nvim_command('" sync')
|
2015-07-04 16:38:41 -07:00
|
|
|
eq(1, nvim_current_line())
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! g;')
|
2015-07-05 15:20:43 -07:00
|
|
|
nvim_command('" sync 2')
|
2015-07-04 16:38:41 -07:00
|
|
|
eq(2, nvim_current_line())
|
|
|
|
end)
|
2017-12-23 14:29:38 -07:00
|
|
|
|
|
|
|
-- -c temporary sets lnum to zero to make `+/pat` work, so calling setpcmark()
|
|
|
|
-- during -c used to add item with zero lnum to jump list.
|
|
|
|
it('does not create incorrect file for non-existent buffers when writing from -c',
|
|
|
|
function()
|
2019-08-09 01:23:57 -07:00
|
|
|
local argv = helpers.new_argv{
|
|
|
|
args_rm={
|
|
|
|
'-i',
|
|
|
|
'--embed', -- no --embed
|
|
|
|
},
|
|
|
|
args={
|
|
|
|
'-i', meths.get_var('tmpname'), -- Use same shada file as parent.
|
|
|
|
'--cmd', 'silent edit '..non_existent_testfilename,
|
|
|
|
'-c', 'qall'},
|
|
|
|
}
|
2017-12-23 14:29:38 -07:00
|
|
|
eq('', funcs.system(argv))
|
|
|
|
eq(0, exc_exec('rshada'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not create incorrect file for non-existent buffers opened from -c',
|
|
|
|
function()
|
2019-08-09 01:23:57 -07:00
|
|
|
local argv = helpers.new_argv{
|
|
|
|
args_rm={
|
|
|
|
'-i',
|
|
|
|
'--embed', -- no --embed
|
|
|
|
},
|
|
|
|
args={
|
|
|
|
'-i', meths.get_var('tmpname'), -- Use same shada file as parent.
|
|
|
|
'-c', 'silent edit '..non_existent_testfilename,
|
|
|
|
'-c', 'autocmd VimEnter * qall'},
|
|
|
|
}
|
2017-12-23 14:29:38 -07:00
|
|
|
eq('', funcs.system(argv))
|
|
|
|
eq(0, exc_exec('rshada'))
|
|
|
|
end)
|
2023-08-30 19:15:49 -07:00
|
|
|
|
2023-09-01 19:23:43 -07:00
|
|
|
it('updates deleted marks with :delmarks', function()
|
2023-08-30 19:15:49 -07:00
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
|
|
|
|
nvim_command('mark A')
|
|
|
|
nvim_command('mark a')
|
|
|
|
-- create a change to set the '.' mark,
|
|
|
|
-- since it can't be set via :mark
|
|
|
|
feed('ggifoobar<esc>')
|
|
|
|
nvim_command('wshada')
|
|
|
|
|
2023-09-01 19:23:43 -07:00
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('normal! `A`a`.')
|
2023-08-30 19:15:49 -07:00
|
|
|
nvim_command('delmarks A a .')
|
|
|
|
nvim_command('wshada')
|
|
|
|
|
|
|
|
reset()
|
2023-09-01 19:23:43 -07:00
|
|
|
nvim_command('edit ' .. testfilename)
|
2023-08-30 19:15:49 -07:00
|
|
|
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A'))
|
|
|
|
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
|
|
|
|
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
|
|
|
|
end)
|
2015-07-11 17:29:31 -07:00
|
|
|
end)
|