aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/vim_spec.lua22
-rw-r--r--test/functional/core/job_spec.lua3
-rw-r--r--test/functional/helpers.lua2
-rw-r--r--test/functional/legacy/051_highlight_spec.lua2
-rw-r--r--test/functional/normal/fold_spec.lua112
-rw-r--r--test/helpers.lua41
6 files changed, 164 insertions, 18 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 3348368a36..8f9f155110 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -153,6 +153,28 @@ describe('api', function()
nvim('set_option', 'equalalways', false)
ok(not nvim('get_option', 'equalalways'))
end)
+
+ it('works to get global value of local options', function()
+ eq(false, nvim('get_option', 'lisp'))
+ eq(8, nvim('get_option', 'shiftwidth'))
+ end)
+
+ it('works to set global value of local options', function()
+ nvim('set_option', 'lisp', true)
+ eq(true, nvim('get_option', 'lisp'))
+ eq(false, helpers.curbuf('get_option', 'lisp'))
+ eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp'))
+ eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp'))
+ nvim('set_option', 'shiftwidth', 20)
+ eq('20', nvim('command_output', 'setglobal shiftwidth?'):match('%d+'))
+ eq('8', nvim('command_output', 'setlocal shiftwidth?'):match('%d+'))
+ end)
+
+ it('most window-local options have no global value', function()
+ local status, err = pcall(nvim, 'get_option', 'foldcolumn')
+ eq(false, status)
+ ok(err:match('Invalid option name') ~= nil)
+ end)
end)
describe('nvim_{get,set}_current_buf, nvim_list_bufs', function()
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index e442c2a317..9ee91f2fe9 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -8,6 +8,7 @@ local clear, eq, eval, exc_exec, execute, feed, insert, neq, next_msg, nvim,
local command = helpers.command
local wait = helpers.wait
local iswin = helpers.iswin
+local get_pathsep = helpers.get_pathsep
local Screen = require('test.functional.ui.screen')
describe('jobs', function()
@@ -65,7 +66,7 @@ describe('jobs', function()
end)
it('changes to given `cwd` directory', function()
- local dir = eval('resolve(tempname())')
+ local dir = eval("resolve(tempname())"):gsub("/", get_pathsep())
mkdir(dir)
nvim('command', "let g:job_opts.cwd = '" .. dir .. "'")
if iswin() then
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 7ce95d0b7c..ab36508262 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -23,7 +23,7 @@ local nvim_prog = os.getenv('NVIM_PROG') or os.getenv('NVIM_PRG') or 'build/bin/
-- Default settings for the test session.
local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent'
..' laststatus=1 undodir=. directory=. viewdir=. backupdir=.'
- ..' belloff= noshowcmd noruler'
+ ..' belloff= noshowcmd noruler nomore'
local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
'--cmd', nvim_set, '--embed'}
diff --git a/test/functional/legacy/051_highlight_spec.lua b/test/functional/legacy/051_highlight_spec.lua
index ef392d8c67..d4d9b7d997 100644
--- a/test/functional/legacy/051_highlight_spec.lua
+++ b/test/functional/legacy/051_highlight_spec.lua
@@ -16,7 +16,7 @@ describe(':highlight', function()
local screen = Screen.new(35, 10)
screen:attach()
-- Basic test if ":highlight" doesn't crash
- execute('highlight')
+ execute('set more', 'highlight')
-- FIXME(tarruda): We need to be sure the prompt is displayed before
-- continuing, or risk a race condition where some of the following input
-- is discarded resulting in test failure
diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua
index 5584db20ba..fc055c4e7a 100644
--- a/test/functional/normal/fold_spec.lua
+++ b/test/functional/normal/fold_spec.lua
@@ -6,12 +6,15 @@ local feed = helpers.feed
local expect = helpers.expect
local execute = helpers.execute
local funcs = helpers.funcs
-local foldlevel, foldclosedend = funcs.foldlevel, funcs.foldclosedend
+local foldlevel = funcs.foldlevel
+local foldclosedend = funcs.foldclosedend
local eq = helpers.eq
describe('Folds', function()
+ local tempfname = 'Xtest-fold.txt'
clear()
before_each(function() execute('enew!') end)
+ after_each(function() os.remove(tempfname) end)
it('manual folding adjusts with filter', function()
insert([[
1
@@ -230,4 +233,111 @@ a]], '2,3m0')
eq({1, 2, 0, 0, 0}, get_folds())
end)
end)
+ it('updates correctly on :read', function()
+ -- luacheck: ignore 621
+ helpers.write_file(tempfname, [[
+ a
+
+
+ a]])
+ insert([[
+ a
+ a
+ a
+ a
+ ]])
+ execute('set foldmethod=indent', '2', '%foldopen')
+ execute('read ' .. tempfname)
+ -- Just to check we have the correct file text.
+ expect([[
+ a
+ a
+ a
+
+
+ a
+ a
+ a
+ ]])
+ for i = 1,2 do
+ eq(1, funcs.foldlevel(i))
+ end
+ for i = 3,5 do
+ eq(0, funcs.foldlevel(i))
+ end
+ for i = 6,8 do
+ eq(1, funcs.foldlevel(i))
+ end
+ end)
+ it('combines folds when removing separating space', function()
+ -- luacheck: ignore 621
+ insert([[
+ a
+ a
+ a
+ a
+ a
+ a
+ a
+ a
+ ]])
+ execute('set foldmethod=indent', '3,5d')
+ eq(5, funcs.foldclosedend(1))
+ end)
+ it("doesn't combine folds that have a specified end", function()
+ insert([[
+ {{{
+ }}}
+
+
+
+ {{{
+
+ }}}
+ ]])
+ execute('set foldmethod=marker', '3,5d', '%foldclose')
+ eq(2, funcs.foldclosedend(1))
+ end)
+ it('splits folds according to >N and <N with foldexpr', function()
+ helpers.source([[
+ function TestFoldExpr(lnum)
+ let thisline = getline(a:lnum)
+ if thisline == 'a'
+ return 1
+ elseif thisline == 'b'
+ return 0
+ elseif thisline == 'c'
+ return '<1'
+ elseif thisline == 'd'
+ return '>1'
+ endif
+ return 0
+ endfunction
+ ]])
+ helpers.write_file(tempfname, [[
+ b
+ b
+ a
+ a
+ d
+ a
+ a
+ c]])
+ insert([[
+ a
+ a
+ a
+ a
+ a
+ a
+ ]])
+ execute('set foldmethod=expr', 'set foldexpr=TestFoldExpr(v:lnum)', '2', 'foldopen')
+ execute('read ' .. tempfname, '%foldclose')
+ eq(2, funcs.foldclosedend(1))
+ eq(0, funcs.foldlevel(3))
+ eq(0, funcs.foldlevel(4))
+ eq(6, funcs.foldclosedend(5))
+ eq(10, funcs.foldclosedend(7))
+ eq(14, funcs.foldclosedend(11))
+ end)
end)
diff --git a/test/helpers.lua b/test/helpers.lua
index 1a86effa1c..82451bc61d 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -106,20 +106,33 @@ local uname = (function()
end)
end)()
-local function tmpname()
- local fname = os.tmpname()
- if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then
- -- In Windows tmpname() returns a filename starting with
- -- special sequence \s, prepend $TEMP path
- local tmpdir = os.getenv('TEMP')
- return tmpdir..fname
- elseif fname:match('^/tmp') and uname() == 'Darwin' then
- -- In OS X /tmp links to /private/tmp
- return '/private'..fname
- else
- return fname
- end
-end
+local tmpname = (function()
+ local seq = 0
+ local tmpdir = os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP')
+ -- Is $TMPDIR defined local to the project workspace?
+ local in_workspace = not not (tmpdir and string.find(tmpdir, 'Xtest'))
+ return (function()
+ if in_workspace then
+ -- Cannot control os.tmpname() dir, so hack our own tmpname() impl.
+ seq = seq + 1
+ local fname = tmpdir..'/nvim-test-lua-'..seq
+ io.open(fname, 'w'):close()
+ return fname
+ else
+ local fname = os.tmpname()
+ if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then
+ -- In Windows tmpname() returns a filename starting with
+ -- special sequence \s, prepend $TEMP path
+ return tmpdir..fname
+ elseif fname:match('^/tmp') and uname() == 'Darwin' then
+ -- In OS X /tmp links to /private/tmp
+ return '/private'..fname
+ else
+ return fname
+ end
+ end
+ end)
+end)()
local function map(func, tab)
local rettab = {}