From 244dbe3a77bf548f73d8781da7327f30e818b08a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Apr 2015 18:47:31 +0300 Subject: viminfo: First version of ShaDa file dumping What works: 1. ShaDa file dumping: header, registers, jump list, history, search patterns, substitute strings, variables. 2. ShaDa file reading: registers, global marks, variables. Most was not tested. TODO: 1. Merging. 2. Reading history, local marks, jump and buffer lists. 3. Documentation update. 4. Converting some data from &encoding. 5. Safer variant of dumping viminfo (dump to temporary file then rename). 6. Removing old viminfo code (currently masked with `#if 0` in a ShaDa file for reference). --- test/functional/ex_getln/history_spec.lua | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/functional/ex_getln/history_spec.lua (limited to 'test') diff --git a/test/functional/ex_getln/history_spec.lua b/test/functional/ex_getln/history_spec.lua new file mode 100644 index 0000000000..c3ef56c8ad --- /dev/null +++ b/test/functional/ex_getln/history_spec.lua @@ -0,0 +1,40 @@ +local helpers = require('test.functional.helpers') +local clear, nvim, call, eq = + helpers.clear, helpers.nvim, helpers.call, helpers.eq + +describe('history support code', function() + before_each(clear) + + local histadd = function(...) return call('histadd', ...) end + local histget = function(...) return call('histget', ...) end + local histdel = function(...) return call('histdel', ...) end + + it('correctly clears start of the history', function() + -- Regression test: check absense of the memory leak when clearing start of + -- the history using ex_getln.c/clr_history(). + eq(1, histadd(':', 'foo')) + eq(1, histdel(':')) + eq('', histget(':', -1)) + end) + + it('correctly clears end of the history', function() + -- Regression test: check absense of the memory leak when clearing end of + -- the history using ex_getln.c/clr_history(). + nvim('set_option', 'history', 1) + eq(1, histadd(':', 'foo')) + eq(1, histdel(':')) + eq('', histget(':', -1)) + end) + + it('correctly removes item from history', function() + -- Regression test: check that ex_getln.c/del_history_idx() correctly clears + -- history index after removing history entry. If it does not then deleting + -- history will result in a double free. + eq(1, histadd(':', 'foo')) + eq(1, histadd(':', 'bar')) + eq(1, histadd(':', 'baz')) + eq(1, histdel(':', -2)) + eq(1, histdel(':')) + eq('', histget(':', -1)) + end) +end) -- cgit From e143be7f3da154db20a0fc3b709a3ab240c0ec7f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Apr 2015 15:31:39 +0300 Subject: functests: Add tests for ShaDa variables dumping/reading --- test/functional/helpers.lua | 9 +++- test/functional/shada/helpers.lua | 53 ++++++++++++++++++++ test/functional/shada/variables_spec.lua | 84 ++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 test/functional/shada/helpers.lua create mode 100644 test/functional/shada/variables_spec.lua (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 80cb1e5ce3..a6f4f7c2e5 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -44,11 +44,15 @@ elseif os.getenv('GDB') then end if prepend_argv then + local new_nvim_argv = {} local len = #prepend_argv + for i = 1, len do + new_nvim_argv[i] = prepend_argv[i] + end for i = 1, #nvim_argv do - prepend_argv[i + len] = nvim_argv[i] + new_nvim_argv[i + len] = nvim_argv[i] end - nvim_argv = prepend_argv + nvim_argv = new_nvim_argv end local session, loop_running, loop_stopped, last_error @@ -338,6 +342,7 @@ local exc_exec = function(cmd) end return { + prepend_argv = prepend_argv, clear = clear, spawn = spawn, dedent = dedent, diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua new file mode 100644 index 0000000000..7e93fcb915 --- /dev/null +++ b/test/functional/shada/helpers.lua @@ -0,0 +1,53 @@ +local helpers = require('test.functional.helpers') +local spawn, set_session, nvim, nvim_prog = + helpers.spawn, helpers.set_session, helpers.nvim, helpers.nvim_prog + +local tmpname = os.tmpname() +local additional_cmd = '' + +local function nvim_argv() + local ret + local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', tmpname, '-N', + '--cmd', 'set shortmess+=I background=light noswapfile', + '--cmd', additional_cmd, + '--embed'} + if helpers.prepend_argv then + ret = {} + for i, v in ipairs(helpers.prepend_argv) do + ret[i] = v + end + local shift = #ret + for i, v in ipairs(nvim_argv) do + ret[i + shift] = v + end + else + ret = nvim_argv + end + return ret +end + +local session = nil + +local reset = function() + if session then + session:exit(0) + end + session = spawn(nvim_argv()) + set_session(session) + nvim('set_var', 'tmpname', tmpname) +end + +local set_additional_cmd = function(s) + additional_cmd = s +end + +local clear = function() + os.remove(tmpname) + set_additional_cmd('') +end + +return { + reset=reset, + set_additional_cmd=set_additional_cmd, + clear=clear, +} diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua new file mode 100644 index 0000000000..c0b94b102e --- /dev/null +++ b/test/functional/shada/variables_spec.lua @@ -0,0 +1,84 @@ +-- ShaDa variables saving/reading support +local helpers = require('test.functional.helpers') +local nvim, nvim_command, nvim_eval, eq = + helpers.nvim, helpers.command, helpers.eval, helpers.eq + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear + +describe('ShaDa support code', function() + before_each(reset) + after_each(clear) + + it('is able to dump and read back string variable', function() + nvim('set_var', 'STRVAR', 'foo') + nvim_command('set viminfo+=!') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo+=!') + nvim_command('rviminfo') + eq('foo', nvim('get_var', 'STRVAR')) + end) + + local autotest = function(tname, varname, varval) + it('is able to dump and read back ' .. tname .. ' variable automatically', + function() + set_additional_cmd('set viminfo+=!') + reset() + nvim('set_var', varname, varval) + -- Exit during `reset` is not a regular exit: it does not write viminfo + -- automatically + nvim_command('qall') + reset() + eq(varval, 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'}}) + + it('does not read back variables without `!` in &viminfo', function() + nvim('set_var', 'STRVAR', 'foo') + nvim_command('set viminfo+=!') + nvim_command('wviminfo') + set_additional_cmd('set viminfo-=!') + reset() + nvim_command('rviminfo') + eq(0, nvim_eval('exists("g:STRVAR")')) + end) + + it('does not dump variables without `!` in &viminfo', function() + nvim_command('set viminfo-=!') + nvim('set_var', 'STRVAR', 'foo') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo+=!') + nvim_command('rviminfo') + eq(0, nvim_eval('exists("g:STRVAR")')) + end) + + it('does not dump session variables', function() + nvim_command('set viminfo+=!') + nvim('set_var', 'StrVar', 'foo') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo+=!') + nvim_command('rviminfo') + eq(0, nvim_eval('exists("g:StrVar")')) + end) + + it('does not dump regular variables', function() + nvim_command('set viminfo+=!') + nvim('set_var', 'str_var', 'foo') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo+=!') + nvim_command('rviminfo') + eq(0, nvim_eval('exists("g:str_var")')) + end) +end) -- cgit From 46387b9aacb12546679603ecff88503f755c3a42 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 12 Jul 2015 03:29:31 +0300 Subject: functests: Add tests for mark dumping/reading --- test/functional/shada/marks_spec.lua | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test/functional/shada/marks_spec.lua (limited to 'test') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua new file mode 100644 index 0000000000..04a49a6d44 --- /dev/null +++ b/test/functional/shada/marks_spec.lua @@ -0,0 +1,77 @@ +-- ShaDa marks saving/reading support +local helpers = require('test.functional.helpers') +local nvim, nvim_window, nvim_curwin, nvim_command, nvim_eval, eq = + helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.eval, + helpers.eq + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear + +local nvim_current_line = function() + return nvim_window('get_cursor', nvim_curwin())[1] +end + +describe('ShaDa support code', function() + testfilename = 'Xtestfile-functional-shada-marks' + before_each(function() + reset() + local fd = io.open(testfilename, 'w') + fd:write('test\n') + fd:write('test2\n') + fd:close() + end) + after_each(function() + clear() + os.remove(testfilename) + end) + + it('is able to dump and read back global mark', function() + nvim_command('edit ' .. testfilename) + nvim_command('mark A') + nvim_command('2') + nvim_command('kB') + nvim_command('wviminfo') + reset() + nvim_command('rviminfo') + nvim_command('normal! `A') + eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) + eq(1, nvim_current_line()) + nvim_command('normal! `B') + eq(2, nvim_current_line()) + end) + + it('does not read back global mark without `f0` in viminfo', function() + nvim_command('edit ' .. testfilename) + nvim_command('mark A') + nvim_command('2') + nvim_command('kB') + nvim_command('wviminfo') + set_additional_cmd('set viminfo+=f0') + reset() + nvim_command('language C') + nvim_command([[ + try + execute "normal! `A" + catch + let exception = v:exception + endtry]]) + eq('Vim(normal):E20: Mark not set', nvim('get_var', 'exception')) + end) + + it('is able to dump and read back local mark', function() + nvim_command('edit ' .. testfilename) + nvim_command('mark a') + nvim_command('2') + nvim_command('kb') + nvim_command('qall') + reset() + nvim_command('edit ' .. testfilename) + nvim_command('normal! `a') + eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) + eq(1, nvim_current_line()) + nvim_command('normal! `b') + eq(2, nvim_current_line()) + end) +end) -- cgit From bc5252261684001d39f2d3a491f8e9295d1f76ed Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Jun 2015 05:18:51 +0300 Subject: functests: Add history tests --- test/functional/shada/history_spec.lua | 105 +++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 test/functional/shada/history_spec.lua (limited to 'test') diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua new file mode 100644 index 0000000000..b73a39f116 --- /dev/null +++ b/test/functional/shada/history_spec.lua @@ -0,0 +1,105 @@ +-- ShaDa history saving/reading support +local helpers = require('test.functional.helpers') +local nvim, nvim_command, nvim_eval, nvim_feed, eq = + helpers.nvim, helpers.command, helpers.eval, helpers.feed, helpers.eq + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear + +describe('ShaDa support code', function() + before_each(reset) + after_each(clear) + + it('is able to dump and read back command-line history', function() + nvim_command('set viminfo=\'0') + nvim_feed(':" Test\n') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo=\'0') + nvim_command('rviminfo') + eq('" Test', nvim_eval('histget(":", -1)')) + end) + + it('is able to dump and read back 2 items in command-line history', function() + nvim_command('set viminfo=\'0 history=2') + nvim_feed(':" Test\n') + nvim_feed(':" Test 2\n') + nvim_command('qall') + reset() + nvim_command('set viminfo=\'0 history=2') + nvim_command('rviminfo') + eq('" Test 2', nvim_eval('histget(":", -1)')) + eq('" Test', nvim_eval('histget(":", -2)')) + nvim_command('qall') + end) + + it('respects &history when dumping', + function() + nvim_command('set viminfo=\'0 history=1') + nvim_feed(':" Test\n') + nvim_feed(':" Test 2\n') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo=\'0 history=2') + nvim_command('rviminfo') + eq('" Test 2', nvim_eval('histget(":", -1)')) + eq('', nvim_eval('histget(":", -2)')) + end) + + it('respects &history when loading', + function() + nvim_command('set viminfo=\'0 history=2') + nvim_feed(':" Test\n') + nvim_feed(':" Test 2\n') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo=\'0 history=1') + nvim_command('rviminfo') + eq('" Test 2', nvim_eval('histget(":", -1)')) + eq('', nvim_eval('histget(":", -2)')) + end) + + it('dumps only requested amount of command-line history items', function() + nvim_command('set viminfo=\'0,:1') + nvim_feed(':" Test\n') + nvim_feed(':" Test 2\n') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo=\'0') + nvim_command('rviminfo') + eq('" Test 2', nvim_eval('histget(":", -1)')) + eq('', nvim_eval('histget(":", -2)')) + end) + + it('does not respect number in &viminfo when loading history', function() + nvim_command('set viminfo=\'0') + nvim_feed(':" Test\n') + nvim_feed(':" Test 2\n') + nvim_command('wviminfo') + reset() + nvim_command('set viminfo=\'0,:1') + nvim_command('rviminfo') + eq('" Test 2', nvim_eval('histget(":", -1)')) + eq('" Test', nvim_eval('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_command('0debuggreedy') + nvim_command('wviminfo') + reset() + nvim_command('rviminfo') + eq('" Test', nvim_eval('histget(":", -1)')) + eq('Test', nvim_eval('histget("/", -1)')) + eq('"Test"', nvim_eval('histget("=", -1)')) + eq('Test 2', nvim_eval('histget("@", -1)')) + eq('c', nvim_eval('histget(">", -1)')) + end) +end) -- cgit From 9ab08c82569d57fad29da95dc776ae288300903e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Jun 2015 07:36:51 +0300 Subject: functests: Test loading last search/substitute pattern/replacement --- test/functional/shada/history_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index b73a39f116..811afd268f 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -102,4 +102,26 @@ describe('ShaDa support code', function() eq('Test 2', nvim_eval('histget("@", -1)')) eq('c', nvim_eval('histget(">", -1)')) end) + + it('dumps and loads last search pattern with offset', function() + nvim_eval('setline(".", ["foo", "bar"])') + nvim_feed('gg0/a/e+1\n') + eq({0, 2, 3, 0}, nvim_eval('getpos(".")')) + nvim_command('wviminfo') + reset() + nvim_eval('setline(".", ["foo", "bar"])') + nvim_feed('gg0n') + eq({0, 2, 3, 0}, nvim_eval('getpos(".")')) + end) + + it('dumps and loads last substitute pattern and replacement string', function() + nvim_eval('setline(".", ["foo", "bar"])') + nvim_command('%s/f/g/g') + eq('goo', nvim_eval('getline(1)')) + nvim_command('wviminfo') + reset() + nvim_eval('setline(".", ["foo", "bar"])') + nvim_command('&') + eq('goo', nvim_eval('getline(1)')) + end) end) -- cgit From 200e62efebe8e87fc612218b675b74def57519f1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Jun 2015 08:06:16 +0300 Subject: shada: Add support for dumping/restoring bufs changes and win jumps --- test/functional/shada/marks_spec.lua | 80 ++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index 04a49a6d44..b853513317 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -1,8 +1,8 @@ -- ShaDa marks saving/reading support local helpers = require('test.functional.helpers') -local nvim, nvim_window, nvim_curwin, nvim_command, nvim_eval, eq = - helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.eval, - helpers.eq +local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = + helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, + helpers.eval, helpers.eq local shada_helpers = require('test.functional.shada.helpers') local reset, set_additional_cmd, clear = @@ -15,16 +15,22 @@ end describe('ShaDa support code', function() testfilename = 'Xtestfile-functional-shada-marks' + testfilename_2 = 'Xtestfile-functional-shada-marks-2' before_each(function() reset() local fd = io.open(testfilename, 'w') fd:write('test\n') fd:write('test2\n') fd:close() + local fd = io.open(testfilename_2, 'w') + fd:write('test3\n') + fd:write('test4\n') + fd:close() end) after_each(function() clear() os.remove(testfilename) + os.remove(testfilename_2) end) it('is able to dump and read back global mark', function() @@ -74,4 +80,72 @@ describe('ShaDa support code', function() nvim_command('normal! `b') eq(2, nvim_current_line()) end) + + it('is able to dump and restore jump list', function() + nvim_command('edit ' .. testfilename_2) + nvim_feed('G') + nvim_feed('gg') + nvim_command('edit ' .. testfilename) + nvim_feed('G') + nvim_feed('gg') + -- nvim_command('redir! >/tmp/jumps.last | jumps | redir END') + -- nvim_command('wviminfo /tmp/foo') + nvim_command('qall') + reset() + nvim_command('redraw') + -- nvim_command('redir! >/tmp/jumps.init | jumps | redir END') + nvim_command('edit ' .. testfilename) + -- nvim_command('redir! >/tmp/jumps | jumps | redir END') + eq(testfilename, nvim_eval('bufname("%")')) + eq(1, nvim_current_line()) + nvim_command('execute "normal! \\"') + eq(testfilename, nvim_eval('bufname("%")')) + eq(1, nvim_current_line()) + nvim_command('execute "normal! \\"') + eq(testfilename, nvim_eval('bufname("%")')) + eq(2, nvim_current_line()) + nvim_command('execute "normal! \\"') + eq(testfilename_2, nvim_eval('bufname("%")')) + eq(1, nvim_current_line()) + nvim_command('execute "normal! \\"') + eq(testfilename_2, nvim_eval('bufname("%")')) + eq(2, nvim_current_line()) + end) + + it('is able to dump and restore jump list with different times (slow!)', + function() + nvim_command('edit ' .. testfilename_2) + nvim_command('sleep 2') + nvim_feed('G') + nvim_command('sleep 2') + nvim_feed('gg') + nvim_command('sleep 2') + nvim_command('edit ' .. testfilename) + nvim_command('sleep 2') + nvim_feed('G') + nvim_command('sleep 2') + nvim_feed('gg') + -- nvim_command('redir! >/tmp/jumps.last | jumps | redir END') + -- nvim_command('wviminfo /tmp/foo') + nvim_command('qall') + reset() + nvim_command('redraw') + -- nvim_command('redir! >/tmp/jumps.init | jumps | redir END') + nvim_command('edit ' .. testfilename) + -- nvim_command('redir! >/tmp/jumps | jumps | redir END') + eq(testfilename, nvim_eval('bufname("%")')) + eq(1, nvim_current_line()) + nvim_command('execute "normal! \\"') + eq(testfilename, nvim_eval('bufname("%")')) + eq(1, nvim_current_line()) + nvim_command('execute "normal! \\"') + eq(testfilename, nvim_eval('bufname("%")')) + eq(2, nvim_current_line()) + nvim_command('execute "normal! \\"') + eq(testfilename_2, nvim_eval('bufname("%")')) + eq(1, nvim_current_line()) + nvim_command('execute "normal! \\"') + eq(testfilename_2, nvim_eval('bufname("%")')) + eq(2, nvim_current_line()) + end) end) -- cgit From 8c93877e1c3205f6b42b3e4c94d9be6262557dfb Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 4 Jul 2015 22:36:06 +0300 Subject: shada: Add support for dumping and restoring buffer list --- test/functional/shada/buffers_spec.lua | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/functional/shada/buffers_spec.lua (limited to 'test') diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua new file mode 100644 index 0000000000..97dafa533b --- /dev/null +++ b/test/functional/shada/buffers_spec.lua @@ -0,0 +1,65 @@ +-- ShaDa buffer list saving/reading support +local helpers = require('test.functional.helpers') +local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = + helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, + helpers.eval, helpers.eq + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear + +local nvim_current_line = function() + return nvim_window('get_cursor', nvim_curwin())[1] +end + +describe('ShaDa support code', function() + testfilename = 'Xtestfile-functional-shada-buffers' + testfilename_2 = 'Xtestfile-functional-shada-buffers-2' + before_each(reset) + after_each(clear) + + it('is able to dump and restore buffer list', function() + set_additional_cmd('set viminfo+=%') + reset() + nvim_command('edit ' .. testfilename) + nvim_command('edit ' .. testfilename_2) + -- nvim_command('redir! > /tmp/vistr | verbose set viminfo? | redir END') + -- nvim_command('wviminfo /tmp/foo') + nvim_command('qall') + reset() + -- nvim_command('call writefile([&viminfo], "/tmp/vistr")') + eq(3, nvim_eval('bufnr("$")')) + eq('', nvim_eval('bufname(1)')) + eq(testfilename, nvim_eval('bufname(2)')) + eq(testfilename_2, nvim_eval('bufname(3)')) + end) + + it('does not restore buffer list without % in &viminfo', function() + set_additional_cmd('set viminfo+=%') + reset() + nvim_command('edit ' .. testfilename) + nvim_command('edit ' .. testfilename_2) + -- nvim_command('redir! > /tmp/vistr | verbose set viminfo? | redir END') + -- nvim_command('wviminfo /tmp/foo') + set_additional_cmd('') + nvim_command('qall') + reset() + -- nvim_command('call writefile([&viminfo], "/tmp/vistr")') + eq(1, nvim_eval('bufnr("$")')) + eq('', nvim_eval('bufname(1)')) + end) + + it('does not dump buffer list without % in &viminfo', function() + nvim_command('edit ' .. testfilename) + nvim_command('edit ' .. testfilename_2) + -- nvim_command('redir! > /tmp/vistr | verbose set viminfo? | redir END') + -- nvim_command('wviminfo /tmp/foo') + set_additional_cmd('set viminfo+=%') + nvim_command('qall') + reset() + -- nvim_command('call writefile([&viminfo], "/tmp/vistr")') + eq(1, nvim_eval('bufnr("$")')) + eq('', nvim_eval('bufname(1)')) + end) +end) -- cgit From 42536abd33a31234fcff9c736002b2e83c2183db Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Jul 2015 02:01:55 +0300 Subject: functests: Add tests for dumping/restoring registers --- test/functional/shada/registers_spec.lua | 141 +++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/functional/shada/registers_spec.lua (limited to 'test') diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua new file mode 100644 index 0000000000..75c86628a6 --- /dev/null +++ b/test/functional/shada/registers_spec.lua @@ -0,0 +1,141 @@ +-- ShaDa registers saving/reading support +local helpers = require('test.functional.helpers') +local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = + helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, + helpers.eval, helpers.eq + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear + +local nvim_current_line = function() + return nvim_window('get_cursor', nvim_curwin())[1] +end + +local setreg = function(name, contents, typ) + local expr = 'setreg("' .. name .. '", [' + if type(contents) == 'string' then + contents = {contents} + end + for _, line in ipairs(contents) do + expr = expr .. '"' .. line:gsub('[\\"]', '\\\\\\0') .. '", ' + end + expr = expr .. '], "' .. typ .. '")' + nvim_eval(expr) +end + +local getreg = function(name) + return { + nvim_eval(('getreg("%s", 1, 1)'):format(name)), + nvim_eval(('getregtype("%s")'):format(name)), + } +end + +describe('ShaDa support code', function() + before_each(reset) + 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') + nvim_command('qa') + reset() + 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 viminfo=\'0,<0') + setreg('c', {'d', 'e', ''}, 'c') + setreg('l', {'a', 'b', 'cde'}, 'l') + setreg('b', {'bca', 'abc', 'cba'}, 'b3') + nvim_command('qa') + reset() + eq({nil, ''}, getreg('c')) + eq({nil, ''}, getreg('l')) + eq({nil, ''}, 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') + set_additional_cmd('set viminfo=\'0,<0') + nvim_command('qa') + reset() + 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 viminfo=\'0,\\"0') + setreg('c', {'d', 'e', ''}, 'c') + setreg('l', {'a', 'b', 'cde'}, 'l') + setreg('b', {'bca', 'abc', 'cba'}, 'b3') + nvim_command('qa') + reset() + eq({nil, ''}, getreg('c')) + eq({nil, ''}, getreg('l')) + eq({nil, ''}, 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') + set_additional_cmd('set viminfo=\'0,\\"0') + nvim_command('qa') + reset() + 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 viminfo=\'0,\\"0,<50') + setreg('c', {'d', 'e', ''}, 'c') + setreg('l', {'a', 'b', 'cde'}, 'l') + setreg('b', {'bca', 'abc', 'cba'}, 'b3') + nvim_command('qa') + reset() + 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 viminfo=\'0,<2') + setreg('o', {'d'}, 'c') + setreg('t', {'a', 'b', 'cde'}, 'l') + nvim_command('qa') + reset() + eq({{'d'}, 'v'}, getreg('o')) + eq({nil, ''}, getreg('t')) + end) + + it('does limit number of lines according to "', function() + nvim_command('set viminfo=\'0,\\"2') + setreg('o', {'d'}, 'c') + setreg('t', {'a', 'b', 'cde'}, 'l') + nvim_command('qa') + reset() + eq({{'d'}, 'v'}, getreg('o')) + eq({nil, ''}, getreg('t')) + end) + + it('does limit number of lines according to < rather then "', function() + nvim_command('set viminfo=\'0,\\"2,<3') + setreg('o', {'d'}, 'c') + setreg('t', {'a', 'b', 'cde'}, 'l') + setreg('h', {'abc', 'acb', 'bac', 'bca', 'cab', 'cba'}, 'b3') + nvim_command('qa') + reset() + eq({{'d'}, 'v'}, getreg('o')) + eq({{'a', 'b', 'cde'}, 'V'}, getreg('t')) + eq({nil, ''}, getreg('h')) + end) +end) -- cgit From cf004c0d41833349eca0d7f7947e80dd8fc7aea7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Jul 2015 02:38:41 +0300 Subject: functests: Test dumping and loading change list --- test/functional/shada/marks_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index b853513317..f1a112bfef 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -148,4 +148,18 @@ describe('ShaDa support code', function() eq(testfilename_2, nvim_eval('bufname("%")')) eq(2, nvim_current_line()) end) + + it('is able to dump and restore change list', function() + nvim_command('edit ' .. testfilename) + nvim_feed('Gra') + nvim_feed('ggrb') + nvim_command('qall!') + reset() + nvim_command('edit ' .. testfilename) + -- nvim_command('rviminfo') + nvim_feed('Gg;') + eq(1, nvim_current_line()) + nvim_feed('g;') + eq(2, nvim_current_line()) + end) end) -- cgit From d1ae27ceec467605d02e6388d5b8007bc9359d52 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Jul 2015 03:13:00 +0300 Subject: shada,functests: Refactor shada items skipping --- test/functional/shada/marks_spec.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index f1a112bfef..a6518ccbf9 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -48,13 +48,13 @@ describe('ShaDa support code', function() eq(2, nvim_current_line()) end) - it('does not read back global mark without `f0` in viminfo', function() + it('does not dump global mark with `f0` in viminfo', function() + nvim_command('set viminfo+=f0') nvim_command('edit ' .. testfilename) nvim_command('mark A') nvim_command('2') nvim_command('kB') nvim_command('wviminfo') - set_additional_cmd('set viminfo+=f0') reset() nvim_command('language C') nvim_command([[ @@ -66,6 +66,20 @@ describe('ShaDa support code', function() eq('Vim(normal):E20: Mark not set', nvim('get_var', 'exception')) end) + it('does read back global mark even with `\'0` and `f0` in viminfo', function() + nvim_command('edit ' .. testfilename) + nvim_command('mark A') + nvim_command('2') + nvim_command('kB') + nvim_command('wviminfo') + set_additional_cmd('set viminfo=\'0,f0') + reset() + nvim_command('language C') + nvim_command('normal! `A') + eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) + eq(1, nvim_current_line()) + end) + it('is able to dump and read back local mark', function() nvim_command('edit ' .. testfilename) nvim_command('mark a') -- cgit From c8c5da875c0b7d37c4aedc6b2301441fdc004ac4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Jul 2015 17:24:02 +0300 Subject: functests: Test &encoding support --- test/functional/shada/history_spec.lua | 155 +++++++++++++++++++++++++++++++ test/functional/shada/registers_spec.lua | 33 +++++++ test/functional/shada/variables_spec.lua | 55 +++++++++++ 3 files changed, 243 insertions(+) (limited to 'test') diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 811afd268f..5a7db2bfa6 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -124,4 +124,159 @@ describe('ShaDa support code', function() nvim_command('&') eq('goo', nvim_eval('getline(1)')) end) + + it('dumps and loads history correctly when &encoding is not UTF-8', function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_feed(':echo "\171"\n') + nvim_command('qall') + reset() + eq('echo "\171"', nvim_eval('histget(":", -1)')) + end) + + it('dumps and loads history correctly when &encoding /= UTF-8 when dumping', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_feed(':echo "\171"\n') + set_additional_cmd('') + nvim_command('qall') + reset() + eq('echo "«"', nvim_eval('histget(":", -1)')) + end) + + it('dumps and loads history correctly when &encoding /= UTF-8 when loading', + function() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_feed(':echo "«"\n') + set_additional_cmd('set encoding=latin1') + nvim_command('qall') + reset() + eq('echo "\171"', nvim_eval('histget(":", -1)')) + end) + + it('dumps and loads replacement correctly when &encoding is not UTF-8', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('substitute/./\171/ge') + nvim_command('qall!') + reset() + nvim_eval('setline(".", ["."])') + nvim_command('&') + eq('\171', nvim_eval('getline(".")')) + end) + + it('dumps&loads replacement correctly when &encoding /= UTF-8 when dumping', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('substitute/./\171/ge') + set_additional_cmd('') + nvim_command('qall') + reset() + nvim_eval('setline(".", ["."])') + nvim_command('&') + eq('«', nvim_eval('getline(".")')) + end) + + it('dumps&loads replacement correctly when &encoding /= UTF-8 when loading', + function() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('substitute/./«/ge') + set_additional_cmd('set encoding=latin1') + nvim_command('qall') + reset() + nvim_eval('setline(".", ["."])') + nvim_command('&') + eq('\171', nvim_eval('getline(".")')) + end) + + it('dumps and loads substitute pattern correctly when &encoding is not UTF-8', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('substitute/\171/./ge') + nvim_command('qall!') + reset() + nvim_eval('setline(".", ["\171«"])') + nvim_command('&') + eq('.«', nvim_eval('getline(".")')) + end) + + it('dumps&loads s/pattern correctly when &encoding /= UTF-8 when dumping', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('substitute/\171/./ge') + set_additional_cmd('') + nvim_command('qall') + reset() + nvim_eval('setline(".", ["«\171"])') + nvim_command('&') + eq('.\171', nvim_eval('getline(".")')) + end) + + it('dumps&loads s/pattern correctly when &encoding /= UTF-8 when loading', + function() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('substitute/«/./ge') + set_additional_cmd('set encoding=latin1') + nvim_command('qall') + reset() + nvim_eval('setline(".", ["\171«"])') + nvim_command('&') + eq('.«', nvim_eval('getline(".")')) + end) + + it('dumps and loads search pattern correctly when &encoding is not UTF-8', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('silent! /\171/') + nvim_command('set viminfo+=/0') + nvim_command('qall!') + reset() + nvim_eval('setline(".", ["\171«"])') + nvim_command('~&') + eq('«', nvim_eval('getline(".")')) + eq('', nvim_eval('histget("/", -1)')) + end) + + it('dumps&loads /pattern correctly when &encoding /= UTF-8 when dumping', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('silent! /\171/') + nvim_command('set viminfo+=/0') + set_additional_cmd('') + nvim_command('qall') + reset() + nvim_eval('setline(".", ["«\171"])') + nvim_command('~&') + eq('\171', nvim_eval('getline(".")')) + eq('', nvim_eval('histget("/", -1)')) + end) + + it('dumps&loads /pattern correctly when &encoding /= UTF-8 when loading', + function() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim_command('silent! /«/') + nvim_command('set viminfo+=/0') + set_additional_cmd('set encoding=latin1') + nvim_command('qall') + reset() + nvim_eval('setline(".", ["\171«"])') + nvim_command('~&') + eq('«', nvim_eval('getline(".")')) + eq('', nvim_eval('histget("/", -1)')) + end) end) diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua index 75c86628a6..7efb100cd6 100644 --- a/test/functional/shada/registers_spec.lua +++ b/test/functional/shada/registers_spec.lua @@ -138,4 +138,37 @@ describe('ShaDa support code', function() eq({{'a', 'b', 'cde'}, 'V'}, getreg('t')) eq({nil, ''}, getreg('h')) end) + + it('dumps and loads register correctly when &encoding is not UTF-8', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + setreg('e', {'\171'}, 'c') + nvim_command('qall') + reset() + eq({{'\171'}, 'v'}, getreg('e')) + end) + + it('dumps and loads history correctly when &encoding /= UTF-8 when dumping', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + setreg('e', {'\171'}, 'c') + set_additional_cmd('') + nvim_command('qall') + reset() + eq({{'«'}, 'v'}, getreg('e')) + end) + + it('dumps and loads history correctly when &encoding /= UTF-8 when loading', + function() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + setreg('e', {'«'}, 'c') + set_additional_cmd('set encoding=latin1') + nvim_command('qall') + reset() + eq({{'\171'}, 'v'}, getreg('e')) + end) end) diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua index c0b94b102e..0ffa524238 100644 --- a/test/functional/shada/variables_spec.lua +++ b/test/functional/shada/variables_spec.lua @@ -81,4 +81,59 @@ describe('ShaDa support code', function() nvim_command('rviminfo') eq(0, nvim_eval('exists("g:str_var")')) end) + + it('dumps and loads variables correctly when &encoding is not UTF-8', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim('set_var', 'STRVAR', '\171') + nvim('set_var', 'LSTVAR', {'\171'}) + nvim('set_var', 'DCTVAR', {['\171']='\171'}) + nvim('set_var', 'NESTEDVAR', {['\171']={{'\171'}, {['\171']='\171'}, + {a='Test'}}}) + nvim_command('qall') + reset() + eq('\171', nvim('get_var', 'STRVAR')) + eq({'\171'}, nvim('get_var', 'LSTVAR')) + eq({['\171']='\171'}, nvim('get_var', 'DCTVAR')) + eq({['\171']={{'\171'}, {['\171']='\171'}, {a='Test'}}}, + nvim('get_var', 'NESTEDVAR')) + end) + + it('dumps and loads variables correctly when &encoding /= UTF-8 when dumping', + function() + set_additional_cmd('set encoding=latin1') + reset() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim('set_var', 'STRVAR', '\171') + nvim('set_var', 'LSTVAR', {'\171'}) + nvim('set_var', 'DCTVAR', {['\171']='\171'}) + nvim('set_var', 'NESTEDVAR', {['\171']={{'\171'}, {['\171']='\171'}, + {a='Test'}}}) + set_additional_cmd('') + nvim_command('qall') + reset() + eq('«', nvim('get_var', 'STRVAR')) + eq({'«'}, nvim('get_var', 'LSTVAR')) + eq({['«']='«'}, nvim('get_var', 'DCTVAR')) + eq({['«']={{'«'}, {['«']='«'}, {a='Test'}}}, nvim('get_var', 'NESTEDVAR')) + end) + + it('dumps and loads variables correctly when &encoding /= UTF-8 when loading', + function() + -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 + nvim('set_var', 'STRVAR', '«') + nvim('set_var', 'LSTVAR', {'«'}) + nvim('set_var', 'DCTVAR', {['«']='«'}) + nvim('set_var', 'NESTEDVAR', {['«']={{'«'}, {['«']='«'}, {a='Test'}}}) + set_additional_cmd('set encoding=latin1') + nvim_command('qall') + reset() + eq('\171', nvim('get_var', 'STRVAR')) + eq({'\171'}, nvim('get_var', 'LSTVAR')) + eq({['\171']='\171'}, nvim('get_var', 'DCTVAR')) + eq({['\171']={{'\171'}, {['\171']='\171'}, {a='Test'}}}, + nvim('get_var', 'NESTEDVAR')) + end) end) -- cgit From 749cae866278469d11e6ec467dd0e98ab6233439 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 6 Jul 2015 01:20:43 +0300 Subject: functests: Fix change list ShaDa test failures --- test/functional/shada/marks_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index a6518ccbf9..25362b406b 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -171,9 +171,15 @@ describe('ShaDa support code', function() reset() nvim_command('edit ' .. testfilename) -- nvim_command('rviminfo') + -- nvim_command('redir! >/tmp/changes | changes | redir END') nvim_feed('Gg;') + -- Note: without “sync” “commands” test has good changes to fail for unknown + -- reason (in first eq expected 1 is compared with 2). Any command inserted + -- causes this to work properly. + nvim_command('" sync') eq(1, nvim_current_line()) nvim_feed('g;') + nvim_command('" sync 2') eq(2, nvim_current_line()) end) end) -- cgit From 9cf9c4a5860212cc0f9b71d349849811fdaf61a1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 6 Jul 2015 02:16:05 +0300 Subject: Replace references to viminfo in various places --- test/functional/ex_cmds/wviminfo_spec.lua | 33 ++++++++++++---------- .../legacy/074_global_var_in_viminfo_spec.lua | 22 ++++++++------- 2 files changed, 30 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index f4911cd3e8..053555c267 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -4,7 +4,7 @@ local clear, execute, eq, neq, spawn, nvim_prog, set_session, wait, write_file helpers.nvim_prog, helpers.set_session, helpers.wait, helpers.write_file describe(':wviminfo', function() - local viminfo_file = 'wviminfo_test' + local shada_file = 'wviminfo_test' local session before_each(function() @@ -17,38 +17,41 @@ describe(':wviminfo', function() '--cmd', 'set swapfile'}) set_session(session) - os.remove(viminfo_file) + os.remove(shada_file) end) - it('creates a viminfo file', function() + it('creates a shada file', function() -- file should _not_ exist - eq(nil, lfs.attributes(viminfo_file)) - execute('wv! '..viminfo_file) + eq(nil, lfs.attributes(shada_file)) + execute('wv! '..shada_file) wait() -- file _should_ exist - neq(nil, lfs.attributes(viminfo_file)) + neq(nil, lfs.attributes(shada_file)) end) it('overwrites existing files', function() local text = 'wviminfo test' -- Create a dummy file - write_file(viminfo_file, text) + write_file(shada_file, text) -- sanity check - eq(text, io.open(viminfo_file):read()) - neq(nil, lfs.attributes(viminfo_file)) + eq(text, io.open(shada_file):read()) + neq(nil, lfs.attributes(shada_file)) - execute('wv! '..viminfo_file) + execute('wv! '..shada_file) wait() - -- File should have been overwritten with a viminfo file. - local line1 = io.lines(viminfo_file)() - assert(nil ~= string.find(line1, 'This viminfo file was generated by Nvim'), - viminfo_file..' should be a viminfo-formatted file') + -- File should have been overwritten with a shada file. + local fp = io.open(shada_file, 'r') + local char1 = fp:read(1) + fp:close() + -- ShaDa file starts with a “header” entry + assert(char1:byte() == 0x01, + shada_file..' should be a shada file') end) teardown(function() - os.remove(viminfo_file) + os.remove(shada_file) end) end) diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua index a89a4181cd..f017ed80a8 100644 --- a/test/functional/legacy/074_global_var_in_viminfo_spec.lua +++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua @@ -1,14 +1,15 @@ --- Tests for storing global variables in the .viminfo file +-- Tests for storing global variables in the .shada file local helpers, lfs = require('test.functional.helpers'), require('lfs') local clear, execute, eq, neq, eval, wait, spawn = helpers.clear, helpers.execute, helpers.eq, helpers.neq, helpers.eval, helpers.wait, helpers.spawn -describe('storing global variables in viminfo files', function() +describe('storing global variables in ShaDa files', function() + local tempname = 'Xtest-functional-legacy-074' setup(function() clear() - os.remove("Xviminfo") + os.remove(tempname) end) it('is working', function() @@ -29,31 +30,32 @@ describe('storing global variables in viminfo files', function() 'set visualbell', 'set viminfo+=!', "let MY_GLOBAL_DICT={'foo': 1, 'bar': 0, 'longvarible': 1000}", - -- Store a really long list, so line wrapping will occur in viminfo - -- file. + -- Store a really long list. Initially this was testing line wrapping in + -- viminfo, but shada files has no line wrapping, no matter how long the + -- list is. 'let MY_GLOBAL_LIST=range(1,100)' ) eq(test_dict, eval('MY_GLOBAL_DICT')) eq(test_list, eval('MY_GLOBAL_LIST')) - execute('wv! Xviminfo') + execute('wv! ' .. tempname) wait() - -- Assert that the viminfo file exists. - neq(nil, lfs.attributes('Xviminfo')) + -- Assert that the shada file exists. + neq(nil, lfs.attributes(tempname)) execute('unlet MY_GLOBAL_DICT', 'unlet MY_GLOBAL_LIST') -- Assert that the variables where deleted. eq(0, eval('exists("MY_GLOBAL_DICT")')) eq(0, eval('exists("MY_GLOBAL_LIST")')) - execute('rv! Xviminfo') + execute('rv! ' .. tempname) eq(test_list, eval('MY_GLOBAL_LIST')) eq(test_dict, eval('MY_GLOBAL_DICT')) end) teardown(function() - os.remove('Xviminfo') + os.remove(tempname) end) end) -- cgit From 8663983cc4c2f66eb0ba58ad8e247ac0686cc79b Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 6 Jul 2015 02:26:44 +0300 Subject: Deprecate &viminfo and :[rw]v, add &shada and :[rw]sh --- test/functional/ex_cmds/wviminfo_spec.lua | 10 ++-- .../legacy/074_global_var_in_viminfo_spec.lua | 6 +-- test/functional/shada/buffers_spec.lua | 28 +++++----- test/functional/shada/history_spec.lua | 62 +++++++++++----------- test/functional/shada/marks_spec.lua | 22 ++++---- test/functional/shada/registers_spec.lua | 16 +++--- test/functional/shada/variables_spec.lua | 48 ++++++++--------- 7 files changed, 96 insertions(+), 96 deletions(-) (limited to 'test') diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index 053555c267..0c85157a0f 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -3,8 +3,8 @@ local clear, execute, eq, neq, spawn, nvim_prog, set_session, wait, write_file = helpers.clear, helpers.execute, helpers.eq, helpers.neq, helpers.spawn, helpers.nvim_prog, helpers.set_session, helpers.wait, helpers.write_file -describe(':wviminfo', function() - local shada_file = 'wviminfo_test' +describe(':wshada', function() + local shada_file = 'wshada_test' local session before_each(function() @@ -23,14 +23,14 @@ describe(':wviminfo', function() it('creates a shada file', function() -- file should _not_ exist eq(nil, lfs.attributes(shada_file)) - execute('wv! '..shada_file) + execute('wsh! '..shada_file) wait() -- file _should_ exist neq(nil, lfs.attributes(shada_file)) end) it('overwrites existing files', function() - local text = 'wviminfo test' + local text = 'wshada test' -- Create a dummy file write_file(shada_file, text) @@ -39,7 +39,7 @@ describe(':wviminfo', function() eq(text, io.open(shada_file):read()) neq(nil, lfs.attributes(shada_file)) - execute('wv! '..shada_file) + execute('wsh! '..shada_file) wait() -- File should have been overwritten with a shada file. diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua index f017ed80a8..2428b7f74d 100644 --- a/test/functional/legacy/074_global_var_in_viminfo_spec.lua +++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua @@ -28,7 +28,7 @@ describe('storing global variables in ShaDa files', function() execute( -- This will cause a few errors, do it silently. 'set visualbell', - 'set viminfo+=!', + 'set shada+=!', "let MY_GLOBAL_DICT={'foo': 1, 'bar': 0, 'longvarible': 1000}", -- Store a really long list. Initially this was testing line wrapping in -- viminfo, but shada files has no line wrapping, no matter how long the @@ -38,7 +38,7 @@ describe('storing global variables in ShaDa files', function() eq(test_dict, eval('MY_GLOBAL_DICT')) eq(test_list, eval('MY_GLOBAL_LIST')) - execute('wv! ' .. tempname) + execute('wsh! ' .. tempname) wait() -- Assert that the shada file exists. @@ -49,7 +49,7 @@ describe('storing global variables in ShaDa files', function() eq(0, eval('exists("MY_GLOBAL_DICT")')) eq(0, eval('exists("MY_GLOBAL_LIST")')) - execute('rv! ' .. tempname) + execute('rsh! ' .. tempname) eq(test_list, eval('MY_GLOBAL_LIST')) eq(test_dict, eval('MY_GLOBAL_DICT')) diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua index 97dafa533b..38a8cad84d 100644 --- a/test/functional/shada/buffers_spec.lua +++ b/test/functional/shada/buffers_spec.lua @@ -20,45 +20,45 @@ describe('ShaDa support code', function() after_each(clear) it('is able to dump and restore buffer list', function() - set_additional_cmd('set viminfo+=%') + set_additional_cmd('set shada+=%') reset() nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - -- nvim_command('redir! > /tmp/vistr | verbose set viminfo? | redir END') - -- nvim_command('wviminfo /tmp/foo') + -- nvim_command('redir! > /tmp/vistr | verbose set shada? | redir END') + -- nvim_command('wshada /tmp/foo') nvim_command('qall') reset() - -- nvim_command('call writefile([&viminfo], "/tmp/vistr")') + -- nvim_command('call writefile([&shada], "/tmp/vistr")') eq(3, nvim_eval('bufnr("$")')) eq('', nvim_eval('bufname(1)')) eq(testfilename, nvim_eval('bufname(2)')) eq(testfilename_2, nvim_eval('bufname(3)')) end) - it('does not restore buffer list without % in &viminfo', function() - set_additional_cmd('set viminfo+=%') + it('does not restore buffer list without % in &shada', function() + set_additional_cmd('set shada+=%') reset() nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - -- nvim_command('redir! > /tmp/vistr | verbose set viminfo? | redir END') - -- nvim_command('wviminfo /tmp/foo') + -- nvim_command('redir! > /tmp/vistr | verbose set shada? | redir END') + -- nvim_command('wshada /tmp/foo') set_additional_cmd('') nvim_command('qall') reset() - -- nvim_command('call writefile([&viminfo], "/tmp/vistr")') + -- nvim_command('call writefile([&shada], "/tmp/vistr")') eq(1, nvim_eval('bufnr("$")')) eq('', nvim_eval('bufname(1)')) end) - it('does not dump buffer list without % in &viminfo', function() + it('does not dump buffer list without % in &shada', function() nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - -- nvim_command('redir! > /tmp/vistr | verbose set viminfo? | redir END') - -- nvim_command('wviminfo /tmp/foo') - set_additional_cmd('set viminfo+=%') + -- nvim_command('redir! > /tmp/vistr | verbose set shada? | redir END') + -- nvim_command('wshada /tmp/foo') + set_additional_cmd('set shada+=%') nvim_command('qall') reset() - -- nvim_command('call writefile([&viminfo], "/tmp/vistr")') + -- nvim_command('call writefile([&shada], "/tmp/vistr")') eq(1, nvim_eval('bufnr("$")')) eq('', nvim_eval('bufname(1)')) end) diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 5a7db2bfa6..595938bfb2 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -13,23 +13,23 @@ describe('ShaDa support code', function() after_each(clear) it('is able to dump and read back command-line history', function() - nvim_command('set viminfo=\'0') + nvim_command('set shada=\'0') nvim_feed(':" Test\n') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('set viminfo=\'0') - nvim_command('rviminfo') + nvim_command('set shada=\'0') + nvim_command('rshada') eq('" Test', nvim_eval('histget(":", -1)')) end) it('is able to dump and read back 2 items in command-line history', function() - nvim_command('set viminfo=\'0 history=2') + nvim_command('set shada=\'0 history=2') nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') nvim_command('qall') reset() - nvim_command('set viminfo=\'0 history=2') - nvim_command('rviminfo') + nvim_command('set shada=\'0 history=2') + nvim_command('rshada') eq('" Test 2', nvim_eval('histget(":", -1)')) eq('" Test', nvim_eval('histget(":", -2)')) nvim_command('qall') @@ -37,50 +37,50 @@ describe('ShaDa support code', function() it('respects &history when dumping', function() - nvim_command('set viminfo=\'0 history=1') + nvim_command('set shada=\'0 history=1') nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('set viminfo=\'0 history=2') - nvim_command('rviminfo') + nvim_command('set shada=\'0 history=2') + nvim_command('rshada') eq('" Test 2', nvim_eval('histget(":", -1)')) eq('', nvim_eval('histget(":", -2)')) end) it('respects &history when loading', function() - nvim_command('set viminfo=\'0 history=2') + nvim_command('set shada=\'0 history=2') nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('set viminfo=\'0 history=1') - nvim_command('rviminfo') + nvim_command('set shada=\'0 history=1') + nvim_command('rshada') eq('" Test 2', nvim_eval('histget(":", -1)')) eq('', nvim_eval('histget(":", -2)')) end) it('dumps only requested amount of command-line history items', function() - nvim_command('set viminfo=\'0,:1') + nvim_command('set shada=\'0,:1') nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('set viminfo=\'0') - nvim_command('rviminfo') + nvim_command('set shada=\'0') + nvim_command('rshada') eq('" Test 2', nvim_eval('histget(":", -1)')) eq('', nvim_eval('histget(":", -2)')) end) - it('does not respect number in &viminfo when loading history', function() - nvim_command('set viminfo=\'0') + it('does not respect number in &shada when loading history', function() + nvim_command('set shada=\'0') nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('set viminfo=\'0,:1') - nvim_command('rviminfo') + nvim_command('set shada=\'0,:1') + nvim_command('rshada') eq('" Test 2', nvim_eval('histget(":", -1)')) eq('" Test', nvim_eval('histget(":", -2)')) end) @@ -93,9 +93,9 @@ describe('ShaDa support code', function() nvim_feed('/Test\n') -- Search history nvim_feed(':" Test\n') -- Command-line history nvim_command('0debuggreedy') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('rviminfo') + nvim_command('rshada') eq('" Test', nvim_eval('histget(":", -1)')) eq('Test', nvim_eval('histget("/", -1)')) eq('"Test"', nvim_eval('histget("=", -1)')) @@ -107,7 +107,7 @@ describe('ShaDa support code', function() nvim_eval('setline(".", ["foo", "bar"])') nvim_feed('gg0/a/e+1\n') eq({0, 2, 3, 0}, nvim_eval('getpos(".")')) - nvim_command('wviminfo') + nvim_command('wshada') reset() nvim_eval('setline(".", ["foo", "bar"])') nvim_feed('gg0n') @@ -118,7 +118,7 @@ describe('ShaDa support code', function() nvim_eval('setline(".", ["foo", "bar"])') nvim_command('%s/f/g/g') eq('goo', nvim_eval('getline(1)')) - nvim_command('wviminfo') + nvim_command('wshada') reset() nvim_eval('setline(".", ["foo", "bar"])') nvim_command('&') @@ -241,7 +241,7 @@ describe('ShaDa support code', function() reset() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 nvim_command('silent! /\171/') - nvim_command('set viminfo+=/0') + nvim_command('set shada+=/0') nvim_command('qall!') reset() nvim_eval('setline(".", ["\171«"])') @@ -256,7 +256,7 @@ describe('ShaDa support code', function() reset() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 nvim_command('silent! /\171/') - nvim_command('set viminfo+=/0') + nvim_command('set shada+=/0') set_additional_cmd('') nvim_command('qall') reset() @@ -270,7 +270,7 @@ describe('ShaDa support code', function() function() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 nvim_command('silent! /«/') - nvim_command('set viminfo+=/0') + nvim_command('set shada+=/0') set_additional_cmd('set encoding=latin1') nvim_command('qall') reset() diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index 25362b406b..b69477b6ed 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -38,9 +38,9 @@ describe('ShaDa support code', function() nvim_command('mark A') nvim_command('2') nvim_command('kB') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('rviminfo') + nvim_command('rshada') nvim_command('normal! `A') eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) eq(1, nvim_current_line()) @@ -48,13 +48,13 @@ describe('ShaDa support code', function() eq(2, nvim_current_line()) end) - it('does not dump global mark with `f0` in viminfo', function() - nvim_command('set viminfo+=f0') + it('does not dump global mark with `f0` in shada', function() + nvim_command('set shada+=f0') nvim_command('edit ' .. testfilename) nvim_command('mark A') nvim_command('2') nvim_command('kB') - nvim_command('wviminfo') + nvim_command('wshada') reset() nvim_command('language C') nvim_command([[ @@ -66,13 +66,13 @@ describe('ShaDa support code', function() eq('Vim(normal):E20: Mark not set', nvim('get_var', 'exception')) end) - it('does read back global mark even with `\'0` and `f0` in viminfo', 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('wviminfo') - set_additional_cmd('set viminfo=\'0,f0') + nvim_command('wshada') + set_additional_cmd('set shada=\'0,f0') reset() nvim_command('language C') nvim_command('normal! `A') @@ -103,7 +103,7 @@ describe('ShaDa support code', function() nvim_feed('G') nvim_feed('gg') -- nvim_command('redir! >/tmp/jumps.last | jumps | redir END') - -- nvim_command('wviminfo /tmp/foo') + -- nvim_command('wshada /tmp/foo') nvim_command('qall') reset() nvim_command('redraw') @@ -140,7 +140,7 @@ describe('ShaDa support code', function() nvim_command('sleep 2') nvim_feed('gg') -- nvim_command('redir! >/tmp/jumps.last | jumps | redir END') - -- nvim_command('wviminfo /tmp/foo') + -- nvim_command('wshada /tmp/foo') nvim_command('qall') reset() nvim_command('redraw') @@ -170,7 +170,7 @@ describe('ShaDa support code', function() nvim_command('qall!') reset() nvim_command('edit ' .. testfilename) - -- nvim_command('rviminfo') + -- nvim_command('rshada') -- nvim_command('redir! >/tmp/changes | changes | redir END') nvim_feed('Gg;') -- Note: without “sync” “commands” test has good changes to fail for unknown diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua index 7efb100cd6..67b0661151 100644 --- a/test/functional/shada/registers_spec.lua +++ b/test/functional/shada/registers_spec.lua @@ -48,7 +48,7 @@ describe('ShaDa support code', function() end) it('does not dump registers with zero <', function() - nvim_command('set viminfo=\'0,<0') + nvim_command('set shada=\'0,<0') setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') @@ -63,7 +63,7 @@ describe('ShaDa support code', function() setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') - set_additional_cmd('set viminfo=\'0,<0') + set_additional_cmd('set shada=\'0,<0') nvim_command('qa') reset() eq({{'d', 'e', ''}, 'v'}, getreg('c')) @@ -72,7 +72,7 @@ describe('ShaDa support code', function() end) it('does not dump registers with zero "', function() - nvim_command('set viminfo=\'0,\\"0') + nvim_command('set shada=\'0,\\"0') setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') @@ -87,7 +87,7 @@ describe('ShaDa support code', function() setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') - set_additional_cmd('set viminfo=\'0,\\"0') + set_additional_cmd('set shada=\'0,\\"0') nvim_command('qa') reset() eq({{'d', 'e', ''}, 'v'}, getreg('c')) @@ -96,7 +96,7 @@ describe('ShaDa support code', function() end) it('does dump registers with zero ", but non-zero <', function() - nvim_command('set viminfo=\'0,\\"0,<50') + nvim_command('set shada=\'0,\\"0,<50') setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') @@ -108,7 +108,7 @@ describe('ShaDa support code', function() end) it('does limit number of lines according to <', function() - nvim_command('set viminfo=\'0,<2') + nvim_command('set shada=\'0,<2') setreg('o', {'d'}, 'c') setreg('t', {'a', 'b', 'cde'}, 'l') nvim_command('qa') @@ -118,7 +118,7 @@ describe('ShaDa support code', function() end) it('does limit number of lines according to "', function() - nvim_command('set viminfo=\'0,\\"2') + nvim_command('set shada=\'0,\\"2') setreg('o', {'d'}, 'c') setreg('t', {'a', 'b', 'cde'}, 'l') nvim_command('qa') @@ -128,7 +128,7 @@ describe('ShaDa support code', function() end) it('does limit number of lines according to < rather then "', function() - nvim_command('set viminfo=\'0,\\"2,<3') + 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') diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua index 0ffa524238..c2fa25bcb1 100644 --- a/test/functional/shada/variables_spec.lua +++ b/test/functional/shada/variables_spec.lua @@ -14,21 +14,21 @@ describe('ShaDa support code', function() it('is able to dump and read back string variable', function() nvim('set_var', 'STRVAR', 'foo') - nvim_command('set viminfo+=!') - nvim_command('wviminfo') + nvim_command('set shada+=!') + nvim_command('wshada') reset() - nvim_command('set viminfo+=!') - nvim_command('rviminfo') + nvim_command('set shada+=!') + nvim_command('rshada') eq('foo', nvim('get_var', 'STRVAR')) end) local autotest = function(tname, varname, varval) it('is able to dump and read back ' .. tname .. ' variable automatically', function() - set_additional_cmd('set viminfo+=!') + set_additional_cmd('set shada+=!') reset() nvim('set_var', varname, varval) - -- Exit during `reset` is not a regular exit: it does not write viminfo + -- Exit during `reset` is not a regular exit: it does not write shada -- automatically nvim_command('qall') reset() @@ -42,43 +42,43 @@ describe('ShaDa support code', function() autotest('dictionary', 'DCTVAR', {a=10}) autotest('list', 'LSTVAR', {{a=10}, {b=10.5}, {c='str'}}) - it('does not read back variables without `!` in &viminfo', function() + it('does not read back variables without `!` in &shada', function() nvim('set_var', 'STRVAR', 'foo') - nvim_command('set viminfo+=!') - nvim_command('wviminfo') - set_additional_cmd('set viminfo-=!') + nvim_command('set shada+=!') + nvim_command('wshada') + set_additional_cmd('set shada-=!') reset() - nvim_command('rviminfo') + nvim_command('rshada') eq(0, nvim_eval('exists("g:STRVAR")')) end) - it('does not dump variables without `!` in &viminfo', function() - nvim_command('set viminfo-=!') + it('does not dump variables without `!` in &shada', function() + nvim_command('set shada-=!') nvim('set_var', 'STRVAR', 'foo') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('set viminfo+=!') - nvim_command('rviminfo') + nvim_command('set shada+=!') + nvim_command('rshada') eq(0, nvim_eval('exists("g:STRVAR")')) end) it('does not dump session variables', function() - nvim_command('set viminfo+=!') + nvim_command('set shada+=!') nvim('set_var', 'StrVar', 'foo') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('set viminfo+=!') - nvim_command('rviminfo') + nvim_command('set shada+=!') + nvim_command('rshada') eq(0, nvim_eval('exists("g:StrVar")')) end) it('does not dump regular variables', function() - nvim_command('set viminfo+=!') + nvim_command('set shada+=!') nvim('set_var', 'str_var', 'foo') - nvim_command('wviminfo') + nvim_command('wshada') reset() - nvim_command('set viminfo+=!') - nvim_command('rviminfo') + nvim_command('set shada+=!') + nvim_command('rshada') eq(0, nvim_eval('exists("g:str_var")')) end) -- cgit From f43a5e692647de81a692e537f1e748667ff84fb4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 7 Jul 2015 23:05:01 +0300 Subject: shada: Save v:hlsearch value --- test/functional/shada/history_spec.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test') diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 595938bfb2..c4d39bd547 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -114,6 +114,31 @@ describe('ShaDa support code', function() eq({0, 2, 3, 0}, nvim_eval('getpos(".")')) end) + it('saves v:hlsearch=1', function() + nvim_command('set hlsearch') + nvim_feed('/test\n') + nvim_command('qall') + reset() + eq(1, nvim_eval('v:hlsearch')) + end) + + it('saves v:hlsearch=0 with :nohl', function() + nvim_command('set hlsearch') + nvim_feed('/test\n') + nvim_command('nohlsearch') + nvim_command('qall') + reset() + eq(0, nvim_eval('v:hlsearch')) + end) + + it('saves v:hlsearch=0 with :set viminfo-=h', function() + nvim_command('set hlsearch viminfo-=h') + nvim_feed('/test\n') + nvim_command('qall') + reset() + eq(0, nvim_eval('v:hlsearch')) + end) + it('dumps and loads last substitute pattern and replacement string', function() nvim_eval('setline(".", ["foo", "bar"])') nvim_command('%s/f/g/g') -- cgit From 1d3823a5c9c7b7494966d4e0851e2c1decbed76c Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 7 Jul 2015 23:49:22 +0300 Subject: shada: Populate v:oldfiles --- test/functional/shada/marks_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index b69477b6ed..4909ae608e 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -95,6 +95,21 @@ describe('ShaDa support code', function() eq(2, nvim_current_line()) end) + it('is able to populate v:oldfiles', function() + nvim_command('edit ' .. testfilename) + local tf_full = nvim_eval('fnamemodify(bufname("%"), ":p")') + nvim_command('edit ' .. testfilename_2) + local tf_full_2 = nvim_eval('fnamemodify(bufname("%"), ":p")') + nvim_command('qall') + reset() + local oldfiles = nvim('get_vvar', 'oldfiles') + eq(2, #oldfiles) + eq(testfilename, oldfiles[1]:sub(-#testfilename)) + eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2)) + eq(tf_full, oldfiles[1]) + eq(tf_full_2, oldfiles[2]) + end) + it('is able to dump and restore jump list', function() nvim_command('edit ' .. testfilename_2) nvim_feed('G') -- cgit From 875d287d4bacffd41bd0d553163da5579ba5e55f Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 10 Jul 2015 20:53:34 +0300 Subject: functests: Test that history is still accessible after :wshada --- test/functional/shada/history_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index c4d39bd547..0c39b65ee1 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -66,6 +66,9 @@ describe('ShaDa support code', function() nvim_feed(':" Test\n') nvim_feed(':" Test 2\n') nvim_command('wshada') + -- Regression test: :wshada should not alter or free history. + eq('" Test 2', nvim_eval('histget(":", -1)')) + eq('" Test', nvim_eval('histget(":", -2)')) reset() nvim_command('set shada=\'0') nvim_command('rshada') -- cgit From e2994a3c62265a26a632ed7cd4d11ce4fb711586 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Jul 2015 01:52:50 +0300 Subject: shada,functests: Test how ShaDa support code reacts on errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some notes: - Replaced msgpack_unpacker usage with regular xmalloc’ed buffer. Also since msgpack_unpack_next (as well as msgpack_unpacker_next) is not ever going to return MSGPACK_UNPACK_EXTRA_BYTES this condition was checked manually. Function that does return this status is msgpack_unpack, but it is marked as obsolete. - Zero type is checked prior to main switch in shada_read_next_item because otherwise check would be skipped. - Zeroing entry at the start of shada_read_next_item makes it safer. - dedent('') does not work. - v:oldfiles list is only replaced with bang, if it is NULL or empty. --- test/functional/helpers.lua | 7 +- test/functional/shada/errors_spec.lua | 399 ++++++++++++++++++++++++++++++++++ test/functional/shada/helpers.lua | 19 +- test/functional/shada/marks_spec.lua | 12 +- 4 files changed, 424 insertions(+), 13 deletions(-) create mode 100644 test/functional/shada/errors_spec.lua (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index a6f4f7c2e5..23581ba4d2 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -220,9 +220,12 @@ local function execute(...) end -- Dedent the given text and write it to the file name. -local function write_file(name, text) +local function write_file(name, text, dont_dedent) local file = io.open(name, 'w') - file:write(dedent(text)) + if not dont_dedent then + text = dedent(text) + end + file:write(text) file:flush() file:close() end diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua new file mode 100644 index 0000000000..5107273115 --- /dev/null +++ b/test/functional/shada/errors_spec.lua @@ -0,0 +1,399 @@ +-- ShaDa errors handling support +local helpers = require('test.functional.helpers') +local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = + helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, + helpers.eval, helpers.eq +local write_file = helpers.write_file + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear, exc_exec = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear, shada_helpers.exc_exec + +local shada_fname = 'Xtest-functional-shada-errors.shada' +local wshada = function(text) + write_file(shada_fname, text, true) +end +local sdrcmd = function(bang) + return 'rshada' .. (bang and '!' or '') .. ' ' .. shada_fname +end + +describe('ShaDa error handling', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + local i = ('a'):byte() + while i < ('z'):byte() do + if not os.remove(shada_fname .. ('.tmp.%c'):format(i)) then + break + end + i = i + 1 + end + end) + + -- Note: most of tests have additional items like sX, mX, rX. These are for + -- valgrind tests, to check for memory leaks (i.e. whether error handling code + -- does (not) forget to call ga_clear). Not needed for array-based items like + -- history because they are not using ad_ga. + + it('does not fail on empty file', function() + wshada('') + eq(0, exc_exec(sdrcmd())) + end) + + it('fails on zero', function() + wshada('\000') + eq('Vim(rshada):E575: 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):E575: 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):E575: 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() + -- Header items are skipped when reading. + wshada('\001\000\000') + eq(0, exc_exec(sdrcmd())) + end) + + it('fails on search pattern item with zero length', function() + wshada('\002\000\000') + eq('Vim(rshada):E575: Failed to parse ShaDa file: incomplete msgpack string at position 0', exc_exec(sdrcmd())) + end) + + it('fails on search pattern item with -2 timestamp', function() + wshada('\002\254\000') + eq('Vim(rshada):E575: 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):E575: 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):E575: 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() + -- 195 (== 0xC1) cannot start any valid messagepack entry (the only byte + -- that cannot do this). Specifically unpack_template.h contains + -- + -- //case 0xc1: // string + -- // again_terminal_trail(NEXT_CS(p), p+1); + -- + -- (literally: commented out code) which means that in place of this code + -- `goto _failed` is used from default: case. I do not know any other way to + -- get MSGPACK_UNPACK_PARSE_ERROR and not MSGPACK_UNPACK_CONTINUE or + -- MSGPACK_UNPACK_EXTRA_BYTES. + wshada('\002\000\001\193') + eq('Vim(rshada):E575: Failed to parse ShaDa file due to a msgpack parser error at position 0', exc_exec(sdrcmd())) + end) + + it('fails on search pattern item with incomplete map', function() + wshada('\002\000\001\129') + eq('Vim(rshada):E575: Failed to parse ShaDa file: incomplete msgpack string at position 0', 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())) + end) + + it('fails on search pattern with extra bytes', function() + wshada('\002\000\002\128\000') + eq('Vim(rshada):E575: Failed to parse ShaDa file: extra bytes in msgpack string at position 0', 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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] + + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + 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())) + end) +end) diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index 7e93fcb915..909fcd62e6 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers') -local spawn, set_session, nvim, nvim_prog = - helpers.spawn, helpers.set_session, helpers.nvim, helpers.nvim_prog +local spawn, set_session, nvim, nvim_prog, nvim_command, nvim_eval = + helpers.spawn, helpers.set_session, helpers.nvim, helpers.nvim_prog, + helpers.command, helpers.eval local tmpname = os.tmpname() local additional_cmd = '' @@ -46,8 +47,22 @@ local clear = function() set_additional_cmd('') end +local exc_exec = function(cmd) + nvim_command(([[ + try + execute "%s" + catch + let g:__exception = v:exception + endtry + ]]):format(cmd:gsub('\n', '\\n'):gsub('[\\"]', '\\%0'))) + local ret = nvim_eval('get(g:, "__exception", 0)') + nvim_command('unlet! g:__exception') + return ret +end + return { reset=reset, set_additional_cmd=set_additional_cmd, clear=clear, + exc_exec=exc_exec, } diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index 4909ae608e..341ca2d647 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -5,9 +5,9 @@ local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.eval, helpers.eq local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear = +local reset, set_additional_cmd, clear, exc_exec = shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear + shada_helpers.clear, shada_helpers.exc_exec local nvim_current_line = function() return nvim_window('get_cursor', nvim_curwin())[1] @@ -57,13 +57,7 @@ describe('ShaDa support code', function() nvim_command('wshada') reset() nvim_command('language C') - nvim_command([[ - try - execute "normal! `A" - catch - let exception = v:exception - endtry]]) - eq('Vim(normal):E20: Mark not set', nvim('get_var', 'exception')) + 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() -- cgit From 56174572bc70947ab1e9e6ef48112272682ad6d8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 2 Aug 2015 02:49:44 +0300 Subject: shada,documentation: Extend read error handling, handle write errors Modifications: - If file was not written due to write error then writing stops and temporary file will not be renamed. - If NeoVim detects that target file is not a ShaDa file then temporary file will not be renamed. --- test/functional/shada/errors_spec.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index 5107273115..4ae7847cc7 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -44,17 +44,17 @@ describe('ShaDa error handling', function() it('fails on zero', function() wshada('\000') - eq('Vim(rshada):E575: 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):E575: 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):E575: 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() @@ -65,22 +65,22 @@ describe('ShaDa error handling', function() it('fails on search pattern item with zero length', function() wshada('\002\000\000') - eq('Vim(rshada):E575: Failed to parse ShaDa file: incomplete msgpack string at position 0', exc_exec(sdrcmd())) + eq('Vim(rshada):E576: Failed to parse ShaDa file: incomplete msgpack string at position 0', exc_exec(sdrcmd())) end) it('fails on search pattern item with -2 timestamp', function() wshada('\002\254\000') - eq('Vim(rshada):E575: 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):E575: 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):E575: 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() @@ -95,12 +95,12 @@ 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):E575: Failed to parse ShaDa file due to a msgpack parser error at position 0', exc_exec(sdrcmd())) + eq('Vim(rshada):E576: Failed to parse ShaDa file due to a msgpack parser error at position 0', exc_exec(sdrcmd())) end) it('fails on search pattern item with incomplete map', function() wshada('\002\000\001\129') - eq('Vim(rshada):E575: Failed to parse ShaDa file: incomplete msgpack string at position 0', exc_exec(sdrcmd())) + eq('Vim(rshada):E576: Failed to parse ShaDa file: incomplete msgpack string at position 0', exc_exec(sdrcmd())) end) it('fails on search pattern item without a pattern', function() @@ -110,7 +110,7 @@ describe('ShaDa error handling', function() it('fails on search pattern with extra bytes', function() wshada('\002\000\002\128\000') - eq('Vim(rshada):E575: Failed to parse ShaDa file: extra bytes in msgpack string at position 0', exc_exec(sdrcmd())) + eq('Vim(rshada):E576: Failed to parse ShaDa file: extra bytes in msgpack string at position 0', exc_exec(sdrcmd())) end) it('fails on search pattern item with NIL value', function() -- cgit From 2244db67aa0dc1100dc5814c2bf070d76cf5f313 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 4 Aug 2015 08:19:01 +0300 Subject: shada: Do not allow empty keys --- test/functional/shada/errors_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index 4ae7847cc7..e3a1dcdbb9 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -124,6 +124,12 @@ describe('ShaDa error handling', function() 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())) + 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())) @@ -192,6 +198,12 @@ describe('ShaDa error handling', function() 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())) + 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())) @@ -244,6 +256,12 @@ describe('ShaDa error handling', function() 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())) + 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())) -- cgit From 12a31c70c1beb3d106c4450bbd2ab33a1f8c2316 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Jul 2015 20:46:40 +0300 Subject: shada,functests: Test compatibility support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For compatibility the following things are done: 1. Items with type greater then greatest type are ignored when reading and copied when writing. 2. Registers with unknown name are ignored when reading and blindly copied when writing. 3. Registers with unknown type are ignored when reading and merged as usual when writing. 4. Local and global marks with unknown names are ignored when reading. When writing global marks are blindly copied and local marks are also blindly copied, but only if file they are attached to fits in the `'N` limit defined in &shada. Unknown local mark’s timestamp is also taken into account when calculating which files exactly should fit into this limit. 5. History items with unknown type are ignored when reading and blindly copied when writing. 6. Unknown keys found in register, local marks, global marks, changes, jumps and search pattern entries are read to additional_data Dictionary and dumped (of course, unless any of these elements were not overwritten later). It obviously works only for values conversible to Object type. 7. Additional elements found in replacement string and history entries are read to additional_elements Array and dumped (same: only if they were not overwritten later). Again this works only for elements conversible to Object type. 8. Additional elements found in variable entries are simply ignored when reading. When writing *new* variables they will be preserved during merging, but that’s all. Variable values dumped from current NeoVim session never have additional elements. --- test/functional/shada/compatibility_spec.lua | 420 +++++++++++++++++++++++++++ 1 file changed, 420 insertions(+) create mode 100644 test/functional/shada/compatibility_spec.lua (limited to 'test') diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua new file mode 100644 index 0000000000..5c48d82f4a --- /dev/null +++ b/test/functional/shada/compatibility_spec.lua @@ -0,0 +1,420 @@ +-- ShaDa compatibility support +local helpers = require('test.functional.helpers') +local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = + helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, + helpers.eval, helpers.eq +local write_file = helpers.write_file + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear, exc_exec = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear, shada_helpers.exc_exec + +local shada_fname = 'Xtest-functional-shada-additional.shada' +local wshada = function(text) + write_file(shada_fname, text, true) +end +local sdrcmd = function(bang) + return 'rshada' .. (bang and '!' or '') .. ' ' .. shada_fname +end + +local msgpack = require('MessagePack') +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 unpacker = msgpack.unpacker(mstring) + local ret = {} + local cur + local i = 0 + while true do + local off, val = unpacker() + if not off then break end + if i % 4 == 0 then + cur = {} + ret[#ret + 1] = cur + end + cur[mpack_keys[(i % 4) + 1]] = val + i = i + 1 + end + return ret +end + +describe('ShaDa forward compatibility support code', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + end) + + it('works with search pattern item with BOOL unknown (sX) key value', function() + wshada('\002\001\011\130\162sX\194\162sp\196\001-') + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('wshada ' .. shada_fname) + local found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and not v.value.ss then + eq(false, v.value.sX) + found = true + end + end + eq(true, found) + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('silent! /---/') + nvim_command('wshada ' .. shada_fname) + found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.ss then + eq(nil, v.value.sX) + found = true + end + end + eq(true, found) + end) + + it('works with s/search pattern item with BOOL unknown (sX) key value', function() + wshada('\002\001\015\131\162sX\194\162ss\195\162sp\196\001-') + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('wshada ' .. shada_fname) + local found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.ss then + eq(false, v.value.sX) + found = true + end + end + eq(true, found) + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('silent! s/--/---/ge') + nvim_command('wshada ' .. shada_fname) + found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.ss then + eq(nil, v.value.sX) + found = true + end + end + eq(true, found) + end) + + it('works with replacement item with BOOL additional value in list', function() + wshada('\003\000\005\146\196\001-\194') + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('wshada ' .. shada_fname) + local found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 3 then + eq(2, #v.value) + eq(false, v.value[2]) + found = true + end + end + eq(true, found) + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('silent! s/--/---/ge') + nvim_command('wshada ' .. shada_fname) + found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 3 then + eq(1, #v.value) + found = true + end + end + eq(true, found) + end) + + for _, v in ipairs({{name='global mark', mpack='\007\001\018\131\162mX\195\161f\196\006/a/b/c\161nA'}, + {name='jump', mpack='\008\001\018\131\162mX\195\161f\196\006/a/b/c\161l\002'}, + {name='local mark', mpack='\010\001\018\131\162mX\195\161f\196\006/a/b/c\161na'}, + {name='change', mpack='\011\001\015\130\162mX\195\161f\196\006/a/b/c'}, + }) do + it('works with ' .. v.name .. ' item with BOOL unknown (mX) key value', function() + nvim_command('silent noautocmd edit /a/b/c') + eq('/a/b/c', nvim_eval('bufname("%")')) + nvim_command('call setline(".", ["1", "2", "3"])') + wshada(v.mpack) + eq(0, exc_exec(sdrcmd(true))) + os.remove(shada_fname) + nvim_command('wshada ' .. shada_fname) + local found = false + for _, subv in ipairs(read_shada_file(shada_fname)) do + if subv.type == v.mpack:byte() then + if subv.value.mX == true then + found = true + end + end + end + eq(true, found) + eq(0, exc_exec(sdrcmd())) + nvim_command('bwipeout!') + nvim_eval('setpos("\'A", [0, 1, 1, 0])') + os.remove(shada_fname) + nvim_command('wshada ' .. shada_fname) + found = false + for _, subv in ipairs(read_shada_file(shada_fname)) do + if subv.type == v.mpack:byte() then + if subv.value.mX == true then + found = true + end + end + end + eq(false, found) + end) + + if v.name == 'global mark' or v.name == 'local mark' then + it('works with ' .. v.name .. ' item with name', function() + nvim_command('silent noautocmd edit /a/b/c') + eq('/a/b/c', nvim_eval('bufname("%")')) + nvim_command('call setline(".", ["1", "2", "3"])') + wshada(v.mpack:gsub('n.$', 'n\001') + .. v.mpack:gsub('n.$', 'n\002') + .. v.mpack:gsub('n.$', 'n\003'):gsub('/a/b/c', '/d/e/f')) + eq(0, exc_exec(sdrcmd(true))) + nvim_command('wshada ' .. shada_fname) + local found = 0 + for i, subv in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, subv.type) + end + if subv.type == v.mpack:byte() then + if subv.value.mX == true and subv.value.n <= 3 then + found = found + 1 + end + end + end + eq(3, found) + nvim_command('wshada! ' .. shada_fname) + local found = 0 + for i, subv in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, subv.type) + end + if subv.type == v.mpack:byte() then + if subv.value.mX == true and subv.value.n <= 3 then + found = found + 1 + end + end + end + eq(0, found) + end) + end + end + + it('works with register item with BOOL unknown (rX) key', function() + wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('wshada ' .. shada_fname) + local found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 5 and v.value.rX == false then + found = true + end + end + eq(true, found) + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('let @a = "Test"') + nvim_command('wshada ' .. shada_fname) + found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 5 and v.value.rX == false then + found = true + end + end + eq(false, found) + end) + + it('works with register item with name', function() + wshada('\005\001\015\131\161n\001\162rX\194\162rc\145\196\001-') + eq(0, exc_exec(sdrcmd(true))) + nvim_command('wshada ' .. shada_fname) + local found = 0 + for i, v in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, v.type) + end + if v.type == 5 then + if v.value.rX == false and v.value.n == 1 then + found = found + 1 + end + end + end + eq(1, found) + nvim_command('wshada! ' .. shada_fname) + local found = 0 + for i, v in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, v.type) + end + if v.type == 5 then + if v.value.rX == false and v.value.n == 1 then + found = found + 1 + end + end + end + eq(0, found) + 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({{}, ''}, nvim_eval('[getreg("a", 1, 1)[:], getregtype("a")]')) + nvim_command('wshada ' .. shada_fname) + local found = 0 + for i, v in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, v.type) + end + if v.type == 5 then + if v.value.rX == false and v.value.rt == 10 then + found = found + 1 + end + end + end + eq(1, found) + nvim_command('wshada! ' .. shada_fname) + local found = 0 + for i, v in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, v.type) + end + if v.type == 5 then + if v.value.rX == false and v.value.rt == 10 then + found = found + 1 + end + end + end + eq(0, found) + 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/a/b/c\162bX\195') + eq(0, exc_exec(sdrcmd())) + eq(2, nvim_eval('bufnr("$")')) + eq('/a/b/c', nvim_eval('bufname(2)')) + os.remove(shada_fname) + nvim_command('wshada ' .. shada_fname) + local found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 9 and #v.value == 1 and v.value[1].bX == true then + found = true + end + end + eq(true, found) + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('buffer 2') + nvim_command('edit!') + nvim_command('wshada ' .. shada_fname) + found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 5 and v.value.rX == false then + found = true + end + end + eq(false, found) + nvim_command('bwipeout!') + end) + + it('works with history item with BOOL additional value in list', function() + wshada('\004\000\006\147\000\196\001-\194') + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_command('wshada ' .. shada_fname) + local found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 and v.value[2] == '-' then + eq(false, v.value[3]) + eq(3, #v.value) + found = true + end + end + eq(true, found) + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + nvim_eval('histadd(":", "--")') + nvim_eval('histadd(":", "-")') + nvim_command('wshada ' .. shada_fname) + found = false + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 and v.value[2] == '-' then + eq(2, #v.value) + found = true + end + end + eq(true, found) + end) + + it('works with history item with type 10', function() + wshada('\004\000\006\147\010\196\001-\194') + eq(0, exc_exec(sdrcmd())) + nvim_command('wshada ' .. shada_fname) + eq(0, exc_exec(sdrcmd())) + local found = 0 + for i, v in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, v.type) + end + if v.type == 4 then + if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then + found = found + 1 + end + end + end + eq(1, found) + nvim_command('wshada! ' .. shada_fname) + local found = 0 + for i, v in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, v.type) + end + if v.type == 4 then + if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then + found = found + 1 + end + end + end + eq(0, found) + end) + + it('works with item with 100 type', function() + wshada('\100\000\006\147\010\196\001-\194') + eq(0, exc_exec(sdrcmd())) + nvim_command('wshada ' .. shada_fname) + eq(0, exc_exec(sdrcmd())) + local found = 0 + for i, v in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, v.type) + end + if v.type == 100 then + if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then + found = found + 1 + end + end + end + eq(1, found) + nvim_command('wshada! ' .. shada_fname) + local found = 0 + for i, v in ipairs(read_shada_file(shada_fname)) do + if i == 1 then + eq(1, v.type) + end + if v.type == 100 then + if v.value[1] == 10 and #v.value == 3 and v.value[3] == false then + found = found + 1 + end + end + end + eq(0, found) + end) +end) -- cgit From 1542fc221e52f31d5102730a222b5dbbae782dcd Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Aug 2015 13:27:55 +0300 Subject: shada,functests: Improve detection of invalid ShaDa files It appears that large portion of non-ShaDa ASCII text files may be parsed as a ShaDa file because it is mostly recognized as a sequence of unknown entries: all ASCII non-control characters are recognized as FIXUINT shada objects, so text like #!/bin/sh powerline "$@" 2>&1 | tee -a powerline (with trailing newline) will be recognized as a correct ShaDa file containing single unknown entry with type 0x23 (dec 35, '#'), timestamp 0x21 (dec 33, '!') and length 0x2F (dec 47, '/') without this commit. With it parsing this entry will fail. --- test/functional/shada/errors_spec.lua | 90 +++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index e3a1dcdbb9..0dfb204b35 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -65,7 +65,7 @@ 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 0', 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() @@ -95,12 +95,12 @@ 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 0', 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 0', 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() @@ -110,7 +110,7 @@ describe('ShaDa error handling', function() 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 0', 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() @@ -414,4 +414,86 @@ describe('ShaDa error handling', function() 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())) end) + + it('fails on invalid ShaDa file (viminfo file)', function() + wshada([[# This viminfo file was generated by Vim 7.4. +# You may edit it if you're careful! + +# Value of 'encoding' when this file was written +*encoding=utf-8 + + +# hlsearch on (H) or off (h): +~h +# Last Search Pattern: +~MSle0~/buffer=abuf + +# Last Substitute Search Pattern: +~MSle0&^$ + +# Last Substitute String: +$ + +# Command Line History (newest to oldest): +:cq + +# Search String History (newest to oldest): +? \ + +# Expression History (newest to oldest): +=system('echo "\xAB"') + +# Input Line History (newest to oldest): +@i + +# Input Line History (newest to oldest): + +# Registers: +"0 LINE 0 + case FLAG_B: puts("B"); break; +"1 LINE 0 + pick 874a489 shada,functests: Test compatibility support +""- CHAR 0 + . + +# global variables: +!STUF_HISTORY_TRANSLIT LIS [] +!TR3_INPUT_HISTORY LIS [] + +# File marks: +'A 8320 12 ~/a.a/Proj/c/neovim-2076/src/nvim/ex_docmd.c +'0 66 5 ~/a.a/Proj/c/neovim/.git/rebase-merge/git-rebase-todo +'1 7 0 ~/.vam/powerline/.git/MERGE_MSG +'2 64 4 ~/a.a/Proj/c/neovim/.git/rebase-merge/git-rebase-todo +'3 9 0 ~/a.a/Proj/c/neovim/.git/COMMIT_EDITMSG +'4 62 0 ~/a.a/Proj/c/neovim/.git/rebase-merge/git-rebase-todo +'5 57 4 ~/a.a/Proj/c/neovim/.git/rebase-merge/git-rebase-todo +'6 1 0 ~/a.a/Proj/c/neovim/.git/rebase-merge/git-rebase-todo +'7 399 7 /usr/share/vim/vim74/doc/motion.txt +'8 1 0 ~/a.a/Proj/c/zpython/build/CMakeFiles/3.2.2/CMakeCCompiler.cmake +'9 1 0 ~/a.a/Proj/c/vim/README.txt + +# Jumplist (newest first): +-' 66 5 ~/a.a/Proj/c/neovim/.git/rebase-merge/git-rebase-todo + +# History of marks within files (newest to oldest): + +> ~/a.a/Proj/c/neovim/.git/rebase-merge/git-rebase-todo + " 66 5 + ^ 66 6 + . 66 5 + + 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(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(0, exc_exec('wshada! ' .. shada_fname)) + end) end) -- cgit From 17b5d27d85e772907fe3ca48fd8f58117564c72c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Aug 2015 14:54:47 +0300 Subject: functests: Move wshada and sdrcmd commands to helpers --- test/functional/shada/compatibility_spec.lua | 14 ++++---------- test/functional/shada/errors_spec.lua | 16 +++++----------- test/functional/shada/helpers.lua | 12 ++++++++++++ 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index 5c48d82f4a..fba6f54feb 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -3,20 +3,14 @@ local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq -local write_file = helpers.write_file local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, exc_exec = +local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear, shada_helpers.exc_exec + shada_helpers.clear, shada_helpers.exc_exec, + shada_helpers.get_shada_rw -local shada_fname = 'Xtest-functional-shada-additional.shada' -local wshada = function(text) - write_file(shada_fname, text, true) -end -local sdrcmd = function(bang) - return 'rshada' .. (bang and '!' or '') .. ' ' .. shada_fname -end +local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-compatibility.shada') local msgpack = require('MessagePack') local mpack_keys = {'type', 'timestamp', 'length', 'value'} diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index 0dfb204b35..a53b5cee2b 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -3,20 +3,14 @@ local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq -local write_file = helpers.write_file local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, exc_exec = +local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear, shada_helpers.exc_exec - -local shada_fname = 'Xtest-functional-shada-errors.shada' -local wshada = function(text) - write_file(shada_fname, text, true) -end -local sdrcmd = function(bang) - return 'rshada' .. (bang and '!' or '') .. ' ' .. shada_fname -end + shada_helpers.clear, shada_helpers.exc_exec, + shada_helpers.get_shada_rw + +local wshada, sdrcmd, shada_fname = get_shada_rw('Xtest-functional-shada-errors.shada') describe('ShaDa error handling', function() before_each(reset) diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index 909fcd62e6..180b6f8c44 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers') local spawn, set_session, nvim, nvim_prog, nvim_command, nvim_eval = helpers.spawn, helpers.set_session, helpers.nvim, helpers.nvim_prog, helpers.command, helpers.eval +local write_file = helpers.write_file local tmpname = os.tmpname() local additional_cmd = '' @@ -60,9 +61,20 @@ local exc_exec = function(cmd) return ret end +local get_shada_rw = function(fname) + local wshada = function(text) + write_file(fname, text, true) + end + local sdrcmd = function(bang) + return 'rshada' .. (bang and '!' or '') .. ' ' .. fname + end + return wshada, sdrcmd, fname +end + return { reset=reset, set_additional_cmd=set_additional_cmd, clear=clear, exc_exec=exc_exec, + get_shada_rw=get_shada_rw, } -- cgit From fd4d5521a3445b36fba69046ba6fb0caad8f398d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Aug 2015 19:47:32 +0300 Subject: shada,functests: Use special sd_reader function for skipping --- test/functional/shada/errors_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index a53b5cee2b..739f2ff148 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -490,4 +490,11 @@ $ 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(0, exc_exec('wshada! ' .. shada_fname)) + end) end) -- cgit From 830c8bd23e693a9081ea7ebeb11b415822b1e3b3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 9 Aug 2015 18:41:25 +0300 Subject: functests: Add a number of “generic” functional tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/functional/shada/compatibility_spec.lua | 24 +---- test/functional/shada/errors_spec.lua | 12 +-- test/functional/shada/helpers.lua | 38 +++++++- test/functional/shada/shada_spec.lua | 130 +++++++++++++++++++++++++++ 4 files changed, 171 insertions(+), 33 deletions(-) create mode 100644 test/functional/shada/shada_spec.lua (limited to 'test') diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index fba6f54feb..45d747658a 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -9,32 +9,10 @@ local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = shada_helpers.reset, shada_helpers.set_additional_cmd, shada_helpers.clear, shada_helpers.exc_exec, 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') -local msgpack = require('MessagePack') -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 unpacker = msgpack.unpacker(mstring) - local ret = {} - local cur - local i = 0 - while true do - local off, val = unpacker() - if not off then break end - if i % 4 == 0 then - cur = {} - ret[#ret + 1] = cur - end - cur[mpack_keys[(i % 4) + 1]] = val - i = i + 1 - end - return ret -end - describe('ShaDa forward compatibility support code', function() before_each(reset) after_each(function() diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index 739f2ff148..ce849fdcbd 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -10,20 +10,14 @@ local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = shada_helpers.clear, shada_helpers.exc_exec, shada_helpers.get_shada_rw -local wshada, sdrcmd, shada_fname = 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) after_each(function() clear() - os.remove(shada_fname) - local i = ('a'):byte() - while i < ('z'):byte() do - if not os.remove(shada_fname .. ('.tmp.%c'):format(i)) then - break - end - i = i + 1 - end + clean() end) -- Note: most of tests have additional items like sX, mX, rX. These are for diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index 180b6f8c44..d37e84f156 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -4,6 +4,8 @@ local spawn, set_session, nvim, nvim_prog, nvim_command, nvim_eval = helpers.command, helpers.eval local write_file = helpers.write_file +local msgpack = require('MessagePack') + local tmpname = os.tmpname() local additional_cmd = '' @@ -68,7 +70,40 @@ local get_shada_rw = function(fname) local sdrcmd = function(bang) return 'rshada' .. (bang and '!' or '') .. ' ' .. fname end - return wshada, sdrcmd, fname + local clean = function() + os.remove(fname) + local i = ('a'):byte() + while i <= ('z'):byte() do + if not os.remove(fname .. ('.tmp.%c'):format(i)) then + break + end + i = i + 1 + end + end + return wshada, sdrcmd, fname, clean +end + +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 unpacker = msgpack.unpacker(mstring) + local ret = {} + local cur + local i = 0 + while true do + local off, val = unpacker() + if not off then break end + if i % 4 == 0 then + cur = {} + ret[#ret + 1] = cur + end + cur[mpack_keys[(i % 4) + 1]] = val + i = i + 1 + end + return ret end return { @@ -77,4 +112,5 @@ return { clear=clear, exc_exec=exc_exec, get_shada_rw=get_shada_rw, + read_shada_file=read_shada_file, } diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua new file mode 100644 index 0000000000..19b8a47244 --- /dev/null +++ b/test/functional/shada/shada_spec.lua @@ -0,0 +1,130 @@ +-- Other ShaDa tests +local helpers = require('test.functional.helpers') +local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = + helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, + helpers.eval, helpers.eq +local write_file = helpers.write_file +local lfs = require('lfs') + +local msgpack = require('MessagePack') + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear, shada_helpers.exc_exec, + shada_helpers.get_shada_rw +local read_shada_file = shada_helpers.read_shada_file + +local wshada, sdrcmd, shada_fname, clean = get_shada_rw('Xtest-functional-shada-shada.shada') + +describe('ShaDa support code', function() + before_each(reset) + after_each(function() + clear() + clean() + 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)) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 100 then + found = found + 1 + end + end + eq(2, found) + eq(0, exc_exec('set shada-=s10 shada+=s1')) + eq(0, exc_exec('wshada ' .. shada_fname)) + found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 100 then + found = found + 1 + end + end + eq(1, found) + end) + + it('preserves `s` item size limit with instance history entries', function() + local hist1 = ('-'):rep(1024 - 5) + local hist2 = ('-'):rep(1025 - 5) + nvim_command('set shada-=s10 shada+=s1') + nvim_eval(('histadd(":", "%s")'):format(hist1)) + nvim_eval(('histadd(":", "%s")'):format(hist2)) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 then + found = found + 1 + eq(hist1, v.value[2]) + end + end + eq(1, found) + end) + + it('leaves .tmp.a in-place when there is error in original ShaDa', function() + wshada('Some text file') + eq('Vim(wshada):E576: Error while reading ShaDa file: last entry specified that it occupies 109 bytes, but file ended earlier', exc_exec('wshada ' .. shada_fname)) + 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, lfs.attributes(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(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 + 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('') + local i = ('a'):byte() + while i <= ('z'):byte() do + write_file(shada_fname .. ('.tmp.%c'):format(i), '', true) + i = i + 1 + end + eq('Vim(wshada):E138: All Xtest-functional-shada-shada.shada.tmp.X files exist, cannot write ShaDa file!', exc_exec('wshada ' .. shada_fname)) + end) + + it('reads correctly various timestamps', function() + local mpack = { + '\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(mpack, e .. s) .. e) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + local typ = select(2, msgpack.unpacker(s)()) + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == typ then + found = found + 1 + eq(select(2, msgpack.unpacker(mpack[found])()), v.timestamp) + end + end + eq(#mpack, found) + end) +end) -- cgit From 4dc3bc8fc1d94f9f97ab06d030b9279e7e3b5934 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 10 Aug 2015 01:39:50 +0300 Subject: shada,functests: Make sure that v:oldfiles list is reset on :rshada! --- test/functional/shada/marks_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index 341ca2d647..8b9e70045c 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -102,6 +102,13 @@ describe('ShaDa support code', function() eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2)) eq(tf_full, oldfiles[1]) eq(tf_full_2, oldfiles[2]) + nvim_command('rshada!') + local oldfiles = nvim('get_vvar', 'oldfiles') + eq(2, #oldfiles) + eq(testfilename, oldfiles[1]:sub(-#testfilename)) + eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2)) + eq(tf_full, oldfiles[1]) + eq(tf_full_2, oldfiles[2]) end) it('is able to dump and restore jump list', function() -- cgit From 74d5084139423177c88e2c49a74d04afb6c00fb2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Aug 2015 15:00:52 +0300 Subject: shada,functests: Add tests for merging ShaDa data --- test/functional/shada/merging_spec.lua | 867 +++++++++++++++++++++++++++++++++ 1 file changed, 867 insertions(+) create mode 100644 test/functional/shada/merging_spec.lua (limited to 'test') diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua new file mode 100644 index 0000000000..e627f8f76e --- /dev/null +++ b/test/functional/shada/merging_spec.lua @@ -0,0 +1,867 @@ +-- ShaDa merging data support +local helpers = require('test.functional.helpers') +local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = + helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, + helpers.eval, helpers.eq + +local shada_helpers = require('test.functional.shada.helpers') +local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = + shada_helpers.reset, shada_helpers.set_additional_cmd, + shada_helpers.clear, shada_helpers.exc_exec, + 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') + +describe('ShaDa history merging code', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + end) + + 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') + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + eq(0, exc_exec('wshada! ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then + eq(1, v.timestamp) + eq('a', v.value[3]) + found = found + 1 + end + end + eq(1, found) + end) + + 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') + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + eq(0, exc_exec('wshada! ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then + eq(0, v.timestamp) + eq('a', v.value[3]) + found = found + 1 + end + end + eq(1, found) + end) + + 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') + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + eq(0, exc_exec('wshada! ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then + eq(1, v.timestamp) + eq('b', v.value[3]) + found = found + 1 + end + end + eq(1, found) + end) + + 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') + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then + eq(1, v.timestamp) + eq('a', v.value[3]) + found = found + 1 + end + end + eq(1, found) + end) + + 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') + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then + eq(0, v.timestamp) + eq('a', v.value[3]) + found = found + 1 + end + end + eq(1, found) + end) + + 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') + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 and v.value[2] == 'ab' then + eq(1, v.timestamp) + eq('b', v.value[3]) + found = found + 1 + end + end + 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' + ) + eq(0, exc_exec(sdrcmd())) + os.remove(shada_fname) + eq(0, exc_exec('wshada! ' .. shada_fname)) + local items = {'ad', 'ab', 'ac', 'af', 'ae'} + for i, v in ipairs(items) do + eq(v, nvim_eval(('histget(":", %i)'):format(i))) + end + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 4 and v.value[1] == 0 then + found = found + 1 + eq(items[found], v.value[2]) + eq('a', v.value[3]) + end + end + 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' + ) + eq(0, exc_exec('wshada ' .. shada_fname)) + 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 + found = found + 1 + eq(items[found], v.value[2]) + eq('a', v.value[3]) + end + end + eq(#items, found) + end) +end) + +describe('ShaDa search pattern support code', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + end) + + 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('-', nvim_eval('@/')) + end) + + 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('?', nvim_eval('@/')) + end) + + 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('-', nvim_eval('@/')) + end) + + 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('?', nvim_eval('@/')) + end) + + 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('-', nvim_eval('@/')) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.sp == '-' then + found = found + 1 + end + end + eq(1, found) + end) + + 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('-', nvim_eval('@/')) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.sp == '-' then + found = found + 1 + end + end + eq(1, found) + end) + + 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('-', nvim_eval('@/')) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.sp == '?' then + found = found + 1 + end + end + eq(1, found) + end) + + 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('-', nvim_eval('@/')) + end) + + 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('?', nvim_eval('@/')) + end) + + 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('-', nvim_eval('@/')) + end) + + 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('?', nvim_eval('@/')) + end) + + 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('-', nvim_eval('@/')) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.sp == '-' then + found = found + 1 + end + end + eq(1, found) + end) + + 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('-', nvim_eval('@/')) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.sp == '-' then + found = found + 1 + end + end + eq(1, found) + end) + + 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('-', nvim_eval('@/')) + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 2 and v.value.sp == '?' then + found = found + 1 + end + end + eq(1, found) + end) +end) + +describe('ShaDa replacement string support code', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + end) + + 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('-', nvim_eval('getline(".")')) + nvim_command('bwipeout!') + end) + + 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('?', nvim_eval('getline(".")')) + nvim_command('bwipeout!') + end) + + 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('-', nvim_eval('getline(".")')) + nvim_command('bwipeout!') + end) + + 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('?', nvim_eval('getline(".")')) + nvim_command('bwipeout!') + end) + + 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?') + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 3 and v.value[1] == '-' then + found = found + 1 + end + end + eq(1, found) + end) + + 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?') + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 3 and v.value[1] == '-' then + found = found + 1 + end + end + eq(1, found) + end) + + 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?') + eq(0, exc_exec('wshada ' .. shada_fname)) + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 3 and v.value[1] == '?' then + found = found + 1 + end + end + eq(1, found) + end) +end) + +describe('ShaDa marks support code', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + end) + + it('uses last A mark with gt timestamp from instance when reading', + function() + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/-\161nA') + eq(0, exc_exec(sdrcmd())) + wshada('\007\000\018\131\162mX\195\161f\196\006/a/b/?\161nA') + eq(0, exc_exec(sdrcmd())) + nvim_command('normal! `A') + eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + end) + + it('uses last A mark with gt timestamp from file when reading with !', + function() + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/-\161nA') + eq(0, exc_exec(sdrcmd())) + wshada('\007\000\018\131\162mX\195\161f\196\006/a/b/?\161nA') + eq(0, exc_exec(sdrcmd(true))) + nvim_command('normal! `A') + eq('?', nvim_eval('fnamemodify(bufname("%"), ":t")')) + end) + + it('uses last A mark with eq timestamp from instance when reading', + function() + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/-\161nA') + eq(0, exc_exec(sdrcmd())) + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/?\161nA') + eq(0, exc_exec(sdrcmd())) + nvim_command('normal! `A') + eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + end) + + it('uses last A mark with gt timestamp from file when reading', + function() + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/-\161nA') + eq(0, exc_exec(sdrcmd())) + wshada('\007\002\018\131\162mX\195\161f\196\006/a/b/?\161nA') + eq(0, exc_exec(sdrcmd())) + nvim_command('normal! `A') + eq('?', nvim_eval('fnamemodify(bufname("%"), ":t")')) + end) + + it('uses last A mark with gt timestamp from instance when writing', + function() + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/-\161nA') + eq(0, exc_exec(sdrcmd())) + wshada('\007\000\018\131\162mX\195\161f\196\006/a/b/?\161nA') + nvim_command('normal! `A') + eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + 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 == '/a/b/-' then + found = found + 1 + end + end + eq(1, found) + end) + + it('uses last A mark with eq timestamp from instance when writing', + function() + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/-\161nA') + eq(0, exc_exec(sdrcmd())) + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/?\161nA') + nvim_command('normal! `A') + eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + 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 == '/a/b/-' then + found = found + 1 + end + end + eq(1, found) + end) + + it('uses last A mark with gt timestamp from file when writing', + function() + wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/-\161nA') + eq(0, exc_exec(sdrcmd())) + wshada('\007\002\018\131\162mX\195\161f\196\006/a/b/?\161nA') + nvim_command('normal! `A') + eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + 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 == '/a/b/?' then + found = found + 1 + end + end + eq(1, found) + end) + + it('uses last a mark with gt timestamp from instance when reading', + function() + nvim_command('edit /a/b/-') + nvim_eval('setline(1, ["-", "?"])') + wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + wshada('\010\000\017\131\161l\002\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + nvim_command('normal! `a') + eq('-', nvim_eval('getline(".")')) + end) + + it('uses last a mark with gt timestamp from file when reading with !', + function() + nvim_command('edit /a/b/-') + nvim_eval('setline(1, ["-", "?"])') + wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + wshada('\010\000\017\131\161l\002\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd(true))) + nvim_command('normal! `a') + eq('?', nvim_eval('getline(".")')) + end) + + it('uses last a mark with eq timestamp from instance when reading', + function() + nvim_command('edit /a/b/-') + nvim_eval('setline(1, ["-", "?"])') + wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + wshada('\010\001\017\131\161l\002\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + nvim_command('normal! `a') + eq('-', nvim_eval('getline(".")')) + end) + + it('uses last a mark with gt timestamp from file when reading', + function() + nvim_command('edit /a/b/-') + nvim_eval('setline(1, ["-", "?"])') + wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + wshada('\010\002\017\131\161l\002\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + nvim_command('normal! `a') + eq('?', nvim_eval('getline(".")')) + end) + + it('uses last a mark with gt timestamp from instance when writing', + function() + nvim_command('edit /a/b/-') + nvim_eval('setline(1, ["-", "?"])') + wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + wshada('\010\000\017\131\161l\002\161f\196\006/a/b/-\161na') + nvim_command('normal! `a') + eq('-', nvim_eval('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 == '/a/b/-' and v.value.n == ('a'):byte() then + eq(true, v.value.l == 1 or v.value.l == nil) + found = found + 1 + end + end + eq(1, found) + end) + + it('uses last a mark with eq timestamp from instance when writing', + function() + nvim_command('edit /a/b/-') + nvim_eval('setline(1, ["-", "?"])') + wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + wshada('\010\001\017\131\161l\002\161f\196\006/a/b/-\161na') + nvim_command('normal! `a') + eq('-', nvim_eval('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 == '/a/b/-' and v.value.n == ('a'):byte() then + eq(true, v.value.l == 1 or v.value.l == nil) + found = found + 1 + end + end + eq(1, found) + end) + + it('uses last a mark with gt timestamp from file when writing', + function() + nvim_command('edit /a/b/-') + nvim_eval('setline(1, ["-", "?"])') + wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') + eq(0, exc_exec(sdrcmd())) + wshada('\010\002\017\131\161l\002\161f\196\006/a/b/-\161na') + nvim_command('normal! `a') + eq('-', nvim_eval('fnamemodify(bufname("%"), ":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 == '/a/b/-' and v.value.n == ('a'):byte() then + eq(2, v.value.l) + found = found + 1 + end + end + eq(1, found) + end) +end) + +describe('ShaDa registers support code', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + end) + + 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('-', nvim_eval('@a')) + end) + + 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('?', nvim_eval('@a')) + end) + + 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('-', nvim_eval('@a')) + end) + + 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('?', nvim_eval('@a')) + end) + + 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('-', nvim_eval('@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) + found = found + 1 + end + end + eq(1, found) + end) + + 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('-', nvim_eval('@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) + found = found + 1 + end + end + eq(1, found) + end) + + 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('-', nvim_eval('@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) + found = found + 1 + end + end + eq(1, found) + end) +end) + +describe('ShaDa jumps support code', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + end) + + it('merges jumps when reading', function() + wshada('\008\001\018\131\162mX\195\161f\196\006/a/b/c\161l\002' + .. '\008\004\018\131\162mX\195\161f\196\006/a/b/d\161l\002' + .. '\008\007\018\131\162mX\195\161f\196\006/a/b/e\161l\002') + eq(0, exc_exec(sdrcmd())) + wshada('\008\001\018\131\162mX\195\161f\196\006/a/b/c\161l\002' + .. '\008\004\018\131\162mX\195\161f\196\006/a/b/d\161l\003' + .. '\008\007\018\131\162mX\195\161f\196\006/a/b/f\161l\002') + eq(0, exc_exec(sdrcmd())) + nvim_command('redir => g:jumps | jumps | redir END') + eq('', nvim_eval('bufname("%")')) + eq('\n' + .. ' jump line col file/text\n' + .. ' 5 2 0 /a/b/c\n' + .. ' 4 3 0 /a/b/d\n' + .. ' 3 2 0 /a/b/d\n' + .. ' 2 2 0 /a/b/f\n' + .. ' 1 2 0 /a/b/e\n' + .. '> 0 1 0 ', nvim_eval('g:jumps')) + end) + + it('merges jumps when writing', function() + wshada('\008\001\018\131\162mX\195\161f\196\006/a/b/c\161l\002' + .. '\008\004\018\131\162mX\195\161f\196\006/a/b/d\161l\002' + .. '\008\007\018\131\162mX\195\161f\196\006/a/b/e\161l\002') + eq(0, exc_exec(sdrcmd())) + wshada('\008\001\018\131\162mX\195\161f\196\006/a/b/c\161l\002' + .. '\008\004\018\131\162mX\195\161f\196\006/a/b/d\161l\003' + .. '\008\007\018\131\162mX\195\161f\196\006/a/b/f\161l\002') + eq(0, exc_exec('wshada ' .. shada_fname)) + local jumps = { + {file='/a/b/c', line=2}, + {file='/a/b/d', line=3}, + {file='/a/b/d', line=2}, + {file='/a/b/f', line=2}, + {file='/a/b/e', line=2}, + } + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 8 then + found = found + 1 + eq(jumps[found].file, v.value.f) + eq(jumps[found].line, v.value.l) + end + end + eq(found, #jumps) + end) +end) + +describe('ShaDa changes support code', function() + before_each(reset) + after_each(function() + clear() + os.remove(shada_fname) + end) + + it('merges changes when reading', function() + nvim_command('edit /a/b/c') + nvim_command('keepjumps call setline(1, range(7))') + wshada('\011\001\018\131\162mX\195\161f\196\006/a/b/c\161l\001' + .. '\011\004\018\131\162mX\195\161f\196\006/a/b/c\161l\002' + .. '\011\007\018\131\162mX\195\161f\196\006/a/b/c\161l\003') + eq(0, exc_exec(sdrcmd())) + wshada('\011\001\018\131\162mX\194\161f\196\006/a/b/c\161l\001' + .. '\011\004\018\131\162mX\195\161f\196\006/a/b/c\161l\005' + .. '\011\008\018\131\162mX\195\161f\196\006/a/b/c\161l\004') + eq(0, exc_exec(sdrcmd())) + nvim_command('redir => g:changes | changes | redir END') + eq('\n' + .. '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' + .. '>', nvim_eval('g:changes')) + end) + + it('merges changes when writing', function() + nvim_command('edit /a/b/c') + nvim_command('keepjumps call setline(1, range(7))') + wshada('\011\001\018\131\162mX\195\161f\196\006/a/b/c\161l\001' + .. '\011\004\018\131\162mX\195\161f\196\006/a/b/c\161l\002' + .. '\011\007\018\131\162mX\195\161f\196\006/a/b/c\161l\003') + eq(0, exc_exec(sdrcmd())) + wshada('\011\001\018\131\162mX\194\161f\196\006/a/b/c\161l\001' + .. '\011\004\018\131\162mX\195\161f\196\006/a/b/c\161l\005' + .. '\011\008\018\131\162mX\195\161f\196\006/a/b/c\161l\004') + eq(0, exc_exec('wshada ' .. shada_fname)) + local changes = { + {line=1}, + {line=2}, + {line=5}, + {line=3}, + {line=4}, + } + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 11 and v.value.f == '/a/b/c' then + found = found + 1 + eq(changes[found].line, v.value.l or 1) + end + end + eq(found, #changes) + end) +end) -- cgit From 17c69258a7128ee31fbf294b46599241f8e226cc Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 12 Aug 2015 21:01:45 +0300 Subject: shada: Use same merging code for jumps and changes --- test/functional/shada/marks_spec.lua | 26 ++++++-------------------- test/functional/shada/merging_spec.lua | 13 +++++++------ 2 files changed, 13 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index 8b9e70045c..dc7a710143 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -118,28 +118,14 @@ describe('ShaDa support code', function() nvim_command('edit ' .. testfilename) nvim_feed('G') nvim_feed('gg') - -- nvim_command('redir! >/tmp/jumps.last | jumps | redir END') - -- nvim_command('wshada /tmp/foo') + nvim_command('enew') + nvim_feed('gg') + nvim_command('redir => g:jumps | jumps | redir END') + local saved = nvim_eval('g:jumps') nvim_command('qall') reset() - nvim_command('redraw') - -- nvim_command('redir! >/tmp/jumps.init | jumps | redir END') - nvim_command('edit ' .. testfilename) - -- nvim_command('redir! >/tmp/jumps | jumps | redir END') - eq(testfilename, nvim_eval('bufname("%")')) - eq(1, nvim_current_line()) - nvim_command('execute "normal! \\"') - eq(testfilename, nvim_eval('bufname("%")')) - eq(1, nvim_current_line()) - nvim_command('execute "normal! \\"') - eq(testfilename, nvim_eval('bufname("%")')) - eq(2, nvim_current_line()) - nvim_command('execute "normal! \\"') - eq(testfilename_2, nvim_eval('bufname("%")')) - eq(1, nvim_current_line()) - nvim_command('execute "normal! \\"') - eq(testfilename_2, nvim_eval('bufname("%")')) - eq(2, nvim_current_line()) + nvim_command('redir => g:jumps | jumps | redir END') + eq(saved, nvim_eval('g:jumps')) end) it('is able to dump and restore jump list with different times (slow!)', diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index e627f8f76e..3daa5af7c2 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -772,12 +772,13 @@ describe('ShaDa jumps support code', function() eq('', nvim_eval('bufname("%")')) eq('\n' .. ' jump line col file/text\n' - .. ' 5 2 0 /a/b/c\n' + .. ' 6 2 0 /a/b/c\n' + .. ' 5 2 0 /a/b/d\n' .. ' 4 3 0 /a/b/d\n' - .. ' 3 2 0 /a/b/d\n' + .. ' 3 2 0 /a/b/e\n' .. ' 2 2 0 /a/b/f\n' - .. ' 1 2 0 /a/b/e\n' - .. '> 0 1 0 ', nvim_eval('g:jumps')) + .. ' 1 1 0 \n' + .. '>', nvim_eval('g:jumps')) end) it('merges jumps when writing', function() @@ -791,10 +792,10 @@ describe('ShaDa jumps support code', function() eq(0, exc_exec('wshada ' .. shada_fname)) local jumps = { {file='/a/b/c', line=2}, - {file='/a/b/d', line=3}, {file='/a/b/d', line=2}, - {file='/a/b/f', line=2}, + {file='/a/b/d', line=3}, {file='/a/b/e', line=2}, + {file='/a/b/f', line=2}, } local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do -- cgit From 0960e169086e5f2d63fa24053e7c1c06e7abc912 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 14 Aug 2015 08:40:49 +0300 Subject: functests: Disable some tests when running with address sanitizer Ref #1350 --- test/functional/shada/history_spec.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 0c39b65ee1..9ec7f9c256 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -12,6 +12,16 @@ describe('ShaDa support code', function() before_each(reset) after_each(clear) + local clang_sanitizer = os.getenv('CLANG_SANITIZER') + local it_noasan + if clang_sanitizer and clang_sanitizer:match('ASAN') then + it_noasan = function(name, test) + pending(name, function() end) + end + else + it_noasan = it + end + it('is able to dump and read back command-line history', function() nvim_command('set shada=\'0') nvim_feed(':" Test\n') @@ -237,7 +247,7 @@ describe('ShaDa support code', function() eq('.«', nvim_eval('getline(".")')) end) - it('dumps&loads s/pattern correctly when &encoding /= UTF-8 when dumping', + it_noasan('dumps&loads s/pattern correctly when &encoding /= UTF-8 when dumping', function() set_additional_cmd('set encoding=latin1') reset() @@ -278,7 +288,7 @@ describe('ShaDa support code', function() eq('', nvim_eval('histget("/", -1)')) end) - it('dumps&loads /pattern correctly when &encoding /= UTF-8 when dumping', + it_noasan('dumps&loads /pattern correctly when &encoding /= UTF-8 when dumping', function() set_additional_cmd('set encoding=latin1') reset() -- cgit From 369081d1c4ccd81c23fa09286f14637ae8136b8e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 15 Aug 2015 14:33:00 +0300 Subject: shada: Fix crash in hmll_insert This problem made test64 to crash. Description of the bug: when removing entry from history when removed entry is not the last one it puts one element to free_entries list, but ignores free entries starting from last_free_element. Possible solutions: 1. First working: simply populate free_entries list with entries which are still free, starting from last_free_element. 2. Better (wastes less CPU): after free_entries list size goes to zero (which is the initial value) continue using last_free_element. 3. Even better (less memory): note that element from the list is *only* removed before adding another one. So replace free_entries array with one item. Also renamed last_free_element to last_free_entry: in any case most of the lines which mention it were altered. --- test/functional/shada/merging_spec.lua | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'test') diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index 3daa5af7c2..fd0111d30d 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -175,6 +175,60 @@ describe('ShaDa history merging code', function() end eq(#items, found) end) + + 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' + ) + eq(0, exc_exec('wshada ' .. shada_fname)) + 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 + found = found + 1 + eq(items[found], v.value[2]) + eq('a', v.value[3]) + end + end + 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' + ) + eq(0, exc_exec('wshada ' .. shada_fname)) + 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 + found = found + 1 + eq(items[found], v.value[2]) + eq('a', v.value[3]) + end + end + eq(#items, found) + end) end) describe('ShaDa search pattern support code', function() -- cgit From 804e0740964bf84891d798d36d82a5c7ffa462f2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 15 Aug 2015 17:20:07 +0300 Subject: eval,functests: Reference all additional_* items created by ShaDa --- test/functional/shada/compatibility_spec.lua | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'test') diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index 45d747658a..13d4c44657 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -45,6 +45,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada! ' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) it('works with s/search pattern item with BOOL unknown (sX) key value', function() @@ -72,6 +77,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) it('works with replacement item with BOOL additional value in list', function() @@ -100,6 +110,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) for _, v in ipairs({{name='global mark', mpack='\007\001\018\131\162mX\195\161f\196\006/a/b/c\161nA'}, @@ -138,6 +153,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(false, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) if v.name == 'global mark' or v.name == 'local mark' then @@ -175,6 +195,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) end end @@ -202,6 +227,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(false, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) it('works with register item with name', function() @@ -233,6 +263,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) it('works with register item with type 10', function() @@ -265,6 +300,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) it('works with buffer list item with BOOL unknown (bX) key', function() @@ -295,6 +335,11 @@ describe('ShaDa forward compatibility support code', function() end eq(false, found) nvim_command('bwipeout!') + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) it('works with history item with BOOL additional value in list', function() @@ -324,6 +369,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) it('works with history item with type 10', function() @@ -356,6 +406,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) it('works with item with 100 type', function() @@ -388,5 +443,10 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') + nvim_command('rshada!' .. shada_fname) + nvim_eval('garbagecollect(1)') + nvim_eval('garbagecollect(1)') end) end) -- cgit From b249529676306760b5cd99a4707e6bf246f8b99b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 15 Aug 2015 17:25:10 +0300 Subject: functests: Make one recover_spec test also use gdb or valgrind --- test/functional/ex_cmds/recover_spec.lua | 3 ++- test/functional/helpers.lua | 20 ++++++++++++++++++-- test/functional/shada/helpers.lua | 14 +++----------- 3 files changed, 23 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua index b92739e40e..a24a60af81 100644 --- a/test/functional/ex_cmds/recover_spec.lua +++ b/test/functional/ex_cmds/recover_spec.lua @@ -47,7 +47,8 @@ describe(':preserve', function() --TODO(justinmk): this is an ugly hack to force `helpers` to support --multiple sessions. - local nvim2 = helpers.spawn({helpers.nvim_prog, '-u', 'NONE', '--embed'}) + local nvim2 = helpers.spawn({helpers.nvim_prog, '-u', 'NONE', '--embed'}, + true) helpers.set_session(nvim2) source(init) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 23581ba4d2..79f1feb7b5 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -178,12 +178,27 @@ local function rawfeed(...) end end -local function spawn(argv) +local function merge_args(...) + local i = 1 + local argv = {} + for anum = 1,select('#', ...) do + local args = select(anum, ...) + if args then + for _, arg in ipairs(args) do + argv[i] = arg + i = i + 1 + end + end + end + return argv +end + +local function spawn(argv, merge) local loop = Loop.new() local msgpack_stream = MsgpackStream.new(loop) local async_session = AsyncSession.new(msgpack_stream) local session = Session.new(async_session) - loop:spawn(argv) + loop:spawn(merge and merge_args(prepend_argv, argv) or argv) return session end @@ -382,4 +397,5 @@ return { rmdir = rmdir, mkdir = lfs.mkdir, exc_exec = exc_exec, + merge_args = merge_args, } diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index d37e84f156..b3153ca7f1 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers') local spawn, set_session, nvim, nvim_prog, nvim_command, nvim_eval = helpers.spawn, helpers.set_session, helpers.nvim, helpers.nvim_prog, helpers.command, helpers.eval -local write_file = helpers.write_file +local write_file, merge_args = helpers.write_file, helpers.merge_args local msgpack = require('MessagePack') @@ -16,18 +16,10 @@ local function nvim_argv() '--cmd', additional_cmd, '--embed'} if helpers.prepend_argv then - ret = {} - for i, v in ipairs(helpers.prepend_argv) do - ret[i] = v - end - local shift = #ret - for i, v in ipairs(nvim_argv) do - ret[i + shift] = v - end + return merge_args(helpers.prepend_argv, nvim_argv) else - ret = nvim_argv + return nvim_argv end - return ret end local session = nil -- cgit From be45e750267a7cb52b625b2e1e71796be18d8061 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Aug 2015 01:16:24 +0300 Subject: shada: Refuse to write ShaDa file when ShaDa was disabled --- test/functional/shada/shada_spec.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 19b8a47244..e256173611 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -3,7 +3,8 @@ local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq -local write_file = helpers.write_file +local write_file, spawn, set_session, nvim_prog = + helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog local lfs = require('lfs') local msgpack = require('MessagePack') @@ -127,4 +128,22 @@ describe('ShaDa support code', function() end eq(#mpack, found) end) + + it('does not write NONE file', function() + local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', + '--cmd', 'qall'}, true) + session:exit(0) + eq(nil, lfs.attributes('NONE')) + eq(nil, lfs.attributes('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'}, + true) + set_session(session) + eq('', nvim_eval('@a')) + session:exit(0) + os.remove('NONE') + end) end) -- cgit From 48ba2f0109ad2b5bc51b08c55848d526b37fd8d0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 18 Aug 2015 21:20:48 +0300 Subject: documentation/functests: Replace NeoVim with Neovim --- test/functional/shada/merging_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index fd0111d30d..2c3eb72e03 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -21,7 +21,7 @@ describe('ShaDa history merging code', function() os.remove(shada_fname) end) - it('takes item with greater timestamp from NeoVim instance when reading', + 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())) @@ -40,7 +40,7 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('takes item with equal timestamp from NeoVim instance when reading', + 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())) @@ -78,7 +78,7 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('takes item with greater timestamp from NeoVim instance when writing', + 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())) @@ -95,7 +95,7 @@ describe('ShaDa history merging code', function() eq(1, found) end) - it('takes item with equal timestamp from NeoVim instance when writing', + 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())) -- cgit From 915a29822335905b79a2dacc73ce6bd219367eeb Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 23 Aug 2015 19:41:00 +0300 Subject: shada,functests: Fix v:hlsearch saving/restoring handling --- test/functional/shada/history_spec.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 9ec7f9c256..599330d6eb 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -128,15 +128,16 @@ describe('ShaDa support code', function() end) it('saves v:hlsearch=1', function() - nvim_command('set hlsearch') + nvim_command('set hlsearch shada-=h') nvim_feed('/test\n') + eq(1, nvim_eval('v:hlsearch')) nvim_command('qall') reset() eq(1, nvim_eval('v:hlsearch')) end) it('saves v:hlsearch=0 with :nohl', function() - nvim_command('set hlsearch') + nvim_command('set hlsearch shada-=h') nvim_feed('/test\n') nvim_command('nohlsearch') nvim_command('qall') @@ -144,9 +145,10 @@ describe('ShaDa support code', function() eq(0, nvim_eval('v:hlsearch')) end) - it('saves v:hlsearch=0 with :set viminfo-=h', function() - nvim_command('set hlsearch viminfo-=h') + it('saves v:hlsearch=0 with default &shada', function() + nvim_command('set hlsearch') nvim_feed('/test\n') + eq(1, nvim_eval('v:hlsearch')) nvim_command('qall') reset() eq(0, nvim_eval('v:hlsearch')) -- cgit From 29a3e972ded23b2a3f960c572c1c69e98646ae67 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 23 Aug 2015 19:58:56 +0300 Subject: shada: Fix v:hlsearch save/restore and do not write empty patterns --- test/functional/shada/compatibility_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index 13d4c44657..485e8a183c 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -39,7 +39,7 @@ describe('ShaDa forward compatibility support code', function() nvim_command('wshada ' .. shada_fname) found = false for _, v in ipairs(read_shada_file(shada_fname)) do - if v.type == 2 and v.value.ss then + if v.type == 2 and not v.value.ss then eq(nil, v.value.sX) found = true end -- cgit From d283e758ea8646d92a53cebb457f16a0ddf49d75 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 6 Sep 2015 05:31:04 +0300 Subject: shada: Fix out-of-bounds array access It leads to a memory leak as well. May overwrite wms->jumps_size. --- test/functional/shada/merging_spec.lua | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'test') diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index 2c3eb72e03..9d0d00f5c6 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -861,6 +861,41 @@ describe('ShaDa jumps support code', function() end eq(found, #jumps) end) + + 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/a/b/c\161l%c' + ):format(i, i) + jumps[i] = {file='/a/b/c', line=i} + end + wshada(shada) + eq(0, exc_exec(sdrcmd())) + local shada = '' + for i = 1,101 do + local t = i * 2 + shada = shada .. ( + '\008\204%c\019\131\162mX\195\161f\196\006/a/b/c\161l\204%c' + ):format(t, t) + jumps[(t > #jumps + 1) and (#jumps + 1) or t] = {file='/a/b/c', line=t} + end + wshada(shada) + eq(0, exc_exec('wshada ' .. shada_fname)) + local shift = #jumps - 100 + for i = 1,100 do + jumps[i] = jumps[i + shift] + end + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 8 then + found = found + 1 + eq(jumps[found].file, v.value.f) + eq(jumps[found].line, v.value.l) + end + end + eq(found, 100) + end) end) describe('ShaDa changes support code', function() @@ -919,4 +954,40 @@ describe('ShaDa changes support code', function() end eq(found, #changes) end) + + it('merges JUMPLISTSIZE changes when writing', function() + nvim_command('edit /a/b/c') + 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/a/b/c\161l%c' + ):format(i, i) + changes[i] = {line=i} + end + wshada(shada) + eq(0, exc_exec(sdrcmd())) + local shada = '' + for i = 1,101 do + local t = i * 2 + shada = shada .. ( + '\011\204%c\019\131\162mX\195\161f\196\006/a/b/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 + changes[i] = changes[i + shift] + end + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 11 and v.value.f == '/a/b/c' then + found = found + 1 + eq(changes[found].line, v.value.l) + end + end + eq(found, 100) + end) end) -- cgit From 56a2549ff8bf2d02bdcf0c0946344d090d958e20 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 18 Sep 2015 23:40:08 +0300 Subject: functests: Do not disable pattern tests Problem that led to this skip was fixed in [#3309][1]. [1]: https://github.com/neovim/neovim/commit/0a116c828debc6192a6bfb6bceb8cf020e867db0 --- test/functional/shada/history_spec.lua | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 599330d6eb..720ad986ea 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -12,16 +12,6 @@ describe('ShaDa support code', function() before_each(reset) after_each(clear) - local clang_sanitizer = os.getenv('CLANG_SANITIZER') - local it_noasan - if clang_sanitizer and clang_sanitizer:match('ASAN') then - it_noasan = function(name, test) - pending(name, function() end) - end - else - it_noasan = it - end - it('is able to dump and read back command-line history', function() nvim_command('set shada=\'0') nvim_feed(':" Test\n') @@ -249,7 +239,7 @@ describe('ShaDa support code', function() eq('.«', nvim_eval('getline(".")')) end) - it_noasan('dumps&loads s/pattern correctly when &encoding /= UTF-8 when dumping', + it('dumps&loads s/pattern correctly when &encoding /= UTF-8 when dumping', function() set_additional_cmd('set encoding=latin1') reset() @@ -290,7 +280,7 @@ describe('ShaDa support code', function() eq('', nvim_eval('histget("/", -1)')) end) - it_noasan('dumps&loads /pattern correctly when &encoding /= UTF-8 when dumping', + it('dumps&loads /pattern correctly when &encoding /= UTF-8 when dumping', function() set_additional_cmd('set encoding=latin1') reset() -- cgit From 7085ea07d8e5f976260476f2e84c38b3a3bf0407 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 19 Sep 2015 20:57:49 +0300 Subject: functests: Move exc_exec to test.functional.helpers --- test/functional/shada/compatibility_spec.lua | 6 +++--- test/functional/shada/errors_spec.lua | 6 +++--- test/functional/shada/helpers.lua | 13 ------------- test/functional/shada/marks_spec.lua | 5 +++-- test/functional/shada/merging_spec.lua | 6 +++--- test/functional/shada/shada_spec.lua | 10 +++++----- 6 files changed, 17 insertions(+), 29 deletions(-) (limited to 'test') diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index 485e8a183c..295678d8d6 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -3,12 +3,12 @@ local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq +local exc_exec = helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = +local reset, set_additional_cmd, clear, get_shada_rw = shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear, shada_helpers.exc_exec, - shada_helpers.get_shada_rw + 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') diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index ce849fdcbd..b612ed48c5 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -3,12 +3,12 @@ local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq +local exc_exec = helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = +local reset, set_additional_cmd, clear, get_shada_rw = shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear, shada_helpers.exc_exec, - shada_helpers.get_shada_rw + shada_helpers.clear, shada_helpers.get_shada_rw local wshada, sdrcmd, shada_fname, clean = get_shada_rw('Xtest-functional-shada-errors.shada') diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index b3153ca7f1..3af92112cb 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -42,19 +42,6 @@ local clear = function() set_additional_cmd('') end -local exc_exec = function(cmd) - nvim_command(([[ - try - execute "%s" - catch - let g:__exception = v:exception - endtry - ]]):format(cmd:gsub('\n', '\\n'):gsub('[\\"]', '\\%0'))) - local ret = nvim_eval('get(g:, "__exception", 0)') - nvim_command('unlet! g:__exception') - return ret -end - local get_shada_rw = function(fname) local wshada = function(text) write_file(fname, text, true) diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index dc7a710143..18ce470cb7 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -3,11 +3,12 @@ local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq +local exc_exec = helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, exc_exec = +local reset, set_additional_cmd, clear = shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear, shada_helpers.exc_exec + shada_helpers.clear local nvim_current_line = function() return nvim_window('get_cursor', nvim_curwin())[1] diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index 9d0d00f5c6..f7a3c4d9ca 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -3,12 +3,12 @@ local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq +local exc_exec = helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = +local reset, set_additional_cmd, clear, get_shada_rw = shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear, shada_helpers.exc_exec, - shada_helpers.get_shada_rw + shada_helpers.clear, shada_helpers.get_shada_rw local read_shada_file = shada_helpers.read_shada_file local wshada, sdrcmd, shada_fname = diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index e256173611..ed022ea65c 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -3,17 +3,17 @@ local helpers = require('test.functional.helpers') local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, helpers.eval, helpers.eq -local write_file, spawn, set_session, nvim_prog = - helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog +local write_file, spawn, set_session, nvim_prog, exc_exec = + helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, + helpers.exc_exec local lfs = require('lfs') local msgpack = require('MessagePack') local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, exc_exec, get_shada_rw = +local reset, set_additional_cmd, clear, get_shada_rw = shada_helpers.reset, shada_helpers.set_additional_cmd, - shada_helpers.clear, shada_helpers.exc_exec, - shada_helpers.get_shada_rw + shada_helpers.clear, shada_helpers.get_shada_rw local read_shada_file = shada_helpers.read_shada_file local wshada, sdrcmd, shada_fname, clean = get_shada_rw('Xtest-functional-shada-shada.shada') -- cgit From 0966e92cf441bbae1d50c68f56809fbb08fab7b6 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 22 Sep 2015 15:03:27 +0300 Subject: shada: When using shada-r normalize option path --- test/config/paths.lua.in | 1 + test/functional/shada/shada_spec.lua | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'test') diff --git a/test/config/paths.lua.in b/test/config/paths.lua.in index a13230ed28..80cc5629d1 100644 --- a/test/config/paths.lua.in +++ b/test/config/paths.lua.in @@ -7,6 +7,7 @@ end module.test_include_path = "${CMAKE_BINARY_DIR}/test/includes/post" module.test_libnvim_path = "${TEST_LIBNVIM_PATH}" +module.test_source_path = "${CMAKE_SOURCE_DIR}" table.insert(module.include_paths, "${CMAKE_BINARY_DIR}/include") return module diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index ed022ea65c..dfd5c436e4 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -7,6 +7,7 @@ local write_file, spawn, set_session, nvim_prog, exc_exec = helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.exc_exec local lfs = require('lfs') +local paths = require('test.config.paths') local msgpack = require('MessagePack') @@ -146,4 +147,42 @@ describe('ShaDa support code', function() session:exit(0) os.remove('NONE') end) + + it('correctly uses shada-r option', function() + nvim('set_var', '__home', paths.test_source_path) + nvim_command('let $HOME = __home') + nvim_command('unlet __home') + nvim_command('edit ~/README.md') + nvim_command('normal! GmAggmaAabc') + nvim_command('undo') + nvim_command('set shada+=%') + nvim_command('wshada! ' .. shada_fname) + local marklike = {[7]=true, [8]=true, [10]=true, [11]=true} + local readme_fname = paths.test_source_path .. '/README.md' + local find_readme = function() + local found = {} + for _, v in ipairs(read_shada_file(shada_fname)) do + if marklike[v.type] and v.value.f == readme_fname then + found[v.type] = (found[v.type] or 0) + 1 + elseif v.type == 9 then + for _, b in ipairs(v.value) do + if b.f == readme_fname then + found[v.type] = (found[v.type] or 0) + 1 + end + end + end + end + return found + end + eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_readme()) + nvim_command('set shada+=r~') + nvim_command('wshada! ' .. shada_fname) + eq({}, find_readme()) + nvim_command('set shada-=r~') + nvim_command('wshada! ' .. shada_fname) + eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_readme()) + nvim_command('set shada+=r' .. paths.test_source_path) + nvim_command('wshada! ' .. shada_fname) + eq({}, find_readme()) + end) end) -- cgit From b8e791559682e4e4ba435564c70ea038022ce364 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 22 Sep 2015 15:22:22 +0300 Subject: shada: Make sure that shada-r option correctly ignores case --- test/functional/shada/shada_spec.lua | 58 +++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'test') diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index dfd5c436e4..6c2694b834 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -148,6 +148,23 @@ describe('ShaDa support code', function() os.remove('NONE') end) + local marklike = {[7]=true, [8]=true, [10]=true, [11]=true} + local find_file = function(fname) + local found = {} + for _, v in ipairs(read_shada_file(shada_fname)) do + if marklike[v.type] and v.value.f == fname then + found[v.type] = (found[v.type] or 0) + 1 + elseif v.type == 9 then + for _, b in ipairs(v.value) do + if b.f == fname then + found[v.type] = (found[v.type] or 0) + 1 + end + end + end + end + return found + end + it('correctly uses shada-r option', function() nvim('set_var', '__home', paths.test_source_path) nvim_command('let $HOME = __home') @@ -157,32 +174,33 @@ describe('ShaDa support code', function() nvim_command('undo') nvim_command('set shada+=%') nvim_command('wshada! ' .. shada_fname) - local marklike = {[7]=true, [8]=true, [10]=true, [11]=true} local readme_fname = paths.test_source_path .. '/README.md' - local find_readme = function() - local found = {} - for _, v in ipairs(read_shada_file(shada_fname)) do - if marklike[v.type] and v.value.f == readme_fname then - found[v.type] = (found[v.type] or 0) + 1 - elseif v.type == 9 then - for _, b in ipairs(v.value) do - if b.f == readme_fname then - found[v.type] = (found[v.type] or 0) + 1 - end - end - end - end - return found - end - eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_readme()) + eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_file(readme_fname)) nvim_command('set shada+=r~') nvim_command('wshada! ' .. shada_fname) - eq({}, find_readme()) + eq({}, find_file(readme_fname)) nvim_command('set shada-=r~') nvim_command('wshada! ' .. shada_fname) - eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_readme()) + eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_file(readme_fname)) nvim_command('set shada+=r' .. paths.test_source_path) nvim_command('wshada! ' .. shada_fname) - eq({}, find_readme()) + eq({}, find_file(readme_fname)) + end) + + it('correctly ignores case with shada-r option', function() + local pwd = nvim('call_function', 'getcwd', {}) + local relfname = 'абв/test' + local fname = pwd .. '/' .. relfname + nvim('set_var', '__fname', fname) + nvim_command('silent! edit `=__fname`') + nvim('call_function', 'setline', {1, {'a', 'b', 'c', 'd'}}) + nvim_command('normal! GmAggmaAabc') + nvim_command('undo') + nvim_command('set shada+=%') + nvim_command('wshada! ' .. shada_fname) + eq({[7]=1, [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) end) -- cgit From 2dd8e05f9fa9caef6fc04882dbdd27f387112266 Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 24 Sep 2015 00:22:58 +0300 Subject: shada: Fix jump/change list merging code Errors happens under following conditions: 1. Jump/change list is full. 2. New jump/change list item should go between some of the old ones. --- test/functional/shada/merging_spec.lua | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test') diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index f7a3c4d9ca..b880bdae8a 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -990,4 +990,46 @@ describe('ShaDa changes support code', function() end eq(found, 100) end) + + it('merges JUMPLISTSIZE changes when writing, with new items between old', + function() + nvim_command('edit /a/b/c') + nvim_command('keepjumps call setline(1, range(202))') + local shada = '' + for i = 1,101 do + local t = i * 2 + shada = shada .. ( + '\011\204%c\019\131\162mX\195\161f\196\006/a/b/c\161l\204%c' + ):format(t, t) + end + wshada(shada) + eq(0, exc_exec(sdrcmd())) + local shada = '' + for i = 1,100 do + shada = shada .. ('\011%c\018\131\162mX\195\161f\196\006/a/b/c\161l%c' + ):format(i, i) + end + local changes = {} + for i = 1, 100 do + 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} + end + wshada(shada) + eq(0, exc_exec('wshada ' .. shada_fname)) + local shift = #changes - 100 + for i = 1,100 do + changes[i] = changes[i + shift] + end + local found = 0 + for _, v in ipairs(read_shada_file(shada_fname)) do + if v.type == 11 and v.value.f == '/a/b/c' then + found = found + 1 + eq(changes[found].line, v.value.l) + end + end + eq(found, 100) + end) end) -- cgit From 1162962d8beaab6be78a32954600205686f5d09b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 27 Sep 2015 02:49:48 +0300 Subject: functests: Refactor tests: - Remove unused variables. - Do not use helpers.nvim_feed in most cases. - Do not use helpers.nvim and helpers.nvim_eval at all. - Add helpers.funcs and helpers.\*meths special tables. Indexing such table creates functions which call helpers.call or helpers.nvim (and similar) with first argument equal to table index. --- test/functional/ex_getln/history_spec.lua | 34 ++++---- test/functional/helpers.lua | 41 +++++++++ test/functional/shada/buffers_spec.lua | 34 +++----- test/functional/shada/compatibility_spec.lua | 123 ++++++++++++++------------- test/functional/shada/errors_spec.lua | 10 +-- test/functional/shada/helpers.lua | 7 +- test/functional/shada/history_spec.lua | 114 ++++++++++++------------- test/functional/shada/marks_spec.lua | 72 +++++++--------- test/functional/shada/merging_spec.lua | 115 ++++++++++++------------- test/functional/shada/registers_spec.lua | 37 +++----- test/functional/shada/shada_spec.lua | 27 +++--- test/functional/shada/variables_spec.lua | 80 ++++++++--------- 12 files changed, 345 insertions(+), 349 deletions(-) (limited to 'test') diff --git a/test/functional/ex_getln/history_spec.lua b/test/functional/ex_getln/history_spec.lua index c3ef56c8ad..532c81dab9 100644 --- a/test/functional/ex_getln/history_spec.lua +++ b/test/functional/ex_getln/history_spec.lua @@ -1,40 +1,36 @@ local helpers = require('test.functional.helpers') -local clear, nvim, call, eq = - helpers.clear, helpers.nvim, helpers.call, helpers.eq +local clear, meths, funcs, eq = + helpers.clear, helpers.meths, helpers.funcs, helpers.eq describe('history support code', function() before_each(clear) - local histadd = function(...) return call('histadd', ...) end - local histget = function(...) return call('histget', ...) end - local histdel = function(...) return call('histdel', ...) end - it('correctly clears start of the history', function() -- Regression test: check absense of the memory leak when clearing start of -- the history using ex_getln.c/clr_history(). - eq(1, histadd(':', 'foo')) - eq(1, histdel(':')) - eq('', histget(':', -1)) + eq(1, funcs.histadd(':', 'foo')) + eq(1, funcs.histdel(':')) + eq('', funcs.histget(':', -1)) end) it('correctly clears end of the history', function() -- Regression test: check absense of the memory leak when clearing end of -- the history using ex_getln.c/clr_history(). - nvim('set_option', 'history', 1) - eq(1, histadd(':', 'foo')) - eq(1, histdel(':')) - eq('', histget(':', -1)) + meths.set_option('history', 1) + eq(1, funcs.histadd(':', 'foo')) + eq(1, funcs.histdel(':')) + eq('', funcs.histget(':', -1)) end) it('correctly removes item from history', function() -- Regression test: check that ex_getln.c/del_history_idx() correctly clears -- history index after removing history entry. If it does not then deleting -- history will result in a double free. - eq(1, histadd(':', 'foo')) - eq(1, histadd(':', 'bar')) - eq(1, histadd(':', 'baz')) - eq(1, histdel(':', -2)) - eq(1, histdel(':')) - eq('', histget(':', -1)) + eq(1, funcs.histadd(':', 'foo')) + eq(1, funcs.histadd(':', 'bar')) + eq(1, funcs.histadd(':', 'baz')) + eq(1, funcs.histdel(':', -2)) + eq(1, funcs.histdel(':')) + eq('', funcs.histget(':', -1)) end) end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 79f1feb7b5..a62f7a3d00 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -359,6 +359,38 @@ local exc_exec = function(cmd) return ret end +local function redir_exec(cmd) + nvim_command(([[ + redir => g:__output + silent! execute "%s" + redir END + ]]):format(cmd:gsub('\n', '\\n'):gsub('[\\"]', '\\%0'))) + local ret = nvim_eval('get(g:, "__output", 0)') + nvim_command('unlet! g:__output') + return ret +end + +local function create_callindex(func) + local tbl = {} + setmetatable(tbl, { + __index = function(tbl, arg1) + ret = function(...) return func(arg1, ...) end + tbl[arg1] = ret + return ret + end, + }) + return tbl +end + +local funcs = create_callindex(nvim_call) +local meths = create_callindex(nvim) +local bufmeths = create_callindex(buffer) +local winmeths = create_callindex(window) +local tabmeths = create_callindex(tabpage) +local curbufmeths = create_callindex(curbuf) +local curwinmeths = create_callindex(curwin) +local curtabmeths = create_callindex(curtab) + return { prepend_argv = prepend_argv, clear = clear, @@ -397,5 +429,14 @@ return { rmdir = rmdir, mkdir = lfs.mkdir, exc_exec = exc_exec, + redir_exec = redir_exec, merge_args = merge_args, + funcs = funcs, + meths = meths, + bufmeths = bufmeths, + winmeths = winmeths, + tabmeths = tabmeths, + curbufmeths = curbufmeths, + curwinmeths = curwinmeths, + curtabmeths = curtabmeths, } diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua index 38a8cad84d..3666b718f0 100644 --- a/test/functional/shada/buffers_spec.lua +++ b/test/functional/shada/buffers_spec.lua @@ -1,18 +1,13 @@ -- ShaDa buffer list saving/reading support local helpers = require('test.functional.helpers') -local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = - helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, - helpers.eval, helpers.eq +local nvim_command, funcs, eq = + helpers.command, helpers.funcs, helpers.eq local shada_helpers = require('test.functional.shada.helpers') local reset, set_additional_cmd, clear = shada_helpers.reset, shada_helpers.set_additional_cmd, shada_helpers.clear -local nvim_current_line = function() - return nvim_window('get_cursor', nvim_curwin())[1] -end - describe('ShaDa support code', function() testfilename = 'Xtestfile-functional-shada-buffers' testfilename_2 = 'Xtestfile-functional-shada-buffers-2' @@ -24,15 +19,12 @@ describe('ShaDa support code', function() reset() nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - -- nvim_command('redir! > /tmp/vistr | verbose set shada? | redir END') - -- nvim_command('wshada /tmp/foo') nvim_command('qall') reset() - -- nvim_command('call writefile([&shada], "/tmp/vistr")') - eq(3, nvim_eval('bufnr("$")')) - eq('', nvim_eval('bufname(1)')) - eq(testfilename, nvim_eval('bufname(2)')) - eq(testfilename_2, nvim_eval('bufname(3)')) + eq(3, funcs.bufnr('$')) + eq('', funcs.bufname(1)) + eq(testfilename, funcs.bufname(2)) + eq(testfilename_2, funcs.bufname(3)) end) it('does not restore buffer list without % in &shada', function() @@ -40,26 +32,20 @@ describe('ShaDa support code', function() reset() nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - -- nvim_command('redir! > /tmp/vistr | verbose set shada? | redir END') - -- nvim_command('wshada /tmp/foo') set_additional_cmd('') nvim_command('qall') reset() - -- nvim_command('call writefile([&shada], "/tmp/vistr")') - eq(1, nvim_eval('bufnr("$")')) - eq('', nvim_eval('bufname(1)')) + eq(1, funcs.bufnr('$')) + eq('', funcs.bufname(1)) end) it('does not dump buffer list without % in &shada', function() nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - -- nvim_command('redir! > /tmp/vistr | verbose set shada? | redir END') - -- nvim_command('wshada /tmp/foo') set_additional_cmd('set shada+=%') nvim_command('qall') reset() - -- nvim_command('call writefile([&shada], "/tmp/vistr")') - eq(1, nvim_eval('bufnr("$")')) - eq('', nvim_eval('bufname(1)')) + eq(1, funcs.bufnr('$')) + eq('', funcs.bufname(1)) end) end) diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index 295678d8d6..342dee377b 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -1,8 +1,6 @@ -- ShaDa compatibility support local helpers = require('test.functional.helpers') -local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = - helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, - helpers.eval, helpers.eq +local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq local exc_exec = helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') @@ -45,11 +43,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada! ' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) it('works with s/search pattern item with BOOL unknown (sX) key value', function() @@ -77,11 +75,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) it('works with replacement item with BOOL additional value in list', function() @@ -110,11 +108,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) for _, v in ipairs({{name='global mark', mpack='\007\001\018\131\162mX\195\161f\196\006/a/b/c\161nA'}, @@ -124,8 +122,8 @@ describe('ShaDa forward compatibility support code', function() }) do it('works with ' .. v.name .. ' item with BOOL unknown (mX) key value', function() nvim_command('silent noautocmd edit /a/b/c') - eq('/a/b/c', nvim_eval('bufname("%")')) - nvim_command('call setline(".", ["1", "2", "3"])') + eq('/a/b/c', funcs.bufname('%')) + funcs.setline('.', {'1', '2', '3'}) wshada(v.mpack) eq(0, exc_exec(sdrcmd(true))) os.remove(shada_fname) @@ -141,7 +139,7 @@ describe('ShaDa forward compatibility support code', function() eq(true, found) eq(0, exc_exec(sdrcmd())) nvim_command('bwipeout!') - nvim_eval('setpos("\'A", [0, 1, 1, 0])') + funcs.setpos('\'A', {0, 1, 1, 0}) os.remove(shada_fname) nvim_command('wshada ' .. shada_fname) found = false @@ -153,18 +151,18 @@ describe('ShaDa forward compatibility support code', function() end end eq(false, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) if v.name == 'global mark' or v.name == 'local mark' then it('works with ' .. v.name .. ' item with name', function() nvim_command('silent noautocmd edit /a/b/c') - eq('/a/b/c', nvim_eval('bufname("%")')) - nvim_command('call setline(".", ["1", "2", "3"])') + eq('/a/b/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('/a/b/c', '/d/e/f')) @@ -195,11 +193,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) end end @@ -227,11 +225,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(false, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) it('works with register item with name', function() @@ -263,17 +261,20 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.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({{}, ''}, nvim_eval('[getreg("a", 1, 1)[:], getregtype("a")]')) + -- getreg may return empty list as list with NULL pointer which API + -- translates into nil for some reason. + eq({}, funcs.getreg('a', 1, 1) or {}) + eq('', funcs.getregtype('a')) nvim_command('wshada ' .. shada_fname) local found = 0 for i, v in ipairs(read_shada_file(shada_fname)) do @@ -300,19 +301,19 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.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/a/b/c\162bX\195') eq(0, exc_exec(sdrcmd())) - eq(2, nvim_eval('bufnr("$")')) - eq('/a/b/c', nvim_eval('bufname(2)')) + eq(2, funcs.bufnr('$')) + eq('/a/b/c', funcs.bufname(2)) os.remove(shada_fname) nvim_command('wshada ' .. shada_fname) local found = false @@ -335,11 +336,11 @@ describe('ShaDa forward compatibility support code', function() end eq(false, found) nvim_command('bwipeout!') - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) it('works with history item with BOOL additional value in list', function() @@ -358,8 +359,8 @@ describe('ShaDa forward compatibility support code', function() eq(true, found) eq(0, exc_exec(sdrcmd())) os.remove(shada_fname) - nvim_eval('histadd(":", "--")') - nvim_eval('histadd(":", "-")') + funcs.histadd(':', '--') + funcs.histadd(':', '-') nvim_command('wshada ' .. shada_fname) found = false for _, v in ipairs(read_shada_file(shada_fname)) do @@ -369,11 +370,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) it('works with history item with type 10', function() @@ -406,11 +407,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) it('works with item with 100 type', function() @@ -443,10 +444,10 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - nvim_eval('garbagecollect(1)') - nvim_eval('garbagecollect(1)') + funcs.garbagecollect(1) + funcs.garbagecollect(1) end) end) diff --git a/test/functional/shada/errors_spec.lua b/test/functional/shada/errors_spec.lua index b612ed48c5..16ae77af02 100644 --- a/test/functional/shada/errors_spec.lua +++ b/test/functional/shada/errors_spec.lua @@ -1,14 +1,10 @@ -- ShaDa errors handling support local helpers = require('test.functional.helpers') -local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = - helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, - helpers.eval, helpers.eq -local exc_exec = 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, set_additional_cmd, clear, get_shada_rw = - shada_helpers.reset, shada_helpers.set_additional_cmd, - 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 wshada, sdrcmd, shada_fname, clean = get_shada_rw('Xtest-functional-shada-errors.shada') diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index 3af92112cb..c2ff4cadd1 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -1,7 +1,6 @@ local helpers = require('test.functional.helpers') -local spawn, set_session, nvim, nvim_prog, nvim_command, nvim_eval = - helpers.spawn, helpers.set_session, helpers.nvim, helpers.nvim_prog, - helpers.command, helpers.eval +local spawn, set_session, meths, nvim_prog = + helpers.spawn, helpers.set_session, helpers.meths, helpers.nvim_prog local write_file, merge_args = helpers.write_file, helpers.merge_args local msgpack = require('MessagePack') @@ -30,7 +29,7 @@ local reset = function() end session = spawn(nvim_argv()) set_session(session) - nvim('set_var', 'tmpname', tmpname) + meths.set_var('tmpname', tmpname) end local set_additional_cmd = function(s) diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 720ad986ea..1123f829d2 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') -local nvim, nvim_command, nvim_eval, nvim_feed, eq = - helpers.nvim, helpers.command, helpers.eval, helpers.feed, helpers.eq +local nvim_command, funcs, meths, nvim_feed, eq = + helpers.command, helpers.funcs, helpers.meths, helpers.feed, helpers.eq local shada_helpers = require('test.functional.shada.helpers') local reset, set_additional_cmd, clear = @@ -19,7 +19,7 @@ describe('ShaDa support code', function() reset() nvim_command('set shada=\'0') nvim_command('rshada') - eq('" Test', nvim_eval('histget(":", -1)')) + eq('" Test', funcs.histget(':', -1)) end) it('is able to dump and read back 2 items in command-line history', function() @@ -30,8 +30,8 @@ describe('ShaDa support code', function() reset() nvim_command('set shada=\'0 history=2') nvim_command('rshada') - eq('" Test 2', nvim_eval('histget(":", -1)')) - eq('" Test', nvim_eval('histget(":", -2)')) + eq('" Test 2', funcs.histget(':', -1)) + eq('" Test', funcs.histget(':', -2)) nvim_command('qall') end) @@ -44,8 +44,8 @@ describe('ShaDa support code', function() reset() nvim_command('set shada=\'0 history=2') nvim_command('rshada') - eq('" Test 2', nvim_eval('histget(":", -1)')) - eq('', nvim_eval('histget(":", -2)')) + eq('" Test 2', funcs.histget(':', -1)) + eq('', funcs.histget(':', -2)) end) it('respects &history when loading', @@ -57,8 +57,8 @@ describe('ShaDa support code', function() reset() nvim_command('set shada=\'0 history=1') nvim_command('rshada') - eq('" Test 2', nvim_eval('histget(":", -1)')) - eq('', nvim_eval('histget(":", -2)')) + eq('" Test 2', funcs.histget(':', -1)) + eq('', funcs.histget(':', -2)) end) it('dumps only requested amount of command-line history items', function() @@ -67,13 +67,13 @@ describe('ShaDa support code', function() nvim_feed(':" Test 2\n') nvim_command('wshada') -- Regression test: :wshada should not alter or free history. - eq('" Test 2', nvim_eval('histget(":", -1)')) - eq('" Test', nvim_eval('histget(":", -2)')) + eq('" Test 2', funcs.histget(':', -1)) + eq('" Test', funcs.histget(':', -2)) reset() nvim_command('set shada=\'0') nvim_command('rshada') - eq('" Test 2', nvim_eval('histget(":", -1)')) - eq('', nvim_eval('histget(":", -2)')) + eq('" Test 2', funcs.histget(':', -1)) + eq('', funcs.histget(':', -2)) end) it('does not respect number in &shada when loading history', function() @@ -84,8 +84,8 @@ describe('ShaDa support code', function() reset() nvim_command('set shada=\'0,:1') nvim_command('rshada') - eq('" Test 2', nvim_eval('histget(":", -1)')) - eq('" Test', nvim_eval('histget(":", -2)')) + eq('" Test 2', funcs.histget(':', -1)) + eq('" Test', funcs.histget(':', -2)) end) it('dumps and loads all kinds of histories', function() @@ -99,31 +99,31 @@ describe('ShaDa support code', function() nvim_command('wshada') reset() nvim_command('rshada') - eq('" Test', nvim_eval('histget(":", -1)')) - eq('Test', nvim_eval('histget("/", -1)')) - eq('"Test"', nvim_eval('histget("=", -1)')) - eq('Test 2', nvim_eval('histget("@", -1)')) - eq('c', nvim_eval('histget(">", -1)')) + 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)) end) it('dumps and loads last search pattern with offset', function() - nvim_eval('setline(".", ["foo", "bar"])') + funcs.setline('.', {'foo', 'bar'}) nvim_feed('gg0/a/e+1\n') - eq({0, 2, 3, 0}, nvim_eval('getpos(".")')) + eq({0, 2, 3, 0}, funcs.getpos('.')) nvim_command('wshada') reset() - nvim_eval('setline(".", ["foo", "bar"])') + funcs.setline('.', {'foo', 'bar'}) nvim_feed('gg0n') - eq({0, 2, 3, 0}, nvim_eval('getpos(".")')) + eq({0, 2, 3, 0}, funcs.getpos('.')) end) it('saves v:hlsearch=1', function() nvim_command('set hlsearch shada-=h') nvim_feed('/test\n') - eq(1, nvim_eval('v:hlsearch')) + eq(1, meths.get_vvar('hlsearch')) nvim_command('qall') reset() - eq(1, nvim_eval('v:hlsearch')) + eq(1, meths.get_vvar('hlsearch')) end) it('saves v:hlsearch=0 with :nohl', function() @@ -132,27 +132,27 @@ describe('ShaDa support code', function() nvim_command('nohlsearch') nvim_command('qall') reset() - eq(0, nvim_eval('v:hlsearch')) + eq(0, meths.get_vvar('hlsearch')) end) it('saves v:hlsearch=0 with default &shada', function() nvim_command('set hlsearch') nvim_feed('/test\n') - eq(1, nvim_eval('v:hlsearch')) + eq(1, meths.get_vvar('hlsearch')) nvim_command('qall') reset() - eq(0, nvim_eval('v:hlsearch')) + eq(0, meths.get_vvar('hlsearch')) end) it('dumps and loads last substitute pattern and replacement string', function() - nvim_eval('setline(".", ["foo", "bar"])') + funcs.setline('.', {'foo', 'bar'}) nvim_command('%s/f/g/g') - eq('goo', nvim_eval('getline(1)')) + eq('goo', funcs.getline(1)) nvim_command('wshada') reset() - nvim_eval('setline(".", ["foo", "bar"])') + funcs.setline('.', {'foo', 'bar'}) nvim_command('&') - eq('goo', nvim_eval('getline(1)')) + eq('goo', funcs.getline(1)) end) it('dumps and loads history correctly when &encoding is not UTF-8', function() @@ -162,7 +162,7 @@ describe('ShaDa support code', function() nvim_feed(':echo "\171"\n') nvim_command('qall') reset() - eq('echo "\171"', nvim_eval('histget(":", -1)')) + eq('echo "\171"', funcs.histget(':', -1)) end) it('dumps and loads history correctly when &encoding /= UTF-8 when dumping', @@ -174,7 +174,7 @@ describe('ShaDa support code', function() set_additional_cmd('') nvim_command('qall') reset() - eq('echo "«"', nvim_eval('histget(":", -1)')) + eq('echo "«"', funcs.histget(':', -1)) end) it('dumps and loads history correctly when &encoding /= UTF-8 when loading', @@ -184,7 +184,7 @@ describe('ShaDa support code', function() set_additional_cmd('set encoding=latin1') nvim_command('qall') reset() - eq('echo "\171"', nvim_eval('histget(":", -1)')) + eq('echo "\171"', funcs.histget(':', -1)) end) it('dumps and loads replacement correctly when &encoding is not UTF-8', @@ -195,9 +195,9 @@ describe('ShaDa support code', function() nvim_command('substitute/./\171/ge') nvim_command('qall!') reset() - nvim_eval('setline(".", ["."])') + funcs.setline('.', {'.'}) nvim_command('&') - eq('\171', nvim_eval('getline(".")')) + eq('\171', funcs.getline('.')) end) it('dumps&loads replacement correctly when &encoding /= UTF-8 when dumping', @@ -209,9 +209,9 @@ describe('ShaDa support code', function() set_additional_cmd('') nvim_command('qall') reset() - nvim_eval('setline(".", ["."])') + funcs.setline('.', {'.'}) nvim_command('&') - eq('«', nvim_eval('getline(".")')) + eq('«', funcs.getline('.')) end) it('dumps&loads replacement correctly when &encoding /= UTF-8 when loading', @@ -221,9 +221,9 @@ describe('ShaDa support code', function() set_additional_cmd('set encoding=latin1') nvim_command('qall') reset() - nvim_eval('setline(".", ["."])') + funcs.setline('.', {'.'}) nvim_command('&') - eq('\171', nvim_eval('getline(".")')) + eq('\171', funcs.getline('.')) end) it('dumps and loads substitute pattern correctly when &encoding is not UTF-8', @@ -234,9 +234,9 @@ describe('ShaDa support code', function() nvim_command('substitute/\171/./ge') nvim_command('qall!') reset() - nvim_eval('setline(".", ["\171«"])') + funcs.setline('.', {'\171«'}) nvim_command('&') - eq('.«', nvim_eval('getline(".")')) + eq('.«', funcs.getline('.')) end) it('dumps&loads s/pattern correctly when &encoding /= UTF-8 when dumping', @@ -248,9 +248,9 @@ describe('ShaDa support code', function() set_additional_cmd('') nvim_command('qall') reset() - nvim_eval('setline(".", ["«\171"])') + funcs.setline('.', {'«\171'}) nvim_command('&') - eq('.\171', nvim_eval('getline(".")')) + eq('.\171', funcs.getline('.')) end) it('dumps&loads s/pattern correctly when &encoding /= UTF-8 when loading', @@ -260,9 +260,9 @@ describe('ShaDa support code', function() set_additional_cmd('set encoding=latin1') nvim_command('qall') reset() - nvim_eval('setline(".", ["\171«"])') + funcs.setline('.', {'\171«'}) nvim_command('&') - eq('.«', nvim_eval('getline(".")')) + eq('.«', funcs.getline('.')) end) it('dumps and loads search pattern correctly when &encoding is not UTF-8', @@ -274,10 +274,10 @@ describe('ShaDa support code', function() nvim_command('set shada+=/0') nvim_command('qall!') reset() - nvim_eval('setline(".", ["\171«"])') + funcs.setline('.', {'\171«'}) nvim_command('~&') - eq('«', nvim_eval('getline(".")')) - eq('', nvim_eval('histget("/", -1)')) + eq('«', funcs.getline('.')) + eq('', funcs.histget('/', -1)) end) it('dumps&loads /pattern correctly when &encoding /= UTF-8 when dumping', @@ -290,10 +290,10 @@ describe('ShaDa support code', function() set_additional_cmd('') nvim_command('qall') reset() - nvim_eval('setline(".", ["«\171"])') + funcs.setline('.', {'«\171'}) nvim_command('~&') - eq('\171', nvim_eval('getline(".")')) - eq('', nvim_eval('histget("/", -1)')) + eq('\171', funcs.getline('.')) + eq('', funcs.histget('/', -1)) end) it('dumps&loads /pattern correctly when &encoding /= UTF-8 when loading', @@ -304,9 +304,9 @@ describe('ShaDa support code', function() set_additional_cmd('set encoding=latin1') nvim_command('qall') reset() - nvim_eval('setline(".", ["\171«"])') + funcs.setline('.', {'\171«'}) nvim_command('~&') - eq('«', nvim_eval('getline(".")')) - eq('', nvim_eval('histget("/", -1)')) + eq('«', funcs.getline('.')) + eq('', funcs.histget('/', -1)) end) end) diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index 18ce470cb7..b03af39662 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -1,9 +1,9 @@ -- ShaDa marks saving/reading support local helpers = require('test.functional.helpers') -local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = - helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, - helpers.eval, helpers.eq -local exc_exec = helpers.exc_exec +local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq = + helpers.meths, helpers.curwinmeths, helpers.curbufmeths, helpers.command, + helpers.funcs, helpers.eq +local exc_exec, redir_exec = helpers.exc_exec, helpers.redir_exec local shada_helpers = require('test.functional.shada.helpers') local reset, set_additional_cmd, clear = @@ -11,7 +11,7 @@ local reset, set_additional_cmd, clear = shada_helpers.clear local nvim_current_line = function() - return nvim_window('get_cursor', nvim_curwin())[1] + return curwinmeths.get_cursor()[1] end describe('ShaDa support code', function() @@ -43,7 +43,7 @@ describe('ShaDa support code', function() reset() nvim_command('rshada') nvim_command('normal! `A') - eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) + eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(1, nvim_current_line()) nvim_command('normal! `B') eq(2, nvim_current_line()) @@ -71,7 +71,7 @@ describe('ShaDa support code', function() reset() nvim_command('language C') nvim_command('normal! `A') - eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) + eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(1, nvim_current_line()) end) @@ -84,7 +84,7 @@ describe('ShaDa support code', function() reset() nvim_command('edit ' .. testfilename) nvim_command('normal! `a') - eq(testfilename, nvim_eval('fnamemodify(@%, ":t")')) + eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(1, nvim_current_line()) nvim_command('normal! `b') eq(2, nvim_current_line()) @@ -92,19 +92,19 @@ describe('ShaDa support code', function() it('is able to populate v:oldfiles', function() nvim_command('edit ' .. testfilename) - local tf_full = nvim_eval('fnamemodify(bufname("%"), ":p")') + local tf_full = curbufmeths.get_name() nvim_command('edit ' .. testfilename_2) - local tf_full_2 = nvim_eval('fnamemodify(bufname("%"), ":p")') + local tf_full_2 = curbufmeths.get_name() nvim_command('qall') reset() - local oldfiles = nvim('get_vvar', 'oldfiles') + local oldfiles = meths.get_vvar('oldfiles') eq(2, #oldfiles) eq(testfilename, oldfiles[1]:sub(-#testfilename)) eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2)) eq(tf_full, oldfiles[1]) eq(tf_full_2, oldfiles[2]) nvim_command('rshada!') - local oldfiles = nvim('get_vvar', 'oldfiles') + local oldfiles = meths.get_vvar('oldfiles') eq(2, #oldfiles) eq(testfilename, oldfiles[1]:sub(-#testfilename)) eq(testfilename_2, oldfiles[2]:sub(-#testfilename_2)) @@ -114,74 +114,66 @@ describe('ShaDa support code', function() it('is able to dump and restore jump list', function() nvim_command('edit ' .. testfilename_2) - nvim_feed('G') - nvim_feed('gg') + nvim_command('normal! G') + nvim_command('normal! gg') nvim_command('edit ' .. testfilename) - nvim_feed('G') - nvim_feed('gg') + nvim_command('normal! G') + nvim_command('normal! gg') nvim_command('enew') - nvim_feed('gg') - nvim_command('redir => g:jumps | jumps | redir END') - local saved = nvim_eval('g:jumps') + nvim_command('normal! gg') + local saved = redir_exec('jumps') nvim_command('qall') reset() - nvim_command('redir => g:jumps | jumps | redir END') - eq(saved, nvim_eval('g:jumps')) + eq(saved, redir_exec('jumps')) end) it('is able to dump and restore jump list with different times (slow!)', function() nvim_command('edit ' .. testfilename_2) nvim_command('sleep 2') - nvim_feed('G') + nvim_command('normal! G') nvim_command('sleep 2') - nvim_feed('gg') + nvim_command('normal! gg') nvim_command('sleep 2') nvim_command('edit ' .. testfilename) nvim_command('sleep 2') - nvim_feed('G') + nvim_command('normal! G') nvim_command('sleep 2') - nvim_feed('gg') - -- nvim_command('redir! >/tmp/jumps.last | jumps | redir END') - -- nvim_command('wshada /tmp/foo') + nvim_command('normal! gg') nvim_command('qall') reset() nvim_command('redraw') - -- nvim_command('redir! >/tmp/jumps.init | jumps | redir END') nvim_command('edit ' .. testfilename) - -- nvim_command('redir! >/tmp/jumps | jumps | redir END') - eq(testfilename, nvim_eval('bufname("%")')) + eq(testfilename, funcs.bufname('%')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') - eq(testfilename, nvim_eval('bufname("%")')) + eq(testfilename, funcs.bufname('%')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') - eq(testfilename, nvim_eval('bufname("%")')) + eq(testfilename, funcs.bufname('%')) eq(2, nvim_current_line()) nvim_command('execute "normal! \\"') - eq(testfilename_2, nvim_eval('bufname("%")')) + eq(testfilename_2, funcs.bufname('%')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\"') - eq(testfilename_2, nvim_eval('bufname("%")')) + eq(testfilename_2, funcs.bufname('%')) eq(2, nvim_current_line()) end) it('is able to dump and restore change list', function() nvim_command('edit ' .. testfilename) - nvim_feed('Gra') - nvim_feed('ggrb') + nvim_command('normal! Gra') + nvim_command('normal! ggrb') nvim_command('qall!') reset() nvim_command('edit ' .. testfilename) - -- nvim_command('rshada') - -- nvim_command('redir! >/tmp/changes | changes | redir END') - nvim_feed('Gg;') + nvim_command('normal! Gg;') -- Note: without “sync” “commands” test has good changes to fail for unknown -- reason (in first eq expected 1 is compared with 2). Any command inserted -- causes this to work properly. nvim_command('" sync') eq(1, nvim_current_line()) - nvim_feed('g;') + nvim_command('normal! g;') nvim_command('" sync 2') eq(2, nvim_current_line()) end) diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index b880bdae8a..7066ca9f54 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -1,14 +1,13 @@ -- ShaDa merging data support local helpers = require('test.functional.helpers') -local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = - helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, - helpers.eval, helpers.eq -local exc_exec = helpers.exc_exec +local nvim_command, meths, funcs, curbufmeths, eq = + helpers.command, helpers.meths, helpers.funcs, + helpers.curbufmeths, helpers.eq +local exc_exec, redir_exec = helpers.exc_exec, helpers.redir_exec local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, get_shada_rw = - shada_helpers.reset, shada_helpers.set_additional_cmd, - 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 = @@ -142,7 +141,7 @@ describe('ShaDa history merging code', function() eq(0, exc_exec('wshada! ' .. shada_fname)) local items = {'ad', 'ab', 'ac', 'af', 'ae'} for i, v in ipairs(items) do - eq(v, nvim_eval(('histget(":", %i)'):format(i))) + eq(v, funcs.histget(':', i)) end local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -244,7 +243,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) end) it('uses last search pattern with gt tstamp from file when reading with bang', @@ -253,7 +252,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', nvim_eval('@/')) + eq('?', funcs.getreg('/')) end) it('uses last search pattern with eq timestamp from instance when reading', @@ -262,7 +261,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) end) it('uses last search pattern with gt timestamp from file when reading', @@ -271,7 +270,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', nvim_eval('@/')) + eq('?', funcs.getreg('/')) end) it('uses last search pattern with gt timestamp from instance when writing', @@ -279,7 +278,7 @@ describe('ShaDa search pattern support code', 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('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -295,7 +294,7 @@ describe('ShaDa search pattern support code', 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('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -311,7 +310,7 @@ describe('ShaDa search pattern support code', 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('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -328,7 +327,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) end) it('uses last s/ pattern with gt timestamp from file when reading with !', @@ -337,7 +336,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', nvim_eval('@/')) + eq('?', funcs.getreg('/')) end) it('uses last s/ pattern with eq timestamp from instance when reading', @@ -346,7 +345,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) end) it('uses last s/ pattern with gt timestamp from file when reading', @@ -355,7 +354,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', nvim_eval('@/')) + eq('?', funcs.getreg('/')) end) it('uses last s/ pattern with gt timestamp from instance when writing', @@ -363,7 +362,7 @@ describe('ShaDa search pattern support code', 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('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -379,7 +378,7 @@ describe('ShaDa search pattern support code', 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('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -395,7 +394,7 @@ describe('ShaDa search pattern support code', 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('-', nvim_eval('@/')) + eq('-', funcs.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -421,7 +420,7 @@ describe('ShaDa replacement string support code', function() wshada('\003\000\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('-', nvim_eval('getline(".")')) + eq('-', funcs.getline('.')) nvim_command('bwipeout!') end) @@ -432,7 +431,7 @@ describe('ShaDa replacement string support code', function() wshada('\003\000\004\145\196\001?') eq(0, exc_exec(sdrcmd(true))) nvim_command('s/.*/~') - eq('?', nvim_eval('getline(".")')) + eq('?', funcs.getline('.')) nvim_command('bwipeout!') end) @@ -443,7 +442,7 @@ describe('ShaDa replacement string support code', function() wshada('\003\001\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('-', nvim_eval('getline(".")')) + eq('-', funcs.getline('.')) nvim_command('bwipeout!') end) @@ -454,7 +453,7 @@ describe('ShaDa replacement string support code', function() wshada('\003\002\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('?', nvim_eval('getline(".")')) + eq('?', funcs.getline('.')) nvim_command('bwipeout!') end) @@ -518,7 +517,7 @@ describe('ShaDa marks support code', function() wshada('\007\000\018\131\162mX\195\161f\196\006/a/b/?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) end) it('uses last A mark with gt timestamp from file when reading with !', @@ -528,7 +527,7 @@ describe('ShaDa marks support code', function() wshada('\007\000\018\131\162mX\195\161f\196\006/a/b/?\161nA') eq(0, exc_exec(sdrcmd(true))) nvim_command('normal! `A') - eq('?', nvim_eval('fnamemodify(bufname("%"), ":t")')) + eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) end) it('uses last A mark with eq timestamp from instance when reading', @@ -538,7 +537,7 @@ describe('ShaDa marks support code', function() wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) end) it('uses last A mark with gt timestamp from file when reading', @@ -548,7 +547,7 @@ describe('ShaDa marks support code', function() wshada('\007\002\018\131\162mX\195\161f\196\006/a/b/?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('?', nvim_eval('fnamemodify(bufname("%"), ":t")')) + eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) end) it('uses last A mark with gt timestamp from instance when writing', @@ -557,7 +556,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\000\018\131\162mX\195\161f\196\006/a/b/?\161nA') nvim_command('normal! `A') - eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -574,7 +573,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\001\018\131\162mX\195\161f\196\006/a/b/?\161nA') nvim_command('normal! `A') - eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -591,7 +590,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\002\018\131\162mX\195\161f\196\006/a/b/?\161nA') nvim_command('normal! `A') - eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -605,60 +604,60 @@ describe('ShaDa marks support code', function() it('uses last a mark with gt timestamp from instance when reading', function() nvim_command('edit /a/b/-') - nvim_eval('setline(1, ["-", "?"])') + funcs.setline(1, {'-', '?'}) wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('-', nvim_eval('getline(".")')) + eq('-', funcs.getline('.')) end) it('uses last a mark with gt timestamp from file when reading with !', function() nvim_command('edit /a/b/-') - nvim_eval('setline(1, ["-", "?"])') + funcs.setline(1, {'-', '?'}) wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd(true))) nvim_command('normal! `a') - eq('?', nvim_eval('getline(".")')) + eq('?', funcs.getline('.')) end) it('uses last a mark with eq timestamp from instance when reading', function() nvim_command('edit /a/b/-') - nvim_eval('setline(1, ["-", "?"])') + funcs.setline(1, {'-', '?'}) wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\001\017\131\161l\002\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('-', nvim_eval('getline(".")')) + eq('-', funcs.getline('.')) end) it('uses last a mark with gt timestamp from file when reading', function() nvim_command('edit /a/b/-') - nvim_eval('setline(1, ["-", "?"])') + funcs.setline(1, {'-', '?'}) wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\002\017\131\161l\002\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('?', nvim_eval('getline(".")')) + eq('?', funcs.getline('.')) end) it('uses last a mark with gt timestamp from instance when writing', function() nvim_command('edit /a/b/-') - nvim_eval('setline(1, ["-", "?"])') + funcs.setline(1, {'-', '?'}) wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006/a/b/-\161na') nvim_command('normal! `a') - eq('-', nvim_eval('getline(".")')) + eq('-', funcs.getline('.')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -673,12 +672,12 @@ describe('ShaDa marks support code', function() it('uses last a mark with eq timestamp from instance when writing', function() nvim_command('edit /a/b/-') - nvim_eval('setline(1, ["-", "?"])') + funcs.setline(1, {'-', '?'}) wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\001\017\131\161l\002\161f\196\006/a/b/-\161na') nvim_command('normal! `a') - eq('-', nvim_eval('getline(".")')) + eq('-', funcs.getline('.')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -693,12 +692,12 @@ describe('ShaDa marks support code', function() it('uses last a mark with gt timestamp from file when writing', function() nvim_command('edit /a/b/-') - nvim_eval('setline(1, ["-", "?"])') + funcs.setline(1, {'-', '?'}) wshada('\010\001\017\131\161l\001\161f\196\006/a/b/-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\002\017\131\161l\002\161f\196\006/a/b/-\161na') nvim_command('normal! `a') - eq('-', nvim_eval('fnamemodify(bufname("%"), ":t")')) + eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -724,7 +723,7 @@ describe('ShaDa registers support code', function() eq(0, exc_exec(sdrcmd())) wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', nvim_eval('@a')) + eq('-', funcs.getreg('a')) end) it('uses last a register with gt timestamp from file when reading with !', @@ -733,7 +732,7 @@ describe('ShaDa registers support code', function() eq(0, exc_exec(sdrcmd())) wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', nvim_eval('@a')) + eq('?', funcs.getreg('a')) end) it('uses last a register with eq timestamp from instance when reading', @@ -742,7 +741,7 @@ describe('ShaDa registers support code', function() eq(0, exc_exec(sdrcmd())) wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', nvim_eval('@a')) + eq('-', funcs.getreg('a')) end) it('uses last a register with gt timestamp from file when reading', @@ -751,7 +750,7 @@ describe('ShaDa registers support code', function() eq(0, exc_exec(sdrcmd())) wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', nvim_eval('@a')) + eq('?', funcs.getreg('a')) end) it('uses last a register with gt timestamp from instance when writing', @@ -759,7 +758,7 @@ describe('ShaDa registers support code', 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('-', nvim_eval('@a')) + eq('-', funcs.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -776,7 +775,7 @@ describe('ShaDa registers support code', 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('-', nvim_eval('@a')) + eq('-', funcs.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -793,7 +792,7 @@ describe('ShaDa registers support code', 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('-', nvim_eval('@a')) + eq('-', funcs.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -822,8 +821,7 @@ describe('ShaDa jumps support code', function() .. '\008\004\018\131\162mX\195\161f\196\006/a/b/d\161l\003' .. '\008\007\018\131\162mX\195\161f\196\006/a/b/f\161l\002') eq(0, exc_exec(sdrcmd())) - nvim_command('redir => g:jumps | jumps | redir END') - eq('', nvim_eval('bufname("%")')) + eq('', curbufmeths.get_name()) eq('\n' .. ' jump line col file/text\n' .. ' 6 2 0 /a/b/c\n' @@ -832,7 +830,7 @@ describe('ShaDa jumps support code', function() .. ' 3 2 0 /a/b/e\n' .. ' 2 2 0 /a/b/f\n' .. ' 1 1 0 \n' - .. '>', nvim_eval('g:jumps')) + .. '>', redir_exec('jumps')) end) it('merges jumps when writing', function() @@ -916,7 +914,6 @@ describe('ShaDa changes support code', function() .. '\011\004\018\131\162mX\195\161f\196\006/a/b/c\161l\005' .. '\011\008\018\131\162mX\195\161f\196\006/a/b/c\161l\004') eq(0, exc_exec(sdrcmd())) - nvim_command('redir => g:changes | changes | redir END') eq('\n' .. 'change line col text\n' .. ' 5 1 0 0\n' @@ -924,7 +921,7 @@ describe('ShaDa changes support code', function() .. ' 3 5 0 4\n' .. ' 2 3 0 2\n' .. ' 1 4 0 3\n' - .. '>', nvim_eval('g:changes')) + .. '>', redir_exec('changes')) end) it('merges changes when writing', function() diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua index 67b0661151..f0133b1086 100644 --- a/test/functional/shada/registers_spec.lua +++ b/test/functional/shada/registers_spec.lua @@ -1,34 +1,23 @@ -- ShaDa registers saving/reading support local helpers = require('test.functional.helpers') -local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = - helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, - helpers.eval, helpers.eq +local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq local shada_helpers = require('test.functional.shada.helpers') local reset, set_additional_cmd, clear = shada_helpers.reset, shada_helpers.set_additional_cmd, shada_helpers.clear -local nvim_current_line = function() - return nvim_window('get_cursor', nvim_curwin())[1] -end - local setreg = function(name, contents, typ) - local expr = 'setreg("' .. name .. '", [' if type(contents) == 'string' then contents = {contents} end - for _, line in ipairs(contents) do - expr = expr .. '"' .. line:gsub('[\\"]', '\\\\\\0') .. '", ' - end - expr = expr .. '], "' .. typ .. '")' - nvim_eval(expr) + funcs.setreg(name, contents, typ) end local getreg = function(name) return { - nvim_eval(('getreg("%s", 1, 1)'):format(name)), - nvim_eval(('getregtype("%s")'):format(name)), + funcs.getreg(name, 1, 1), + funcs.getregtype(name), } end @@ -40,7 +29,7 @@ describe('ShaDa support code', function() setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') - nvim_command('qa') + nvim_command('qall') reset() eq({{'d', 'e', ''}, 'v'}, getreg('c')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) @@ -52,7 +41,7 @@ describe('ShaDa support code', function() setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') - nvim_command('qa') + nvim_command('qall') reset() eq({nil, ''}, getreg('c')) eq({nil, ''}, getreg('l')) @@ -64,7 +53,7 @@ describe('ShaDa support code', function() setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') set_additional_cmd('set shada=\'0,<0') - nvim_command('qa') + nvim_command('qall') reset() eq({{'d', 'e', ''}, 'v'}, getreg('c')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) @@ -76,7 +65,7 @@ describe('ShaDa support code', function() setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') - nvim_command('qa') + nvim_command('qall') reset() eq({nil, ''}, getreg('c')) eq({nil, ''}, getreg('l')) @@ -88,7 +77,7 @@ describe('ShaDa support code', function() setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') set_additional_cmd('set shada=\'0,\\"0') - nvim_command('qa') + nvim_command('qall') reset() eq({{'d', 'e', ''}, 'v'}, getreg('c')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) @@ -100,7 +89,7 @@ describe('ShaDa support code', function() setreg('c', {'d', 'e', ''}, 'c') setreg('l', {'a', 'b', 'cde'}, 'l') setreg('b', {'bca', 'abc', 'cba'}, 'b3') - nvim_command('qa') + nvim_command('qall') reset() eq({{'d', 'e', ''}, 'v'}, getreg('c')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('l')) @@ -111,7 +100,7 @@ describe('ShaDa support code', function() nvim_command('set shada=\'0,<2') setreg('o', {'d'}, 'c') setreg('t', {'a', 'b', 'cde'}, 'l') - nvim_command('qa') + nvim_command('qall') reset() eq({{'d'}, 'v'}, getreg('o')) eq({nil, ''}, getreg('t')) @@ -121,7 +110,7 @@ describe('ShaDa support code', function() nvim_command('set shada=\'0,\\"2') setreg('o', {'d'}, 'c') setreg('t', {'a', 'b', 'cde'}, 'l') - nvim_command('qa') + nvim_command('qall') reset() eq({{'d'}, 'v'}, getreg('o')) eq({nil, ''}, getreg('t')) @@ -132,7 +121,7 @@ describe('ShaDa support code', function() setreg('o', {'d'}, 'c') setreg('t', {'a', 'b', 'cde'}, 'l') setreg('h', {'abc', 'acb', 'bac', 'bca', 'cab', 'cba'}, 'b3') - nvim_command('qa') + nvim_command('qall') reset() eq({{'d'}, 'v'}, getreg('o')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('t')) diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 6c2694b834..7a30d3b87d 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -1,8 +1,7 @@ -- Other ShaDa tests local helpers = require('test.functional.helpers') -local nvim, nvim_window, nvim_curwin, nvim_command, nvim_feed, nvim_eval, eq = - helpers.nvim, helpers.window, helpers.curwin, helpers.command, helpers.feed, - helpers.eval, helpers.eq +local meths, nvim_command, funcs, eq = + helpers.meths, helpers.command, helpers.funcs, 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 @@ -12,12 +11,12 @@ local paths = require('test.config.paths') local msgpack = require('MessagePack') local shada_helpers = require('test.functional.shada.helpers') -local reset, set_additional_cmd, clear, get_shada_rw = - shada_helpers.reset, shada_helpers.set_additional_cmd, - 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, clean = get_shada_rw('Xtest-functional-shada-shada.shada') +local wshada, _, shada_fname, clean = + get_shada_rw('Xtest-functional-shada-shada.shada') describe('ShaDa support code', function() before_each(reset) @@ -52,8 +51,8 @@ describe('ShaDa support code', function() local hist1 = ('-'):rep(1024 - 5) local hist2 = ('-'):rep(1025 - 5) nvim_command('set shada-=s10 shada+=s1') - nvim_eval(('histadd(":", "%s")'):format(hist1)) - nvim_eval(('histadd(":", "%s")'):format(hist2)) + funcs.histadd(':', hist1) + funcs.histadd(':', hist2) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -143,7 +142,7 @@ describe('ShaDa support code', function() local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, true) set_session(session) - eq('', nvim_eval('@a')) + eq('', funcs.getreg('a')) session:exit(0) os.remove('NONE') end) @@ -166,7 +165,7 @@ describe('ShaDa support code', function() end it('correctly uses shada-r option', function() - nvim('set_var', '__home', paths.test_source_path) + meths.set_var('__home', paths.test_source_path) nvim_command('let $HOME = __home') nvim_command('unlet __home') nvim_command('edit ~/README.md') @@ -188,12 +187,12 @@ describe('ShaDa support code', function() end) it('correctly ignores case with shada-r option', function() - local pwd = nvim('call_function', 'getcwd', {}) + local pwd = funcs.getcwd() local relfname = 'абв/test' local fname = pwd .. '/' .. relfname - nvim('set_var', '__fname', fname) + meths.set_var('__fname', fname) nvim_command('silent! edit `=__fname`') - nvim('call_function', 'setline', {1, {'a', 'b', 'c', 'd'}}) + funcs.setline(1, {'a', 'b', 'c', 'd'}) nvim_command('normal! GmAggmaAabc') nvim_command('undo') nvim_command('set shada+=%') diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua index c2fa25bcb1..6225971e5f 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') -local nvim, nvim_command, nvim_eval, eq = - helpers.nvim, helpers.command, helpers.eval, helpers.eq +local meths, funcs, nvim_command, eq = + helpers.meths, helpers.funcs, helpers.command, helpers.eq local shada_helpers = require('test.functional.shada.helpers') local reset, set_additional_cmd, clear = @@ -13,13 +13,13 @@ describe('ShaDa support code', function() after_each(clear) it('is able to dump and read back string variable', function() - nvim('set_var', 'STRVAR', 'foo') + meths.set_var('STRVAR', 'foo') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq('foo', nvim('get_var', 'STRVAR')) + eq('foo', meths.get_var('STRVAR')) end) local autotest = function(tname, varname, varval) @@ -27,12 +27,12 @@ describe('ShaDa support code', function() function() set_additional_cmd('set shada+=!') reset() - nvim('set_var', varname, varval) + meths.set_var(varname, varval) -- Exit during `reset` is not a regular exit: it does not write shada -- automatically nvim_command('qall') reset() - eq(varval, nvim('get_var', varname)) + eq(varval, meths.get_var(varname)) end) end @@ -43,43 +43,43 @@ describe('ShaDa support code', function() autotest('list', 'LSTVAR', {{a=10}, {b=10.5}, {c='str'}}) it('does not read back variables without `!` in &shada', function() - nvim('set_var', 'STRVAR', 'foo') + meths.set_var('STRVAR', 'foo') nvim_command('set shada+=!') nvim_command('wshada') set_additional_cmd('set shada-=!') reset() nvim_command('rshada') - eq(0, nvim_eval('exists("g:STRVAR")')) + eq(0, funcs.exists('g:STRVAR')) end) it('does not dump variables without `!` in &shada', function() nvim_command('set shada-=!') - nvim('set_var', 'STRVAR', 'foo') + meths.set_var('STRVAR', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, nvim_eval('exists("g:STRVAR")')) + eq(0, funcs.exists('g:STRVAR')) end) it('does not dump session variables', function() nvim_command('set shada+=!') - nvim('set_var', 'StrVar', 'foo') + meths.set_var('StrVar', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, nvim_eval('exists("g:StrVar")')) + eq(0, funcs.exists('g:StrVar')) end) it('does not dump regular variables', function() nvim_command('set shada+=!') - nvim('set_var', 'str_var', 'foo') + meths.set_var('str_var', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, nvim_eval('exists("g:str_var")')) + eq(0, funcs.exists('g:str_var')) end) it('dumps and loads variables correctly when &encoding is not UTF-8', @@ -87,18 +87,18 @@ describe('ShaDa support code', function() set_additional_cmd('set encoding=latin1') reset() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 - nvim('set_var', 'STRVAR', '\171') - nvim('set_var', 'LSTVAR', {'\171'}) - nvim('set_var', 'DCTVAR', {['\171']='\171'}) - nvim('set_var', 'NESTEDVAR', {['\171']={{'\171'}, {['\171']='\171'}, - {a='Test'}}}) + 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'}}}) nvim_command('qall') reset() - eq('\171', nvim('get_var', 'STRVAR')) - eq({'\171'}, nvim('get_var', 'LSTVAR')) - eq({['\171']='\171'}, nvim('get_var', 'DCTVAR')) + 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'}}}, - nvim('get_var', 'NESTEDVAR')) + meths.get_var('NESTEDVAR')) end) it('dumps and loads variables correctly when &encoding /= UTF-8 when dumping', @@ -106,34 +106,34 @@ describe('ShaDa support code', function() set_additional_cmd('set encoding=latin1') reset() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 - nvim('set_var', 'STRVAR', '\171') - nvim('set_var', 'LSTVAR', {'\171'}) - nvim('set_var', 'DCTVAR', {['\171']='\171'}) - nvim('set_var', 'NESTEDVAR', {['\171']={{'\171'}, {['\171']='\171'}, - {a='Test'}}}) + 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'}}}) set_additional_cmd('') nvim_command('qall') reset() - eq('«', nvim('get_var', 'STRVAR')) - eq({'«'}, nvim('get_var', 'LSTVAR')) - eq({['«']='«'}, nvim('get_var', 'DCTVAR')) - eq({['«']={{'«'}, {['«']='«'}, {a='Test'}}}, nvim('get_var', 'NESTEDVAR')) + eq('«', meths.get_var('STRVAR')) + eq({'«'}, meths.get_var('LSTVAR')) + eq({['«']='«'}, meths.get_var('DCTVAR')) + eq({['«']={{'«'}, {['«']='«'}, {a='Test'}}}, meths.get_var('NESTEDVAR')) end) it('dumps and loads variables correctly when &encoding /= UTF-8 when loading', function() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 - nvim('set_var', 'STRVAR', '«') - nvim('set_var', 'LSTVAR', {'«'}) - nvim('set_var', 'DCTVAR', {['«']='«'}) - nvim('set_var', 'NESTEDVAR', {['«']={{'«'}, {['«']='«'}, {a='Test'}}}) + meths.set_var('STRVAR', '«') + meths.set_var('LSTVAR', {'«'}) + meths.set_var('DCTVAR', {['«']='«'}) + meths.set_var('NESTEDVAR', {['«']={{'«'}, {['«']='«'}, {a='Test'}}}) set_additional_cmd('set encoding=latin1') nvim_command('qall') reset() - eq('\171', nvim('get_var', 'STRVAR')) - eq({'\171'}, nvim('get_var', 'LSTVAR')) - eq({['\171']='\171'}, nvim('get_var', 'DCTVAR')) + 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'}}}, - nvim('get_var', 'NESTEDVAR')) + meths.get_var('NESTEDVAR')) end) end) -- cgit From 3a4a9418853338c3a0e00358b411186b5723184a Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 6 Oct 2015 02:24:16 +0300 Subject: shada: Fix memory leak and double free when setting both &vi and &sd --- test/functional/shada/shada_spec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test') diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 7a30d3b87d..2bc855a239 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -202,4 +202,31 @@ describe('ShaDa support code', function() nvim_command('wshada! ' .. shada_fname) eq({}, find_file(fname)) end) + + it('is able to set &shada after &viminfo', function() + meths.set_option('viminfo', '\'10') + eq('\'10', meths.get_option('viminfo')) + eq('\'10', meths.get_option('shada')) + meths.set_option('shada', '') + eq('', meths.get_option('viminfo')) + eq('', meths.get_option('shada')) + end) + + it('is able to set all& after setting &shada', function() + meths.set_option('shada', '\'10') + eq('\'10', meths.get_option('viminfo')) + eq('\'10', meths.get_option('shada')) + nvim_command('set all&') + eq('!,\'100,<50,s10,h', meths.get_option('viminfo')) + eq('!,\'100,<50,s10,h', meths.get_option('shada')) + end) + + it('is able to set &shada after &viminfo using :set', function() + nvim_command('set viminfo=\'10') + eq('\'10', meths.get_option('viminfo')) + eq('\'10', meths.get_option('shada')) + nvim_command('set shada=') + eq('', meths.get_option('viminfo')) + eq('', meths.get_option('shada')) + end) end) -- cgit