diff options
Diffstat (limited to 'test/functional/shada')
-rw-r--r-- | test/functional/shada/buffers_spec.lua | 51 | ||||
-rw-r--r-- | test/functional/shada/compatibility_spec.lua | 154 | ||||
-rw-r--r-- | test/functional/shada/errors_spec.lua | 593 | ||||
-rw-r--r-- | test/functional/shada/helpers.lua | 31 | ||||
-rw-r--r-- | test/functional/shada/history_spec.lua | 168 | ||||
-rw-r--r-- | test/functional/shada/marks_spec.lua | 89 | ||||
-rw-r--r-- | test/functional/shada/merging_spec.lua | 743 | ||||
-rw-r--r-- | test/functional/shada/registers_spec.lua | 177 | ||||
-rw-r--r-- | test/functional/shada/shada_spec.lua | 201 | ||||
-rw-r--r-- | test/functional/shada/variables_spec.lua | 106 |
10 files changed, 1417 insertions, 896 deletions
diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua index b1c4ded541..9fead98fed 100644 --- a/test/functional/shada/buffers_spec.lua +++ b/test/functional/shada/buffers_spec.lua @@ -1,7 +1,6 @@ -- shada buffer list saving/reading support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, eq, curbufmeths, meths = - helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths, helpers.meths +local nvim_command, fn, eq, api = helpers.command, helpers.fn, helpers.eq, helpers.api local expect_exit = helpers.expect_exit local shada_helpers = require('test.functional.shada.helpers') @@ -18,10 +17,10 @@ describe('shada support code', function() nvim_command('edit ' .. testfilename_2) expect_exit(nvim_command, 'qall') reset('set shada+=%') - eq(3, funcs.bufnr('$')) - eq('', funcs.bufname(1)) - eq(testfilename, funcs.bufname(2)) - eq(testfilename_2, funcs.bufname(3)) + eq(3, fn.bufnr('$')) + eq('', fn.bufname(1)) + eq(testfilename, fn.bufname(2)) + eq(testfilename_2, fn.bufname(3)) end) it('does not restore buffer list without % in &shada', function() @@ -30,8 +29,8 @@ describe('shada support code', function() nvim_command('edit ' .. testfilename_2) expect_exit(nvim_command, 'qall') reset() - eq(1, funcs.bufnr('$')) - eq('', funcs.bufname(1)) + eq(1, fn.bufnr('$')) + eq('', fn.bufname(1)) end) it('does not dump buffer list without % in &shada', function() @@ -40,44 +39,44 @@ describe('shada support code', function() nvim_command('edit ' .. testfilename_2) expect_exit(nvim_command, 'qall') reset('set shada+=%') - eq(1, funcs.bufnr('$')) - eq('', funcs.bufname(1)) + eq(1, fn.bufnr('$')) + eq('', fn.bufname(1)) end) it('does not dump unlisted buffer', function() reset('set shada+=%') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - meths.set_option_value('buflisted', false, {}) + api.nvim_set_option_value('buflisted', false, {}) expect_exit(nvim_command, 'qall') reset('set shada+=%') - eq(2, funcs.bufnr('$')) - eq('', funcs.bufname(1)) - eq(testfilename, funcs.bufname(2)) + eq(2, fn.bufnr('$')) + eq('', fn.bufname(1)) + eq(testfilename, fn.bufname(2)) end) it('does not dump quickfix buffer', function() reset('set shada+=%') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - meths.set_option_value('buftype', 'quickfix', {}) + api.nvim_set_option_value('buftype', 'quickfix', {}) expect_exit(nvim_command, 'qall') reset('set shada+=%') - eq(2, funcs.bufnr('$')) - eq('', funcs.bufname(1)) - eq(testfilename, funcs.bufname(2)) + eq(2, fn.bufnr('$')) + eq('', fn.bufname(1)) + eq(testfilename, fn.bufname(2)) end) it('does not dump unnamed buffers', function() reset('set shada+=% hidden') - curbufmeths.set_lines(0, 1, true, {'foo'}) + api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' }) nvim_command('enew') - curbufmeths.set_lines(0, 1, true, {'bar'}) - eq(2, funcs.bufnr('$')) + api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' }) + eq(2, fn.bufnr('$')) expect_exit(nvim_command, 'qall!') reset('set shada+=% hidden') - eq(1, funcs.bufnr('$')) - eq('', funcs.bufname(1)) + eq(1, fn.bufnr('$')) + eq('', fn.bufname(1)) end) it('restores 1 buffer with %1 in &shada, #5759', function() @@ -86,8 +85,8 @@ describe('shada support code', function() nvim_command('edit ' .. testfilename_2) expect_exit(nvim_command, 'qall') reset('set shada+=%1') - eq(2, funcs.bufnr('$')) - eq('', funcs.bufname(1)) - eq(testfilename, funcs.bufname(2)) + eq(2, fn.bufnr('$')) + eq('', fn.bufname(1)) + eq(testfilename, fn.bufname(2)) end) end) diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index fb656735dd..bc4e9675c6 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -1,11 +1,11 @@ -- ShaDa compatibility support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq +local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq local exc_exec = helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') -local reset, clear, get_shada_rw = shada_helpers.reset, shada_helpers.clear, - shada_helpers.get_shada_rw +local reset, clear, get_shada_rw = + shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw local read_shada_file = shada_helpers.read_shada_file local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-compatibility.shada') @@ -49,11 +49,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada! ' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with s/search pattern item with BOOL unknown (sX) key value', function() @@ -81,11 +81,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with replacement item with BOOL additional value in list', function() @@ -114,22 +114,32 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) - for _, v in ipairs({{name='global mark', mpack='\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161nA'}, - {name='jump', mpack='\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002'}, - {name='local mark', mpack='\010\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161na'}, - {name='change', mpack='\011\001\015\130\162mX\195\161f\196\006' .. mock_file_path .. 'c'}, - }) do + for _, v in ipairs({ + { + name = 'global mark', + mpack = '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161nA', + }, + { + name = 'jump', + mpack = '\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002', + }, + { + name = 'local mark', + mpack = '\010\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161na', + }, + { name = 'change', mpack = '\011\001\015\130\162mX\195\161f\196\006' .. mock_file_path .. 'c' }, + }) do it('works with ' .. v.name .. ' item with BOOL unknown (mX) key value', function() nvim_command('silent noautocmd edit ' .. mock_file_path .. 'c') - eq('' .. mock_file_path .. 'c', funcs.bufname('%')) - funcs.setline('.', {'1', '2', '3'}) + eq('' .. mock_file_path .. 'c', fn.bufname('%')) + fn.setline('.', { '1', '2', '3' }) wshada(v.mpack) eq(0, exc_exec(sdrcmd(true))) os.remove(shada_fname) @@ -145,7 +155,7 @@ describe('ShaDa forward compatibility support code', function() eq(true, found) eq(0, exc_exec(sdrcmd())) nvim_command('bwipeout!') - funcs.setpos('\'A', {0, 1, 1, 0}) + fn.setpos("'A", { 0, 1, 1, 0 }) os.remove(shada_fname) nvim_command('wshada ' .. shada_fname) found = false @@ -157,21 +167,25 @@ describe('ShaDa forward compatibility support code', function() end end eq(false, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) if v.name == 'global mark' or v.name == 'local mark' then it('works with ' .. v.name .. ' item with <C-a> name', function() nvim_command('silent noautocmd edit ' .. mock_file_path .. 'c') - eq('' .. mock_file_path .. 'c', funcs.bufname('%')) - funcs.setline('.', {'1', '2', '3'}) - wshada(v.mpack:gsub('n.$', 'n\001') - .. v.mpack:gsub('n.$', 'n\002') - .. v.mpack:gsub('n.$', 'n\003'):gsub('' .. mock_file_path .. 'c', '' .. mock_file_path2 .. 'f')) + eq('' .. mock_file_path .. 'c', fn.bufname('%')) + fn.setline('.', { '1', '2', '3' }) + wshada( + v.mpack:gsub('n.$', 'n\001') + .. v.mpack:gsub('n.$', 'n\002') + .. v.mpack + :gsub('n.$', 'n\003') + :gsub('' .. mock_file_path .. 'c', '' .. mock_file_path2 .. 'f') + ) eq(0, exc_exec(sdrcmd(true))) nvim_command('wshada ' .. shada_fname) local found = 0 @@ -199,11 +213,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) end end @@ -231,11 +245,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(false, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with register item with <C-a> name', function() @@ -267,18 +281,18 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with register item with type 10', function() wshada('\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010') eq(0, exc_exec(sdrcmd(true))) - eq({}, funcs.getreg('a', 1, 1)) - eq('', funcs.getregtype('a')) + eq({}, fn.getreg('a', 1, 1)) + eq('', fn.getregtype('a')) nvim_command('wshada ' .. shada_fname) local found = 0 for i, v in ipairs(read_shada_file(shada_fname)) do @@ -305,19 +319,19 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with buffer list item with BOOL unknown (bX) key', function() nvim_command('set shada+=%') wshada('\009\000\016\145\130\161f\196\006' .. mock_file_path .. 'c\162bX\195') eq(0, exc_exec(sdrcmd())) - eq(2, funcs.bufnr('$')) - eq('' .. mock_file_path .. 'c', funcs.bufname(2)) + eq(2, fn.bufnr('$')) + eq('' .. mock_file_path .. 'c', fn.bufname(2)) os.remove(shada_fname) nvim_command('wshada ' .. shada_fname) local found = false @@ -340,11 +354,11 @@ describe('ShaDa forward compatibility support code', function() end eq(false, found) nvim_command('bwipeout!') - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with history item with BOOL additional value in list', function() @@ -363,8 +377,8 @@ describe('ShaDa forward compatibility support code', function() eq(true, found) eq(0, exc_exec(sdrcmd())) os.remove(shada_fname) - funcs.histadd(':', '--') - funcs.histadd(':', '-') + fn.histadd(':', '--') + fn.histadd(':', '-') nvim_command('wshada ' .. shada_fname) found = false for _, v in ipairs(read_shada_file(shada_fname)) do @@ -374,11 +388,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with history item with type 10', function() @@ -411,11 +425,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with item with 100 type', function() @@ -448,10 +462,10 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) end) diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index ebfd73cf85..233f03e5c0 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -1,14 +1,12 @@ -- ShaDa errors handling support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, eq, exc_exec = - helpers.command, helpers.eq, helpers.exc_exec +local nvim_command, eq, exc_exec = helpers.command, helpers.eq, helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') local reset, clear, get_shada_rw = shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw -local wshada, sdrcmd, shada_fname, clean = - get_shada_rw('Xtest-functional-shada-errors.shada') +local wshada, sdrcmd, shada_fname, clean = get_shada_rw('Xtest-functional-shada-errors.shada') describe('ShaDa error handling', function() before_each(reset) @@ -29,17 +27,26 @@ describe('ShaDa error handling', function() it('fails on zero', function() wshada('\000') - eq('Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 0, but got nothing', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 0, but got nothing', + exc_exec(sdrcmd()) + ) end) it('fails on missing item', function() wshada('\000\000\000') - eq('Vim(rshada):E576: Error while reading ShaDa file: there is an item at position 0 that must not be there: Missing items are for internal uses only', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Error while reading ShaDa file: there is an item at position 0 that must not be there: Missing items are for internal uses only', + exc_exec(sdrcmd()) + ) end) it('fails on -2 type', function() wshada('\254\000\000') - eq('Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 0', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 0', + exc_exec(sdrcmd()) + ) end) it('does not fail on header with zero length', function() @@ -50,22 +57,34 @@ describe('ShaDa error handling', function() it('fails on search pattern item with zero length', function() wshada('\002\000\000') - eq('Vim(rshada):E576: Failed to parse ShaDa file: incomplete msgpack string at position 3', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Failed to parse ShaDa file: incomplete msgpack string at position 3', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with -2 timestamp', function() wshada('\002\254\000') - eq('Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 1', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 1', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with -2 length', function() wshada('\002\000\254') - eq('Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 2', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Error while reading ShaDa file: expected positive integer at position 2', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with length greater then file length', function() wshada('\002\000\002\000') - eq('Vim(rshada):E576: Error while reading ShaDa file: last entry specified that it occupies 2 bytes, but file ended earlier', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Error while reading ShaDa file: last entry specified that it occupies 2 bytes, but file ended earlier', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with invalid byte', function() @@ -80,334 +99,523 @@ describe('ShaDa error handling', function() -- get MSGPACK_UNPACK_PARSE_ERROR and not MSGPACK_UNPACK_CONTINUE or -- MSGPACK_UNPACK_EXTRA_BYTES. wshada('\002\000\001\193') - eq('Vim(rshada):E576: Failed to parse ShaDa file due to a msgpack parser error at position 3', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Failed to parse ShaDa file due to a msgpack parser error at position 3', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with incomplete map', function() wshada('\002\000\001\129') - eq('Vim(rshada):E576: Failed to parse ShaDa file: incomplete msgpack string at position 3', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Failed to parse ShaDa file: incomplete msgpack string at position 3', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item without a pattern', function() wshada('\002\000\005\129\162sX\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has no pattern', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has no pattern', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern with extra bytes', function() wshada('\002\000\002\128\000') - eq('Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL value', function() wshada('\002\000\001\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 is not a dictionary', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 is not a dictionary', + exc_exec(sdrcmd()) + ) end) -- sp entry is here because it causes an allocation. it('fails on search pattern item with BIN key', function() wshada('\002\000\014\131\162sp\196\001a\162sX\192\196\000\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has key which is not a string', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has key which is not a string', + exc_exec(sdrcmd()) + ) end) -- sp entry is here because it causes an allocation. it('fails on search pattern item with empty key', function() wshada('\002\000\013\131\162sp\196\001a\162sX\192\160\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has empty key', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has empty key', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL magic key value', function() wshada('\002\000\009\130\162sX\192\162sm\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sm key value which is not a boolean', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sm key value which is not a boolean', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL smartcase key value', function() wshada('\002\000\009\130\162sX\192\162sc\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sc key value which is not a boolean', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sc key value which is not a boolean', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL search_backward key value', function() wshada('\002\000\009\130\162sX\192\162sb\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sb key value which is not a boolean', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sb key value which is not a boolean', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL has_line_offset key value', function() wshada('\002\000\009\130\162sX\192\162sl\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sl key value which is not a boolean', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sl key value which is not a boolean', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL place_cursor_at_end key value', function() wshada('\002\000\009\130\162sX\192\162se\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has se key value which is not a boolean', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has se key value which is not a boolean', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL is_last_used key value', function() wshada('\002\000\009\130\162sX\192\162su\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has su key value which is not a boolean', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has su key value which is not a boolean', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL is_substitute_pattern key value', function() wshada('\002\000\009\130\162sX\192\162ss\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has ss key value which is not a boolean', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has ss key value which is not a boolean', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL highlighted key value', function() wshada('\002\000\009\130\162sX\192\162sh\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sh key value which is not a boolean', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sh key value which is not a boolean', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL offset key value', function() wshada('\002\000\009\130\162sX\192\162so\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has so key value which is not an integer', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has so key value which is not an integer', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with NIL pat key value', function() wshada('\002\000\009\130\162sX\192\162sp\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sp key value which is not a binary', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sp key value which is not a binary', + exc_exec(sdrcmd()) + ) end) it('fails on search pattern item with STR pat key value', function() wshada('\002\000\011\130\162sX\192\162sp\162sp') - eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sp key value which is not a binary', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sp key value which is not a binary', + exc_exec(sdrcmd()) + ) end) - for _, v in ipairs({{name='global mark', mpack='\007'}, - {name='jump', mpack='\008'}, - {name='local mark', mpack='\010'}, - {name='change', mpack='\011'}, - }) do - local is_mark_test = ({['global mark']=true, ['local mark']=true})[v.name] + for _, v in ipairs({ + { name = 'global mark', mpack = '\007' }, + { name = 'jump', mpack = '\008' }, + { name = 'local mark', mpack = '\010' }, + { name = 'change', mpack = '\011' }, + }) do + local is_mark_test = ({ ['global mark'] = true, ['local mark'] = true })[v.name] it('fails on ' .. v.name .. ' item with NIL value', function() wshada(v.mpack .. '\000\001\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 is not a dictionary', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 is not a dictionary', + exc_exec(sdrcmd()) + ) end) -- f entry is here because it causes an allocation. it('fails on ' .. v.name .. ' item with BIN key', function() wshada(v.mpack .. '\000\013\131\161f\196\001/\162mX\192\196\000\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has key which is not a string', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has key which is not a string', + exc_exec(sdrcmd()) + ) end) -- f entry is here because it causes an allocation. it('fails on ' .. v.name .. ' item with empty key', function() wshada(v.mpack .. '\000\012\131\161f\196\001/\162mX\192\160\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has empty key', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has empty key', + exc_exec(sdrcmd()) + ) end) it('fails on ' .. v.name .. ' item without f key', function() wshada(v.mpack .. '\000\008\130\162mX\192\161l\001') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 is missing file name', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 is missing file name', + exc_exec(sdrcmd()) + ) end) it('fails on ' .. v.name .. ' item with zero l key', function() wshada(v.mpack .. '\000\013\131\162mX\192\161f\196\001/\161l\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid line number', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid line number', + exc_exec(sdrcmd()) + ) end) it('fails on ' .. v.name .. ' item with negative l key', function() wshada(v.mpack .. '\000\013\131\162mX\192\161f\196\001/\161l\255') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid line number', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid line number', + exc_exec(sdrcmd()) + ) end) it('fails on ' .. v.name .. ' item with negative c key', function() wshada(v.mpack .. '\000\013\131\162mX\192\161f\196\001/\161c\255') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid column number', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has invalid column number', + exc_exec(sdrcmd()) + ) end) it('fails on ' .. v.name .. ' item with STR n key value', function() wshada(v.mpack .. '\000\011\130\162mX\192\161n\163spa') - eq(is_mark_test and 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has n key value which is not an unsigned integer' or 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has n key which is only valid for local and global mark entries', exc_exec(sdrcmd())) + eq( + is_mark_test + and 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has n key value which is not an unsigned integer' + or 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has n key which is only valid for local and global mark entries', + exc_exec(sdrcmd()) + ) end) it('fails on ' .. v.name .. ' item with STR l key value', function() wshada(v.mpack .. '\000\010\130\162mX\192\161l\162sp') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has l key value which is not an integer', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has l key value which is not an integer', + exc_exec(sdrcmd()) + ) end) it('fails on ' .. v.name .. ' item with STR c key value', function() wshada(v.mpack .. '\000\010\130\162mX\192\161c\162sp') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has c key value which is not an integer', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has c key value which is not an integer', + exc_exec(sdrcmd()) + ) end) it('fails on ' .. v.name .. ' item with STR f key value', function() wshada(v.mpack .. '\000\010\130\162mX\192\161f\162sp') - eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has f key value which is not a binary', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has f key value which is not a binary', + exc_exec(sdrcmd()) + ) end) end it('fails on register item with NIL value', function() wshada('\005\000\001\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 is not a dictionary', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 is not a dictionary', + exc_exec(sdrcmd()) + ) end) -- rc entry is here because it causes an allocation it('fails on register item with BIN key', function() wshada('\005\000\015\131\162rc\145\196\001a\162rX\192\196\000\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has key which is not a string', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has key which is not a string', + exc_exec(sdrcmd()) + ) end) -- rc entry is here because it causes an allocation it('fails on register item with BIN key', function() wshada('\005\000\014\131\162rc\145\196\001a\162rX\192\160\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has empty key', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has empty key', + exc_exec(sdrcmd()) + ) end) it('fails on register item with NIL rt key value', function() wshada('\005\000\009\130\162rX\192\162rt\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rt key value which is not an unsigned integer', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rt key value which is not an unsigned integer', + exc_exec(sdrcmd()) + ) end) it('fails on register item with NIL rw key value', function() wshada('\005\000\009\130\162rX\192\162rw\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rw key value which is not an unsigned integer', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rw key value which is not an unsigned integer', + exc_exec(sdrcmd()) + ) end) it('fails on register item with NIL rc key value', function() wshada('\005\000\009\130\162rX\192\162rc\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc key with non-array value', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc key with non-array value', + exc_exec(sdrcmd()) + ) end) it('fails on register item with empty rc key value', function() wshada('\005\000\009\130\162rX\192\162rc\144') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc key with empty array', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc key with empty array', + exc_exec(sdrcmd()) + ) end) it('fails on register item with NIL in rc array', function() wshada('\005\000\013\130\162rX\192\162rc\146\196\001a\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc array with non-binary value', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rc array with non-binary value', + exc_exec(sdrcmd()) + ) end) it('fails on register item without rc array', function() wshada('\005\000\009\129\162rX\146\196\001a\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has missing rc array', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has missing rc array', + exc_exec(sdrcmd()) + ) end) it('fails on history item with NIL value', function() wshada('\004\000\001\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 is not an array', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 is not an array', + exc_exec(sdrcmd()) + ) end) it('fails on history item with empty value', function() wshada('\004\000\001\144') - eq('Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 does not have enough elements', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 does not have enough elements', + exc_exec(sdrcmd()) + ) end) it('fails on history item with single element value', function() wshada('\004\000\002\145\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 does not have enough elements', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 does not have enough elements', + exc_exec(sdrcmd()) + ) end) it('fails on history item with NIL first item', function() wshada('\004\000\003\146\192\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 has wrong history type type', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 has wrong history type type', + exc_exec(sdrcmd()) + ) end) it('fails on history item with FIXUINT second item', function() wshada('\004\000\003\146\000\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 has wrong history string type', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 has wrong history string type', + exc_exec(sdrcmd()) + ) end) it('fails on history item with second item with zero byte', function() wshada('\004\000\007\146\000\196\003ab\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 contains string with zero byte inside', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: history entry at position 0 contains string with zero byte inside', + exc_exec(sdrcmd()) + ) end) it('fails on search history item without third item', function() wshada('\004\000\007\146\001\196\003abc') - eq('Vim(rshada):E575: Error while reading ShaDa file: search history entry at position 0 does not have separator character', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search history entry at position 0 does not have separator character', + exc_exec(sdrcmd()) + ) end) it('fails on search history item with NIL third item', function() wshada('\004\000\007\147\001\196\002ab\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: search history entry at position 0 has wrong history separator type', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: search history entry at position 0 has wrong history separator type', + exc_exec(sdrcmd()) + ) end) it('fails on variable item with NIL value', function() wshada('\006\000\001\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 is not an array', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 is not an array', + exc_exec(sdrcmd()) + ) end) it('fails on variable item with empty value', function() wshada('\006\000\001\144') - eq('Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 does not have enough elements', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 does not have enough elements', + exc_exec(sdrcmd()) + ) end) it('fails on variable item with single element value', function() wshada('\006\000\002\145\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 does not have enough elements', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 does not have enough elements', + exc_exec(sdrcmd()) + ) end) it('fails on variable item with NIL first item', function() wshada('\006\000\003\146\192\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 has wrong variable name type', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 has wrong variable name type', + exc_exec(sdrcmd()) + ) end) it('fails on variable item with BIN value and type value != VAR_TYPE_BLOB', function() wshada('\006\000\007\147\196\001\065\196\000\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 has wrong variable type', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: variable entry at position 0 has wrong variable type', + exc_exec(sdrcmd()) + ) end) it('fails on replacement item with NIL value', function() wshada('\003\000\001\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 is not an array', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 is not an array', + exc_exec(sdrcmd()) + ) end) it('fails on replacement item with empty value', function() wshada('\003\000\001\144') - eq('Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 does not have enough elements', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 does not have enough elements', + exc_exec(sdrcmd()) + ) end) it('fails on replacement item with NIL first item', function() wshada('\003\000\002\145\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 has wrong sub string type', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: sub string entry at position 0 has wrong sub string type', + exc_exec(sdrcmd()) + ) end) it('fails on buffer list item with NIL value', function() nvim_command('set shada+=%') wshada('\009\000\001\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: buffer list entry at position 0 is not an array', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: buffer list entry at position 0 is not an array', + exc_exec(sdrcmd()) + ) end) it('fails on buffer list item with NIL item in the array', function() nvim_command('set shada+=%') wshada('\009\000\008\146\129\161f\196\001/\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry that is not a dictionary', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry that is not a dictionary', + exc_exec(sdrcmd()) + ) end) it('fails on buffer list item with empty item', function() nvim_command('set shada+=%') wshada('\009\000\008\146\129\161f\196\001/\128') - eq('Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry that does not have a file name', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry that does not have a file name', + exc_exec(sdrcmd()) + ) end) it('fails on buffer list item with NIL l key', function() nvim_command('set shada+=%') wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161l\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: buffer list entry entry at position 0 has l key value which is not an integer', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: buffer list entry entry at position 0 has l key value which is not an integer', + exc_exec(sdrcmd()) + ) end) it('fails on buffer list item with zero l key', function() nvim_command('set shada+=%') wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161l\000') - eq('Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid line number', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid line number', + exc_exec(sdrcmd()) + ) end) it('fails on buffer list item with negative l key', function() nvim_command('set shada+=%') wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161l\255') - eq('Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid line number', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid line number', + exc_exec(sdrcmd()) + ) end) it('fails on buffer list item with negative c key', function() nvim_command('set shada+=%') wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161c\255') - eq('Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid column number', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: buffer list at position 0 contains entry with invalid column number', + exc_exec(sdrcmd()) + ) end) it('fails on buffer list item with NIL c key', function() nvim_command('set shada+=%') wshada('\009\000\017\146\129\161f\196\001/\130\161f\196\002/a\161c\192') - eq('Vim(rshada):E575: Error while reading ShaDa file: buffer list entry entry at position 0 has c key value which is not an integer', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E575: Error while reading ShaDa file: buffer list entry entry at position 0 has c key value which is not an integer', + exc_exec(sdrcmd()) + ) end) it('fails on invalid ShaDa file (viminfo file)', function() @@ -480,40 +688,229 @@ $ + 65 0 + 65 0 ]]) - eq('Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', exc_exec(sdrcmd())) - eq('Vim(wshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', exc_exec('wshada ' .. shada_fname)) + eq( + 'Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', + exc_exec(sdrcmd()) + ) + eq( + 'Vim(wshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', + exc_exec('wshada ' .. shada_fname) + ) eq(0, exc_exec('wshada! ' .. shada_fname)) end) it('fails on invalid ShaDa file (wrapper script)', function() wshada('#!/bin/sh\n\npowerline "$@" 2>&1 | tee -a powerline\n') - eq('Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', exc_exec(sdrcmd())) - eq('Vim(wshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', exc_exec('wshada ' .. shada_fname)) + eq( + 'Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', + exc_exec(sdrcmd()) + ) + eq( + 'Vim(wshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 3', + exc_exec('wshada ' .. shada_fname) + ) eq(0, exc_exec('wshada! ' .. shada_fname)) end) it('fails on invalid ShaDa file (failing skip in second item)', function() wshada('\001\000\001\128#!/') - eq('Vim(rshada):E576: Error while reading ShaDa file: last entry specified that it occupies 47 bytes, but file ended earlier', exc_exec(sdrcmd())) - eq('Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 47 bytes, but file ended earlier', exc_exec('wshada ' .. shada_fname)) + eq( + 'Vim(rshada):E576: Error while reading ShaDa file: last entry specified that it occupies 47 bytes, but file ended earlier', + exc_exec(sdrcmd()) + ) + eq( + 'Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 47 bytes, but file ended earlier', + exc_exec('wshada ' .. shada_fname) + ) eq(0, exc_exec('wshada! ' .. shada_fname)) end) it('errors with too large items', function() wshada({ - 1, 206, 70, 90, 31, 179, 86, 133, 169, 103, 101, 110, 101, 114, 97, - 116, 111, 114, 196, 4, 145, 145, 145, 145, 145, 145, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 145, 145, 145, 145, 111, 110, 196, 25, 78, 86, 73, 77, 32, - 118, 1, 46, 50, 46, 48, 45, 51, 48, 51, 45, 103, 98, 54, 55, - 52, 102, 100, 50, 99, 169, 109, 97, 120, 95, 107, 98, 121, 116, 101, - 10, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, - 207, 207, 207, 207, 207, 207, 207, 207, 16, 8, 206, 89, 90, 30, 253, - 35, 129, 161, 102, 196, 30, 47, 100, 101, 118, 47, 115, 104, 109, 47, - 102, 117, 122, 122, 105, 110, 103, 45, 110, 118, 105, 109, 45, 115, 104, - 97, 100, 97, 47, 108, 115, 2, 206, 89, 90, 30, 251, 13, 130, 162, - 115, 112, 196, 3, 102, 111, 111, 162, 115, 99, 195, 3, 146, 10, 0, + 1, + 206, + 70, + 90, + 31, + 179, + 86, + 133, + 169, + 103, + 101, + 110, + 101, + 114, + 97, + 116, + 111, + 114, + 196, + 4, + 145, + 145, + 145, + 145, + 145, + 145, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 96, + 145, + 145, + 145, + 145, + 111, + 110, + 196, + 25, + 78, + 86, + 73, + 77, + 32, + 118, + 1, + 46, + 50, + 46, + 48, + 45, + 51, + 48, + 51, + 45, + 103, + 98, + 54, + 55, + 52, + 102, + 100, + 50, + 99, + 169, + 109, + 97, + 120, + 95, + 107, + 98, + 121, + 116, + 101, + 10, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 207, + 16, + 8, + 206, + 89, + 90, + 30, + 253, + 35, + 129, + 161, + 102, + 196, + 30, + 47, + 100, + 101, + 118, + 47, + 115, + 104, + 109, + 47, + 102, + 117, + 122, + 122, + 105, + 110, + 103, + 45, + 110, + 118, + 105, + 109, + 45, + 115, + 104, + 97, + 100, + 97, + 47, + 108, + 115, + 2, + 206, + 89, + 90, + 30, + 251, + 13, + 130, + 162, + 115, + 112, + 196, + 3, + 102, + 111, + 111, + 162, + 115, + 99, + 195, + 3, + 146, + 10, + 0, }) - eq('Vim(rshada):E576: Error while reading ShaDa file: there is an item at position 93 that is stated to be too long', exc_exec(sdrcmd())) + eq( + 'Vim(rshada):E576: Error while reading ShaDa file: there is an item at position 93 that is stated to be too long', + exc_exec(sdrcmd()) + ) end) end) diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index cd99d38345..baa27889f3 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -1,10 +1,8 @@ local helpers = require('test.functional.helpers')(nil) -local meths = helpers.meths +local api = helpers.api local write_file = helpers.write_file local concat_tables = helpers.concat_tables -local mpack = require('mpack') - local tmpname = helpers.tmpname() -- o={ @@ -17,19 +15,20 @@ local function reset(o) o = o and o or {} local args_rm = o.args_rm or {} table.insert(args_rm, '-i') - local args={ - '-i', o.shadafile or tmpname, + local args = { + '-i', + o.shadafile or tmpname, } if type(o) == 'string' then - args = concat_tables(args, {'--cmd', o}) + args = concat_tables(args, { '--cmd', o }) elseif o.args then args = concat_tables(args, o.args) end - helpers.clear{ - args_rm=args_rm, - args=args, + helpers.clear { + args_rm = args_rm, + args = args, } - meths.set_var('tmpname', tmpname) + api.nvim_set_var('tmpname', tmpname) end local clear = function() @@ -57,13 +56,13 @@ local get_shada_rw = function(fname) return wshada, sdrcmd, fname, clean end -local mpack_keys = {'type', 'timestamp', 'length', 'value'} +local mpack_keys = { 'type', 'timestamp', 'length', 'value' } local read_shada_file = function(fname) local fd = io.open(fname, 'r') local mstring = fd:read('*a') fd:close() - local unpack = mpack.Unpacker() + local unpack = vim.mpack.Unpacker() local ret = {} local cur, val local i = 0 @@ -81,8 +80,8 @@ local read_shada_file = function(fname) end return { - reset=reset, - clear=clear, - get_shada_rw=get_shada_rw, - read_shada_file=read_shada_file, + reset = reset, + clear = clear, + get_shada_rw = get_shada_rw, + read_shada_file = read_shada_file, } diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 433db3171e..c8a19bb082 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -1,7 +1,7 @@ -- ShaDa history saving/reading support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, meths, nvim_feed, eq = - helpers.command, helpers.funcs, helpers.meths, helpers.feed, helpers.eq +local nvim_command, fn, api, nvim_feed, eq = + helpers.command, helpers.fn, helpers.api, helpers.feed, helpers.eq local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit @@ -13,134 +13,131 @@ describe('ShaDa support code', function() after_each(clear) it('is able to dump and read back command-line history', function() - nvim_command('set shada=\'0') + nvim_command("set shada='0") nvim_feed(':" Test\n') nvim_command('wshada') reset() - nvim_command('set shada=\'0') + nvim_command("set shada='0") nvim_command('rshada') - eq('" Test', funcs.histget(':', -1)) + eq('" Test', fn.histget(':', -1)) end) it('is able to dump and read back 2 items in command-line history', function() - nvim_command('set shada=\'0 history=2') + nvim_command("set shada='0 history=2") nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') expect_exit(nvim_command, 'qall') reset() - nvim_command('set shada=\'0 history=2') + nvim_command("set shada='0 history=2") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('" Test', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('" Test', fn.histget(':', -2)) end) - it('respects &history when dumping', - function() - nvim_command('set shada=\'0 history=1') + it('respects &history when dumping', function() + nvim_command("set shada='0 history=1") nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') nvim_command('wshada') reset() - nvim_command('set shada=\'0 history=2') + nvim_command("set shada='0 history=2") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('', fn.histget(':', -2)) end) - it('respects &history when loading', - function() - nvim_command('set shada=\'0 history=2') + it('respects &history when loading', function() + nvim_command("set shada='0 history=2") nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') nvim_command('wshada') reset() - nvim_command('set shada=\'0 history=1') + nvim_command("set shada='0 history=1") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('', fn.histget(':', -2)) end) it('dumps only requested amount of command-line history items', function() - nvim_command('set shada=\'0,:1') + nvim_command("set shada='0,:1") nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') nvim_command('wshada') -- Regression test: :wshada should not alter or free history. - eq('" Test 2', funcs.histget(':', -1)) - eq('" Test', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('" Test', fn.histget(':', -2)) reset() - nvim_command('set shada=\'0') + nvim_command("set shada='0") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('', fn.histget(':', -2)) end) it('does not respect number in &shada when loading history', function() - nvim_command('set shada=\'0') + nvim_command("set shada='0") nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') nvim_command('wshada') reset() - nvim_command('set shada=\'0,:1') + nvim_command("set shada='0,:1") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('" Test', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('" Test', fn.histget(':', -2)) end) it('dumps and loads all kinds of histories', function() nvim_command('debuggreedy') - nvim_feed(':debug echo "Test"\n" Test 2\nc\n') -- Debug history. - nvim_feed(':call input("")\nTest 2\n') -- Input history. - nvim_feed('"="Test"\nyy') -- Expression history. - nvim_feed('/Test\n') -- Search history - nvim_feed(':" Test\n') -- Command-line history + nvim_feed(':debug echo "Test"\n" Test 2\nc\n') -- Debug history. + nvim_feed(':call input("")\nTest 2\n') -- Input history. + nvim_feed('"="Test"\nyy') -- Expression history. + nvim_feed('/Test\n') -- Search history + nvim_feed(':" Test\n') -- Command-line history nvim_command('0debuggreedy') nvim_command('wshada') reset() nvim_command('rshada') - eq('" Test', funcs.histget(':', -1)) - eq('Test', funcs.histget('/', -1)) - eq('"Test"', funcs.histget('=', -1)) - eq('Test 2', funcs.histget('@', -1)) - eq('c', funcs.histget('>', -1)) + eq('" Test', fn.histget(':', -1)) + eq('Test', fn.histget('/', -1)) + eq('"Test"', fn.histget('=', -1)) + eq('Test 2', fn.histget('@', -1)) + eq('c', fn.histget('>', -1)) end) it('dumps and loads last search pattern with offset', function() - meths.set_option_value('wrapscan', false, {}) - funcs.setline('.', {'foo', 'bar--'}) + api.nvim_set_option_value('wrapscan', false, {}) + fn.setline('.', { 'foo', 'bar--' }) nvim_feed('gg0/a/e+1\n') - eq({0, 2, 3, 0}, funcs.getpos('.')) + eq({ 0, 2, 3, 0 }, fn.getpos('.')) nvim_command('wshada') reset() - meths.set_option_value('wrapscan', false, {}) - funcs.setline('.', {'foo', 'bar--'}) + api.nvim_set_option_value('wrapscan', false, {}) + fn.setline('.', { 'foo', 'bar--' }) nvim_feed('gg0n') - eq({0, 2, 3, 0}, funcs.getpos('.')) - eq(1, meths.get_vvar('searchforward')) + eq({ 0, 2, 3, 0 }, fn.getpos('.')) + eq(1, api.nvim_get_vvar('searchforward')) end) - it('dumps and loads last search pattern with offset and backward direction', - function() - meths.set_option_value('wrapscan', false, {}) - funcs.setline('.', {'foo', 'bar--'}) + it('dumps and loads last search pattern with offset and backward direction', function() + api.nvim_set_option_value('wrapscan', false, {}) + fn.setline('.', { 'foo', 'bar--' }) nvim_feed('G$?a?e+1\n') - eq({0, 2, 3, 0}, funcs.getpos('.')) + eq({ 0, 2, 3, 0 }, fn.getpos('.')) nvim_command('wshada') reset() - meths.set_option_value('wrapscan', false, {}) - funcs.setline('.', {'foo', 'bar--'}) + api.nvim_set_option_value('wrapscan', false, {}) + fn.setline('.', { 'foo', 'bar--' }) nvim_feed('G$n') - eq({0, 2, 3, 0}, funcs.getpos('.')) - eq(0, meths.get_vvar('searchforward')) + eq({ 0, 2, 3, 0 }, fn.getpos('.')) + eq(0, api.nvim_get_vvar('searchforward')) end) it('saves v:hlsearch=1', function() nvim_command('set hlsearch shada-=h') nvim_feed('/test\n') - eq(1, meths.get_vvar('hlsearch')) + eq(1, api.nvim_get_vvar('hlsearch')) expect_exit(nvim_command, 'qall') reset() - eq(1, meths.get_vvar('hlsearch')) + eq(1, api.nvim_get_vvar('hlsearch')) end) it('saves v:hlsearch=0 with :nohl', function() @@ -149,27 +146,27 @@ describe('ShaDa support code', function() nvim_command('nohlsearch') expect_exit(nvim_command, 'qall') reset() - eq(0, meths.get_vvar('hlsearch')) + eq(0, api.nvim_get_vvar('hlsearch')) end) it('saves v:hlsearch=0 with default &shada', function() nvim_command('set hlsearch') nvim_feed('/test\n') - eq(1, meths.get_vvar('hlsearch')) + eq(1, api.nvim_get_vvar('hlsearch')) expect_exit(nvim_command, 'qall') reset() - eq(0, meths.get_vvar('hlsearch')) + eq(0, api.nvim_get_vvar('hlsearch')) end) it('dumps and loads last substitute pattern and replacement string', function() - funcs.setline('.', {'foo', 'bar'}) + fn.setline('.', { 'foo', 'bar' }) nvim_command('%s/f/g/g') - eq('goo', funcs.getline(1)) + eq('goo', fn.getline(1)) nvim_command('wshada') reset() - funcs.setline('.', {'foo', 'bar'}) + fn.setline('.', { 'foo', 'bar' }) nvim_command('&') - eq('goo', funcs.getline(1)) + eq('goo', fn.getline(1)) end) it('dumps and loads history with UTF-8 characters', function() @@ -177,52 +174,48 @@ describe('ShaDa support code', function() nvim_feed(':echo "«"\n') expect_exit(nvim_command, 'qall') reset() - eq('echo "«"', funcs.histget(':', -1)) + eq('echo "«"', fn.histget(':', -1)) end) - it('dumps and loads replacement with UTF-8 characters', - function() + it('dumps and loads replacement with UTF-8 characters', function() nvim_command('substitute/./«/ge') expect_exit(nvim_command, 'qall!') reset() - funcs.setline('.', {'.'}) + fn.setline('.', { '.' }) nvim_command('&') - eq('«', funcs.getline('.')) + eq('«', fn.getline('.')) end) - it('dumps and loads substitute pattern with UTF-8 characters', - function() + it('dumps and loads substitute pattern with UTF-8 characters', function() nvim_command('substitute/«/./ge') expect_exit(nvim_command, 'qall!') reset() - funcs.setline('.', {'«\171'}) + fn.setline('.', { '«\171' }) nvim_command('&') - eq('.\171', funcs.getline('.')) + eq('.\171', fn.getline('.')) end) - it('dumps and loads search pattern with UTF-8 characters', - function() + it('dumps and loads search pattern with UTF-8 characters', function() nvim_command('silent! /«/') nvim_command('set shada+=/0') expect_exit(nvim_command, 'qall!') reset() - funcs.setline('.', {'\171«'}) + fn.setline('.', { '\171«' }) nvim_command('~&') - eq('\171', funcs.getline('.')) - eq('', funcs.histget('/', -1)) + eq('\171', fn.getline('.')) + eq('', fn.histget('/', -1)) end) - it('dumps and loads search pattern with 8-bit single-byte', - function() + it('dumps and loads search pattern with 8-bit single-byte', function() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 nvim_command('silent! /\171/') nvim_command('set shada+=/0') expect_exit(nvim_command, 'qall!') reset() - funcs.setline('.', {'\171«'}) + fn.setline('.', { '\171«' }) nvim_command('~&') - eq('«', funcs.getline('.')) - eq('', funcs.histget('/', -1)) + eq('«', fn.getline('.')) + eq('', fn.histget('/', -1)) end) it('does not crash when dumping last search pattern (#10945)', function() @@ -239,12 +232,11 @@ describe('ShaDa support code', function() end) it('does not crash when number of history save to zero (#11497)', function() - nvim_command('set shada=\'10') + nvim_command("set shada='10") nvim_feed(':" Test\n') nvim_command('wshada') - nvim_command('set shada=\'10,:0') + nvim_command("set shada='10,:0") nvim_command('wshada') assert_alive() end) - end) diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index 7f03022ab8..3f29a02506 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -1,8 +1,6 @@ -- ShaDa marks saving/reading support local helpers = require('test.functional.helpers')(after_each) -local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq = - helpers.meths, helpers.curwinmeths, helpers.curbufmeths, helpers.command, - helpers.funcs, helpers.eq +local api, nvim_command, fn, eq = helpers.api, helpers.command, helpers.fn, helpers.eq local feed = helpers.feed local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture local expect_exit = helpers.expect_exit @@ -11,7 +9,7 @@ local shada_helpers = require('test.functional.shada.helpers') local reset, clear = shada_helpers.reset, shada_helpers.clear local nvim_current_line = function() - return curwinmeths.get_cursor()[1] + return api.nvim_win_get_cursor(0)[1] end describe('ShaDa support code', function() @@ -45,7 +43,7 @@ describe('ShaDa support code', function() reset() nvim_command('rshada') nvim_command('normal! `A') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) nvim_command('normal! `B') eq(2, nvim_current_line()) @@ -63,16 +61,16 @@ describe('ShaDa support code', function() 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() + 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') - reset('set shada=\'0,f0') + reset("set shada='0,f0") nvim_command('language C') nvim_command('normal! `A') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) end) @@ -85,7 +83,7 @@ describe('ShaDa support code', function() reset() nvim_command('edit ' .. testfilename) nvim_command('normal! `a') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) nvim_command('normal! `b') eq(2, nvim_current_line()) @@ -115,12 +113,12 @@ describe('ShaDa support code', function() it('is able to populate v:oldfiles', function() nvim_command('edit ' .. testfilename) - local tf_full = curbufmeths.get_name() + local tf_full = api.nvim_buf_get_name(0) nvim_command('edit ' .. testfilename_2) - local tf_full_2 = curbufmeths.get_name() + local tf_full_2 = api.nvim_buf_get_name(0) expect_exit(nvim_command, 'qall') reset() - local oldfiles = meths.get_vvar('oldfiles') + local oldfiles = api.nvim_get_vvar('oldfiles') table.sort(oldfiles) eq(2, #oldfiles) eq(testfilename, oldfiles[1]:sub(-#testfilename)) @@ -128,7 +126,7 @@ describe('ShaDa support code', function() eq(tf_full, oldfiles[1]) eq(tf_full_2, oldfiles[2]) nvim_command('rshada!') - oldfiles = meths.get_vvar('oldfiles') + oldfiles = api.nvim_get_vvar('oldfiles') table.sort(oldfiles) eq(2, #oldfiles) eq(testfilename, oldfiles[1]:sub(-#testfilename)) @@ -160,13 +158,12 @@ describe('ShaDa support code', function() 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()) + nvim_command('normal! \15') -- <C-o> + eq(testfilename_2, fn.bufname('%')) + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) end) - it('is able to dump and restore jump list with different times (slow!)', - function() + it('is able to dump and restore jump list with different times (slow!)', function() nvim_command('edit ' .. testfilename_2) nvim_command('sleep 2') nvim_command('normal! G') @@ -182,19 +179,19 @@ describe('ShaDa support code', function() reset() nvim_command('redraw') nvim_command('edit ' .. testfilename) - eq(testfilename, funcs.bufname('%')) + eq(testfilename, fn.bufname('%')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\<C-o>"') - eq(testfilename, funcs.bufname('%')) + eq(testfilename, fn.bufname('%')) eq(2, nvim_current_line()) nvim_command('execute "normal! \\<C-o>"') - eq(testfilename_2, funcs.bufname('%')) + eq(testfilename_2, fn.bufname('%')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\<C-o>"') - eq(testfilename_2, funcs.bufname('%')) + eq(testfilename_2, fn.bufname('%')) eq(2, nvim_current_line()) nvim_command('execute "normal! \\<C-o>"') - eq(testfilename_2, funcs.bufname('%')) + eq(testfilename_2, fn.bufname('%')) eq(2, nvim_current_line()) end) @@ -218,35 +215,41 @@ describe('ShaDa support code', function() -- -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() - local argv = helpers.new_argv{ - args_rm={ + it('does not create incorrect file for non-existent buffers when writing from -c', function() + local argv = helpers.new_argv { + args_rm = { '-i', - '--embed', -- no --embed + '--embed', -- no --embed + }, + args = { + '-i', + api.nvim_get_var('tmpname'), -- Use same shada file as parent. + '--cmd', + 'silent edit ' .. non_existent_testfilename, + '-c', + 'qall', }, - args={ - '-i', meths.get_var('tmpname'), -- Use same shada file as parent. - '--cmd', 'silent edit '..non_existent_testfilename, - '-c', 'qall'}, } - eq('', funcs.system(argv)) + eq('', fn.system(argv)) eq(0, exc_exec('rshada')) end) - it('does not create incorrect file for non-existent buffers opened from -c', - function() - local argv = helpers.new_argv{ - args_rm={ + it('does not create incorrect file for non-existent buffers opened from -c', function() + local argv = helpers.new_argv { + args_rm = { + '-i', + '--embed', -- no --embed + }, + args = { '-i', - '--embed', -- no --embed + api.nvim_get_var('tmpname'), -- Use same shada file as parent. + '-c', + 'silent edit ' .. non_existent_testfilename, + '-c', + 'autocmd VimEnter * qall', }, - args={ - '-i', meths.get_var('tmpname'), -- Use same shada file as parent. - '-c', 'silent edit '..non_existent_testfilename, - '-c', 'autocmd VimEnter * qall'}, } - eq('', funcs.system(argv)) + eq('', fn.system(argv)) eq(0, exc_exec('rshada')) end) diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index dad7aa851d..1b5c0eab5d 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -1,17 +1,15 @@ -- ShaDa merging data support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, curbufmeths, eq = - helpers.command, helpers.funcs, - helpers.curbufmeths, helpers.eq +local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture +local api = helpers.api local shada_helpers = require('test.functional.shada.helpers') local reset, clear, get_shada_rw = shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw local read_shada_file = shada_helpers.read_shada_file -local wshada, sdrcmd, shada_fname = - get_shada_rw('Xtest-functional-shada-merging.shada') +local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-merging.shada') local mock_file_path = '/a/b/' if helpers.is_os('win') then @@ -25,8 +23,7 @@ describe('ShaDa history merging code', function() os.remove(shada_fname) end) - it('takes item with greater timestamp from Neovim instance when reading', - function() + it('takes item with greater timestamp from Neovim instance when reading', function() wshada('\004\001\009\147\000\196\002ab\196\001a') eq(0, exc_exec(sdrcmd())) wshada('\004\000\009\147\000\196\002ab\196\001b') @@ -44,8 +41,7 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('takes item with equal timestamp from Neovim instance when reading', - function() + it('takes item with equal timestamp from Neovim instance when reading', function() wshada('\004\000\009\147\000\196\002ab\196\001a') eq(0, exc_exec(sdrcmd())) wshada('\004\000\009\147\000\196\002ab\196\001b') @@ -63,8 +59,7 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('takes item with greater timestamp from ShaDa when reading', - function() + it('takes item with greater timestamp from ShaDa when reading', function() wshada('\004\000\009\147\000\196\002ab\196\001a') eq(0, exc_exec(sdrcmd())) wshada('\004\001\009\147\000\196\002ab\196\001b') @@ -82,8 +77,7 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('takes item with greater timestamp from Neovim instance when writing', - function() + it('takes item with greater timestamp from Neovim instance when writing', function() wshada('\004\001\009\147\000\196\002ab\196\001a') eq(0, exc_exec(sdrcmd())) wshada('\004\000\009\147\000\196\002ab\196\001b') @@ -99,8 +93,7 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('takes item with equal timestamp from Neovim instance when writing', - function() + it('takes item with equal timestamp from Neovim instance when writing', function() wshada('\004\000\009\147\000\196\002ab\196\001a') eq(0, exc_exec(sdrcmd())) wshada('\004\000\009\147\000\196\002ab\196\001b') @@ -116,8 +109,7 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('takes item with greater timestamp from ShaDa when writing', - function() + it('takes item with greater timestamp from ShaDa when writing', function() wshada('\004\000\009\147\000\196\002ab\196\001a') eq(0, exc_exec(sdrcmd())) wshada('\004\001\009\147\000\196\002ab\196\001b') @@ -133,20 +125,20 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('correctly reads history items with messed up timestamps', - function() - wshada('\004\010\009\147\000\196\002ab\196\001a' - .. '\004\010\009\147\000\196\002ac\196\001a' - .. '\004\005\009\147\000\196\002ad\196\001a' - .. '\004\100\009\147\000\196\002ae\196\001a' - .. '\004\090\009\147\000\196\002af\196\001a' - ) + it('correctly reads history items with messed up timestamps', function() + wshada( + '\004\010\009\147\000\196\002ab\196\001a' + .. '\004\010\009\147\000\196\002ac\196\001a' + .. '\004\005\009\147\000\196\002ad\196\001a' + .. '\004\100\009\147\000\196\002ae\196\001a' + .. '\004\090\009\147\000\196\002af\196\001a' + ) eq(0, exc_exec(sdrcmd())) os.remove(shada_fname) eq(0, exc_exec('wshada! ' .. shada_fname)) - local items = {'ad', 'ab', 'ac', 'af', 'ae'} + local items = { 'ad', 'ab', 'ac', 'af', 'ae' } for i, v in ipairs(items) do - eq(v, funcs.histget(':', i)) + eq(v, fn.histget(':', i)) end local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -159,16 +151,16 @@ describe('ShaDa history merging code', function() eq(#items, found) end) - it('correctly reorders history items with messed up timestamps when writing', - function() - wshada('\004\010\009\147\000\196\002ab\196\001a' - .. '\004\010\009\147\000\196\002ac\196\001a' - .. '\004\005\009\147\000\196\002ad\196\001a' - .. '\004\100\009\147\000\196\002ae\196\001a' - .. '\004\090\009\147\000\196\002af\196\001a' - ) + it('correctly reorders history items with messed up timestamps when writing', function() + wshada( + '\004\010\009\147\000\196\002ab\196\001a' + .. '\004\010\009\147\000\196\002ac\196\001a' + .. '\004\005\009\147\000\196\002ad\196\001a' + .. '\004\100\009\147\000\196\002ae\196\001a' + .. '\004\090\009\147\000\196\002af\196\001a' + ) eq(0, exc_exec('wshada ' .. shada_fname)) - local items = {'ad', 'ab', 'ac', 'af', 'ae'} + local items = { 'ad', 'ab', 'ac', 'af', 'ae' } local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == 4 and v.value[1] == 0 then @@ -180,24 +172,24 @@ describe('ShaDa history merging code', function() eq(#items, found) end) - it('correctly merges history items with duplicate mid entry when writing', - function() + it('correctly merges history items with duplicate mid entry when writing', function() -- Regression test: ShaDa code used to crash here. -- Conditions: -- 1. Entry which is duplicate to non-last entry. -- 2. At least one more non-duplicate entry. - wshada('\004\000\009\147\000\196\002ab\196\001a' - .. '\004\001\009\147\000\196\002ac\196\001a' - .. '\004\002\009\147\000\196\002ad\196\001a' - .. '\004\003\009\147\000\196\002ac\196\001a' - .. '\004\004\009\147\000\196\002af\196\001a' - .. '\004\005\009\147\000\196\002ae\196\001a' - .. '\004\006\009\147\000\196\002ag\196\001a' - .. '\004\007\009\147\000\196\002ah\196\001a' - .. '\004\008\009\147\000\196\002ai\196\001a' - ) + wshada( + '\004\000\009\147\000\196\002ab\196\001a' + .. '\004\001\009\147\000\196\002ac\196\001a' + .. '\004\002\009\147\000\196\002ad\196\001a' + .. '\004\003\009\147\000\196\002ac\196\001a' + .. '\004\004\009\147\000\196\002af\196\001a' + .. '\004\005\009\147\000\196\002ae\196\001a' + .. '\004\006\009\147\000\196\002ag\196\001a' + .. '\004\007\009\147\000\196\002ah\196\001a' + .. '\004\008\009\147\000\196\002ai\196\001a' + ) eq(0, exc_exec('wshada ' .. shada_fname)) - local items = {'ab', 'ad', 'ac', 'af', 'ae', 'ag', 'ah', 'ai'} + local items = { 'ab', 'ad', 'ac', 'af', 'ae', 'ag', 'ah', 'ai' } local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == 4 and v.value[1] == 0 then @@ -209,20 +201,20 @@ describe('ShaDa history merging code', function() eq(#items, found) end) - it('correctly merges history items with duplicate adj entry when writing', - function() - wshada('\004\000\009\147\000\196\002ab\196\001a' - .. '\004\001\009\147\000\196\002ac\196\001a' - .. '\004\002\009\147\000\196\002ad\196\001a' - .. '\004\003\009\147\000\196\002ad\196\001a' - .. '\004\004\009\147\000\196\002af\196\001a' - .. '\004\005\009\147\000\196\002ae\196\001a' - .. '\004\006\009\147\000\196\002ag\196\001a' - .. '\004\007\009\147\000\196\002ah\196\001a' - .. '\004\008\009\147\000\196\002ai\196\001a' - ) + it('correctly merges history items with duplicate adj entry when writing', function() + wshada( + '\004\000\009\147\000\196\002ab\196\001a' + .. '\004\001\009\147\000\196\002ac\196\001a' + .. '\004\002\009\147\000\196\002ad\196\001a' + .. '\004\003\009\147\000\196\002ad\196\001a' + .. '\004\004\009\147\000\196\002af\196\001a' + .. '\004\005\009\147\000\196\002ae\196\001a' + .. '\004\006\009\147\000\196\002ag\196\001a' + .. '\004\007\009\147\000\196\002ah\196\001a' + .. '\004\008\009\147\000\196\002ai\196\001a' + ) eq(0, exc_exec('wshada ' .. shada_fname)) - local items = {'ab', 'ac', 'ad', 'af', 'ae', 'ag', 'ah', 'ai'} + local items = { 'ab', 'ac', 'ad', 'af', 'ae', 'ag', 'ah', 'ai' } local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == 4 and v.value[1] == 0 then @@ -242,48 +234,43 @@ describe('ShaDa search pattern support code', function() os.remove(shada_fname) end) - it('uses last search pattern with gt timestamp from instance when reading', - function() + it('uses last search pattern with gt timestamp from instance when reading', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) end) - it('uses last search pattern with gt tstamp from file when reading with bang', - function() + it('uses last search pattern with gt tstamp from file when reading with bang', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', funcs.getreg('/')) + eq('?', fn.getreg('/')) end) - it('uses last search pattern with eq timestamp from instance when reading', - function() + it('uses last search pattern with eq timestamp from instance when reading', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) end) - it('uses last search pattern with gt timestamp from file when reading', - function() + it('uses last search pattern with gt timestamp from file when reading', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', funcs.getreg('/')) + eq('?', fn.getreg('/')) end) - it('uses last search pattern with gt timestamp from instance when writing', - function() + it('uses last search pattern with gt timestamp from instance when writing', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162sX\194\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -294,12 +281,11 @@ describe('ShaDa search pattern support code', function() eq(1, found) end) - it('uses last search pattern with eq timestamp from instance when writing', - function() + it('uses last search pattern with eq timestamp from instance when writing', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162sX\194\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -310,12 +296,11 @@ describe('ShaDa search pattern support code', function() eq(1, found) end) - it('uses last search pattern with gt timestamp from file when writing', - function() + it('uses last search pattern with gt timestamp from file when writing', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162sX\194\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -326,48 +311,43 @@ describe('ShaDa search pattern support code', function() eq(1, found) end) - it('uses last s/ pattern with gt timestamp from instance when reading', - function() + it('uses last s/ pattern with gt timestamp from instance when reading', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) end) - it('uses last s/ pattern with gt timestamp from file when reading with !', - function() + it('uses last s/ pattern with gt timestamp from file when reading with !', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', funcs.getreg('/')) + eq('?', fn.getreg('/')) end) - it('uses last s/ pattern with eq timestamp from instance when reading', - function() + it('uses last s/ pattern with eq timestamp from instance when reading', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) end) - it('uses last s/ pattern with gt timestamp from file when reading', - function() + it('uses last s/ pattern with gt timestamp from file when reading', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', funcs.getreg('/')) + eq('?', fn.getreg('/')) end) - it('uses last s/ pattern with gt timestamp from instance when writing', - function() + it('uses last s/ pattern with gt timestamp from instance when writing', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162ss\195\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -378,12 +358,11 @@ describe('ShaDa search pattern support code', function() eq(1, found) end) - it('uses last s/ pattern with eq timestamp from instance when writing', - function() + it('uses last s/ pattern with eq timestamp from instance when writing', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162ss\195\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -394,12 +373,11 @@ describe('ShaDa search pattern support code', function() eq(1, found) end) - it('uses last s/ pattern with gt timestamp from file when writing', - function() + it('uses last s/ pattern with gt timestamp from file when writing', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162ss\195\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -418,52 +396,47 @@ describe('ShaDa replacement string support code', function() os.remove(shada_fname) end) - it('uses last replacement with gt timestamp from instance when reading', - function() + it('uses last replacement with gt timestamp from instance when reading', function() wshada('\003\001\004\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\003\000\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) nvim_command('bwipeout!') end) - it('uses last replacement with gt timestamp from file when reading with bang', - function() + it('uses last replacement with gt timestamp from file when reading with bang', function() wshada('\003\001\004\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\003\000\004\145\196\001?') eq(0, exc_exec(sdrcmd(true))) nvim_command('s/.*/~') - eq('?', funcs.getline('.')) + eq('?', fn.getline('.')) nvim_command('bwipeout!') end) - it('uses last replacement with eq timestamp from instance when reading', - function() + it('uses last replacement with eq timestamp from instance when reading', function() wshada('\003\001\004\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\003\001\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) nvim_command('bwipeout!') end) - it('uses last replacement with gt timestamp from file when reading', - function() + it('uses last replacement with gt timestamp from file when reading', function() wshada('\003\001\004\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\003\002\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('?', funcs.getline('.')) + eq('?', fn.getline('.')) nvim_command('bwipeout!') end) - it('uses last replacement with gt timestamp from instance when writing', - function() + it('uses last replacement with gt timestamp from instance when writing', function() wshada('\003\001\004\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\003\000\004\145\196\001?') @@ -477,8 +450,7 @@ describe('ShaDa replacement string support code', function() eq(1, found) end) - it('uses last replacement with eq timestamp from instance when writing', - function() + it('uses last replacement with eq timestamp from instance when writing', function() wshada('\003\001\004\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\003\001\004\145\196\001?') @@ -492,8 +464,7 @@ describe('ShaDa replacement string support code', function() eq(1, found) end) - it('uses last replacement with gt timestamp from file when writing', - function() + it('uses last replacement with gt timestamp from file when writing', function() wshada('\003\001\004\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\003\002\004\145\196\001?') @@ -515,21 +486,20 @@ describe('ShaDa marks support code', function() os.remove(shada_fname) end) - it('uses last A mark with gt timestamp from instance when reading', - function() + it('uses last A mark with gt timestamp from instance when reading', function() wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA') eq(0, exc_exec(sdrcmd())) wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) it('can merge with file with mark 9 as the only numeric mark', function() wshada('\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `9oabc') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -538,37 +508,66 @@ describe('ShaDa marks support code', function() found[name] = (found[name] or 0) + 1 end end - eq({['0']=1, ['1']=1}, found) + eq({ ['0'] = 1, ['1'] = 1 }, found) end) it('removes duplicates while merging', function() - wshada('\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9' - .. '\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9') + wshada( + '\007\001\014\130\161f\196\006' + .. mock_file_path + .. '-\161n9' + .. '\007\001\014\130\161f\196\006' + .. mock_file_path + .. '-\161n9' + ) eq(0, exc_exec(sdrcmd())) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == 7 and v.value.f == mock_file_path .. '-' then - print(require('test.helpers').format_luav(v)) + print(require('test.format_string').format_luav(v)) found = found + 1 end end eq(1, found) end) - it('does not leak when no append is performed due to too many marks', - function() - wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'a\161n0' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'b\161n1' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161n2' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'd\161n3' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'e\161n4' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'f\161n5' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'g\161n6' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'h\161n7' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'i\161n8' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'j\161n9' - .. '\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'k\161n9') + it('does not leak when no append is performed due to too many marks', function() + wshada( + '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'a\161n0' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'b\161n1' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161n2' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'd\161n3' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'e\161n4' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'f\161n5' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'g\161n6' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'h\161n7' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'i\161n8' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'j\161n9' + .. '\007\001\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'k\161n9' + ) eq(0, exc_exec(sdrcmd())) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} @@ -577,22 +576,45 @@ describe('ShaDa marks support code', function() found[#found + 1] = v.value.f:sub(#v.value.f) end end - eq({'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}, found) - end) - - it('does not leak when last mark in file removes some of the earlier ones', - function() - wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'a\161n0' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'b\161n1' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161n2' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'd\161n3' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'e\161n4' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'f\161n5' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'g\161n6' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'h\161n7' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'i\161n8' - .. '\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'j\161n9' - .. '\007\003\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'k\161n9') + eq({ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }, found) + end) + + it('does not leak when last mark in file removes some of the earlier ones', function() + wshada( + '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'a\161n0' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'b\161n1' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161n2' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'd\161n3' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'e\161n4' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'f\161n5' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'g\161n6' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'h\161n7' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'i\161n8' + .. '\007\002\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'j\161n9' + .. '\007\003\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'k\161n9' + ) eq(0, exc_exec(sdrcmd())) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} @@ -601,46 +623,42 @@ describe('ShaDa marks support code', function() found[#found + 1] = v.value.f:sub(#v.value.f) end end - eq({'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k'}, found) + eq({ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k' }, found) end) - it('uses last A mark with gt timestamp from file when reading with !', - function() + it('uses last A mark with gt timestamp from file when reading with !', function() wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA') eq(0, exc_exec(sdrcmd())) wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd(true))) nvim_command('normal! `A') - eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('?', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) - it('uses last A mark with eq timestamp from instance when reading', - function() + it('uses last A mark with eq timestamp from instance when reading', function() wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA') eq(0, exc_exec(sdrcmd())) wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) - it('uses last A mark with gt timestamp from file when reading', - function() + it('uses last A mark with gt timestamp from file when reading', function() wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA') eq(0, exc_exec(sdrcmd())) wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('?', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) - it('uses last A mark with gt timestamp from instance when writing', - function() + it('uses last A mark with gt timestamp from instance when writing', function() wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA') eq(0, exc_exec(sdrcmd())) wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -649,16 +667,15 @@ describe('ShaDa marks support code', function() found[name] = (found[name] or 0) + 1 end end - eq({['0']=1, A=1}, found) + eq({ ['0'] = 1, A = 1 }, found) end) - it('uses last A mark with eq timestamp from instance when writing', - function() + it('uses last A mark with eq timestamp from instance when writing', function() wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '-\161nA') eq(0, exc_exec(sdrcmd())) wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -667,7 +684,7 @@ describe('ShaDa marks support code', function() found[name] = (found[name] or 0) + 1 end end - eq({['0']=1, A=1}, found) + eq({ ['0'] = 1, A = 1 }, found) end) it('uses last A mark with gt timestamp from file when writing', function() @@ -675,7 +692,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -686,70 +703,69 @@ describe('ShaDa marks support code', function() found[name] = t end end - eq({['0']={[mock_file_path .. '-']=1}, A={[mock_file_path .. '?']=1}}, found) + eq({ ['0'] = { [mock_file_path .. '-'] = 1 }, A = { [mock_file_path .. '?'] = 1 } }, found) end) - it('uses last a mark with gt timestamp from instance when reading', - function() + it('uses last a mark with gt timestamp from instance when reading', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, {'-', '?'}) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) end) - it('uses last a mark with gt timestamp from file when reading with !', - function() + it('uses last a mark with gt timestamp from file when reading with !', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, {'-', '?'}) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd(true))) nvim_command('normal! `a') - eq('?', funcs.getline('.')) + eq('?', fn.getline('.')) end) - it('uses last a mark with eq timestamp from instance when reading', - function() + it('uses last a mark with eq timestamp from instance when reading', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, {'-', '?'}) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) end) - it('uses last a mark with gt timestamp from file when reading', - function() + it('uses last a mark with gt timestamp from file when reading', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, {'-', '?'}) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('?', funcs.getline('.')) + eq('?', fn.getline('.')) end) - it('uses last a mark with gt timestamp from instance when writing', - function() + it('uses last a mark with gt timestamp from instance when writing', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, {'-', '?'}) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') nvim_command('normal! `a') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do - if v.type == 10 and v.value.f == '' .. mock_file_path .. '-' and v.value.n == ('a'):byte() then + if + v.type == 10 + and v.value.f == '' .. mock_file_path .. '-' + and v.value.n == ('a'):byte() + then eq(true, v.value.l == 1 or v.value.l == nil) found = found + 1 end @@ -757,19 +773,22 @@ describe('ShaDa marks support code', function() eq(1, found) end) - it('uses last a mark with eq timestamp from instance when writing', - function() + it('uses last a mark with eq timestamp from instance when writing', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, {'-', '?'}) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') nvim_command('normal! `a') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do - if v.type == 10 and v.value.f == '' .. mock_file_path .. '-' and v.value.n == ('a'):byte() then + if + v.type == 10 + and v.value.f == '' .. mock_file_path .. '-' + and v.value.n == ('a'):byte() + then eq(true, v.value.l == 1 or v.value.l == nil) found = found + 1 end @@ -777,19 +796,22 @@ describe('ShaDa marks support code', function() eq(1, found) end) - it('uses last a mark with gt timestamp from file when writing', - function() + it('uses last a mark with gt timestamp from file when writing', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, {'-', '?'}) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') nvim_command('normal! `a') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do - if v.type == 10 and v.value.f == '' .. mock_file_path .. '-' and v.value.n == ('a'):byte() then + if + v.type == 10 + and v.value.f == '' .. mock_file_path .. '-' + and v.value.n == ('a'):byte() + then eq(2, v.value.l) found = found + 1 end @@ -805,87 +827,80 @@ describe('ShaDa registers support code', function() os.remove(shada_fname) end) - it('uses last a register with gt timestamp from instance when reading', - function() + it('uses last a register with gt timestamp from instance when reading', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) end) - it('uses last a register with gt timestamp from file when reading with !', - function() + it('uses last a register with gt timestamp from file when reading with !', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', funcs.getreg('a')) + eq('?', fn.getreg('a')) end) - it('uses last a register with eq timestamp from instance when reading', - function() + it('uses last a register with eq timestamp from instance when reading', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) end) - it('uses last a register with gt timestamp from file when reading', - function() + it('uses last a register with gt timestamp from file when reading', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', funcs.getreg('a')) + eq('?', fn.getreg('a')) end) - it('uses last a register with gt timestamp from instance when writing', - function() + it('uses last a register with gt timestamp from instance when writing', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?') - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == 5 and v.value.n == ('a'):byte() then - eq({'-'}, v.value.rc) + eq({ '-' }, v.value.rc) found = found + 1 end end eq(1, found) end) - it('uses last a register with eq timestamp from instance when writing', - function() + it('uses last a register with eq timestamp from instance when writing', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?') - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == 5 and v.value.n == ('a'):byte() then - eq({'-'}, v.value.rc) + eq({ '-' }, v.value.rc) found = found + 1 end end eq(1, found) end) - it('uses last a register with gt timestamp from file when writing', - function() + it('uses last a register with gt timestamp from file when writing', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?') - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == 5 and v.value.n == ('a'):byte() then - eq({'?'}, v.value.rc) + eq({ '?' }, v.value.rc) found = found + 1 end end @@ -901,39 +916,84 @@ describe('ShaDa jumps support code', function() end) it('merges jumps when reading', function() - wshada('\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002' - .. '\008\004\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'd\161l\002' - .. '\008\007\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'e\161l\002') - eq(0, exc_exec(sdrcmd())) - wshada('\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002' - .. '\008\004\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'd\161l\003' - .. '\008\007\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'f\161l\002') - eq(0, exc_exec(sdrcmd())) - eq('', curbufmeths.get_name()) - eq( ' jump line col file/text\n' - .. ' 5 2 0 ' .. mock_file_path .. 'c\n' - .. ' 4 2 0 ' .. mock_file_path .. 'd\n' - .. ' 3 3 0 ' .. mock_file_path .. 'd\n' - .. ' 2 2 0 ' .. mock_file_path .. 'e\n' - .. ' 1 2 0 ' .. mock_file_path .. 'f\n' - .. '>', exec_capture('jumps')) + wshada( + '\008\001\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\002' + .. '\008\004\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'd\161l\002' + .. '\008\007\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'e\161l\002' + ) + eq(0, exc_exec(sdrcmd())) + wshada( + '\008\001\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\002' + .. '\008\004\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'd\161l\003' + .. '\008\007\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'f\161l\002' + ) + eq(0, exc_exec(sdrcmd())) + eq('', api.nvim_buf_get_name(0)) + eq( + ' jump line col file/text\n' + .. ' 5 2 0 ' + .. mock_file_path + .. 'c\n' + .. ' 4 2 0 ' + .. mock_file_path + .. 'd\n' + .. ' 3 3 0 ' + .. mock_file_path + .. 'd\n' + .. ' 2 2 0 ' + .. mock_file_path + .. 'e\n' + .. ' 1 2 0 ' + .. mock_file_path + .. 'f\n' + .. '>', + exec_capture('jumps') + ) end) it('merges jumps when writing', function() - wshada('\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002' - .. '\008\004\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'd\161l\002' - .. '\008\007\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'e\161l\002') - eq(0, exc_exec(sdrcmd())) - wshada('\008\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002' - .. '\008\004\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'd\161l\003' - .. '\008\007\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'f\161l\002') + wshada( + '\008\001\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\002' + .. '\008\004\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'd\161l\002' + .. '\008\007\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'e\161l\002' + ) + eq(0, exc_exec(sdrcmd())) + wshada( + '\008\001\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\002' + .. '\008\004\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'd\161l\003' + .. '\008\007\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'f\161l\002' + ) eq(0, exc_exec('wshada ' .. shada_fname)) local jumps = { - {file='' .. mock_file_path .. 'c', line=2}, - {file='' .. mock_file_path .. 'd', line=2}, - {file='' .. mock_file_path .. 'd', line=3}, - {file='' .. mock_file_path .. 'e', line=2}, - {file='' .. mock_file_path .. 'f', line=2}, + { file = '' .. mock_file_path .. 'c', line = 2 }, + { file = '' .. mock_file_path .. 'd', line = 2 }, + { file = '' .. mock_file_path .. 'd', line = 3 }, + { file = '' .. mock_file_path .. 'e', line = 2 }, + { file = '' .. mock_file_path .. 'f', line = 2 }, } local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -949,25 +1009,28 @@ describe('ShaDa jumps support code', function() it('merges JUMPLISTSIZE jumps when writing', function() local jumps = {} local shada = '' - for i = 1,100 do - shada = shada .. ('\008%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c' - ):format(i, i) - jumps[i] = {file='' .. mock_file_path .. 'c', line=i} + for i = 1, 100 do + shada = shada + .. ('\008%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c'):format(i, i) + jumps[i] = { file = '' .. mock_file_path .. 'c', line = i } end wshada(shada) eq(0, exc_exec(sdrcmd())) shada = '' - for i = 1,101 do + for i = 1, 101 do local t = i * 2 - shada = shada .. ( - '\008\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c' - ):format(t, t) - jumps[(t > #jumps + 1) and (#jumps + 1) or t] = {file='' .. mock_file_path .. 'c', line=t} + shada = shada + .. ('\008\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format( + t, + t + ) + jumps[(t > #jumps + 1) and (#jumps + 1) or t] = + { file = '' .. mock_file_path .. 'c', line = t } end wshada(shada) eq(0, exc_exec('wshada ' .. shada_fname)) local shift = #jumps - 100 - for i = 1,100 do + for i = 1, 100 do jumps[i] = jumps[i + shift] end local found = 0 @@ -992,40 +1055,75 @@ describe('ShaDa changes support code', function() it('merges changes when reading', function() nvim_command('edit ' .. mock_file_path .. 'c') nvim_command('keepjumps call setline(1, range(7))') - wshada('\011\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\001' - .. '\011\004\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002' - .. '\011\007\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\003') - eq(0, exc_exec(sdrcmd())) - wshada('\011\001\018\131\162mX\194\161f\196\006' .. mock_file_path .. 'c\161l\001' - .. '\011\004\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\005' - .. '\011\008\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\004') - eq(0, exc_exec(sdrcmd())) - eq( 'change line col text\n' - .. ' 5 1 0 0\n' - .. ' 4 2 0 1\n' - .. ' 3 5 0 4\n' - .. ' 2 3 0 2\n' - .. ' 1 4 0 3\n' - .. '>', exec_capture('changes')) + wshada( + '\011\001\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\001' + .. '\011\004\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\002' + .. '\011\007\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\003' + ) + eq(0, exc_exec(sdrcmd())) + wshada( + '\011\001\018\131\162mX\194\161f\196\006' + .. mock_file_path + .. 'c\161l\001' + .. '\011\004\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\005' + .. '\011\008\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\004' + ) + eq(0, exc_exec(sdrcmd())) + eq( + 'change line col text\n' + .. ' 5 1 0 0\n' + .. ' 4 2 0 1\n' + .. ' 3 5 0 4\n' + .. ' 2 3 0 2\n' + .. ' 1 4 0 3\n' + .. '>', + exec_capture('changes') + ) end) it('merges changes when writing', function() nvim_command('edit ' .. mock_file_path .. 'c') nvim_command('keepjumps call setline(1, range(7))') - wshada('\011\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\001' - .. '\011\004\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\002' - .. '\011\007\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\003') - eq(0, exc_exec(sdrcmd())) - wshada('\011\001\018\131\162mX\194\161f\196\006' .. mock_file_path .. 'c\161l\001' - .. '\011\004\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\005' - .. '\011\008\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\004') + wshada( + '\011\001\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\001' + .. '\011\004\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\002' + .. '\011\007\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\003' + ) + eq(0, exc_exec(sdrcmd())) + wshada( + '\011\001\018\131\162mX\194\161f\196\006' + .. mock_file_path + .. 'c\161l\001' + .. '\011\004\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\005' + .. '\011\008\018\131\162mX\195\161f\196\006' + .. mock_file_path + .. 'c\161l\004' + ) eq(0, exc_exec('wshada ' .. shada_fname)) local changes = { - {line=1}, - {line=2}, - {line=5}, - {line=3}, - {line=4}, + { line = 1 }, + { line = 2 }, + { line = 5 }, + { line = 3 }, + { line = 4 }, } local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -1042,25 +1140,27 @@ describe('ShaDa changes support code', function() nvim_command('keepjumps call setline(1, range(202))') local changes = {} local shada = '' - for i = 1,100 do - shada = shada .. ('\011%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c' - ):format(i, i) - changes[i] = {line=i} + for i = 1, 100 do + shada = shada + .. ('\011%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c'):format(i, i) + changes[i] = { line = i } end wshada(shada) eq(0, exc_exec(sdrcmd())) shada = '' - for i = 1,101 do + for i = 1, 101 do local t = i * 2 - shada = shada .. ( - '\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c' - ):format(t, t) - changes[(t > #changes + 1) and (#changes + 1) or t] = {line=t} + shada = shada + .. ('\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format( + t, + t + ) + changes[(t > #changes + 1) and (#changes + 1) or t] = { line = t } end wshada(shada) eq(0, exc_exec('wshada ' .. shada_fname)) local shift = #changes - 100 - for i = 1,100 do + for i = 1, 100 do changes[i] = changes[i + shift] end local found = 0 @@ -1073,36 +1173,37 @@ describe('ShaDa changes support code', function() eq(found, 100) end) - it('merges JUMPLISTSIZE changes when writing, with new items between old', - function() + it('merges JUMPLISTSIZE changes when writing, with new items between old', function() nvim_command('edit ' .. mock_file_path .. 'c') nvim_command('keepjumps call setline(1, range(202))') local shada = '' - for i = 1,101 do + for i = 1, 101 do local t = i * 2 - shada = shada .. ( - '\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c' - ):format(t, t) + shada = shada + .. ('\011\204%c\019\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l\204%c'):format( + t, + t + ) end wshada(shada) eq(0, exc_exec(sdrcmd())) shada = '' - for i = 1,100 do - shada = shada .. ('\011%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c' - ):format(i, i) + for i = 1, 100 do + shada = shada + .. ('\011%c\018\131\162mX\195\161f\196\006' .. mock_file_path .. 'c\161l%c'):format(i, i) end local changes = {} for i = 1, 100 do - changes[i] = {line=i} + changes[i] = { line = i } end for i = 1, 101 do local t = i * 2 - changes[(t > #changes + 1) and (#changes + 1) or t] = {line=t} + changes[(t > #changes + 1) and (#changes + 1) or t] = { line = t } end wshada(shada) eq(0, exc_exec('wshada ' .. shada_fname)) local shift = #changes - 100 - for i = 1,100 do + for i = 1, 100 do changes[i] = changes[i + shift] end local found = 0 diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua index 6aaa54cce8..ef15ab9a05 100644 --- a/test/functional/shada/registers_spec.lua +++ b/test/functional/shada/registers_spec.lua @@ -1,6 +1,6 @@ -- ShaDa registers saving/reading support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq +local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq local shada_helpers = require('test.functional.shada.helpers') local reset, clear = shada_helpers.reset, shada_helpers.clear @@ -8,15 +8,15 @@ local expect_exit = helpers.expect_exit local setreg = function(name, contents, typ) if type(contents) == 'string' then - contents = {contents} + contents = { contents } end - funcs.setreg(name, contents, typ) + fn.setreg(name, contents, typ) end local getreg = function(name) return { - funcs.getreg(name, 1, 1), - funcs.getregtype(name), + fn.getreg(name, 1, 1), + fn.getregtype(name), } end @@ -25,159 +25,154 @@ describe('ShaDa support code', function() after_each(clear) it('is able to dump and restore registers and their type', function() - setreg('c', {'d', 'e', ''}, 'c') - setreg('l', {'a', 'b', 'cde'}, 'l') - setreg('b', {'bca', 'abc', 'cba'}, 'b3') + setreg('c', { 'd', 'e', '' }, 'c') + setreg('l', { 'a', 'b', 'cde' }, 'l') + setreg('b', { 'bca', 'abc', 'cba' }, 'b3') expect_exit(nvim_command, 'qall') reset() - eq({{'d', 'e', ''}, 'v'}, getreg('c')) - eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) - eq({{'bca', 'abc', 'cba'}, '\0223'}, getreg('b')) + eq({ { 'd', 'e', '' }, 'v' }, getreg('c')) + eq({ { 'a', 'b', 'cde' }, 'V' }, getreg('l')) + eq({ { 'bca', 'abc', 'cba' }, '\0223' }, getreg('b')) end) it('does not dump registers with zero <', function() - nvim_command('set shada=\'0,<0') - setreg('c', {'d', 'e', ''}, 'c') - setreg('l', {'a', 'b', 'cde'}, 'l') - setreg('b', {'bca', 'abc', 'cba'}, 'b3') + nvim_command("set shada='0,<0") + setreg('c', { 'd', 'e', '' }, 'c') + setreg('l', { 'a', 'b', 'cde' }, 'l') + setreg('b', { 'bca', 'abc', 'cba' }, 'b3') expect_exit(nvim_command, 'qall') reset() - eq({{}, ''}, getreg('c')) - eq({{}, ''}, getreg('l')) - eq({{}, ''}, getreg('b')) + eq({ {}, '' }, getreg('c')) + eq({ {}, '' }, getreg('l')) + eq({ {}, '' }, getreg('b')) end) it('does restore registers with zero <', function() - setreg('c', {'d', 'e', ''}, 'c') - setreg('l', {'a', 'b', 'cde'}, 'l') - setreg('b', {'bca', 'abc', 'cba'}, 'b3') + setreg('c', { 'd', 'e', '' }, 'c') + setreg('l', { 'a', 'b', 'cde' }, 'l') + setreg('b', { 'bca', 'abc', 'cba' }, 'b3') expect_exit(nvim_command, 'qall') - reset('set shada=\'0,<0') - eq({{'d', 'e', ''}, 'v'}, getreg('c')) - eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) - eq({{'bca', 'abc', 'cba'}, '\0223'}, getreg('b')) + reset("set shada='0,<0") + eq({ { 'd', 'e', '' }, 'v' }, getreg('c')) + eq({ { 'a', 'b', 'cde' }, 'V' }, getreg('l')) + eq({ { 'bca', 'abc', 'cba' }, '\0223' }, getreg('b')) end) it('does not dump registers with zero "', function() nvim_command('set shada=\'0,\\"0') - setreg('c', {'d', 'e', ''}, 'c') - setreg('l', {'a', 'b', 'cde'}, 'l') - setreg('b', {'bca', 'abc', 'cba'}, 'b3') + setreg('c', { 'd', 'e', '' }, 'c') + setreg('l', { 'a', 'b', 'cde' }, 'l') + setreg('b', { 'bca', 'abc', 'cba' }, 'b3') expect_exit(nvim_command, 'qall') reset() - eq({{}, ''}, getreg('c')) - eq({{}, ''}, getreg('l')) - eq({{}, ''}, getreg('b')) + eq({ {}, '' }, getreg('c')) + eq({ {}, '' }, getreg('l')) + eq({ {}, '' }, getreg('b')) end) it('does restore registers with zero "', function() - setreg('c', {'d', 'e', ''}, 'c') - setreg('l', {'a', 'b', 'cde'}, 'l') - setreg('b', {'bca', 'abc', 'cba'}, 'b3') + setreg('c', { 'd', 'e', '' }, 'c') + setreg('l', { 'a', 'b', 'cde' }, 'l') + setreg('b', { 'bca', 'abc', 'cba' }, 'b3') expect_exit(nvim_command, 'qall') reset('set shada=\'0,\\"0') - eq({{'d', 'e', ''}, 'v'}, getreg('c')) - eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) - eq({{'bca', 'abc', 'cba'}, '\0223'}, getreg('b')) + eq({ { 'd', 'e', '' }, 'v' }, getreg('c')) + eq({ { 'a', 'b', 'cde' }, 'V' }, getreg('l')) + eq({ { 'bca', 'abc', 'cba' }, '\0223' }, getreg('b')) end) it('does dump registers with zero ", but non-zero <', function() nvim_command('set shada=\'0,\\"0,<50') - setreg('c', {'d', 'e', ''}, 'c') - setreg('l', {'a', 'b', 'cde'}, 'l') - setreg('b', {'bca', 'abc', 'cba'}, 'b3') + setreg('c', { 'd', 'e', '' }, 'c') + setreg('l', { 'a', 'b', 'cde' }, 'l') + setreg('b', { 'bca', 'abc', 'cba' }, 'b3') expect_exit(nvim_command, 'qall') reset() - eq({{'d', 'e', ''}, 'v'}, getreg('c')) - eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) - eq({{'bca', 'abc', 'cba'}, '\0223'}, getreg('b')) + eq({ { 'd', 'e', '' }, 'v' }, getreg('c')) + eq({ { 'a', 'b', 'cde' }, 'V' }, getreg('l')) + eq({ { 'bca', 'abc', 'cba' }, '\0223' }, getreg('b')) end) it('does limit number of lines according to <', function() - nvim_command('set shada=\'0,<2') - setreg('o', {'d'}, 'c') - setreg('t', {'a', 'b', 'cde'}, 'l') + nvim_command("set shada='0,<2") + setreg('o', { 'd' }, 'c') + setreg('t', { 'a', 'b', 'cde' }, 'l') expect_exit(nvim_command, 'qall') reset() - eq({{'d'}, 'v'}, getreg('o')) - eq({{}, ''}, getreg('t')) + eq({ { 'd' }, 'v' }, getreg('o')) + eq({ {}, '' }, getreg('t')) end) it('does limit number of lines according to "', function() nvim_command('set shada=\'0,\\"2') - setreg('o', {'d'}, 'c') - setreg('t', {'a', 'b', 'cde'}, 'l') + setreg('o', { 'd' }, 'c') + setreg('t', { 'a', 'b', 'cde' }, 'l') expect_exit(nvim_command, 'qall') reset() - eq({{'d'}, 'v'}, getreg('o')) - eq({{}, ''}, getreg('t')) + eq({ { 'd' }, 'v' }, getreg('o')) + eq({ {}, '' }, getreg('t')) end) it('does limit number of lines according to < rather then "', function() nvim_command('set shada=\'0,\\"2,<3') - setreg('o', {'d'}, 'c') - setreg('t', {'a', 'b', 'cde'}, 'l') - setreg('h', {'abc', 'acb', 'bac', 'bca', 'cab', 'cba'}, 'b3') + setreg('o', { 'd' }, 'c') + setreg('t', { 'a', 'b', 'cde' }, 'l') + setreg('h', { 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' }, 'b3') expect_exit(nvim_command, 'qall') reset() - eq({{'d'}, 'v'}, getreg('o')) - eq({{'a', 'b', 'cde'}, 'V'}, getreg('t')) - eq({{}, ''}, getreg('h')) + eq({ { 'd' }, 'v' }, getreg('o')) + eq({ { 'a', 'b', 'cde' }, 'V' }, getreg('t')) + eq({ {}, '' }, getreg('h')) end) - it('dumps and loads register correctly with utf-8 contents', - function() + it('dumps and loads register correctly with utf-8 contents', function() reset() - setreg('e', {'«'}, 'c') + setreg('e', { '«' }, 'c') expect_exit(nvim_command, 'qall') reset() - eq({{'«'}, 'v'}, getreg('e')) + eq({ { '«' }, 'v' }, getreg('e')) end) - it('dumps and loads history correctly with 8-bit single-byte', - function() + it('dumps and loads history correctly with 8-bit single-byte', function() reset() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 - setreg('e', {'\171«'}, 'c') + setreg('e', { '\171«' }, 'c') expect_exit(nvim_command, 'qall') reset() - eq({{'\171«'}, 'v'}, getreg('e')) + eq({ { '\171«' }, 'v' }, getreg('e')) end) - it('has a blank unnamed register if it wasn\'t set and register 0 is empty', - function() - setreg('1', {'one'}, 'c') - setreg('2', {'two'}, 'c') - setreg('a', {'a'}, 'c') + it("has a blank unnamed register if it wasn't set and register 0 is empty", function() + setreg('1', { 'one' }, 'c') + setreg('2', { 'two' }, 'c') + setreg('a', { 'a' }, 'c') expect_exit(nvim_command, 'qall') reset() - eq({{}, ''}, getreg('0')) - eq({{'one'}, 'v'}, getreg('1')) - eq({{}, ''}, getreg('"')) - eq({{'a'}, 'v'}, getreg('a')) + eq({ {}, '' }, getreg('0')) + eq({ { 'one' }, 'v' }, getreg('1')) + eq({ {}, '' }, getreg('"')) + eq({ { 'a' }, 'v' }, getreg('a')) end) - it('defaults the unnamed register to register 0 if it wasn\'t set', - function() - setreg('0', {'zero'}, 'c') - setreg('1', {'one'}, 'c') - setreg('2', {'two'}, 'c') + it("defaults the unnamed register to register 0 if it wasn't set", function() + setreg('0', { 'zero' }, 'c') + setreg('1', { 'one' }, 'c') + setreg('2', { 'two' }, 'c') expect_exit(nvim_command, 'qall') reset() - eq({{'zero'}, 'v'}, getreg('0')) - eq({{'one'}, 'v'}, getreg('1')) - eq({{'zero'}, 'v'}, getreg('"')) + eq({ { 'zero' }, 'v' }, getreg('0')) + eq({ { 'one' }, 'v' }, getreg('1')) + eq({ { 'zero' }, 'v' }, getreg('"')) end) - it('remembers which register was the unnamed register when loading', - function() - setreg('0', {'zero'}, 'c') - setreg('1', {'one'}, 'cu') - setreg('2', {'two'}, 'c') + it('remembers which register was the unnamed register when loading', function() + setreg('0', { 'zero' }, 'c') + setreg('1', { 'one' }, 'cu') + setreg('2', { 'two' }, 'c') expect_exit(nvim_command, 'qall') reset() - eq({{'zero'}, 'v'}, getreg('0')) - eq({{'one'}, 'v'}, getreg('1')) - eq({{'one'}, 'v'}, getreg('"')) + eq({ { 'zero' }, 'v' }, getreg('0')) + eq({ { 'one' }, 'v' }, getreg('1')) + eq({ { 'one' }, 'v' }, getreg('"')) end) end) diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 3a3238eb34..6eb318015d 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -1,25 +1,20 @@ -- Other ShaDa tests local helpers = require('test.functional.helpers')(after_each) -local meths, nvim_command, funcs, eq = - helpers.meths, helpers.command, helpers.funcs, helpers.eq +local api, nvim_command, fn, eq = helpers.api, helpers.command, helpers.fn, helpers.eq local write_file, spawn, set_session, nvim_prog, exc_exec = - helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, - helpers.exc_exec + helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.exc_exec local is_os = helpers.is_os local skip = helpers.skip -local luv = require('luv') -local paths = require('test.cmakeconfig.paths') - -local mpack = require('mpack') +local uv = vim.uv +local paths = helpers.paths local shada_helpers = require('test.functional.shada.helpers') local reset, clear, get_shada_rw = shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw local read_shada_file = shada_helpers.read_shada_file -local wshada, _, shada_fname, clean = - get_shada_rw('Xtest-functional-shada-shada.shada') +local wshada, _, shada_fname, clean = get_shada_rw('Xtest-functional-shada-shada.shada') local dirname = 'Xtest-functional-shada-shada.d' local dirshada = dirname .. '/main.shada' @@ -29,12 +24,16 @@ describe('ShaDa support code', function() after_each(function() clear() clean() - luv.fs_rmdir(dirname) + uv.fs_rmdir(dirname) 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)) + 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) + ) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -58,8 +57,8 @@ describe('ShaDa support code', function() local hist1 = ('-'):rep(1024 - 5) local hist2 = ('-'):rep(1025 - 5) nvim_command('set shada-=s10 shada+=s1') - funcs.histadd(':', hist1) - funcs.histadd(':', hist2) + fn.histadd(':', hist1) + fn.histadd(':', hist2) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -73,35 +72,53 @@ describe('ShaDa support code', function() 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)) + 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(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) - eq(nil, luv.fs_stat(shada_fname .. '.tmp.a')) - 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) + eq(nil, uv.fs_stat(shada_fname .. '.tmp.a')) + 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)) + 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) + ) 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 + 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 + end + 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(1, read_shada_file(shada_fname .. '.tmp.z')[1].type) end - 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(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('') @@ -110,33 +127,36 @@ describe('ShaDa support code', function() 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)) + eq( + 'Vim(wshada):E138: All Xtest-functional-shada-shada.shada.tmp.X files exist, cannot write ShaDa file!', + exc_exec('wshada ' .. shada_fname) + ) end) it('reads correctly various timestamps', function() local msgpack = { - '\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 + '\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' wshada(s .. table.concat(msgpack, e .. s) .. e) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 - local typ = mpack.decode(s) + local typ = vim.mpack.decode(s) for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == typ then found = found + 1 - eq(mpack.decode(msgpack[found]), v.timestamp) + eq(vim.mpack.decode(msgpack[found]), v.timestamp) end end eq(#msgpack, found) end) - local marklike = {[7]=true, [8]=true, [10]=true, [11]=true} + 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 @@ -155,7 +175,7 @@ describe('ShaDa support code', function() it('correctly uses shada-r option', function() nvim_command('set shellslash') - meths.set_var('__home', paths.test_source_path) + api.nvim_set_var('__home', paths.test_source_path) nvim_command('let $HOME = __home') nvim_command('unlet __home') nvim_command('edit ~/README.md') @@ -163,104 +183,107 @@ describe('ShaDa support code', function() nvim_command('undo') nvim_command('set shada+=%') nvim_command('wshada! ' .. shada_fname) - local readme_fname = funcs.resolve(paths.test_source_path) .. '/README.md' - eq({[7]=2, [8]=2, [9]=1, [10]=4, [11]=1}, find_file(readme_fname)) + local readme_fname = fn.resolve(paths.test_source_path) .. '/README.md' + eq({ [7] = 2, [8] = 2, [9] = 1, [10] = 4, [11] = 1 }, find_file(readme_fname)) nvim_command('set shada+=r~') nvim_command('wshada! ' .. shada_fname) eq({}, find_file(readme_fname)) nvim_command('set shada-=r~') nvim_command('wshada! ' .. shada_fname) - eq({[7]=2, [8]=2, [9]=1, [10]=4, [11]=1}, find_file(readme_fname)) - nvim_command('set shada+=r' .. funcs.escape( - funcs.escape(paths.test_source_path, '$~'), ' "\\,')) + eq({ [7] = 2, [8] = 2, [9] = 1, [10] = 4, [11] = 1 }, find_file(readme_fname)) + nvim_command('set shada+=r' .. fn.escape(fn.escape(paths.test_source_path, '$~'), ' "\\,')) nvim_command('wshada! ' .. shada_fname) eq({}, find_file(readme_fname)) end) it('correctly ignores case with shada-r option', function() nvim_command('set shellslash') - local pwd = funcs.getcwd() + local pwd = fn.getcwd() local relfname = 'абв/test' local fname = pwd .. '/' .. relfname - meths.set_var('__fname', fname) + api.nvim_set_var('__fname', fname) nvim_command('silent! edit `=__fname`') - funcs.setline(1, {'a', 'b', 'c', 'd'}) + fn.setline(1, { 'a', 'b', 'c', 'd' }) nvim_command('normal! GmAggmaAabc') nvim_command('undo') nvim_command('set shada+=%') nvim_command('wshada! ' .. shada_fname) - eq({[7]=2, [8]=2, [9]=1, [10]=4, [11]=2}, find_file(fname)) + eq({ [7] = 2, [8] = 2, [9] = 1, [10] = 4, [11] = 2 }, find_file(fname)) nvim_command('set shada+=r' .. pwd .. '/АБВ') nvim_command('wshada! ' .. shada_fname) eq({}, find_file(fname)) end) it('is able to set &shada after &viminfo', function() - meths.set_option_value('viminfo', '\'10', {}) - eq('\'10', meths.get_option_value('viminfo', {})) - eq('\'10', meths.get_option_value('shada', {})) - meths.set_option_value('shada', '', {}) - eq('', meths.get_option_value('viminfo', {})) - eq('', meths.get_option_value('shada', {})) + 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', {})) end) it('is able to set all& after setting &shada', function() - meths.set_option_value('shada', '\'10', {}) - eq('\'10', meths.get_option_value('viminfo', {})) - eq('\'10', meths.get_option_value('shada', {})) + api.nvim_set_option_value('shada', "'10", {}) + eq("'10", api.nvim_get_option_value('viminfo', {})) + eq("'10", api.nvim_get_option_value('shada', {})) nvim_command('set all&') - eq('!,\'100,<50,s10,h', meths.get_option_value('viminfo', {})) - eq('!,\'100,<50,s10,h', meths.get_option_value('shada', {})) + eq("!,'100,<50,s10,h", api.nvim_get_option_value('viminfo', {})) + eq("!,'100,<50,s10,h", api.nvim_get_option_value('shada', {})) end) it('is able to set &shada after &viminfo using :set', function() - nvim_command('set viminfo=\'10') - eq('\'10', meths.get_option_value('viminfo', {})) - eq('\'10', meths.get_option_value('shada', {})) + nvim_command("set viminfo='10") + eq("'10", api.nvim_get_option_value('viminfo', {})) + eq("'10", api.nvim_get_option_value('shada', {})) nvim_command('set shada=') - eq('', meths.get_option_value('viminfo', {})) - eq('', meths.get_option_value('shada', {})) + eq('', api.nvim_get_option_value('viminfo', {})) + eq('', api.nvim_get_option_value('shada', {})) end) 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))) + 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)) + ) end end) it('does not crash when ShaDa file directory is not writable', function() skip(is_os('win')) - funcs.mkdir(dirname, '', 0) - eq(0, funcs.filewritable(dirname)) - reset{shadafile=dirshada, args={'--cmd', 'set shada='}} - meths.set_option_value('shada', '\'10', {}) - 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')) - meths.set_option_value('shada', '', {}) + fn.mkdir(dirname, '', 0) + eq(0, fn.filewritable(dirname)) + reset { shadafile = dirshada, args = { '--cmd', 'set shada=' } } + api.nvim_set_option_value('shada', "'10", {}) + 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') + ) + api.nvim_set_option_value('shada', '', {}) end) end) 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) + local session = spawn( + { nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', '--headless', '--cmd', 'qall' }, + true + ) session:close() - eq(nil, luv.fs_stat('NONE')) - eq(nil, luv.fs_stat('NONE.tmp.a')) + eq(nil, uv.fs_stat('NONE')) + eq(nil, uv.fs_stat('NONE.tmp.a')) 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) + local session = spawn({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', '--headless' }, true) set_session(session) - eq('', funcs.getreg('a')) + eq('', fn.getreg('a')) session:close() os.remove('NONE') end) diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua index a91b7eb193..d70f5deded 100644 --- a/test/functional/shada/variables_spec.lua +++ b/test/functional/shada/variables_spec.lua @@ -1,7 +1,7 @@ -- ShaDa variables saving/reading support local helpers = require('test.functional.helpers')(after_each) -local meths, funcs, nvim_command, eq, eval = - helpers.meths, helpers.funcs, helpers.command, helpers.eq, helpers.eval +local api, fn, nvim_command, eq, eval = + helpers.api, helpers.fn, helpers.command, helpers.eq, helpers.eval local expect_exit = helpers.expect_exit local shada_helpers = require('test.functional.shada.helpers') @@ -12,24 +12,23 @@ describe('ShaDa support code', function() after_each(clear) it('is able to dump and read back string variable', function() - meths.set_var('STRVAR', 'foo') + api.nvim_set_var('STRVAR', 'foo') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq('foo', meths.get_var('STRVAR')) + eq('foo', api.nvim_get_var('STRVAR')) end) local autotest = function(tname, varname, varval, val_is_expr) - it('is able to dump and read back ' .. tname .. ' variable automatically', - function() + it('is able to dump and read back ' .. tname .. ' variable automatically', function() reset('set shada+=!') if val_is_expr then nvim_command('let g:' .. varname .. ' = ' .. varval) - varval = meths.get_var(varname) + varval = api.nvim_get_var(varname) else - meths.set_var(varname, varval) + api.nvim_set_var(varname, varval) end local vartype = eval('type(g:' .. varname .. ')') -- Exit during `reset` is not a regular exit: it does not write shada @@ -37,15 +36,15 @@ describe('ShaDa support code', function() expect_exit(nvim_command, 'qall') reset('set shada+=!') eq(vartype, eval('type(g:' .. varname .. ')')) - eq(varval, meths.get_var(varname)) + eq(varval, api.nvim_get_var(varname)) end) end autotest('string', 'STRVAR', 'foo') autotest('number', 'NUMVAR', 42) autotest('float', 'FLTVAR', 42.5) - autotest('dictionary', 'DCTVAR', {a=10}) - autotest('list', 'LSTVAR', {{a=10}, {b=10.5}, {c='str'}}) + autotest('dictionary', 'DCTVAR', { a = 10 }) + autotest('list', 'LSTVAR', { { a = 10 }, { b = 10.5 }, { c = 'str' } }) autotest('true', 'TRUEVAR', true) autotest('false', 'FALSEVAR', false) autotest('null', 'NULLVAR', 'v:null', true) @@ -54,111 +53,110 @@ describe('ShaDa support code', function() autotest('blob (with NULs)', 'BLOBVARNULS', '0z004e554c7300', true) it('does not read back variables without `!` in &shada', function() - meths.set_var('STRVAR', 'foo') + api.nvim_set_var('STRVAR', 'foo') nvim_command('set shada+=!') nvim_command('wshada') reset('set shada-=!') nvim_command('rshada') - eq(0, funcs.exists('g:STRVAR')) + eq(0, fn.exists('g:STRVAR')) end) it('does not dump variables without `!` in &shada', function() nvim_command('set shada-=!') - meths.set_var('STRVAR', 'foo') + api.nvim_set_var('STRVAR', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, funcs.exists('g:STRVAR')) + eq(0, fn.exists('g:STRVAR')) end) it('does not dump session variables', function() nvim_command('set shada+=!') - meths.set_var('StrVar', 'foo') + api.nvim_set_var('StrVar', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, funcs.exists('g:StrVar')) + eq(0, fn.exists('g:StrVar')) end) it('does not dump regular variables', function() nvim_command('set shada+=!') - meths.set_var('str_var', 'foo') + api.nvim_set_var('str_var', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, funcs.exists('g:str_var')) + eq(0, fn.exists('g:str_var')) end) - it('dumps and loads variables correctly with utf-8 strings', - function() + it('dumps and loads variables correctly with utf-8 strings', function() reset() - meths.set_var('STRVAR', '«') - meths.set_var('LSTVAR', {'«'}) - meths.set_var('DCTVAR', {['«']='«'}) - meths.set_var('NESTEDVAR', {['«']={{'«'}, {['«']='«'}, {a='Test'}}}) + api.nvim_set_var('STRVAR', '«') + api.nvim_set_var('LSTVAR', { '«' }) + api.nvim_set_var('DCTVAR', { ['«'] = '«' }) + api.nvim_set_var('NESTEDVAR', { ['«'] = { { '«' }, { ['«'] = '«' }, { a = 'Test' } } }) expect_exit(nvim_command, 'qall') reset() - eq('«', meths.get_var('STRVAR')) - eq({'«'}, meths.get_var('LSTVAR')) - eq({['«']='«'}, meths.get_var('DCTVAR')) - eq({['«']={{'«'}, {['«']='«'}, {a='Test'}}}, meths.get_var('NESTEDVAR')) + eq('«', api.nvim_get_var('STRVAR')) + eq({ '«' }, api.nvim_get_var('LSTVAR')) + eq({ ['«'] = '«' }, api.nvim_get_var('DCTVAR')) + eq({ ['«'] = { { '«' }, { ['«'] = '«' }, { a = 'Test' } } }, api.nvim_get_var('NESTEDVAR')) end) - it('dumps and loads variables correctly with 8-bit strings', - function() + it('dumps and loads variables correctly with 8-bit strings', function() reset() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 -- This is invalid unicode, but we should still dump and restore it. - meths.set_var('STRVAR', '\171') - meths.set_var('LSTVAR', {'\171'}) - meths.set_var('DCTVAR', {['«\171']='«\171'}) - meths.set_var('NESTEDVAR', {['\171']={{'\171«'}, {['\171']='\171'}, - {a='Test'}}}) + api.nvim_set_var('STRVAR', '\171') + api.nvim_set_var('LSTVAR', { '\171' }) + api.nvim_set_var('DCTVAR', { ['«\171'] = '«\171' }) + api.nvim_set_var( + 'NESTEDVAR', + { ['\171'] = { { '\171«' }, { ['\171'] = '\171' }, { a = 'Test' } } } + ) expect_exit(nvim_command, 'qall') reset() - eq('\171', meths.get_var('STRVAR')) - eq({'\171'}, meths.get_var('LSTVAR')) - eq({['«\171']='«\171'}, meths.get_var('DCTVAR')) - eq({['\171']={{'\171«'}, {['\171']='\171'}, {a='Test'}}}, - meths.get_var('NESTEDVAR')) + eq('\171', api.nvim_get_var('STRVAR')) + eq({ '\171' }, api.nvim_get_var('LSTVAR')) + eq({ ['«\171'] = '«\171' }, api.nvim_get_var('DCTVAR')) + eq( + { ['\171'] = { { '\171«' }, { ['\171'] = '\171' }, { a = 'Test' } } }, + api.nvim_get_var('NESTEDVAR') + ) end) - it('ignore when a funcref is stored in a variable', - function() + it('ignore when a funcref is stored in a variable', function() nvim_command('let F = function("tr")') - meths.set_var('U', '10') + api.nvim_set_var('U', '10') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq('10', meths.get_var('U')) + eq('10', api.nvim_get_var('U')) end) - it('ignore when a partial is stored in a variable', - function() + it('ignore when a partial is stored in a variable', function() nvim_command('let P = { -> 1 }') - meths.set_var('U', '10') + api.nvim_set_var('U', '10') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq('10', meths.get_var('U')) + eq('10', api.nvim_get_var('U')) end) - it('ignore when a self-referencing list is stored in a variable', - function() - meths.set_var('L', {}) + it('ignore when a self-referencing list is stored in a variable', function() + api.nvim_set_var('L', {}) nvim_command('call add(L, L)') - meths.set_var('U', '10') + api.nvim_set_var('U', '10') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('rshada') - eq('10', meths.get_var('U')) + eq('10', api.nvim_get_var('U')) end) end) |