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)
|
2024-01-12 10:59:57 -07:00
|
|
|
local api, nvim_command, fn, eq = helpers.api, helpers.command, helpers.fn, 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()
|
2024-01-12 10:59:57 -07:00
|
|
|
return api.nvim_win_get_cursor(0)[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')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':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')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':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')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':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)
|
2024-01-12 10:59:57 -07:00
|
|
|
local tf_full = api.nvim_buf_get_name(0)
|
2015-07-07 13:49:22 -07:00
|
|
|
nvim_command('edit ' .. testfilename_2)
|
2024-01-12 10:59:57 -07:00
|
|
|
local tf_full_2 = api.nvim_buf_get_name(0)
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(nvim_command, 'qall')
|
2015-07-07 13:49:22 -07:00
|
|
|
reset()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldfiles = api.nvim_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!')
|
2024-01-12 10:59:57 -07:00
|
|
|
oldfiles = api.nvim_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>
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename_2, fn.bufname('%'))
|
|
|
|
eq({ 2, 0 }, api.nvim_win_get_cursor(0))
|
2016-07-17 05:28:14 -07:00
|
|
|
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)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename, fn.bufname('%'))
|
2015-06-27 22:06:16 -07:00
|
|
|
eq(1, nvim_current_line())
|
|
|
|
nvim_command('execute "normal! \\<C-o>"')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename, fn.bufname('%'))
|
2015-06-27 22:06:16 -07:00
|
|
|
eq(2, nvim_current_line())
|
|
|
|
nvim_command('execute "normal! \\<C-o>"')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename_2, fn.bufname('%'))
|
2015-06-27 22:06:16 -07:00
|
|
|
eq(1, nvim_current_line())
|
|
|
|
nvim_command('execute "normal! \\<C-o>"')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename_2, fn.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>"')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(testfilename_2, fn.bufname('%'))
|
2019-04-01 15:50:28 -07:00
|
|
|
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
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
|
|
|
args = {
|
|
|
|
'-i',
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_var('tmpname'), -- Use same shada file as parent.
|
2024-01-02 18:09:18 -07:00
|
|
|
'--cmd',
|
2019-08-09 01:23:57 -07:00
|
|
|
'silent edit ' .. non_existent_testfilename,
|
2024-01-02 18:09:18 -07:00
|
|
|
'-c',
|
|
|
|
'qall',
|
2019-08-09 01:23:57 -07:00
|
|
|
},
|
|
|
|
}
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('', fn.system(argv))
|
2017-12-23 14:29:38 -07:00
|
|
|
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 = {
|
2024-01-02 18:09:18 -07:00
|
|
|
'-i',
|
2019-08-09 01:23:57 -07:00
|
|
|
'--embed', -- no --embed
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
|
|
|
args = {
|
2019-08-09 01:23:57 -07:00
|
|
|
'-i',
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_get_var('tmpname'), -- Use same shada file as parent.
|
2019-08-09 01:23:57 -07:00
|
|
|
'-c',
|
|
|
|
'silent edit ' .. non_existent_testfilename,
|
2024-01-02 18:09:18 -07:00
|
|
|
'-c',
|
2019-08-09 01:23:57 -07:00
|
|
|
'autocmd VimEnter * qall',
|
|
|
|
},
|
|
|
|
}
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('', fn.system(argv))
|
2017-12-23 14:29:38 -07:00
|
|
|
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)
|
2023-09-02 19:34:09 -07:00
|
|
|
|
|
|
|
it('updates deleted marks with :delmarks!', function()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
|
|
|
|
nvim_command('mark A')
|
|
|
|
nvim_command('mark a')
|
|
|
|
feed('ggifoobar<esc>')
|
|
|
|
nvim_command('wshada')
|
|
|
|
|
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
nvim_command('normal! `A`a`.')
|
|
|
|
nvim_command('delmarks!')
|
|
|
|
nvim_command('wshada')
|
|
|
|
|
|
|
|
reset()
|
|
|
|
nvim_command('edit ' .. testfilename)
|
|
|
|
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `a'))
|
|
|
|
eq('Vim(normal):E20: Mark not set', exc_exec('normal! `.'))
|
|
|
|
-- Make sure that uppercase marks aren't deleted.
|
|
|
|
nvim_command('normal! `A')
|
|
|
|
end)
|
2015-07-11 17:29:31 -07:00
|
|
|
end)
|