2015-07-11 17:29:31 -07:00
|
|
|
-- ShaDa marks saving/reading support
|
|
|
|
local helpers = require('test.functional.helpers')
|
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
|
|
|
|
local exc_exec, redir_exec = helpers.exc_exec, helpers.redir_exec
|
2015-07-11 17:29:31 -07:00
|
|
|
|
|
|
|
local shada_helpers = require('test.functional.shada.helpers')
|
2015-09-19 10:57:49 -07:00
|
|
|
local reset, set_additional_cmd, clear =
|
2015-07-11 17:29:31 -07:00
|
|
|
shada_helpers.reset, shada_helpers.set_additional_cmd,
|
2015-09-19 10:57:49 -07:00
|
|
|
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'
|
2015-07-11 17:29:31 -07:00
|
|
|
before_each(function()
|
|
|
|
reset()
|
|
|
|
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')
|
|
|
|
set_additional_cmd('set shada=\'0,f0')
|
2015-07-04 17:13:00 -07:00
|
|
|
reset()
|
|
|
|
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')
|
|
|
|
nvim_command('qall')
|
|
|
|
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')
|
|
|
|
nvim_command('qall')
|
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('normal! `"')
|
|
|
|
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()
|
2015-07-07 13:49:22 -07:00
|
|
|
nvim_command('qall')
|
|
|
|
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')
|
|
|
|
local saved = redir_exec('jumps')
|
2015-06-27 22:06:16 -07:00
|
|
|
nvim_command('qall')
|
|
|
|
reset()
|
2015-09-26 16:49:48 -07:00
|
|
|
eq(saved, redir_exec('jumps'))
|
2015-06-27 22:06:16 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
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')
|
2015-06-27 22:06:16 -07:00
|
|
|
nvim_command('qall')
|
|
|
|
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(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())
|
|
|
|
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')
|
2015-07-04 16:38:41 -07:00
|
|
|
nvim_command('qall!')
|
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
2015-09-26 16:49:48 -07:00
|
|
|
nvim_command('normal! Gg;')
|
2015-07-05 15:20:43 -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
|
|
|
|
-- 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)
|
2015-07-11 17:29:31 -07:00
|
|
|
end)
|