diff options
Diffstat (limited to 'test/functional/options')
-rw-r--r-- | test/functional/options/autochdir_spec.lua | 35 | ||||
-rw-r--r-- | test/functional/options/chars_spec.lua | 144 | ||||
-rw-r--r-- | test/functional/options/cursorbind_spec.lua | 33 | ||||
-rw-r--r-- | test/functional/options/defaults_spec.lua | 1218 | ||||
-rw-r--r-- | test/functional/options/keymap_spec.lua | 35 | ||||
-rw-r--r-- | test/functional/options/mousescroll_spec.lua | 10 | ||||
-rw-r--r-- | test/functional/options/num_options_spec.lua | 52 | ||||
-rw-r--r-- | test/functional/options/shortmess_spec.lua | 28 | ||||
-rw-r--r-- | test/functional/options/tabstop_spec.lua | 2 |
9 files changed, 953 insertions, 604 deletions
diff --git a/test/functional/options/autochdir_spec.lua b/test/functional/options/autochdir_spec.lua index c75a98f35b..11f71912a9 100644 --- a/test/functional/options/autochdir_spec.lua +++ b/test/functional/options/autochdir_spec.lua @@ -1,8 +1,7 @@ -local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command local mkdir = helpers.mkdir @@ -11,34 +10,34 @@ describe("'autochdir'", function() local targetdir = 'test/functional/fixtures' -- By default 'autochdir' is off, thus getcwd() returns the repo root. - clear(targetdir..'/tty-test.c') - local rootdir = funcs.getcwd() + clear(targetdir .. '/tty-test.c') + local rootdir = fn.getcwd() local expected = rootdir .. '/' .. targetdir -- With 'autochdir' on, we should get the directory of tty-test.c. - clear('--cmd', 'set autochdir', targetdir..'/tty-test.c') - eq(helpers.is_os('win') and expected:gsub('/', '\\') or expected, funcs.getcwd()) + clear('--cmd', 'set autochdir', targetdir .. '/tty-test.c') + eq(helpers.is_os('win') and expected:gsub('/', '\\') or expected, fn.getcwd()) end) - it('is not overwritten by getwinvar() call #17609',function() - local curdir = string.gsub(luv.cwd(), '\\', '/') - local dir_a = curdir..'/Xtest-functional-options-autochdir.dir_a' - local dir_b = curdir..'/Xtest-functional-options-autochdir.dir_b' + it('is not overwritten by getwinvar() call #17609', function() + local curdir = vim.uv.cwd():gsub('\\', '/') + local dir_a = curdir .. '/Xtest-functional-options-autochdir.dir_a' + local dir_b = curdir .. '/Xtest-functional-options-autochdir.dir_b' mkdir(dir_a) mkdir(dir_b) clear() command('set shellslash') command('set autochdir') - command('edit '..dir_a..'/file1') - eq(dir_a, funcs.getcwd()) - command('lcd '..dir_b) - eq(dir_b, funcs.getcwd()) + command('edit ' .. dir_a .. '/file1') + eq(dir_a, fn.getcwd()) + command('lcd ' .. dir_b) + eq(dir_b, fn.getcwd()) command('botright vnew ../file2') - eq(curdir, funcs.getcwd()) + eq(curdir, fn.getcwd()) command('wincmd w') - eq(dir_a, funcs.getcwd()) - funcs.getwinvar(2, 'foo') - eq(dir_a, funcs.getcwd()) + eq(dir_a, fn.getcwd()) + fn.getwinvar(2, 'foo') + eq(dir_a, fn.getcwd()) helpers.rmdir(dir_a) helpers.rmdir(dir_b) end) diff --git a/test/functional/options/chars_spec.lua b/test/functional/options/chars_spec.lua index a082204980..e9c20b5da9 100644 --- a/test/functional/options/chars_spec.lua +++ b/test/functional/options/chars_spec.lua @@ -1,11 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, command = helpers.clear, helpers.command +local pcall_err = helpers.pcall_err local eval = helpers.eval local eq = helpers.eq -local exc_exec = helpers.exc_exec local insert = helpers.insert local feed = helpers.feed +local api = helpers.api describe("'fillchars'", function() local screen @@ -16,91 +17,124 @@ describe("'fillchars'", function() screen:attach() end) - local function shouldfail(val,errval) - errval = errval or val - eq('Vim(set):E474: Invalid argument: fillchars='..errval, - exc_exec('set fillchars='..val)) - end - describe('"eob" flag', function() it("uses '~' by default", function() eq('', eval('&fillchars')) screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 | ]]) end) + it('supports whitespace', function() screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 | ]]) command('set fillchars=eob:\\ ') screen:expect([[ ^ | - | - | - | - | + |*4 ]]) end) + it('supports multibyte char', function() command('set fillchars=eob:ñ') screen:expect([[ ^ | - ñ | - ñ | - ñ | + ñ |*3 | ]]) end) + + it('supports composing multibyte char', function() + command('set fillchars=eob:å̲') + screen:expect([[ + ^ | + å̲ |*3 + | + ]]) + end) + it('handles invalid values', function() - shouldfail('eob:') -- empty string - shouldfail('eob:馬') -- doublewidth char - shouldfail('eob:å̲') -- composing chars - shouldfail('eob:xy') -- two ascii chars - shouldfail('eob:\255', 'eob:<ff>') -- invalid UTF-8 + eq( + 'Vim(set):E1511: Wrong number of characters for field "eob": fillchars=eob:', + pcall_err(command, 'set fillchars=eob:') -- empty string + ) + eq( + 'Vim(set):E1512: Wrong character width for field "eob": fillchars=eob:馬', + pcall_err(command, 'set fillchars=eob:馬') -- doublewidth char + ) + eq( + 'Vim(set):E1511: Wrong number of characters for field "eob": fillchars=eob:xy', + pcall_err(command, 'set fillchars=eob:xy') -- two ascii chars + ) + eq( + 'Vim(set):E1512: Wrong character width for field "eob": fillchars=eob:<ff>', + pcall_err(command, 'set fillchars=eob:\255') -- invalid UTF-8 + ) end) end) + + it('"diff" flag', function() + screen:try_resize(45, 8) + screen:set_default_attr_ids({ + [1] = { background = Screen.colors.Grey, foreground = Screen.colors.DarkBlue }, + [2] = { background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1 }, + [3] = { background = Screen.colors.LightBlue }, + [4] = { reverse = true }, + [5] = { reverse = true, bold = true }, + }) + command('set fillchars=diff:…') + insert('a\nb\nc\nd\ne') + command('vnew') + insert('a\nd\ne\nf') + command('windo diffthis') + screen:expect([[ + {1: }a │{1: }a | + {1: }{2:……………………………………………………}│{1: }{3:b }| + {1: }{2:……………………………………………………}│{1: }{3:c }| + {1: }d │{1: }d | + {1: }e │{1: }^e | + {1: }{3:f }│{1: }{2:……………………………………………………}| + {4:[No Name] [+] }{5:[No Name] [+] }| + | + ]]) + end) + it('has global value', function() screen:try_resize(50, 5) - insert("foo\nbar") + insert('foo\nbar') command('set laststatus=0') command('1,2fold') command('vsplit') command('set fillchars=fold:x') screen:expect([[ ^+-- 2 lines: fooxxxxxxxx│+-- 2 lines: fooxxxxxxx| - ~ │~ | - ~ │~ | - ~ │~ | + ~ │~ |*3 | ]]) end) + it('has window-local value', function() screen:try_resize(50, 5) - insert("foo\nbar") + insert('foo\nbar') command('set laststatus=0') command('1,2fold') command('vsplit') command('setl fillchars=fold:x') screen:expect([[ ^+-- 2 lines: fooxxxxxxxx│+-- 2 lines: foo·······| - ~ │~ | - ~ │~ | - ~ │~ | + ~ │~ |*3 | ]]) end) + it('using :set clears window-local value', function() screen:try_resize(50, 5) - insert("foo\nbar") + insert('foo\nbar') command('set laststatus=0') command('setl fillchars=fold:x') command('1,2fold') @@ -108,9 +142,7 @@ describe("'fillchars'", function() command('set fillchars&') screen:expect([[ ^+-- 2 lines: foo········│+-- 2 lines: fooxxxxxxx| - ~ │~ | - ~ │~ | - ~ │~ | + ~ │~ |*3 | ]]) end) @@ -132,12 +164,11 @@ describe("'listchars'", function() command('set listchars=tab:<->') screen:expect([[ <------><------>^<------> │<------><------><------>| - ~ │~ | - ~ │~ | - ~ │~ | + ~ │~ |*3 | ]]) end) + it('has window-local value', function() feed('i<tab><tab><tab><esc>') command('set list laststatus=0') @@ -146,12 +177,11 @@ describe("'listchars'", function() command('setl listchars<') screen:expect([[ > > ^> │<------><------><------>| - ~ │~ | - ~ │~ | - ~ │~ | + ~ │~ |*3 | ]]) end) + it('using :set clears window-local value', function() feed('i<tab><tab><tab><esc>') command('set list laststatus=0') @@ -160,9 +190,31 @@ describe("'listchars'", function() command('set listchars=tab:>-,eol:$') screen:expect([[ >------->-------^>-------$│<------><------><------>| - ~ │~ | - ~ │~ | - ~ │~ | + ~ │~ |*3 + | + ]]) + end) + + it('supports composing chars', function() + screen:set_default_attr_ids { + [1] = { foreground = Screen.colors.Blue1, bold = true }, + } + feed('i<tab><tab><tab>x<esc>') + command('set list laststatus=0') + -- tricky: the tab value forms three separate one-cell chars, + -- thus it should be accepted despite being a mess. + command('set listchars=tab:d̞̄̃̒̉̎ò́̌̌̂̐l̞̀̄̆̌̚,eol:å̲') + screen:expect([[ + {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} | + {1:~ }|*3 + | + ]]) + + api.nvim__invalidate_glyph_cache() + screen:_reset() + screen:expect([[ + {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} | + {1:~ }|*3 | ]]) end) diff --git a/test/functional/options/cursorbind_spec.lua b/test/functional/options/cursorbind_spec.lua index 498206936a..cafdc83de2 100644 --- a/test/functional/options/cursorbind_spec.lua +++ b/test/functional/options/cursorbind_spec.lua @@ -12,10 +12,10 @@ describe("'cursorbind'", function() it("behaves consistently whether 'cursorline' is set or not vim-patch:8.2.4795", function() local screen = Screen.new(60, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [2] = {bold = true, reverse = true}, -- StatusLine - [3] = {reverse = true}, -- StatusLineNC - [4] = {background = Screen.colors.Grey90}, -- CursorLine, CursorColumn + [1] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [2] = { bold = true, reverse = true }, -- StatusLine + [3] = { reverse = true }, -- StatusLineNC + [4] = { background = Screen.colors.Grey90 }, -- CursorLine, CursorColumn }) screen:attach() exec([[ @@ -32,10 +32,7 @@ describe("'cursorbind'", function() feed('20l') screen:expect([[ a bb cc dd ee ff gg │aa bb cc dd ee ff gg^ hh ii jj kk ll mm | - {4: }│ {4: } | - {4: }│ {4: } | - {4: }│ {4: } | - {4: }│ {4: } | + {4: }│ {4: } |*4 {1:~ }│{1:~ }| {3:[No Name] [+] }{2:[No Name] [+] }| | @@ -43,10 +40,7 @@ describe("'cursorbind'", function() feed('10l') screen:expect([[ hh ii jj kk ll mm n│aa bb cc dd ee ff gg hh ii jj ^kk ll mm | - {4: } │ {4: } | - {4: } │ {4: } | - {4: } │ {4: } | - {4: } │ {4: } | + {4: } │ {4: } |*4 {1:~ }│{1:~ }| {3:[No Name] [+] }{2:[No Name] [+] }| | @@ -56,10 +50,7 @@ describe("'cursorbind'", function() feed('20l') screen:expect([[ {4:a bb cc dd ee ff gg }│{4:aa bb cc dd ee ff gg^ hh ii jj kk ll mm }| - {4: }│ {4: } | - {4: }│ {4: } | - {4: }│ {4: } | - {4: }│ {4: } | + {4: }│ {4: } |*4 {1:~ }│{1:~ }| {3:[No Name] [+] }{2:[No Name] [+] }| | @@ -67,10 +58,7 @@ describe("'cursorbind'", function() feed('10l') screen:expect([[ {4: hh ii jj kk ll mm n}│{4:aa bb cc dd ee ff gg hh ii jj ^kk ll mm }| - {4: } │ {4: } | - {4: } │ {4: } | - {4: } │ {4: } | - {4: } │ {4: } | + {4: } │ {4: } |*4 {1:~ }│{1:~ }| {3:[No Name] [+] }{2:[No Name] [+] }| | @@ -80,10 +68,7 @@ describe("'cursorbind'", function() feed('40l') screen:expect([[ kk ll mm nn oo pp qq│ bb cc dd ee ff gg hh ii jj kk ll mm n^n| - │ | - │ | - │ | - │ | + │ |*4 {1:~ }│{1:~ }| {3:[No Name] [+] }{2:[No Name] [+] }| | diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 7858b626de..d27fa375ee 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -4,7 +4,7 @@ local Screen = require('test.functional.ui.screen') local assert_alive = helpers.assert_alive local assert_log = helpers.assert_log -local meths = helpers.meths +local api = helpers.api local command = helpers.command local clear = helpers.clear local exc_exec = helpers.exc_exec @@ -12,13 +12,13 @@ local exec_lua = helpers.exec_lua local eval = helpers.eval local eq = helpers.eq local ok = helpers.ok -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert local neq = helpers.neq local mkdir = helpers.mkdir local rmdir = helpers.rmdir local alter_slashes = helpers.alter_slashes -local tbl_contains = helpers.tbl_contains +local tbl_contains = vim.tbl_contains local expect_exit = helpers.expect_exit local is_os = helpers.is_os @@ -32,51 +32,39 @@ describe('startup defaults', function() command('filetype') screen:expect([[ ^ | - ~ | - ~ | - ]]..expected - ) + ~ |*2 + ]] .. expected) end it('all ON after `-u NORC`', function() clear('-u', 'NORC') - expect_filetype( - 'filetype detection:ON plugin:ON indent:ON |') + expect_filetype('filetype detection:ON plugin:ON indent:ON |') end) it('all ON after `:syntax …` #7765', function() clear('-u', 'NORC', '--cmd', 'syntax on') - expect_filetype( - 'filetype detection:ON plugin:ON indent:ON |') + expect_filetype('filetype detection:ON plugin:ON indent:ON |') clear('-u', 'NORC', '--cmd', 'syntax off') - expect_filetype( - 'filetype detection:ON plugin:ON indent:ON |') + expect_filetype('filetype detection:ON plugin:ON indent:ON |') end) it('all OFF after `-u NONE`', function() clear('-u', 'NONE') - expect_filetype( - 'filetype detection:OFF plugin:OFF indent:OFF |') + expect_filetype('filetype detection:OFF plugin:OFF indent:OFF |') end) it('explicit OFF stays OFF', function() - clear('-u', 'NORC', '--cmd', - 'syntax off | filetype off | filetype plugin indent off') - expect_filetype( - 'filetype detection:OFF plugin:OFF indent:OFF |') + clear('-u', 'NORC', '--cmd', 'syntax off | filetype off | filetype plugin indent off') + expect_filetype('filetype detection:OFF plugin:OFF indent:OFF |') clear('-u', 'NORC', '--cmd', 'syntax off | filetype plugin indent off') - expect_filetype( - 'filetype detection:ON plugin:OFF indent:OFF |') + expect_filetype('filetype detection:ON plugin:OFF indent:OFF |') clear('-u', 'NORC', '--cmd', 'filetype indent off') - expect_filetype( - 'filetype detection:ON plugin:ON indent:OFF |') + expect_filetype('filetype detection:ON plugin:ON indent:OFF |') clear('-u', 'NORC', '--cmd', 'syntax off | filetype off') - expect_filetype( - 'filetype detection:OFF plugin:(on) indent:(on) |') + expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |') -- Swap the order. clear('-u', 'NORC', '--cmd', 'filetype off | syntax off') - expect_filetype( - 'filetype detection:OFF plugin:(on) indent:(on) |') + expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |') end) it('all ON after early `:filetype … on`', function() @@ -84,26 +72,20 @@ describe('startup defaults', function() -- Only an explicit `:filetype … off` sets OFF. clear('-u', 'NORC', '--cmd', 'filetype on') - expect_filetype( - 'filetype detection:ON plugin:ON indent:ON |') + expect_filetype('filetype detection:ON plugin:ON indent:ON |') clear('-u', 'NORC', '--cmd', 'filetype plugin on') - expect_filetype( - 'filetype detection:ON plugin:ON indent:ON |') + expect_filetype('filetype detection:ON plugin:ON indent:ON |') clear('-u', 'NORC', '--cmd', 'filetype indent on') - expect_filetype( - 'filetype detection:ON plugin:ON indent:ON |') + expect_filetype('filetype detection:ON plugin:ON indent:ON |') end) it('late `:filetype … off` stays OFF', function() clear('-u', 'NORC', '-c', 'filetype off') - expect_filetype( - 'filetype detection:OFF plugin:(on) indent:(on) |') + expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |') clear('-u', 'NORC', '-c', 'filetype plugin off') - expect_filetype( - 'filetype detection:ON plugin:OFF indent:ON |') + expect_filetype('filetype detection:ON plugin:OFF indent:ON |') clear('-u', 'NORC', '-c', 'filetype indent off') - expect_filetype( - 'filetype detection:ON plugin:ON indent:OFF |') + expect_filetype('filetype detection:ON plugin:ON indent:OFF |') end) end) @@ -167,7 +149,7 @@ describe('startup defaults', function() ]]) -- change "vert" character to single-cell - funcs.setcellwidths({{0x2502, 0x2502, 1}}) + fn.setcellwidths({ { 0x2502, 0x2502, 1 } }) screen:expect([[ 1 │1 | ^+-- 2 lines: 2----------│+-- 2 lines: 2---------| @@ -177,7 +159,7 @@ describe('startup defaults', function() ]]) -- change "vert" character to double-cell - funcs.setcellwidths({{0x2502, 0x2502, 2}}) + fn.setcellwidths({ { 0x2502, 0x2502, 2 } }) screen:expect([[ 1 |1 | ^+-- 2 lines: 2----------|+-- 2 lines: 2---------| @@ -199,18 +181,22 @@ describe('startup defaults', function() end) it("'shadafile' ('viminfofile')", function() - local env = {XDG_DATA_HOME='Xtest-userdata', XDG_STATE_HOME='Xtest-userstate', XDG_CONFIG_HOME='Xtest-userconfig'} + local env = { + XDG_DATA_HOME = 'Xtest-userdata', + XDG_STATE_HOME = 'Xtest-userstate', + XDG_CONFIG_HOME = 'Xtest-userconfig', + } finally(function() - command('set shadafile=NONE') -- Avoid writing shada file on exit + command('set shadafile=NONE') -- Avoid writing shada file on exit rmdir('Xtest-userstate') os.remove('Xtest-foo') end) - clear{args={}, args_rm={'-i'}, env=env} + clear { args = {}, args_rm = { '-i' }, env = env } -- Default 'shadafile' is empty. -- This means use the default location. :help shada-file-name - eq('', meths.get_option_value('shadafile', {})) - eq('', meths.get_option_value('viminfofile', {})) + eq('', api.nvim_get_option_value('shadafile', {})) + eq('', api.nvim_get_option_value('viminfofile', {})) -- Handles viminfo/viminfofile as alias for shada/shadafile. eq('\n shadafile=', eval('execute("set shadafile?")')) eq('\n shadafile=', eval('execute("set viminfofile?")')) @@ -223,22 +209,22 @@ describe('startup defaults', function() local f = eval('fnamemodify(@%,":p")') assert(string.len(f) > 3) expect_exit(command, 'qall') - clear{args={}, args_rm={'-i'}, env=env} + clear { args = {}, args_rm = { '-i' }, env = env } eq({ f }, eval('v:oldfiles')) end) it("'packpath'", function() - clear{ - args_rm={'runtimepath'}, + clear { + args_rm = { 'runtimepath' }, } -- Defaults to &runtimepath. - eq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {})) + eq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {})) -- Does not follow modifications to runtimepath. - meths.command('set runtimepath+=foo') - neq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {})) - meths.command('set packpath+=foo') - eq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {})) + command('set runtimepath+=foo') + neq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {})) + command('set packpath+=foo') + eq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {})) end) it('v:progpath is set to the absolute path', function() @@ -248,33 +234,37 @@ describe('startup defaults', function() describe('$NVIM_LOG_FILE', function() local xdgdir = 'Xtest-startup-xdg-logpath' - local xdgstatedir = is_os('win') and xdgdir..'/nvim-data' or xdgdir..'/nvim' + local xdgstatedir = is_os('win') and xdgdir .. '/nvim-data' or xdgdir .. '/nvim' after_each(function() os.remove('Xtest-logpath') rmdir(xdgdir) end) it('is used if expansion succeeds', function() - clear({env={ - NVIM_LOG_FILE='Xtest-logpath', - }}) + clear({ env = { + NVIM_LOG_FILE = 'Xtest-logpath', + } }) eq('Xtest-logpath', eval('$NVIM_LOG_FILE')) end) it('defaults to stdpath("log")/log if empty', function() eq(true, mkdir(xdgdir) and mkdir(xdgstatedir)) - clear({env={ - XDG_STATE_HOME=xdgdir, - NVIM_LOG_FILE='', -- Empty is invalid. - }}) - eq(xdgstatedir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/')) + clear({ + env = { + XDG_STATE_HOME = xdgdir, + NVIM_LOG_FILE = '', -- Empty is invalid. + }, + }) + eq(xdgstatedir .. '/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/')) end) it('defaults to stdpath("log")/log if invalid', function() eq(true, mkdir(xdgdir) and mkdir(xdgstatedir)) - clear({env={ - XDG_STATE_HOME=xdgdir, - NVIM_LOG_FILE='.', -- Any directory is invalid. - }}) - eq(xdgstatedir..'/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/')) + clear({ + env = { + XDG_STATE_HOME = xdgdir, + NVIM_LOG_FILE = '.', -- Any directory is invalid. + }, + }) + eq(xdgstatedir .. '/log', string.gsub(eval('$NVIM_LOG_FILE'), '\\', '/')) end) end) end) @@ -291,11 +281,12 @@ describe('XDG defaults', function() clear() local rtp = eval('split(&runtimepath, ",")') local rv = {} - local expected = (is_os('win') - and { [[\nvim-data\site]], [[\nvim-data\site\after]], } - or { '/nvim/site', '/nvim/site/after', }) + local expected = ( + is_os('win') and { [[\nvim-data\site]], [[\nvim-data\site\after]] } + or { '/nvim/site', '/nvim/site/after' } + ) - for _,v in ipairs(rtp) do + for _, v in ipairs(rtp) do local m = string.match(v, [=[[/\]nvim[^/\]*[/\]site.*$]=]) if m and not tbl_contains(rv, m) then table.insert(rv, m) @@ -306,28 +297,30 @@ describe('XDG defaults', function() 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_STATE_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_value('backupdir', {})) - eq('.', meths.get_option_value('viewdir', {})) - eq('.', meths.get_option_value('directory', {})) - eq('.', meths.get_option_value('undodir', {})) - ok((funcs.tempname()):len() > 4) + clear({ + env = { + XDG_CONFIG_HOME = nil, + XDG_DATA_HOME = nil, + XDG_CACHE_HOME = nil, + XDG_STATE_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('.', api.nvim_get_option_value('backupdir', {})) + eq('.', api.nvim_get_option_value('viewdir', {})) + eq('.', api.nvim_get_option_value('directory', {})) + eq('.', api.nvim_get_option_value('undodir', {})) + ok((fn.tempname()):len() > 4) end) end) @@ -335,7 +328,7 @@ describe('XDG defaults', function() local vimruntime = eval('$VIMRUNTIME') -- libdir is hard to calculate reliably across various ci platforms -- local libdir = string.gsub(vimruntime, "share/nvim/runtime$", "lib/nvim") - local libdir = meths._get_lib_dir() + local libdir = api.nvim__get_lib_dir() return vimruntime, libdir end @@ -347,20 +340,21 @@ describe('XDG defaults', function() describe('with too long XDG variables', function() before_each(function() clear({ - args_rm={'runtimepath'}, - env={ - NVIM_LOG_FILE=testlog, - XDG_CONFIG_HOME=(root_path .. ('/x'):rep(4096)), - XDG_CONFIG_DIRS=(root_path .. ('/a'):rep(2048) - .. env_sep.. root_path .. ('/b'):rep(2048) - .. (env_sep .. root_path .. '/c'):rep(512)), - XDG_DATA_HOME=(root_path .. ('/X'):rep(4096)), - XDG_RUNTIME_DIR=(root_path .. ('/X'):rep(4096)), - XDG_STATE_HOME=(root_path .. ('/X'):rep(4096)), - XDG_DATA_DIRS=(root_path .. ('/A'):rep(2048) - .. env_sep .. root_path .. ('/B'):rep(2048) - .. (env_sep .. root_path .. '/C'):rep(512)), - }}) + args_rm = { 'runtimepath' }, + env = { + NVIM_LOG_FILE = testlog, + XDG_CONFIG_HOME = (root_path .. ('/x'):rep(4096)), + XDG_CONFIG_DIRS = (root_path .. ('/a'):rep(2048) .. env_sep .. root_path .. ('/b'):rep( + 2048 + ) .. (env_sep .. root_path .. '/c'):rep(512)), + XDG_DATA_HOME = (root_path .. ('/X'):rep(4096)), + XDG_RUNTIME_DIR = (root_path .. ('/X'):rep(4096)), + XDG_STATE_HOME = (root_path .. ('/X'):rep(4096)), + XDG_DATA_DIRS = (root_path .. ('/A'):rep(2048) .. env_sep .. root_path .. ('/B'):rep( + 2048 + ) .. (env_sep .. root_path .. '/C'):rep(512)), + }, + }) end) it('are correctly set', function() @@ -370,209 +364,506 @@ describe('XDG defaults', function() local vimruntime, libdir = vimruntime_and_libdir() - eq(((root_path .. ('/x'):rep(4096) .. '/nvim' - .. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim' - .. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim' - .. (',' .. root_path .. '/c/nvim'):rep(512) - .. ',' .. root_path .. ('/X'):rep(4096) .. '/' .. data_dir .. '/site' - .. ',' .. root_path .. ('/A'):rep(2048) .. '/nvim/site' - .. ',' .. root_path .. ('/B'):rep(2048) .. '/nvim/site' - .. (',' .. root_path .. '/C/nvim/site'):rep(512) - .. ',' .. vimruntime - .. ',' .. libdir - .. (',' .. root_path .. '/C/nvim/site/after'):rep(512) - .. ',' .. root_path .. ('/B'):rep(2048) .. '/nvim/site/after' - .. ',' .. root_path .. ('/A'):rep(2048) .. '/nvim/site/after' - .. ',' .. root_path .. ('/X'):rep(4096) .. '/' .. data_dir .. '/site/after' - .. (',' .. root_path .. '/c/nvim/after'):rep(512) - .. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim/after' - .. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim/after' - .. ',' .. root_path .. ('/x'):rep(4096) .. '/nvim/after' - ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/')) - meths.command('set runtimepath&') - meths.command('set backupdir&') - meths.command('set directory&') - meths.command('set undodir&') - meths.command('set viewdir&') - eq(((root_path .. ('/x'):rep(4096) .. '/nvim' - .. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim' - .. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim' - .. (',' .. root_path .. '/c/nvim'):rep(512) - .. ',' .. root_path .. ('/X'):rep(4096) .. '/' .. data_dir .. '/site' - .. ',' .. root_path .. ('/A'):rep(2048) .. '/nvim/site' - .. ',' .. root_path .. ('/B'):rep(2048) .. '/nvim/site' - .. (',' .. root_path .. '/C/nvim/site'):rep(512) - .. ',' .. vimruntime - .. ',' .. libdir - .. (',' .. root_path .. '/C/nvim/site/after'):rep(512) - .. ',' .. root_path .. ('/B'):rep(2048) .. '/nvim/site/after' - .. ',' .. root_path .. ('/A'):rep(2048) .. '/nvim/site/after' - .. ',' .. root_path .. ('/X'):rep(4096) .. '/' .. data_dir .. '/site/after' - .. (',' .. root_path .. '/c/nvim/after'):rep(512) - .. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim/after' - .. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim/after' - .. ',' .. root_path .. ('/x'):rep(4096) .. '/nvim/after' - ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/')) - eq('.,' .. root_path .. ('/X'):rep(4096).. '/' .. state_dir .. '/backup//', - (meths.get_option_value('backupdir', {}):gsub('\\', '/'))) - eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/swap//', - (meths.get_option_value('directory', {})):gsub('\\', '/')) - eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/undo//', - (meths.get_option_value('undodir', {})):gsub('\\', '/')) - eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/view//', - (meths.get_option_value('viewdir', {})):gsub('\\', '/')) + eq( + ( + ( + root_path + .. ('/x'):rep(4096) + .. '/nvim' + .. ',' + .. root_path + .. ('/a'):rep(2048) + .. '/nvim' + .. ',' + .. root_path + .. ('/b'):rep(2048) + .. '/nvim' + .. (',' .. root_path .. '/c/nvim'):rep(512) + .. ',' + .. root_path + .. ('/X'):rep(4096) + .. '/' + .. data_dir + .. '/site' + .. ',' + .. root_path + .. ('/A'):rep(2048) + .. '/nvim/site' + .. ',' + .. root_path + .. ('/B'):rep(2048) + .. '/nvim/site' + .. (',' .. root_path .. '/C/nvim/site'):rep(512) + .. ',' + .. vimruntime + .. ',' + .. libdir + .. (',' .. root_path .. '/C/nvim/site/after'):rep(512) + .. ',' + .. root_path + .. ('/B'):rep(2048) + .. '/nvim/site/after' + .. ',' + .. root_path + .. ('/A'):rep(2048) + .. '/nvim/site/after' + .. ',' + .. root_path + .. ('/X'):rep(4096) + .. '/' + .. data_dir + .. '/site/after' + .. (',' .. root_path .. '/c/nvim/after'):rep(512) + .. ',' + .. root_path + .. ('/b'):rep(2048) + .. '/nvim/after' + .. ',' + .. root_path + .. ('/a'):rep(2048) + .. '/nvim/after' + .. ',' + .. root_path + .. ('/x'):rep(4096) + .. '/nvim/after' + ):gsub('\\', '/') + ), + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') + ) + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') + eq( + ( + ( + root_path + .. ('/x'):rep(4096) + .. '/nvim' + .. ',' + .. root_path + .. ('/a'):rep(2048) + .. '/nvim' + .. ',' + .. root_path + .. ('/b'):rep(2048) + .. '/nvim' + .. (',' .. root_path .. '/c/nvim'):rep(512) + .. ',' + .. root_path + .. ('/X'):rep(4096) + .. '/' + .. data_dir + .. '/site' + .. ',' + .. root_path + .. ('/A'):rep(2048) + .. '/nvim/site' + .. ',' + .. root_path + .. ('/B'):rep(2048) + .. '/nvim/site' + .. (',' .. root_path .. '/C/nvim/site'):rep(512) + .. ',' + .. vimruntime + .. ',' + .. libdir + .. (',' .. root_path .. '/C/nvim/site/after'):rep(512) + .. ',' + .. root_path + .. ('/B'):rep(2048) + .. '/nvim/site/after' + .. ',' + .. root_path + .. ('/A'):rep(2048) + .. '/nvim/site/after' + .. ',' + .. root_path + .. ('/X'):rep(4096) + .. '/' + .. data_dir + .. '/site/after' + .. (',' .. root_path .. '/c/nvim/after'):rep(512) + .. ',' + .. root_path + .. ('/b'):rep(2048) + .. '/nvim/after' + .. ',' + .. root_path + .. ('/a'):rep(2048) + .. '/nvim/after' + .. ',' + .. root_path + .. ('/x'):rep(4096) + .. '/nvim/after' + ):gsub('\\', '/') + ), + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') + ) + eq( + '.,' .. root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/backup//', + (api.nvim_get_option_value('backupdir', {}):gsub('\\', '/')) + ) + eq( + root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/swap//', + (api.nvim_get_option_value('directory', {})):gsub('\\', '/') + ) + eq( + root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/undo//', + (api.nvim_get_option_value('undodir', {})):gsub('\\', '/') + ) + eq( + root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/view//', + (api.nvim_get_option_value('viewdir', {})):gsub('\\', '/') + ) end) end) describe('with XDG variables that can be expanded', function() before_each(function() clear({ - args_rm={'runtimepath'}, - env={ - NVIM_LOG_FILE=testlog, - XDG_CONFIG_HOME='$XDG_DATA_HOME', - XDG_CONFIG_DIRS='$XDG_DATA_DIRS', - XDG_DATA_HOME='$XDG_CONFIG_HOME', - XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR', - XDG_STATE_HOME='$XDG_CONFIG_HOME', - XDG_DATA_DIRS='$XDG_CONFIG_DIRS', - } + args_rm = { 'runtimepath' }, + env = { + NVIM_LOG_FILE = testlog, + XDG_CONFIG_HOME = '$XDG_DATA_HOME', + XDG_CONFIG_DIRS = '$XDG_DATA_DIRS', + XDG_DATA_HOME = '$XDG_CONFIG_HOME', + XDG_RUNTIME_DIR = '$XDG_RUNTIME_DIR', + XDG_STATE_HOME = '$XDG_CONFIG_HOME', + XDG_DATA_DIRS = '$XDG_CONFIG_DIRS', + }, }) end) after_each(function() - command('set shadafile=NONE') -- Avoid writing shada file on exit + command('set shadafile=NONE') -- Avoid writing shada file on exit end) it('are not expanded', function() if not is_os('win') then - assert_log('Failed to start server: no such file or directory: %$XDG_RUNTIME_DIR%/', testlog, 10) + assert_log( + 'Failed to start server: no such file or directory: %$XDG_RUNTIME_DIR%/', + testlog, + 10 + ) end local vimruntime, libdir = vimruntime_and_libdir() - eq((('$XDG_DATA_HOME/nvim' - .. ',$XDG_DATA_DIRS/nvim' - .. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site' - .. ',$XDG_CONFIG_DIRS/nvim/site' - .. ',' .. vimruntime - .. ',' .. libdir - .. ',$XDG_CONFIG_DIRS/nvim/site/after' - .. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after' - .. ',$XDG_DATA_DIRS/nvim/after' - .. ',$XDG_DATA_HOME/nvim/after' - ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/')) - 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/' .. data_dir .. '/site' - .. ',$XDG_CONFIG_DIRS/nvim/site' - .. ',' .. vimruntime - .. ',' .. libdir - .. ',$XDG_CONFIG_DIRS/nvim/site/after' - .. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after' - .. ',$XDG_DATA_DIRS/nvim/after' - .. ',$XDG_DATA_HOME/nvim/after' - ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/')) - eq(('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'), - meths.get_option_value('backupdir', {}):gsub('\\', '/')) - eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'), - meths.get_option_value('directory', {}):gsub('\\', '/')) - eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'), - meths.get_option_value('undodir', {}):gsub('\\', '/')) - eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), - meths.get_option_value('viewdir', {}):gsub('\\', '/')) - meths.command('set all&') - eq(('$XDG_DATA_HOME/nvim' + eq( + ( + ( + '$XDG_DATA_HOME/nvim' + .. ',$XDG_DATA_DIRS/nvim' + .. ',$XDG_CONFIG_HOME/' + .. data_dir + .. '/site' + .. ',$XDG_CONFIG_DIRS/nvim/site' + .. ',' + .. vimruntime + .. ',' + .. libdir + .. ',$XDG_CONFIG_DIRS/nvim/site/after' + .. ',$XDG_CONFIG_HOME/' + .. data_dir + .. '/site/after' + .. ',$XDG_DATA_DIRS/nvim/after' + .. ',$XDG_DATA_HOME/nvim/after' + ):gsub('\\', '/') + ), + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') + ) + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') + eq( + ( + ( + '$XDG_DATA_HOME/nvim' + .. ',$XDG_DATA_DIRS/nvim' + .. ',$XDG_CONFIG_HOME/' + .. data_dir + .. '/site' + .. ',$XDG_CONFIG_DIRS/nvim/site' + .. ',' + .. vimruntime + .. ',' + .. libdir + .. ',$XDG_CONFIG_DIRS/nvim/site/after' + .. ',$XDG_CONFIG_HOME/' + .. data_dir + .. '/site/after' + .. ',$XDG_DATA_DIRS/nvim/after' + .. ',$XDG_DATA_HOME/nvim/after' + ):gsub('\\', '/') + ), + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') + ) + eq( + ('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'), + api.nvim_get_option_value('backupdir', {}):gsub('\\', '/') + ) + eq( + ('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'), + api.nvim_get_option_value('directory', {}):gsub('\\', '/') + ) + eq( + ('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'), + api.nvim_get_option_value('undodir', {}):gsub('\\', '/') + ) + eq( + ('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), + api.nvim_get_option_value('viewdir', {}):gsub('\\', '/') + ) + command('set all&') + eq( + ( + '$XDG_DATA_HOME/nvim' .. ',$XDG_DATA_DIRS/nvim' - .. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site' + .. ',$XDG_CONFIG_HOME/' + .. data_dir + .. '/site' .. ',$XDG_CONFIG_DIRS/nvim/site' - .. ',' .. vimruntime - .. ',' .. libdir + .. ',' + .. vimruntime + .. ',' + .. libdir .. ',$XDG_CONFIG_DIRS/nvim/site/after' - .. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after' + .. ',$XDG_CONFIG_HOME/' + .. data_dir + .. '/site/after' .. ',$XDG_DATA_DIRS/nvim/after' .. ',$XDG_DATA_HOME/nvim/after' - ):gsub('\\', '/'), (meths.get_option_value('runtimepath', {})):gsub('\\', '/')) - eq(('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'), - meths.get_option_value('backupdir', {}):gsub('\\', '/')) - eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'), - meths.get_option_value('directory', {}):gsub('\\', '/')) - eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'), - meths.get_option_value('undodir', {}):gsub('\\', '/')) - eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), - meths.get_option_value('viewdir', {}):gsub('\\', '/')) - eq(nil, (funcs.tempname()):match('XDG_RUNTIME_DIR')) + ):gsub('\\', '/'), + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') + ) + eq( + ('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'), + api.nvim_get_option_value('backupdir', {}):gsub('\\', '/') + ) + eq( + ('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'), + api.nvim_get_option_value('directory', {}):gsub('\\', '/') + ) + eq( + ('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'), + api.nvim_get_option_value('undodir', {}):gsub('\\', '/') + ) + eq( + ('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), + api.nvim_get_option_value('viewdir', {}):gsub('\\', '/') + ) + eq(nil, (fn.tempname()):match('XDG_RUNTIME_DIR')) end) end) describe('with commas', function() before_each(function() clear({ - args_rm={'runtimepath'}, - env={ - XDG_CONFIG_HOME=', , ,', - XDG_CONFIG_DIRS=',-,-,' .. env_sep .. '-,-,-', - XDG_DATA_HOME=',=,=,', - XDG_STATE_HOME=',=,=,', - XDG_DATA_DIRS=',≡,≡,' .. env_sep .. '≡,≡,≡', - }}) + args_rm = { 'runtimepath' }, + env = { + XDG_CONFIG_HOME = ', , ,', + XDG_CONFIG_DIRS = ',-,-,' .. env_sep .. '-,-,-', + XDG_DATA_HOME = ',=,=,', + XDG_STATE_HOME = ',=,=,', + XDG_DATA_DIRS = ',≡,≡,' .. env_sep .. '≡,≡,≡', + }, + }) end) it('are escaped properly', function() local vimruntime, libdir = vimruntime_and_libdir() local path_sep = is_os('win') and '\\' or '/' - eq(('\\, \\, \\,' .. path_sep .. 'nvim' - .. ',\\,-\\,-\\,' .. path_sep .. 'nvim' - .. ',-\\,-\\,-' .. path_sep .. 'nvim' - .. ',\\,=\\,=\\,' .. path_sep .. data_dir .. path_sep .. 'site' - .. ',\\,≡\\,≡\\,' .. path_sep .. 'nvim' .. path_sep .. 'site' - .. ',≡\\,≡\\,≡' .. path_sep .. 'nvim' .. path_sep .. 'site' - .. ',' .. vimruntime - .. ',' .. libdir - .. ',≡\\,≡\\,≡' .. path_sep .. 'nvim' .. path_sep .. 'site' .. path_sep .. 'after' - .. ',\\,≡\\,≡\\,' .. path_sep .. 'nvim' .. path_sep .. 'site' .. path_sep .. 'after' - .. ',\\,=\\,=\\,' .. path_sep.. data_dir .. path_sep .. 'site' .. path_sep .. 'after' - .. ',-\\,-\\,-' .. path_sep .. 'nvim' .. path_sep .. 'after' - .. ',\\,-\\,-\\,' .. path_sep .. 'nvim' .. path_sep .. 'after' - .. ',\\, \\, \\,' .. path_sep .. 'nvim' .. path_sep .. 'after' - ), meths.get_option_value('runtimepath', {})) - meths.command('set runtimepath&') - meths.command('set backupdir&') - meths.command('set directory&') - meths.command('set undodir&') - meths.command('set viewdir&') - eq(('\\, \\, \\,' .. path_sep .. 'nvim' - .. ',\\,-\\,-\\,' .. path_sep ..'nvim' - .. ',-\\,-\\,-' .. path_sep ..'nvim' - .. ',\\,=\\,=\\,' .. path_sep ..'' .. data_dir .. '' .. path_sep ..'site' - .. ',\\,≡\\,≡\\,' .. path_sep ..'nvim' .. path_sep ..'site' - .. ',≡\\,≡\\,≡' .. path_sep ..'nvim' .. path_sep ..'site' - .. ',' .. vimruntime - .. ',' .. libdir - .. ',≡\\,≡\\,≡' .. path_sep ..'nvim' .. path_sep ..'site' .. path_sep ..'after' - .. ',\\,≡\\,≡\\,' .. path_sep ..'nvim' .. path_sep ..'site' .. path_sep ..'after' - .. ',\\,=\\,=\\,' .. path_sep ..'' .. data_dir .. '' .. path_sep ..'site' .. path_sep ..'after' - .. ',-\\,-\\,-' .. path_sep ..'nvim' .. path_sep ..'after' - .. ',\\,-\\,-\\,' .. path_sep ..'nvim' .. path_sep ..'after' - .. ',\\, \\, \\,' .. path_sep ..'nvim' .. path_sep ..'after' - ), meths.get_option_value('runtimepath', {})) - eq('.,\\,=\\,=\\,' .. path_sep .. state_dir .. '' .. path_sep ..'backup' .. (path_sep):rep(2), - meths.get_option_value('backupdir', {})) - eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'swap' .. (path_sep):rep(2), - meths.get_option_value('directory', {})) - eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'undo' .. (path_sep):rep(2), - meths.get_option_value('undodir', {})) - eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'view' .. (path_sep):rep(2), - meths.get_option_value('viewdir', {})) + eq( + ( + '\\, \\, \\,' + .. path_sep + .. 'nvim' + .. ',\\,-\\,-\\,' + .. path_sep + .. 'nvim' + .. ',-\\,-\\,-' + .. path_sep + .. 'nvim' + .. ',\\,=\\,=\\,' + .. path_sep + .. data_dir + .. path_sep + .. 'site' + .. ',\\,≡\\,≡\\,' + .. path_sep + .. 'nvim' + .. path_sep + .. 'site' + .. ',≡\\,≡\\,≡' + .. path_sep + .. 'nvim' + .. path_sep + .. 'site' + .. ',' + .. vimruntime + .. ',' + .. libdir + .. ',≡\\,≡\\,≡' + .. path_sep + .. 'nvim' + .. path_sep + .. 'site' + .. path_sep + .. 'after' + .. ',\\,≡\\,≡\\,' + .. path_sep + .. 'nvim' + .. path_sep + .. 'site' + .. path_sep + .. 'after' + .. ',\\,=\\,=\\,' + .. path_sep + .. data_dir + .. path_sep + .. 'site' + .. path_sep + .. 'after' + .. ',-\\,-\\,-' + .. path_sep + .. 'nvim' + .. path_sep + .. 'after' + .. ',\\,-\\,-\\,' + .. path_sep + .. 'nvim' + .. path_sep + .. 'after' + .. ',\\, \\, \\,' + .. path_sep + .. 'nvim' + .. path_sep + .. 'after' + ), + api.nvim_get_option_value('runtimepath', {}) + ) + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') + eq( + ( + '\\, \\, \\,' + .. path_sep + .. 'nvim' + .. ',\\,-\\,-\\,' + .. path_sep + .. 'nvim' + .. ',-\\,-\\,-' + .. path_sep + .. 'nvim' + .. ',\\,=\\,=\\,' + .. path_sep + .. '' + .. data_dir + .. '' + .. path_sep + .. 'site' + .. ',\\,≡\\,≡\\,' + .. path_sep + .. 'nvim' + .. path_sep + .. 'site' + .. ',≡\\,≡\\,≡' + .. path_sep + .. 'nvim' + .. path_sep + .. 'site' + .. ',' + .. vimruntime + .. ',' + .. libdir + .. ',≡\\,≡\\,≡' + .. path_sep + .. 'nvim' + .. path_sep + .. 'site' + .. path_sep + .. 'after' + .. ',\\,≡\\,≡\\,' + .. path_sep + .. 'nvim' + .. path_sep + .. 'site' + .. path_sep + .. 'after' + .. ',\\,=\\,=\\,' + .. path_sep + .. '' + .. data_dir + .. '' + .. path_sep + .. 'site' + .. path_sep + .. 'after' + .. ',-\\,-\\,-' + .. path_sep + .. 'nvim' + .. path_sep + .. 'after' + .. ',\\,-\\,-\\,' + .. path_sep + .. 'nvim' + .. path_sep + .. 'after' + .. ',\\, \\, \\,' + .. path_sep + .. 'nvim' + .. path_sep + .. 'after' + ), + api.nvim_get_option_value('runtimepath', {}) + ) + eq( + '.,\\,=\\,=\\,' .. path_sep .. state_dir .. '' .. path_sep .. 'backup' .. (path_sep):rep(2), + api.nvim_get_option_value('backupdir', {}) + ) + eq( + '\\,=\\,=\\,' + .. path_sep + .. '' + .. state_dir + .. '' + .. path_sep + .. 'swap' + .. (path_sep):rep(2), + api.nvim_get_option_value('directory', {}) + ) + eq( + '\\,=\\,=\\,' + .. path_sep + .. '' + .. state_dir + .. '' + .. path_sep + .. 'undo' + .. (path_sep):rep(2), + api.nvim_get_option_value('undodir', {}) + ) + eq( + '\\,=\\,=\\,' + .. path_sep + .. '' + .. state_dir + .. '' + .. path_sep + .. 'view' + .. (path_sep):rep(2), + api.nvim_get_option_value('viewdir', {}) + ) end) end) end) - describe('stdpath()', function() -- Windows appends 'nvim-data' instead of just 'nvim' to prevent collisions -- due to XDG_CONFIG_HOME, XDG_DATA_HOME and XDG_STATE_HOME being the same. @@ -585,41 +876,45 @@ describe('stdpath()', function() local env_sep = is_os('win') and ';' or ':' it('acceptance', function() - clear() -- Do not explicitly set any env vars. - - eq('nvim', funcs.fnamemodify(funcs.stdpath('cache'), ':t')) - eq('nvim', funcs.fnamemodify(funcs.stdpath('config'), ':t')) - eq(datadir, funcs.fnamemodify(funcs.stdpath('data'), ':t')) - eq(statedir, funcs.fnamemodify(funcs.stdpath('state'), ':t')) - eq('table', type(funcs.stdpath('config_dirs'))) - eq('table', type(funcs.stdpath('data_dirs'))) - eq('string', type(funcs.stdpath('run'))) - assert_alive() -- Check for crash. #8393 + clear() -- Do not explicitly set any env vars. + + eq('nvim', fn.fnamemodify(fn.stdpath('cache'), ':t')) + eq('nvim', fn.fnamemodify(fn.stdpath('config'), ':t')) + eq(datadir, fn.fnamemodify(fn.stdpath('data'), ':t')) + eq(statedir, fn.fnamemodify(fn.stdpath('state'), ':t')) + eq('table', type(fn.stdpath('config_dirs'))) + eq('table', type(fn.stdpath('data_dirs'))) + eq('string', type(fn.stdpath('run'))) + assert_alive() -- Check for crash. #8393 end) it('reacts to $NVIM_APPNAME', function() local appname = 'NVIM_APPNAME_TEST' .. ('_'):rep(106) - clear({env={ NVIM_APPNAME=appname }}) - eq(appname, funcs.fnamemodify(funcs.stdpath('config'), ':t')) - eq(appname, funcs.fnamemodify(funcs.stdpath('cache'), ':t')) - eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('log'), ':t')) - eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('data'), ':t')) - eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('state'), ':t')) + clear({ env = { NVIM_APPNAME = appname } }) + eq(appname, fn.fnamemodify(fn.stdpath('config'), ':t')) + eq(appname, fn.fnamemodify(fn.stdpath('cache'), ':t')) + eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('log'), ':t')) + eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('data'), ':t')) + eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('state'), ':t')) -- config_dirs and data_dirs are empty on windows, so don't check them on -- that platform if not is_os('win') then - eq(appname, funcs.fnamemodify(funcs.stdpath('config_dirs')[1], ':t')) - eq(appname, funcs.fnamemodify(funcs.stdpath('data_dirs')[1], ':t')) + eq(appname, fn.fnamemodify(fn.stdpath('config_dirs')[1], ':t')) + eq(appname, fn.fnamemodify(fn.stdpath('data_dirs')[1], ':t')) end - assert_alive() -- Check for crash. #8393 + assert_alive() -- Check for crash. #8393 -- Check that Nvim rejects invalid APPNAMEs -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. local function test_appname(testAppname, expected_exitcode) - local lua_code = string.format([[ + local lua_code = string.format( + [[ local child = vim.fn.jobstart({ vim.v.progpath, '--clean', '--headless', '+qall!' }, { env = { NVIM_APPNAME = %q } }) return vim.fn.jobwait({ child }, %d)[1] - ]], alter_slashes(testAppname), 3000) + ]], + alter_slashes(testAppname), + 3000 + ) eq(expected_exitcode, exec_lua(lua_code)) end -- Invalid appnames: @@ -636,136 +931,149 @@ describe('stdpath()', function() end) describe('returns a String', function() - - describe('with "config"' , function () + describe('with "config"', function() it('knows XDG_CONFIG_HOME', function() - clear({env={ - XDG_CONFIG_HOME=alter_slashes('/home/docwhat/.config'), - }}) - eq(alter_slashes('/home/docwhat/.config/nvim'), funcs.stdpath('config')) + clear({ + env = { + XDG_CONFIG_HOME = alter_slashes('/home/docwhat/.config'), + }, + }) + eq(alter_slashes('/home/docwhat/.config/nvim'), fn.stdpath('config')) end) it('handles changes during runtime', function() - clear({env={ - XDG_CONFIG_HOME=alter_slashes('/home/original'), - }}) - eq(alter_slashes('/home/original/nvim'), funcs.stdpath('config')) - command("let $XDG_CONFIG_HOME='"..alter_slashes('/home/new').."'") - eq(alter_slashes('/home/new/nvim'), funcs.stdpath('config')) + clear({ env = { + XDG_CONFIG_HOME = alter_slashes('/home/original'), + } }) + eq(alter_slashes('/home/original/nvim'), fn.stdpath('config')) + command("let $XDG_CONFIG_HOME='" .. alter_slashes('/home/new') .. "'") + eq(alter_slashes('/home/new/nvim'), fn.stdpath('config')) end) it("doesn't expand $VARIABLES", function() - clear({env={ - XDG_CONFIG_HOME='$VARIABLES', - VARIABLES='this-should-not-happen', - }}) - eq(alter_slashes('$VARIABLES/nvim'), funcs.stdpath('config')) + clear({ + env = { + XDG_CONFIG_HOME = '$VARIABLES', + VARIABLES = 'this-should-not-happen', + }, + }) + eq(alter_slashes('$VARIABLES/nvim'), fn.stdpath('config')) end) it("doesn't expand ~/", function() - clear({env={ - XDG_CONFIG_HOME=alter_slashes('~/frobnitz'), - }}) - eq(alter_slashes('~/frobnitz/nvim'), funcs.stdpath('config')) + clear({ env = { + XDG_CONFIG_HOME = alter_slashes('~/frobnitz'), + } }) + eq(alter_slashes('~/frobnitz/nvim'), fn.stdpath('config')) end) end) - describe('with "data"' , function () + describe('with "data"', function() it('knows XDG_DATA_HOME', function() - clear({env={ - XDG_DATA_HOME=alter_slashes('/home/docwhat/.local'), - }}) - eq(alter_slashes('/home/docwhat/.local/'..datadir), funcs.stdpath('data')) + clear({ env = { + XDG_DATA_HOME = alter_slashes('/home/docwhat/.local'), + } }) + eq(alter_slashes('/home/docwhat/.local/' .. datadir), fn.stdpath('data')) end) it('handles changes during runtime', function() - clear({env={ - XDG_DATA_HOME=alter_slashes('/home/original'), - }}) - eq(alter_slashes('/home/original/'..datadir), funcs.stdpath('data')) - command("let $XDG_DATA_HOME='"..alter_slashes('/home/new').."'") - eq(alter_slashes('/home/new/'..datadir), funcs.stdpath('data')) + clear({ env = { + XDG_DATA_HOME = alter_slashes('/home/original'), + } }) + eq(alter_slashes('/home/original/' .. datadir), fn.stdpath('data')) + command("let $XDG_DATA_HOME='" .. alter_slashes('/home/new') .. "'") + eq(alter_slashes('/home/new/' .. datadir), fn.stdpath('data')) end) it("doesn't expand $VARIABLES", function() - clear({env={ - XDG_DATA_HOME='$VARIABLES', - VARIABLES='this-should-not-happen', - }}) - eq(alter_slashes('$VARIABLES/'..datadir), funcs.stdpath('data')) + clear({ + env = { + XDG_DATA_HOME = '$VARIABLES', + VARIABLES = 'this-should-not-happen', + }, + }) + eq(alter_slashes('$VARIABLES/' .. datadir), fn.stdpath('data')) end) it("doesn't expand ~/", function() - clear({env={ - XDG_DATA_HOME=alter_slashes('~/frobnitz'), - }}) - eq(alter_slashes('~/frobnitz/'..datadir), funcs.stdpath('data')) + clear({ env = { + XDG_DATA_HOME = alter_slashes('~/frobnitz'), + } }) + eq(alter_slashes('~/frobnitz/' .. datadir), fn.stdpath('data')) end) end) - describe('with "state"' , function () + describe('with "state"', function() it('knows XDG_STATE_HOME', function() - clear({env={ - XDG_STATE_HOME=alter_slashes('/home/docwhat/.local'), - }}) - eq(alter_slashes('/home/docwhat/.local/'..statedir), funcs.stdpath('state')) + clear({ + env = { + XDG_STATE_HOME = alter_slashes('/home/docwhat/.local'), + }, + }) + eq(alter_slashes('/home/docwhat/.local/' .. statedir), fn.stdpath('state')) end) it('handles changes during runtime', function() - clear({env={ - XDG_STATE_HOME=alter_slashes('/home/original'), - }}) - eq(alter_slashes('/home/original/'..statedir), funcs.stdpath('state')) - command("let $XDG_STATE_HOME='"..alter_slashes('/home/new').."'") - eq(alter_slashes('/home/new/'..statedir), funcs.stdpath('state')) + clear({ env = { + XDG_STATE_HOME = alter_slashes('/home/original'), + } }) + eq(alter_slashes('/home/original/' .. statedir), fn.stdpath('state')) + command("let $XDG_STATE_HOME='" .. alter_slashes('/home/new') .. "'") + eq(alter_slashes('/home/new/' .. statedir), fn.stdpath('state')) end) it("doesn't expand $VARIABLES", function() - clear({env={ - XDG_STATE_HOME='$VARIABLES', - VARIABLES='this-should-not-happen', - }}) - eq(alter_slashes('$VARIABLES/'..statedir), funcs.stdpath('state')) + clear({ + env = { + XDG_STATE_HOME = '$VARIABLES', + VARIABLES = 'this-should-not-happen', + }, + }) + eq(alter_slashes('$VARIABLES/' .. statedir), fn.stdpath('state')) end) it("doesn't expand ~/", function() - clear({env={ - XDG_STATE_HOME=alter_slashes('~/frobnitz'), - }}) - eq(alter_slashes('~/frobnitz/'..statedir), funcs.stdpath('state')) + clear({ env = { + XDG_STATE_HOME = alter_slashes('~/frobnitz'), + } }) + eq(alter_slashes('~/frobnitz/' .. statedir), fn.stdpath('state')) end) end) - describe('with "cache"' , function () + describe('with "cache"', function() it('knows XDG_CACHE_HOME', function() - clear({env={ - XDG_CACHE_HOME=alter_slashes('/home/docwhat/.cache'), - }}) - eq(alter_slashes('/home/docwhat/.cache/nvim'), funcs.stdpath('cache')) + clear({ + env = { + XDG_CACHE_HOME = alter_slashes('/home/docwhat/.cache'), + }, + }) + eq(alter_slashes('/home/docwhat/.cache/nvim'), fn.stdpath('cache')) end) it('handles changes during runtime', function() - clear({env={ - XDG_CACHE_HOME=alter_slashes('/home/original'), - }}) - eq(alter_slashes('/home/original/nvim'), funcs.stdpath('cache')) - command("let $XDG_CACHE_HOME='"..alter_slashes('/home/new').."'") - eq(alter_slashes('/home/new/nvim'), funcs.stdpath('cache')) + clear({ env = { + XDG_CACHE_HOME = alter_slashes('/home/original'), + } }) + eq(alter_slashes('/home/original/nvim'), fn.stdpath('cache')) + command("let $XDG_CACHE_HOME='" .. alter_slashes('/home/new') .. "'") + eq(alter_slashes('/home/new/nvim'), fn.stdpath('cache')) end) it("doesn't expand $VARIABLES", function() - clear({env={ - XDG_CACHE_HOME='$VARIABLES', - VARIABLES='this-should-not-happen', - }}) - eq(alter_slashes('$VARIABLES/nvim'), funcs.stdpath('cache')) + clear({ + env = { + XDG_CACHE_HOME = '$VARIABLES', + VARIABLES = 'this-should-not-happen', + }, + }) + eq(alter_slashes('$VARIABLES/nvim'), fn.stdpath('cache')) end) it("doesn't expand ~/", function() - clear({env={ - XDG_CACHE_HOME=alter_slashes('~/frobnitz'), - }}) - eq(alter_slashes('~/frobnitz/nvim'), funcs.stdpath('cache')) + clear({ env = { + XDG_CACHE_HOME = alter_slashes('~/frobnitz'), + } }) + eq(alter_slashes('~/frobnitz/nvim'), fn.stdpath('cache')) end) end) end) @@ -775,23 +1083,23 @@ describe('stdpath()', function() local function base_env() if is_os('win') then return { - HOME='C:\\Users\\docwhat', -- technically, is not a usual PATH - HOMEDRIVE='C:', - HOMEPATH='\\Users\\docwhat', - LOCALAPPDATA='C:\\Users\\docwhat\\AppData\\Local', - TEMP='C:\\Users\\docwhat\\AppData\\Local\\Temp', - TMPDIR='C:\\Users\\docwhat\\AppData\\Local\\Temp', - TMP='C:\\Users\\docwhat\\AppData\\Local\\Temp', + HOME = 'C:\\Users\\docwhat', -- technically, is not a usual PATH + HOMEDRIVE = 'C:', + HOMEPATH = '\\Users\\docwhat', + LOCALAPPDATA = 'C:\\Users\\docwhat\\AppData\\Local', + TEMP = 'C:\\Users\\docwhat\\AppData\\Local\\Temp', + TMPDIR = 'C:\\Users\\docwhat\\AppData\\Local\\Temp', + TMP = 'C:\\Users\\docwhat\\AppData\\Local\\Temp', } else return { - HOME='/home/docwhat', - HOMEDRIVE='HOMEDRIVE-should-be-ignored', - HOMEPATH='HOMEPATH-should-be-ignored', - LOCALAPPDATA='LOCALAPPDATA-should-be-ignored', - TEMP='TEMP-should-be-ignored', - TMPDIR='TMPDIR-should-be-ignored', - TMP='TMP-should-be-ignored', + HOME = '/home/docwhat', + HOMEDRIVE = 'HOMEDRIVE-should-be-ignored', + HOMEPATH = 'HOMEPATH-should-be-ignored', + LOCALAPPDATA = 'LOCALAPPDATA-should-be-ignored', + TEMP = 'TEMP-should-be-ignored', + TMPDIR = 'TMPDIR-should-be-ignored', + TMP = 'TMP-should-be-ignored', } end end @@ -799,12 +1107,12 @@ describe('stdpath()', function() local function set_paths_via_system(var_name, paths) local env = base_env() env[var_name] = table.concat(paths, env_sep) - clear({env=env}) + clear({ env = env }) end local function set_paths_at_runtime(var_name, paths) - clear({env=base_env()}) - meths.set_var('env_val', table.concat(paths, env_sep)) + clear({ env = base_env() }) + api.nvim_set_var('env_val', table.concat(paths, env_sep)) command(('let $%s=g:env_val'):format(var_name)) end @@ -812,105 +1120,102 @@ describe('stdpath()', function() describe(msg, function() it('set via system', function() set_paths_via_system(env_var_name, paths) - eq(expected_paths, funcs.stdpath(stdpath_arg)) + eq(expected_paths, fn.stdpath(stdpath_arg)) end) it('set at runtime', function() set_paths_at_runtime(env_var_name, paths) - eq(expected_paths, funcs.stdpath(stdpath_arg)) + eq(expected_paths, fn.stdpath(stdpath_arg)) end) end) end - describe('with "config_dirs"' , function () + describe('with "config_dirs"', function() behaves_like_dir_list_env( 'handles XDG_CONFIG_DIRS with one path', - 'config_dirs', 'XDG_CONFIG_DIRS', + 'config_dirs', + 'XDG_CONFIG_DIRS', { - alter_slashes('/home/docwhat/.config') + alter_slashes('/home/docwhat/.config'), }, { - alter_slashes('/home/docwhat/.config/nvim') - }) + alter_slashes('/home/docwhat/.config/nvim'), + } + ) behaves_like_dir_list_env( 'handles XDG_CONFIG_DIRS with two paths', - 'config_dirs', 'XDG_CONFIG_DIRS', + 'config_dirs', + 'XDG_CONFIG_DIRS', { alter_slashes('/home/docwhat/.config'), - alter_slashes('/etc/config') + alter_slashes('/etc/config'), }, { alter_slashes('/home/docwhat/.config/nvim'), - alter_slashes('/etc/config/nvim') - }) + alter_slashes('/etc/config/nvim'), + } + ) behaves_like_dir_list_env( "doesn't expand $VAR and $IBLES", - 'config_dirs', 'XDG_CONFIG_DIRS', + 'config_dirs', + 'XDG_CONFIG_DIRS', { '$HOME', '$TMP' }, { alter_slashes('$HOME/nvim'), - alter_slashes('$TMP/nvim') - }) - + alter_slashes('$TMP/nvim'), + } + ) - behaves_like_dir_list_env( - "doesn't expand ~/", - 'config_dirs', 'XDG_CONFIG_DIRS', - { - alter_slashes('~/.oldconfig'), - alter_slashes('~/.olderconfig') - }, - { - alter_slashes('~/.oldconfig/nvim'), - alter_slashes('~/.olderconfig/nvim') - }) + behaves_like_dir_list_env("doesn't expand ~/", 'config_dirs', 'XDG_CONFIG_DIRS', { + alter_slashes('~/.oldconfig'), + alter_slashes('~/.olderconfig'), + }, { + alter_slashes('~/.oldconfig/nvim'), + alter_slashes('~/.olderconfig/nvim'), + }) end) - describe('with "data_dirs"' , function () - behaves_like_dir_list_env( - 'knows XDG_DATA_DIRS with one path', - 'data_dirs', 'XDG_DATA_DIRS', - { - alter_slashes('/home/docwhat/.data') - }, - { - alter_slashes('/home/docwhat/.data/nvim') - }) + describe('with "data_dirs"', function() + behaves_like_dir_list_env('knows XDG_DATA_DIRS with one path', 'data_dirs', 'XDG_DATA_DIRS', { + alter_slashes('/home/docwhat/.data'), + }, { + alter_slashes('/home/docwhat/.data/nvim'), + }) behaves_like_dir_list_env( 'knows XDG_DATA_DIRS with two paths', - 'data_dirs', 'XDG_DATA_DIRS', + 'data_dirs', + 'XDG_DATA_DIRS', { alter_slashes('/home/docwhat/.data'), - alter_slashes('/etc/local') + alter_slashes('/etc/local'), }, { alter_slashes('/home/docwhat/.data/nvim'), alter_slashes('/etc/local/nvim'), - }) + } + ) behaves_like_dir_list_env( "doesn't expand $VAR and $IBLES", - 'data_dirs', 'XDG_DATA_DIRS', + 'data_dirs', + 'XDG_DATA_DIRS', { '$HOME', '$TMP' }, { alter_slashes('$HOME/nvim'), - alter_slashes('$TMP/nvim') - }) + alter_slashes('$TMP/nvim'), + } + ) - behaves_like_dir_list_env( - "doesn't expand ~/", - 'data_dirs', 'XDG_DATA_DIRS', - { - alter_slashes('~/.oldconfig'), - alter_slashes('~/.olderconfig') - }, - { - alter_slashes('~/.oldconfig/nvim'), - alter_slashes('~/.olderconfig/nvim'), - }) + behaves_like_dir_list_env("doesn't expand ~/", 'data_dirs', 'XDG_DATA_DIRS', { + alter_slashes('~/.oldconfig'), + alter_slashes('~/.olderconfig'), + }, { + alter_slashes('~/.oldconfig/nvim'), + alter_slashes('~/.olderconfig/nvim'), + }) end) end) @@ -927,3 +1232,22 @@ describe('stdpath()', function() end) end) end) + +describe('autocommands', function() + it('closes terminal with default shell on success', function() + api.nvim_set_option_value('shell', helpers.testprg('shell-test'), {}) + command('set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=') + + -- Should not block other events + command('let g:n=0') + command('au BufEnter * let g:n = g:n + 1') + + command('terminal') + eq(eval('get(g:, "n", 0)'), 1) + + helpers.retry(nil, 1000, function() + neq(api.nvim_get_option_value('buftype', { buf = 0 }), 'terminal') + eq(eval('get(g:, "n", 0)'), 2) + end) + end) +end) diff --git a/test/functional/options/keymap_spec.lua b/test/functional/options/keymap_spec.lua index c390e3d943..7be58888bc 100644 --- a/test/functional/options/keymap_spec.lua +++ b/test/functional/options/keymap_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq -local expect, command, eval = helpers.expect, helpers.command, helpers.eval +local expect, command, eval = helpers.expect, helpers.command, helpers.eval local insert, call = helpers.insert, helpers.call local exec_capture, dedent = helpers.exec_capture, helpers.dedent @@ -10,7 +10,7 @@ describe("'keymap' / :lmap", function() clear() before_each(function() clear() - insert("lllaaa") + insert('lllaaa') command('set iminsert=1') command('set imsearch=1') command('lmap l a') @@ -31,7 +31,8 @@ describe("'keymap' / :lmap", function() command('set keymap=dvorak') command('set nomore') local bindings = exec_capture('lmap') - eq(dedent([[ + eq( + dedent([[ l " @_ l ' @- @@ -104,20 +105,22 @@ describe("'keymap' / :lmap", function() l z @; l { @? l | @| - l } @+]]), bindings) + l } @+]]), + bindings + ) end) end) describe("'iminsert' option", function() - it("Uses :lmap in insert mode when ON", function() + it('Uses :lmap in insert mode when ON', function() feed('il<esc>') expect('alllaaa') end) - it("Ignores :lmap in insert mode when OFF", function() + it('Ignores :lmap in insert mode when OFF', function() command('set iminsert=0') feed('il<esc>') expect('llllaaa') end) - it("Can be toggled with <C-^> in insert mode", function() + it('Can be toggled with <C-^> in insert mode', function() feed('i<C-^>l<C-^>l<esc>') expect('lalllaaa') eq(1, eval('&iminsert')) @@ -126,16 +129,16 @@ describe("'keymap' / :lmap", function() end) end) describe("'imsearch' option", function() - it("Uses :lmap at search prompt when ON", function() + it('Uses :lmap at search prompt when ON', function() feed('/lll<cr>3x') expect('lll') end) - it("Ignores :lmap at search prompt when OFF", function() + it('Ignores :lmap at search prompt when OFF', function() command('set imsearch=0') feed('gg/lll<cr>3x') expect('aaa') end) - it("Can be toggled with C-^", function() + it('Can be toggled with C-^', function() eq(1, eval('&imsearch')) feed('/<C-^>lll<cr>3x') expect('aaa') @@ -156,28 +159,28 @@ describe("'keymap' / :lmap", function() eq(0, eval('&iminsert')) end) end) - it(":lmap not applied to macros", function() + it(':lmap not applied to macros', function() command("call setreg('a', 'il')") feed('@a') expect('llllaaa') eq('il', call('getreg', 'a')) end) - it(":lmap applied to macro recording", function() + it(':lmap applied to macro recording', function() feed('qail<esc>q@a') expect('aalllaaa') eq('ia', call('getreg', 'a')) end) - it(":lmap not applied to mappings", function() + it(':lmap not applied to mappings', function() command('imap t l') feed('it<esc>') expect('llllaaa') end) - it("mappings applied to keys created with :lmap", function() + it('mappings applied to keys created with :lmap', function() command('imap a x') feed('il<esc>') expect('xlllaaa') end) - it("mappings not applied to keys gotten with :lnoremap", function() + it('mappings not applied to keys gotten with :lnoremap', function() command('lmapclear') command('lnoremap l a') command('imap a x') @@ -196,7 +199,7 @@ describe("'keymap' / :lmap", function() feed('@a') expect('aalllaaa') end) - it("is applied when using f/F t/T", function() + it('is applied when using f/F t/T', function() feed('flx') expect('lllaa') feed('0ia<esc>4lFlx') diff --git a/test/functional/options/mousescroll_spec.lua b/test/functional/options/mousescroll_spec.lua index 38a9692792..96af8987b8 100644 --- a/test/functional/options/mousescroll_spec.lua +++ b/test/functional/options/mousescroll_spec.lua @@ -23,11 +23,11 @@ describe("'mousescroll'", function() local digit_expected = 'Vim(set):E5080: Digit expected: mousescroll=' local function should_fail(val, errorstr) - eq(errorstr..val, exc_exec('set mousescroll='..val)) + eq(errorstr .. val, exc_exec('set mousescroll=' .. val)) end local function should_succeed(val) - eq(0, exc_exec('set mousescroll='..val)) + eq(0, exc_exec('set mousescroll=' .. val)) end before_each(function() @@ -147,15 +147,15 @@ describe("'mousescroll'", function() command('set mousescroll=hor:1') scroll('right') - eq(9, screencol()) + eq(9, screencol()) command('set mousescroll=hor:3') scroll('right') - eq(6, screencol()) + eq(6, screencol()) command('set mousescroll=hor:2') scroll('left') - eq(8, screencol()) + eq(8, screencol()) end it('controls horizontal scrolling in normal mode', function() diff --git a/test/functional/options/num_options_spec.lua b/test/functional/options/num_options_spec.lua index 16a53c75e6..0614bcf814 100644 --- a/test/functional/options/num_options_spec.lua +++ b/test/functional/options/num_options_spec.lua @@ -1,40 +1,40 @@ -- Tests for :setlocal and :setglobal local helpers = require('test.functional.helpers')(after_each) -local clear, feed_command, eval, eq, meths = - helpers.clear, helpers.feed_command, helpers.eval, helpers.eq, helpers.meths +local clear, feed_command, eval, eq, api = + helpers.clear, helpers.feed_command, helpers.eval, helpers.eq, helpers.api local function should_fail(opt, value, errmsg) feed_command('setglobal ' .. opt .. '=' .. value) - eq(errmsg, eval("v:errmsg"):match("E%d*")) + eq(errmsg, eval('v:errmsg'):match('E%d*')) feed_command('let v:errmsg = ""') feed_command('setlocal ' .. opt .. '=' .. value) - eq(errmsg, eval("v:errmsg"):match("E%d*")) + eq(errmsg, eval('v:errmsg'):match('E%d*')) feed_command('let v:errmsg = ""') - local status, err = pcall(meths.set_option_value, opt, value, {}) + local status, err = pcall(api.nvim_set_option_value, opt, value, {}) eq(status, false) - eq(errmsg, err:match("E%d*")) - eq('', eval("v:errmsg")) + eq(errmsg, err:match('E%d*')) + eq('', eval('v:errmsg')) end local function should_succeed(opt, value) feed_command('setglobal ' .. opt .. '=' .. value) feed_command('setlocal ' .. opt .. '=' .. value) - meths.set_option_value(opt, value, {}) - eq(value, meths.get_option_value(opt, {})) - eq('', eval("v:errmsg")) + api.nvim_set_option_value(opt, value, {}) + eq(value, api.nvim_get_option_value(opt, {})) + eq('', eval('v:errmsg')) end describe(':setlocal', function() before_each(clear) it('setlocal sets only local value', function() - eq(0, meths.get_option_value('iminsert', {scope='global'})) + eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' })) feed_command('setlocal iminsert=1') - eq(0, meths.get_option_value('iminsert', {scope='global'})) - eq(-1, meths.get_option_value('imsearch', {scope='global'})) + eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' })) + eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' })) feed_command('setlocal imsearch=1') - eq(-1, meths.get_option_value('imsearch', {scope='global'})) + eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' })) end) end) @@ -77,44 +77,44 @@ describe(':set validation', function() -- If smaller than 1 this one is set to 'lines'-1 feed_command('setglobal window=-10') - meths.set_option_value('window', -10, {}) - eq(23, meths.get_option_value('window', {})) - eq('', eval("v:errmsg")) + api.nvim_set_option_value('window', -10, {}) + eq(23, api.nvim_get_option_value('window', {})) + eq('', eval('v:errmsg')) -- 'scrolloff' and 'sidescrolloff' can have a -1 value when -- set for the current window, but not globally feed_command('setglobal scrolloff=-1') - eq('E487', eval("v:errmsg"):match("E%d*")) + eq('E487', eval('v:errmsg'):match('E%d*')) feed_command('setglobal sidescrolloff=-1') - eq('E487', eval("v:errmsg"):match("E%d*")) + eq('E487', eval('v:errmsg'):match('E%d*')) feed_command('let v:errmsg=""') feed_command('setlocal scrolloff=-1') - eq('', eval("v:errmsg")) + eq('', eval('v:errmsg')) feed_command('setlocal sidescrolloff=-1') - eq('', eval("v:errmsg")) + eq('', eval('v:errmsg')) end) it('set wmh/wh wmw/wiw checks', function() feed_command('set winheight=2') feed_command('set winminheight=3') - eq('E591', eval("v:errmsg"):match("E%d*")) + eq('E591', eval('v:errmsg'):match('E%d*')) feed_command('set winwidth=2') feed_command('set winminwidth=3') - eq('E592', eval("v:errmsg"):match("E%d*")) + eq('E592', eval('v:errmsg'):match('E%d*')) end) it('set maxcombine resets to 6', function() local function setto(value) feed_command('setglobal maxcombine=' .. value) feed_command('setlocal maxcombine=' .. value) - meths.set_option_value('maxcombine', value, {}) - eq(6, meths.get_option_value('maxcombine', {})) - eq('', eval("v:errmsg")) + api.nvim_set_option_value('maxcombine', value, {}) + eq(6, api.nvim_get_option_value('maxcombine', {})) + eq('', eval('v:errmsg')) end setto(0) setto(1) diff --git a/test/functional/options/shortmess_spec.lua b/test/functional/options/shortmess_spec.lua index a56e9c09b4..6bc00ca1c5 100644 --- a/test/functional/options/shortmess_spec.lua +++ b/test/functional/options/shortmess_spec.lua @@ -22,9 +22,7 @@ describe("'shortmess'", function() feed(':edit foo<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 "foo" [New] | ]]) eq(1, eval('bufnr("%")')) @@ -33,9 +31,7 @@ describe("'shortmess'", function() feed(':edit bar<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 :edit bar | ]]) eq(2, eval('bufnr("%")')) @@ -47,27 +43,21 @@ describe("'shortmess'", function() feed(':edit foo<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 "foo" [New] | ]]) eq(1, eval('bufnr("%")')) feed(':edit bar<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 "bar" [New] | ]]) eq(2, eval('bufnr("%")')) feed(':bprevious<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 "foo" [New] --No lines in buffer-- | ]]) eq(1, eval('bufnr("%")')) @@ -76,18 +66,14 @@ describe("'shortmess'", function() feed(':bnext<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 :bnext | ]]) eq(2, eval('bufnr("%")')) feed(':bprevious<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 :bprevious | ]]) eq(1, eval('bufnr("%")')) diff --git a/test/functional/options/tabstop_spec.lua b/test/functional/options/tabstop_spec.lua index e34f678650..9070db8257 100644 --- a/test/functional/options/tabstop_spec.lua +++ b/test/functional/options/tabstop_spec.lua @@ -11,7 +11,7 @@ describe("'tabstop' option", function() -- NOTE: Setting 'tabstop' to a big number reproduces crash #2838. -- Disallowing big 'tabstop' would not fix #2838, only hide it. - it("tabstop=<big-number> does not crash #2838", function() + it('tabstop=<big-number> does not crash #2838', function() -- Insert a <Tab> character for 'tabstop' to work with. feed('i<Tab><Esc>') -- Set 'tabstop' to a very high value. |