functests: Refactor legacy/012_directory_spec

This commit is contained in:
ZyX
2017-04-08 21:58:13 +03:00
parent b0731290e8
commit 47b451c52b

View File

@@ -5,10 +5,17 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local lfs = require('lfs') local lfs = require('lfs')
local insert, eq = helpers.insert, helpers.eq
local neq, eval = helpers.neq, helpers.eval local eq = helpers.eq
local clear, execute = helpers.clear, helpers.execute local neq = helpers.neq
local wait, write_file = helpers.wait, helpers.write_file local wait = helpers.wait
local funcs = helpers.funcs
local meths = helpers.meths
local clear = helpers.clear
local insert = helpers.insert
local command = helpers.command
local write_file = helpers.write_file
local curbufmeths = helpers.curbufmeths
local function ls_dir_sorted(dirname) local function ls_dir_sorted(dirname)
local files = {} local files = {}
@@ -36,7 +43,7 @@ describe("'directory' option", function()
clear() clear()
end) end)
teardown(function() teardown(function()
execute('qall!') command('qall!')
helpers.rmdir('Xtest.je') helpers.rmdir('Xtest.je')
helpers.rmdir('Xtest2') helpers.rmdir('Xtest2')
os.remove('Xtest1') os.remove('Xtest1')
@@ -49,21 +56,22 @@ describe("'directory' option", function()
line 3 Abcdefghij line 3 Abcdefghij
end of testfile]]) end of testfile]])
execute('set swapfile') meths.set_option('swapfile', true)
execute('set dir=.,~') curbufmeths.set_option('swapfile', true)
meths.set_option('directory', '.')
-- sanity check: files should not exist yet. -- sanity check: files should not exist yet.
eq(nil, lfs.attributes('.Xtest1.swp')) eq(nil, lfs.attributes('.Xtest1.swp'))
execute('e! Xtest1') command('edit! Xtest1')
wait() wait()
eq('Xtest1', eval('buffer_name("%")')) eq('Xtest1', funcs.buffer_name('%'))
-- Verify that the swapfile exists. In the legacy test this was done by -- Verify that the swapfile exists. In the legacy test this was done by
-- reading the output from :!ls. -- reading the output from :!ls.
neq(nil, lfs.attributes('.Xtest1.swp')) neq(nil, lfs.attributes('.Xtest1.swp'))
execute('set dir=./Xtest2,.,~') meths.set_option('directory', './Xtest2,.')
execute('e Xtest1') command('edit Xtest1')
wait() wait()
-- swapfile should no longer exist in CWD. -- swapfile should no longer exist in CWD.
@@ -71,9 +79,9 @@ describe("'directory' option", function()
eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2")) eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2"))
execute('set dir=Xtest.je,~') meths.set_option('directory', 'Xtest.je')
execute('e Xtest2/Xtest3') command('edit Xtest2/Xtest3')
eq(1, eval('&swapfile')) eq(true, curbufmeths.get_option('swapfile'))
wait() wait()
eq({ "Xtest3" }, ls_dir_sorted("Xtest2")) eq({ "Xtest3" }, ls_dir_sorted("Xtest2"))