From d080375813f91ca92a156726329d5411f7bf78df Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Tue, 5 May 2015 10:45:49 +0200 Subject: tests: Migrate legacy test 74. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helped-By: David Bürgin <676c7473@gmail.com> Helped-By: Justin M. Keyes --- .../legacy/074_global_var_in_viminfo_spec.lua | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/functional/legacy/074_global_var_in_viminfo_spec.lua (limited to 'test') diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua new file mode 100644 index 0000000000..4f05db6a69 --- /dev/null +++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua @@ -0,0 +1,59 @@ +-- Tests for storing global variables in the .viminfo 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() + setup(function() + clear() + os.remove("Xviminfo") + end) + + it('is working', function() + local nvim2 = helpers.spawn({helpers.nvim_prog, '-u', 'NONE', '--embed'}) + helpers.set_session(nvim2) + + local test_dict = {foo = 1, bar = 0, longvarible = 1000} + local test_list = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100} + + execute( + -- This will cause a few errors, do it silently. + '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. + 'let MY_GLOBAL_LIST=range(1,100)' + ) + eq(test_dict, eval('MY_GLOBAL_DICT')) + eq(test_list, eval('MY_GLOBAL_LIST')) + -- Assert that the viminfo file does not exists. + eq(nil, lfs.attributes('Xviminfo')) + execute('wv! Xviminfo') + wait() + -- Assert that the viminfo file exists. + neq(nil, lfs.attributes('Xviminfo')) + 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') + -- Assert that the variables where restored. + eq(1, eval('exists("MY_GLOBAL_DICT")')) + eq(1, eval('exists("MY_GLOBAL_LIST")')) + eq(test_list, eval('MY_GLOBAL_LIST')) + eq(test_dict, eval('MY_GLOBAL_DICT')) + end) + + teardown(function() + os.remove('Xviminfo') + end) +end) -- cgit From fa4b5211c63b4015df0b035bdda05379ea6ac897 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 7 May 2015 09:26:04 +0200 Subject: tests: Add tests for the :wv command. --- test/functional/ex_cmds/wviminfo_spec.lua | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/functional/ex_cmds/wviminfo_spec.lua (limited to 'test') diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua new file mode 100644 index 0000000000..bff180521b --- /dev/null +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -0,0 +1,62 @@ +local helpers, lfs = require('test.functional.helpers'), require('lfs') +local clear, execute, eq, neq, spawn, nvim_prog, set_session, wait = + helpers.clear, helpers.execute, helpers.eq, helpers.neq, helpers.spawn, + helpers.nvim_prog, helpers.set_session, helpers.wait + +-- Lua does not have a sleep function so we use the system command. If the +-- command does not support sub second precision we use math.floor() to get +-- full seconds. +local sleep = function(millisec) + local sec = millisec / 1000 + local round = math.floor(sec) + if round == 0 then round = 1 end + os.execute('sleep '..sec..' || sleep '..round) +end + +describe(':wviminfo', function() + local file = 'foo' + before_each(function() + clear() + os.remove(file) + end) + + it('creates a file', function() + -- TODO + -- Set up the nvim session to be able to write viminfo files. Is it + -- possible to do this outside of the it() call? + local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'}) + --local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed', '--cmd', 'let hans=42' }) + set_session(nvim2) + --eq(43, eval('hans')) + + -- Assert that the file does not exist. + eq(nil, lfs.attributes(file)) + execute('wv! '..file) + wait() + -- Assert that the file does exist. + neq(nil, lfs.attributes(file)) + end) + + it('overwrites existing files', function() + -- TODO see above + local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'}) + set_session(nvim2) + + local text = 'foo test' + + local fp = io.open(file, 'w') + fp:write(text) + fp:flush() + fp:close() + -- Assert that the file already exists. + neq(nil, lfs.attributes(file)) + execute('wv! '..file) + wait() + -- Assert that the contents of the file changed. + neq(text, io.open(file):read()) + end) + + teardown(function() + os.remove(file) + end) +end) -- cgit From 1f0830f7004c60f899fc169baecd68960f26ea70 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 12 Jun 2015 03:09:12 -0400 Subject: tests: wviminfo_spec.lua: rework 074_global_var_in_viminfo_spec: remove some redundant sanity checks. --- test/functional/ex_cmds/wviminfo_spec.lua | 73 ++++++++++------------ .../legacy/074_global_var_in_viminfo_spec.lua | 11 ++-- 2 files changed, 39 insertions(+), 45 deletions(-) (limited to 'test') diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index bff180521b..21176f1845 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -3,60 +3,55 @@ local clear, execute, eq, neq, spawn, nvim_prog, set_session, wait = helpers.clear, helpers.execute, helpers.eq, helpers.neq, helpers.spawn, helpers.nvim_prog, helpers.set_session, helpers.wait --- Lua does not have a sleep function so we use the system command. If the --- command does not support sub second precision we use math.floor() to get --- full seconds. -local sleep = function(millisec) - local sec = millisec / 1000 - local round = math.floor(sec) - if round == 0 then round = 1 end - os.execute('sleep '..sec..' || sleep '..round) -end - describe(':wviminfo', function() - local file = 'foo' + local viminfo_file = 'wviminfo_test' + local session + before_each(function() - clear() - os.remove(file) + if session then + session:exit(0) + end + + -- Override the default session because we need 'swapfile' for these tests. + local session = spawn({nvim_prog, '-u', 'NONE', '--embed', + '--cmd', 'set swapfile'}) + set_session(session) + + os.remove(viminfo_file) end) - it('creates a file', function() - -- TODO - -- Set up the nvim session to be able to write viminfo files. Is it - -- possible to do this outside of the it() call? - local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'}) - --local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed', '--cmd', 'let hans=42' }) - set_session(nvim2) - --eq(43, eval('hans')) - - -- Assert that the file does not exist. - eq(nil, lfs.attributes(file)) - execute('wv! '..file) + it('creates a viminfo file', function() + -- file should _not_ exist + eq(nil, lfs.attributes(viminfo_file)) + execute('wv! '..viminfo_file) wait() - -- Assert that the file does exist. - neq(nil, lfs.attributes(file)) + -- file _should_ exist + neq(nil, lfs.attributes(viminfo_file)) end) it('overwrites existing files', function() - -- TODO see above - local nvim2 = spawn({nvim_prog, '-u', 'NONE', '--embed'}) - set_session(nvim2) + local text = 'wviminfo test' - local text = 'foo test' - - local fp = io.open(file, 'w') + -- Create a dummy file + local fp = io.open(viminfo_file, 'w') fp:write(text) fp:flush() fp:close() - -- Assert that the file already exists. - neq(nil, lfs.attributes(file)) - execute('wv! '..file) + + -- sanity check + eq(text, io.open(viminfo_file):read()) + neq(nil, lfs.attributes(viminfo_file)) + + execute('wv! '..viminfo_file) wait() - -- Assert that the contents of the file changed. - neq(text, io.open(file):read()) + + -- 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') end) teardown(function() - os.remove(file) + os.remove(viminfo_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 4f05db6a69..180071118a 100644 --- a/test/functional/legacy/074_global_var_in_viminfo_spec.lua +++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua @@ -34,21 +34,20 @@ describe('storing global variables in viminfo files', function() ) eq(test_dict, eval('MY_GLOBAL_DICT')) eq(test_list, eval('MY_GLOBAL_LIST')) - -- Assert that the viminfo file does not exists. - eq(nil, lfs.attributes('Xviminfo')) + execute('wv! Xviminfo') wait() + -- Assert that the viminfo file exists. neq(nil, lfs.attributes('Xviminfo')) execute('unlet MY_GLOBAL_DICT', - 'unlet MY_GLOBAL_LIST') + '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') - -- Assert that the variables where restored. - eq(1, eval('exists("MY_GLOBAL_DICT")')) - eq(1, eval('exists("MY_GLOBAL_LIST")')) + eq(test_list, eval('MY_GLOBAL_LIST')) eq(test_dict, eval('MY_GLOBAL_DICT')) end) -- cgit