diff options
author | Lucas Hoffmann <l-m-h@web.de> | 2015-05-07 09:26:04 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-06-12 00:10:58 -0400 |
commit | fa4b5211c63b4015df0b035bdda05379ea6ac897 (patch) | |
tree | 664b4aef186bc5b2a0c693842a2af25537d7428c | |
parent | d080375813f91ca92a156726329d5411f7bf78df (diff) | |
download | rneovim-fa4b5211c63b4015df0b035bdda05379ea6ac897.tar.gz rneovim-fa4b5211c63b4015df0b035bdda05379ea6ac897.tar.bz2 rneovim-fa4b5211c63b4015df0b035bdda05379ea6ac897.zip |
tests: Add tests for the :wv command.
-rw-r--r-- | test/functional/ex_cmds/wviminfo_spec.lua | 62 |
1 files changed, 62 insertions, 0 deletions
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) |