diff options
Diffstat (limited to 'test/functional/options/defaults_spec.lua')
-rw-r--r-- | test/functional/options/defaults_spec.lua | 233 |
1 files changed, 227 insertions, 6 deletions
diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index d4c3267997..caeca5e4e2 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -1,7 +1,13 @@ -local helpers = require('test.functional.helpers') +local helpers = require('test.functional.helpers')(after_each) + local Screen = require('test.functional.ui.screen') -local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq + +local meths = helpers.meths local execute = helpers.execute +local clear = helpers.clear +local eval = helpers.eval +local eq = helpers.eq +local neq = helpers.neq local function init_session(...) local args = { helpers.nvim_prog, '-i', 'NONE', '--embed', @@ -15,11 +21,9 @@ local function init_session(...) end describe('startup defaults', function() - before_each(function() - clear() - end) - describe(':filetype', function() + if helpers.pending_win32(pending) then return end + local function expect_filetype(expected) local screen = Screen.new(48, 4) screen:attach() @@ -79,6 +83,223 @@ describe('startup defaults', function() eq(0, eval('exists("g:syntax_on")')) end) end) + + describe('packpath', function() + it('defaults to &runtimepath', function() + eq(meths.get_option('runtimepath'), meths.get_option('packpath')) + end) + + it('does not follow modifications to runtimepath', function() + meths.command('set runtimepath+=foo') + neq(meths.get_option('runtimepath'), meths.get_option('packpath')) + meths.command('set packpath+=foo') + eq(meths.get_option('runtimepath'), meths.get_option('packpath')) + end) + end) end) +describe('XDG-based defaults', function() + -- Need separate describe() blocks to not run clear() twice. + -- Do not put before_each() here for the same reasons. + + describe('with empty/broken environment', function() + it('sets correct defaults', function() + clear({env={ + XDG_CONFIG_HOME=nil, + XDG_DATA_HOME=nil, + XDG_CACHE_HOME=nil, + XDG_RUNTIME_DIR=nil, + XDG_CONFIG_DIRS=nil, + XDG_DATA_DIRS=nil, + LOCALAPPDATA=nil, + HOMEPATH=nil, + HOMEDRIVE=nil, + HOME=nil, + TEMP=nil, + VIMRUNTIME=nil, + USER=nil, + }}) + + eq('.', meths.get_option('backupdir')) + eq('.', meths.get_option('viewdir')) + eq('.', meths.get_option('directory')) + eq('.', meths.get_option('undodir')) + end) + end) + + -- TODO(jkeyes): tests below fail on win32 because of path separator. + if helpers.pending_win32(pending) then return end + describe('with too long XDG variables', function() + before_each(function() + clear({env={ + XDG_CONFIG_HOME=('/x'):rep(4096), + XDG_CONFIG_DIRS=(('/a'):rep(2048) + .. ':' .. ('/b'):rep(2048) + .. (':/c'):rep(512)), + XDG_DATA_HOME=('/X'):rep(4096), + XDG_DATA_DIRS=(('/A'):rep(2048) + .. ':' .. ('/B'):rep(2048) + .. (':/C'):rep(512)), + }}) + end) + + it('are correctly set', function() + eq((('/x'):rep(4096) .. '/nvim' + .. ',' .. ('/a'):rep(2048) .. '/nvim' + .. ',' .. ('/b'):rep(2048) .. '/nvim' + .. (',' .. '/c/nvim'):rep(512) + .. ',' .. ('/X'):rep(4096) .. '/nvim/site' + .. ',' .. ('/A'):rep(2048) .. '/nvim/site' + .. ',' .. ('/B'):rep(2048) .. '/nvim/site' + .. (',' .. '/C/nvim/site'):rep(512) + .. ',' .. eval('$VIMRUNTIME') + .. (',' .. '/C/nvim/site/after'):rep(512) + .. ',' .. ('/B'):rep(2048) .. '/nvim/site/after' + .. ',' .. ('/A'):rep(2048) .. '/nvim/site/after' + .. ',' .. ('/X'):rep(4096) .. '/nvim/site/after' + .. (',' .. '/c/nvim/after'):rep(512) + .. ',' .. ('/b'):rep(2048) .. '/nvim/after' + .. ',' .. ('/a'):rep(2048) .. '/nvim/after' + .. ',' .. ('/x'):rep(4096) .. '/nvim/after' + ), meths.get_option('runtimepath')) + meths.command('set runtimepath&') + meths.command('set backupdir&') + meths.command('set directory&') + meths.command('set undodir&') + meths.command('set viewdir&') + eq((('/x'):rep(4096) .. '/nvim' + .. ',' .. ('/a'):rep(2048) .. '/nvim' + .. ',' .. ('/b'):rep(2048) .. '/nvim' + .. (',' .. '/c/nvim'):rep(512) + .. ',' .. ('/X'):rep(4096) .. '/nvim/site' + .. ',' .. ('/A'):rep(2048) .. '/nvim/site' + .. ',' .. ('/B'):rep(2048) .. '/nvim/site' + .. (',' .. '/C/nvim/site'):rep(512) + .. ',' .. eval('$VIMRUNTIME') + .. (',' .. '/C/nvim/site/after'):rep(512) + .. ',' .. ('/B'):rep(2048) .. '/nvim/site/after' + .. ',' .. ('/A'):rep(2048) .. '/nvim/site/after' + .. ',' .. ('/X'):rep(4096) .. '/nvim/site/after' + .. (',' .. '/c/nvim/after'):rep(512) + .. ',' .. ('/b'):rep(2048) .. '/nvim/after' + .. ',' .. ('/a'):rep(2048) .. '/nvim/after' + .. ',' .. ('/x'):rep(4096) .. '/nvim/after' + ), meths.get_option('runtimepath')) + eq('.,' .. ('/X'):rep(4096) .. '/nvim/backup', + meths.get_option('backupdir')) + eq(('/X'):rep(4096) .. '/nvim/swap//', meths.get_option('directory')) + eq(('/X'):rep(4096) .. '/nvim/undo', meths.get_option('undodir')) + eq(('/X'):rep(4096) .. '/nvim/view', meths.get_option('viewdir')) + end) + end) + + describe('with XDG variables that can be expanded', function() + before_each(function() + clear({env={ + XDG_CONFIG_HOME='$XDG_DATA_HOME', + XDG_CONFIG_DIRS='$XDG_DATA_DIRS', + XDG_DATA_HOME='$XDG_CONFIG_HOME', + XDG_DATA_DIRS='$XDG_CONFIG_DIRS', + }}) + end) + + it('are not expanded', function() + eq(('$XDG_DATA_HOME/nvim' + .. ',$XDG_DATA_DIRS/nvim' + .. ',$XDG_CONFIG_HOME/nvim/site' + .. ',$XDG_CONFIG_DIRS/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',$XDG_CONFIG_DIRS/nvim/site/after' + .. ',$XDG_CONFIG_HOME/nvim/site/after' + .. ',$XDG_DATA_DIRS/nvim/after' + .. ',$XDG_DATA_HOME/nvim/after' + ), meths.get_option('runtimepath')) + meths.command('set runtimepath&') + meths.command('set backupdir&') + meths.command('set directory&') + meths.command('set undodir&') + meths.command('set viewdir&') + eq(('$XDG_DATA_HOME/nvim' + .. ',$XDG_DATA_DIRS/nvim' + .. ',$XDG_CONFIG_HOME/nvim/site' + .. ',$XDG_CONFIG_DIRS/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',$XDG_CONFIG_DIRS/nvim/site/after' + .. ',$XDG_CONFIG_HOME/nvim/site/after' + .. ',$XDG_DATA_DIRS/nvim/after' + .. ',$XDG_DATA_HOME/nvim/after' + ), meths.get_option('runtimepath')) + eq('.,$XDG_CONFIG_HOME/nvim/backup', meths.get_option('backupdir')) + eq('$XDG_CONFIG_HOME/nvim/swap//', meths.get_option('directory')) + eq('$XDG_CONFIG_HOME/nvim/undo', meths.get_option('undodir')) + eq('$XDG_CONFIG_HOME/nvim/view', meths.get_option('viewdir')) + meths.command('set all&') + eq(('$XDG_DATA_HOME/nvim' + .. ',$XDG_DATA_DIRS/nvim' + .. ',$XDG_CONFIG_HOME/nvim/site' + .. ',$XDG_CONFIG_DIRS/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',$XDG_CONFIG_DIRS/nvim/site/after' + .. ',$XDG_CONFIG_HOME/nvim/site/after' + .. ',$XDG_DATA_DIRS/nvim/after' + .. ',$XDG_DATA_HOME/nvim/after' + ), meths.get_option('runtimepath')) + eq('.,$XDG_CONFIG_HOME/nvim/backup', meths.get_option('backupdir')) + eq('$XDG_CONFIG_HOME/nvim/swap//', meths.get_option('directory')) + eq('$XDG_CONFIG_HOME/nvim/undo', meths.get_option('undodir')) + eq('$XDG_CONFIG_HOME/nvim/view', meths.get_option('viewdir')) + end) + end) + + describe('with commas', function() + before_each(function() + clear({env={ + XDG_CONFIG_HOME=', , ,', + XDG_CONFIG_DIRS=',-,-,:-,-,-', + XDG_DATA_HOME=',=,=,', + XDG_DATA_DIRS=',≡,≡,:≡,≡,≡', + }}) + end) + + it('are escaped properly', function() + eq(('\\, \\, \\,/nvim' + .. ',\\,-\\,-\\,/nvim' + .. ',-\\,-\\,-/nvim' + .. ',\\,=\\,=\\,/nvim/site' + .. ',\\,≡\\,≡\\,/nvim/site' + .. ',≡\\,≡\\,≡/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',≡\\,≡\\,≡/nvim/site/after' + .. ',\\,≡\\,≡\\,/nvim/site/after' + .. ',\\,=\\,=\\,/nvim/site/after' + .. ',-\\,-\\,-/nvim/after' + .. ',\\,-\\,-\\,/nvim/after' + .. ',\\, \\, \\,/nvim/after' + ), meths.get_option('runtimepath')) + meths.command('set runtimepath&') + meths.command('set backupdir&') + meths.command('set directory&') + meths.command('set undodir&') + meths.command('set viewdir&') + eq(('\\, \\, \\,/nvim' + .. ',\\,-\\,-\\,/nvim' + .. ',-\\,-\\,-/nvim' + .. ',\\,=\\,=\\,/nvim/site' + .. ',\\,≡\\,≡\\,/nvim/site' + .. ',≡\\,≡\\,≡/nvim/site' + .. ',' .. eval('$VIMRUNTIME') + .. ',≡\\,≡\\,≡/nvim/site/after' + .. ',\\,≡\\,≡\\,/nvim/site/after' + .. ',\\,=\\,=\\,/nvim/site/after' + .. ',-\\,-\\,-/nvim/after' + .. ',\\,-\\,-\\,/nvim/after' + .. ',\\, \\, \\,/nvim/after' + ), meths.get_option('runtimepath')) + eq('.,\\,=\\,=\\,/nvim/backup', meths.get_option('backupdir')) + eq('\\,=\\,=\\,/nvim/swap//', meths.get_option('directory')) + eq('\\,=\\,=\\,/nvim/undo', meths.get_option('undodir')) + eq('\\,=\\,=\\,/nvim/view', meths.get_option('viewdir')) + end) + end) +end) |