2015-08-09 08:41:25 -07:00
|
|
|
-- Other ShaDa tests
|
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
|
2015-09-19 10:57:49 -07:00
|
|
|
local write_file, spawn, set_session, nvim_prog, exc_exec =
|
|
|
|
helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.exc_exec
|
2022-11-21 17:13:30 -07:00
|
|
|
local is_os = helpers.is_os
|
2022-11-13 06:52:19 -07:00
|
|
|
local skip = helpers.skip
|
2016-09-05 00:16:56 -07:00
|
|
|
|
2024-01-12 05:03:25 -07:00
|
|
|
local uv = vim.uv
|
2024-01-15 12:41:22 -07:00
|
|
|
local paths = helpers.paths
|
2015-08-09 08:41:25 -07:00
|
|
|
|
|
|
|
local shada_helpers = require('test.functional.shada.helpers')
|
2015-09-26 16:49:48 -07:00
|
|
|
local reset, clear, get_shada_rw =
|
|
|
|
shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw
|
2015-08-09 08:41:25 -07:00
|
|
|
local read_shada_file = shada_helpers.read_shada_file
|
|
|
|
|
2015-09-26 16:49:48 -07:00
|
|
|
local wshada, _, shada_fname, clean = get_shada_rw('Xtest-functional-shada-shada.shada')
|
2015-08-09 08:41:25 -07:00
|
|
|
|
2016-09-05 00:16:56 -07:00
|
|
|
local dirname = 'Xtest-functional-shada-shada.d'
|
|
|
|
local dirshada = dirname .. '/main.shada'
|
|
|
|
|
2015-08-09 08:41:25 -07:00
|
|
|
describe('ShaDa support code', function()
|
|
|
|
before_each(reset)
|
|
|
|
after_each(function()
|
|
|
|
clear()
|
|
|
|
clean()
|
2024-01-12 05:03:25 -07:00
|
|
|
uv.fs_rmdir(dirname)
|
2015-08-09 08:41:25 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('preserves `s` item size limit with unknown entries', function()
|
|
|
|
wshada(
|
|
|
|
'\100\000\207\000\000\000\000\000\000\004\000\218\003\253'
|
|
|
|
.. ('-'):rep(1024 - 3)
|
|
|
|
.. '\100\000\207\000\000\000\000\000\000\004\001\218\003\254'
|
|
|
|
.. ('-'):rep(1025 - 3)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-08-09 08:41:25 -07:00
|
|
|
eq(0, exc_exec('wshada ' .. shada_fname))
|
|
|
|
local found = 0
|
|
|
|
for _, v in ipairs(read_shada_file(shada_fname)) do
|
|
|
|
if v.type == 100 then
|
|
|
|
found = found + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
eq(2, found)
|
|
|
|
eq(0, exc_exec('set shada-=s10 shada+=s1'))
|
|
|
|
eq(0, exc_exec('wshada ' .. shada_fname))
|
|
|
|
found = 0
|
|
|
|
for _, v in ipairs(read_shada_file(shada_fname)) do
|
|
|
|
if v.type == 100 then
|
|
|
|
found = found + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
eq(1, found)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('preserves `s` item size limit with instance history entries', function()
|
|
|
|
local hist1 = ('-'):rep(1024 - 5)
|
|
|
|
local hist2 = ('-'):rep(1025 - 5)
|
|
|
|
nvim_command('set shada-=s10 shada+=s1')
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.histadd(':', hist1)
|
|
|
|
fn.histadd(':', hist2)
|
2015-08-09 08:41:25 -07:00
|
|
|
eq(0, exc_exec('wshada ' .. shada_fname))
|
|
|
|
local found = 0
|
|
|
|
for _, v in ipairs(read_shada_file(shada_fname)) do
|
|
|
|
if v.type == 4 then
|
|
|
|
found = found + 1
|
|
|
|
eq(hist1, v.value[2])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
eq(1, found)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('leaves .tmp.a in-place when there is error in original ShaDa', function()
|
|
|
|
wshada('Some text file')
|
|
|
|
eq(
|
|
|
|
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier',
|
|
|
|
exc_exec('wshada ' .. shada_fname)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-08-09 08:41:25 -07:00
|
|
|
eq(1, read_shada_file(shada_fname .. '.tmp.a')[1].type)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it(
|
|
|
|
'does not leave .tmp.a in-place when there is error in original ShaDa, but writing with bang',
|
|
|
|
function()
|
|
|
|
wshada('Some text file')
|
|
|
|
eq(0, exc_exec('wshada! ' .. shada_fname))
|
|
|
|
eq(1, read_shada_file(shada_fname)[1].type)
|
2024-01-12 05:03:25 -07:00
|
|
|
eq(nil, uv.fs_stat(shada_fname .. '.tmp.a'))
|
2015-08-09 08:41:25 -07:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
it('leaves .tmp.b in-place when there is error in original ShaDa and it has .tmp.a', function()
|
|
|
|
wshada('Some text file')
|
|
|
|
eq(
|
|
|
|
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier',
|
|
|
|
exc_exec('wshada ' .. shada_fname)
|
|
|
|
)
|
|
|
|
eq(
|
|
|
|
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier',
|
|
|
|
exc_exec('wshada ' .. shada_fname)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-08-09 08:41:25 -07:00
|
|
|
eq(1, read_shada_file(shada_fname .. '.tmp.a')[1].type)
|
|
|
|
eq(1, read_shada_file(shada_fname .. '.tmp.b')[1].type)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it(
|
|
|
|
'leaves .tmp.z in-place when there is error in original ShaDa and it has .tmp.a … .tmp.x',
|
|
|
|
function()
|
|
|
|
wshada('Some text file')
|
|
|
|
local i = ('a'):byte()
|
|
|
|
while i < ('z'):byte() do
|
|
|
|
write_file(shada_fname .. ('.tmp.%c'):format(i), 'Some text file', true)
|
|
|
|
i = i + 1
|
2024-01-02 18:09:18 -07:00
|
|
|
end
|
|
|
|
eq(
|
2015-08-09 08:41:25 -07:00
|
|
|
'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier',
|
|
|
|
exc_exec('wshada ' .. shada_fname)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-08-09 08:41:25 -07:00
|
|
|
eq(1, read_shada_file(shada_fname .. '.tmp.z')[1].type)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
it('errors out when there are .tmp.a … .tmp.z ShaDa files', function()
|
|
|
|
wshada('')
|
|
|
|
local i = ('a'):byte()
|
|
|
|
while i <= ('z'):byte() do
|
|
|
|
write_file(shada_fname .. ('.tmp.%c'):format(i), '', true)
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
eq(
|
|
|
|
'Vim(wshada):E138: All Xtest-functional-shada-shada.shada.tmp.X files exist, cannot write ShaDa file!',
|
|
|
|
exc_exec('wshada ' .. shada_fname)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2015-08-09 08:41:25 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('reads correctly various timestamps', function()
|
2016-04-13 05:21:32 -07:00
|
|
|
local msgpack = {
|
2015-08-09 08:41:25 -07:00
|
|
|
'\100', -- Positive fixnum 100
|
|
|
|
'\204\255', -- uint 8 255
|
|
|
|
'\205\010\003', -- uint 16 2563
|
|
|
|
'\206\255\010\030\004', -- uint 32 4278853124
|
|
|
|
'\207\005\100\060\250\255\010\030\004', -- uint 64 388502516579048964
|
|
|
|
}
|
|
|
|
local s = '\100'
|
|
|
|
local e = '\001\192'
|
2016-04-13 05:21:32 -07:00
|
|
|
wshada(s .. table.concat(msgpack, e .. s) .. e)
|
2015-08-09 08:41:25 -07:00
|
|
|
eq(0, exc_exec('wshada ' .. shada_fname))
|
|
|
|
local found = 0
|
2024-01-12 05:03:25 -07:00
|
|
|
local typ = vim.mpack.decode(s)
|
2015-08-09 08:41:25 -07:00
|
|
|
for _, v in ipairs(read_shada_file(shada_fname)) do
|
|
|
|
if v.type == typ then
|
|
|
|
found = found + 1
|
2024-01-12 05:03:25 -07:00
|
|
|
eq(vim.mpack.decode(msgpack[found]), v.timestamp)
|
2015-08-09 08:41:25 -07:00
|
|
|
end
|
|
|
|
end
|
2016-04-13 05:21:32 -07:00
|
|
|
eq(#msgpack, found)
|
2015-08-09 08:41:25 -07:00
|
|
|
end)
|
2015-08-15 15:16:24 -07:00
|
|
|
|
2015-09-22 05:22:22 -07:00
|
|
|
local marklike = { [7] = true, [8] = true, [10] = true, [11] = true }
|
|
|
|
local find_file = function(fname)
|
|
|
|
local found = {}
|
|
|
|
for _, v in ipairs(read_shada_file(shada_fname)) do
|
|
|
|
if marklike[v.type] and v.value.f == fname then
|
|
|
|
found[v.type] = (found[v.type] or 0) + 1
|
|
|
|
elseif v.type == 9 then
|
|
|
|
for _, b in ipairs(v.value) do
|
|
|
|
if b.f == fname then
|
|
|
|
found[v.type] = (found[v.type] or 0) + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return found
|
|
|
|
end
|
|
|
|
|
2015-09-22 05:03:27 -07:00
|
|
|
it('correctly uses shada-r option', function()
|
2016-08-31 05:18:18 -07:00
|
|
|
nvim_command('set shellslash')
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('__home', paths.test_source_path)
|
2015-09-22 05:03:27 -07:00
|
|
|
nvim_command('let $HOME = __home')
|
|
|
|
nvim_command('unlet __home')
|
|
|
|
nvim_command('edit ~/README.md')
|
|
|
|
nvim_command('normal! GmAggmaAabc')
|
|
|
|
nvim_command('undo')
|
|
|
|
nvim_command('set shada+=%')
|
|
|
|
nvim_command('wshada! ' .. shada_fname)
|
2024-01-12 10:59:57 -07:00
|
|
|
local readme_fname = fn.resolve(paths.test_source_path) .. '/README.md'
|
2017-01-07 19:23:45 -07:00
|
|
|
eq({ [7] = 2, [8] = 2, [9] = 1, [10] = 4, [11] = 1 }, find_file(readme_fname))
|
2015-09-22 05:03:27 -07:00
|
|
|
nvim_command('set shada+=r~')
|
|
|
|
nvim_command('wshada! ' .. shada_fname)
|
2015-09-22 05:22:22 -07:00
|
|
|
eq({}, find_file(readme_fname))
|
2015-09-22 05:03:27 -07:00
|
|
|
nvim_command('set shada-=r~')
|
|
|
|
nvim_command('wshada! ' .. shada_fname)
|
2017-01-07 19:23:45 -07:00
|
|
|
eq({ [7] = 2, [8] = 2, [9] = 1, [10] = 4, [11] = 1 }, find_file(readme_fname))
|
2024-01-12 10:59:57 -07:00
|
|
|
nvim_command('set shada+=r' .. fn.escape(fn.escape(paths.test_source_path, '$~'), ' "\\,'))
|
2015-09-22 05:03:27 -07:00
|
|
|
nvim_command('wshada! ' .. shada_fname)
|
2015-09-22 05:22:22 -07:00
|
|
|
eq({}, find_file(readme_fname))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('correctly ignores case with shada-r option', function()
|
2016-08-31 05:18:18 -07:00
|
|
|
nvim_command('set shellslash')
|
2024-01-12 10:59:57 -07:00
|
|
|
local pwd = fn.getcwd()
|
2015-09-22 05:22:22 -07:00
|
|
|
local relfname = 'абв/test'
|
|
|
|
local fname = pwd .. '/' .. relfname
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_var('__fname', fname)
|
2015-09-22 05:22:22 -07:00
|
|
|
nvim_command('silent! edit `=__fname`')
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline(1, { 'a', 'b', 'c', 'd' })
|
2015-09-22 05:22:22 -07:00
|
|
|
nvim_command('normal! GmAggmaAabc')
|
|
|
|
nvim_command('undo')
|
|
|
|
nvim_command('set shada+=%')
|
|
|
|
nvim_command('wshada! ' .. shada_fname)
|
2017-01-07 19:23:45 -07:00
|
|
|
eq({ [7] = 2, [8] = 2, [9] = 1, [10] = 4, [11] = 2 }, find_file(fname))
|
2015-09-22 05:22:22 -07:00
|
|
|
nvim_command('set shada+=r' .. pwd .. '/АБВ')
|
|
|
|
nvim_command('wshada! ' .. shada_fname)
|
|
|
|
eq({}, find_file(fname))
|
2015-09-22 05:03:27 -07:00
|
|
|
end)
|
2015-10-05 16:24:16 -07:00
|
|
|
|
|
|
|
it('is able to set &shada after &viminfo', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('viminfo', "'10", {})
|
|
|
|
eq("'10", api.nvim_get_option_value('viminfo', {}))
|
|
|
|
eq("'10", api.nvim_get_option_value('shada', {}))
|
|
|
|
api.nvim_set_option_value('shada', '', {})
|
|
|
|
eq('', api.nvim_get_option_value('viminfo', {}))
|
|
|
|
eq('', api.nvim_get_option_value('shada', {}))
|
2015-10-05 16:24:16 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('is able to set all& after setting &shada', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('shada', "'10", {})
|
|
|
|
eq("'10", api.nvim_get_option_value('viminfo', {}))
|
|
|
|
eq("'10", api.nvim_get_option_value('shada', {}))
|
2015-10-05 16:24:16 -07:00
|
|
|
nvim_command('set all&')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq("!,'100,<50,s10,h", api.nvim_get_option_value('viminfo', {}))
|
|
|
|
eq("!,'100,<50,s10,h", api.nvim_get_option_value('shada', {}))
|
2015-10-05 16:24:16 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('is able to set &shada after &viminfo using :set', function()
|
|
|
|
nvim_command("set viminfo='10")
|
2024-01-12 10:59:57 -07:00
|
|
|
eq("'10", api.nvim_get_option_value('viminfo', {}))
|
|
|
|
eq("'10", api.nvim_get_option_value('shada', {}))
|
2015-10-05 16:24:16 -07:00
|
|
|
nvim_command('set shada=')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('', api.nvim_get_option_value('viminfo', {}))
|
|
|
|
eq('', api.nvim_get_option_value('shada', {}))
|
2015-10-05 16:24:16 -07:00
|
|
|
end)
|
2016-09-05 00:16:56 -07:00
|
|
|
|
2022-09-21 18:43:37 -07:00
|
|
|
it('setting &shada gives proper error message on missing number', function()
|
|
|
|
eq([[Vim(set):E526: Missing number after <">: shada="]], exc_exec([[set shada=\"]]))
|
|
|
|
for _, c in ipairs({ "'", '/', ':', '<', '@', 's' }) do
|
|
|
|
eq(
|
|
|
|
([[Vim(set):E526: Missing number after <%s>: shada=%s]]):format(c, c),
|
|
|
|
exc_exec(([[set shada=%s]]):format(c))
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-09-21 18:43:37 -07:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-09-05 00:16:56 -07:00
|
|
|
it('does not crash when ShaDa file directory is not writable', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_os('win'))
|
2016-08-31 05:18:18 -07:00
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.mkdir(dirname, '', 0)
|
|
|
|
eq(0, fn.filewritable(dirname))
|
2019-08-09 01:23:57 -07:00
|
|
|
reset { shadafile = dirshada, args = { '--cmd', 'set shada=' } }
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('shada', "'10", {})
|
2016-09-05 00:16:56 -07:00
|
|
|
eq(
|
|
|
|
'Vim(wshada):E886: System error while opening ShaDa file '
|
|
|
|
.. 'Xtest-functional-shada-shada.d/main.shada for reading to merge '
|
|
|
|
.. 'before writing it: permission denied',
|
|
|
|
exc_exec('wshada')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('shada', '', {})
|
2016-09-05 00:16:56 -07:00
|
|
|
end)
|
2015-08-09 08:41:25 -07:00
|
|
|
end)
|
2023-02-11 03:25:01 -07:00
|
|
|
|
|
|
|
describe('ShaDa support code', function()
|
|
|
|
it('does not write NONE file', function()
|
|
|
|
local session = spawn(
|
|
|
|
{ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', '--headless', '--cmd', 'qall' },
|
|
|
|
true
|
|
|
|
)
|
|
|
|
session:close()
|
2024-01-12 05:03:25 -07:00
|
|
|
eq(nil, uv.fs_stat('NONE'))
|
|
|
|
eq(nil, uv.fs_stat('NONE.tmp.a'))
|
2023-02-11 03:25:01 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not read NONE file', function()
|
|
|
|
write_file('NONE', '\005\001\015\131\161na\162rX\194\162rc\145\196\001-')
|
|
|
|
local session = spawn({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', '--headless' }, true)
|
|
|
|
set_session(session)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('', fn.getreg('a'))
|
2023-02-11 03:25:01 -07:00
|
|
|
session:close()
|
|
|
|
os.remove('NONE')
|
|
|
|
end)
|
|
|
|
end)
|