diff --git a/test/functional/autoread/focus_spec.lua b/test/functional/autocmd/focus_spec.lua similarity index 100% rename from test/functional/autoread/focus_spec.lua rename to test/functional/autocmd/focus_spec.lua diff --git a/test/functional/cmdline/ctrl_r_spec.lua b/test/functional/cmdline/ctrl_r_spec.lua deleted file mode 100644 index a0f3955282..0000000000 --- a/test/functional/cmdline/ctrl_r_spec.lua +++ /dev/null @@ -1,34 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, insert, funcs, eq, feed = - helpers.clear, helpers.insert, helpers.funcs, helpers.eq, helpers.feed - -describe('cmdline CTRL-R', function() - before_each(clear) - - it('pasting non-special register inserts *between* lines', function() - insert([[ - line1abc - line2somemoretext - ]]) - -- Yank 2 lines linewise, then paste to cmdline. - feed([[gg0yj:0]]) - -- inserted between lines, NOT after the final line. - eq('line1abc\rline2somemoretext', funcs.getcmdline()) - - -- Yank 2 lines charwise, then paste to cmdline. - feed([[gg05lyvj:0]]) - -- inserted between lines, NOT after the final line. - eq('abc\rline2', funcs.getcmdline()) - - -- Yank 1 line linewise, then paste to cmdline. - feed([[ggyy:0]]) - -- No inserted. - eq('line1abc', funcs.getcmdline()) - end) - - it('pasting special register inserts , ', function() - feed([[:="foo\nbar\rbaz"]]) - eq('foo\nbar\rbaz', funcs.getcmdline()) - end) -end) - diff --git a/test/functional/normal/K_spec.lua b/test/functional/editor/K_spec.lua similarity index 100% rename from test/functional/normal/K_spec.lua rename to test/functional/editor/K_spec.lua diff --git a/test/functional/viml/completion_spec.lua b/test/functional/editor/completion_spec.lua similarity index 100% rename from test/functional/viml/completion_spec.lua rename to test/functional/editor/completion_spec.lua diff --git a/test/functional/normal/count_spec.lua b/test/functional/editor/count_spec.lua similarity index 100% rename from test/functional/normal/count_spec.lua rename to test/functional/editor/count_spec.lua diff --git a/test/functional/normal/fold_spec.lua b/test/functional/editor/fold_spec.lua similarity index 100% rename from test/functional/normal/fold_spec.lua rename to test/functional/editor/fold_spec.lua diff --git a/test/functional/normal/jump_spec.lua b/test/functional/editor/jump_spec.lua similarity index 100% rename from test/functional/normal/jump_spec.lua rename to test/functional/editor/jump_spec.lua diff --git a/test/functional/normal/lang_spec.lua b/test/functional/editor/lang_spec.lua similarity index 100% rename from test/functional/normal/lang_spec.lua rename to test/functional/editor/lang_spec.lua diff --git a/test/functional/normal/langmap_spec.lua b/test/functional/editor/langmap_spec.lua similarity index 100% rename from test/functional/normal/langmap_spec.lua rename to test/functional/editor/langmap_spec.lua diff --git a/test/functional/normal/macro_spec.lua b/test/functional/editor/macro_spec.lua similarity index 100% rename from test/functional/normal/macro_spec.lua rename to test/functional/editor/macro_spec.lua diff --git a/test/functional/insert/insert_spec.lua b/test/functional/editor/meta_key_spec.lua similarity index 54% rename from test/functional/insert/insert_spec.lua rename to test/functional/editor/meta_key_spec.lua index 330cfbd830..2a9541ba96 100644 --- a/test/functional/insert/insert_spec.lua +++ b/test/functional/editor/meta_key_spec.lua @@ -1,32 +1,40 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command = helpers.command -local eq = helpers.eq local expect = helpers.expect local funcs = helpers.funcs +local eq = helpers.eq -describe('insert-mode', function() +describe('meta-keys #8226 #13042', function() before_each(function() clear() end) - it('CTRL-@', function() - -- Inserts last-inserted text, leaves insert-mode. + it('ALT/META, normal-mode', function() + -- Unmapped ALT-chords behave as ESC+c insert('hello') - feed('ix') - expect('hellhello') - - -- C-Space is the same as C-@. - -- CTRL-SPC inserts last-inserted text, leaves insert-mode. - feed('ix') - expect('hellhellhello') - - -- CTRL-A inserts last inserted text - feed('ix') - expect('hellhellhellhelloxo') + feed('0') + expect('llo') + -- Mapped ALT-chord behaves as mapped. + command('nnoremap Ameta-l') + command('nnoremap Aalt-j') + feed('') + expect('lloalt-jmeta-l') end) - it('ALT/META #8213', function() + it('ALT/META, visual-mode', function() + -- Unmapped ALT-chords behave as ESC+c + insert('peaches') + feed('viwviw') + expect('peach') + -- Mapped ALT-chord behaves as mapped. + command('vnoremap Ameta-l') + command('vnoremap Aalt-j') + feed('viwviw') + expect('peachalt-jmeta-l') + end) + + it('ALT/META insert-mode', function() -- Mapped ALT-chord behaves as mapped. command('inoremap meta-l') command('inoremap alt-j') diff --git a/test/functional/cmdline/history_spec.lua b/test/functional/editor/mode_cmdline_spec.lua similarity index 51% rename from test/functional/cmdline/history_spec.lua rename to test/functional/editor/mode_cmdline_spec.lua index ee2d36f642..0f7d821bb5 100644 --- a/test/functional/cmdline/history_spec.lua +++ b/test/functional/editor/mode_cmdline_spec.lua @@ -1,8 +1,41 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, meths, funcs, eq = - helpers.clear, helpers.meths, helpers.funcs, helpers.eq +-- Cmdline-mode tests. -describe('history support code', function() +local helpers = require('test.functional.helpers')(after_each) +local clear, insert, funcs, eq, feed = + helpers.clear, helpers.insert, helpers.funcs, helpers.eq, helpers.feed +local meths = helpers.meths + +describe('cmdline CTRL-R', function() + before_each(clear) + + it('pasting non-special register inserts *between* lines', function() + insert([[ + line1abc + line2somemoretext + ]]) + -- Yank 2 lines linewise, then paste to cmdline. + feed([[gg0yj:0]]) + -- inserted between lines, NOT after the final line. + eq('line1abc\rline2somemoretext', funcs.getcmdline()) + + -- Yank 2 lines charwise, then paste to cmdline. + feed([[gg05lyvj:0]]) + -- inserted between lines, NOT after the final line. + eq('abc\rline2', funcs.getcmdline()) + + -- Yank 1 line linewise, then paste to cmdline. + feed([[ggyy:0]]) + -- No inserted. + eq('line1abc', funcs.getcmdline()) + end) + + it('pasting special register inserts , ', function() + feed([[:="foo\nbar\rbaz"]]) + eq('foo\nbar\rbaz', funcs.getcmdline()) + end) +end) + +describe('cmdline history', function() before_each(clear) it('correctly clears start of the history', function() diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua new file mode 100644 index 0000000000..46ab483036 --- /dev/null +++ b/test/functional/editor/mode_insert_spec.lua @@ -0,0 +1,89 @@ +-- Insert-mode tests. + +local helpers = require('test.functional.helpers')(after_each) +local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert +local expect = helpers.expect +local command = helpers.command +local eq = helpers.eq +local eval = helpers.eval +local meths = helpers.meths + +describe('insert-mode', function() + before_each(function() + clear() + end) + + it('CTRL-@', function() + -- Inserts last-inserted text, leaves insert-mode. + insert('hello') + feed('ix') + expect('hellhello') + + -- C-Space is the same as C-@. + -- CTRL-SPC inserts last-inserted text, leaves insert-mode. + feed('ix') + expect('hellhellhello') + + -- CTRL-A inserts last inserted text + feed('ix') + expect('hellhellhellhelloxo') + end) + + describe('Ctrl-R', function() + it('works', function() + command("let @@ = 'test'") + feed('i"') + expect('test') + end) + + it('works with multi-byte text', function() + command("let @@ = 'påskägg'") + feed('i"') + expect('påskägg') + end) + end) + + describe('Ctrl-O', function() + it('enters command mode for one command', function() + feed('ihello world') + feed(':let ctrlo = "test"') + feed('iii') + expect('hello worldiii') + eq(1, eval('ctrlo ==# "test"')) + end) + + it('re-enters insert mode at the end of the line when running startinsert', function() + -- #6962 + feed('ihello world') + feed(':startinsert') + feed('iii') + expect('hello worldiii') + end) + + it('re-enters insert mode at the beginning of the line when running startinsert', function() + insert('hello world') + feed('0') + feed(':startinsert') + feed('aaa') + expect('aaahello world') + end) + + it('re-enters insert mode in the middle of the line when running startinsert', function() + insert('hello world') + feed('bi') + feed(':startinsert') + feed('ooo') + expect('hello oooworld') + end) + + it("doesn't cancel Ctrl-O mode when processing event", function() + feed('iHello World') + eq({mode='niI', blocking=false}, meths.get_mode()) -- fast event + eq(2, eval('1+1')) -- causes K_EVENT key + eq({mode='niI', blocking=false}, meths.get_mode()) -- still in ctrl-o mode + feed('dd') + eq({mode='i', blocking=false}, meths.get_mode()) -- left ctrl-o mode + expect('') -- executed the command + end) + end) +end) diff --git a/test/functional/visual/ctrl_o_spec.lua b/test/functional/editor/mode_visual_spec.lua similarity index 82% rename from test/functional/visual/ctrl_o_spec.lua rename to test/functional/editor/mode_visual_spec.lua index 65a128053c..e9c117a1e5 100644 --- a/test/functional/visual/ctrl_o_spec.lua +++ b/test/functional/editor/mode_visual_spec.lua @@ -1,3 +1,5 @@ +-- Visual-mode tests. + local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq @@ -6,10 +8,10 @@ local expect = helpers.expect local feed = helpers.feed local meths = helpers.meths -describe('select-mode Ctrl-O', function() +describe('visual-mode', function() before_each(clear) - it("doesn't cancel Ctrl-O mode when processing event", function() + it("select-mode Ctrl-O doesn't cancel Ctrl-O mode when processing event #15688", function() feed('iHello Worldgh') eq({mode='vs', blocking=false}, meths.get_mode()) -- fast event eq(2, eval('1+1')) -- causes K_EVENT key @@ -21,3 +23,4 @@ describe('select-mode Ctrl-O', function() expect('h') -- selection is the whole line and is replaced end) end) + diff --git a/test/functional/normal/put_spec.lua b/test/functional/editor/put_spec.lua similarity index 100% rename from test/functional/normal/put_spec.lua rename to test/functional/editor/put_spec.lua diff --git a/test/functional/normal/search_spec.lua b/test/functional/editor/search_spec.lua similarity index 100% rename from test/functional/normal/search_spec.lua rename to test/functional/editor/search_spec.lua diff --git a/test/functional/normal/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua similarity index 100% rename from test/functional/normal/tabpage_spec.lua rename to test/functional/editor/tabpage_spec.lua diff --git a/test/functional/normal/undo_spec.lua b/test/functional/editor/undo_spec.lua similarity index 100% rename from test/functional/normal/undo_spec.lua rename to test/functional/editor/undo_spec.lua diff --git a/test/functional/eval/backtick_expansion_spec.lua b/test/functional/eval/backtick_expansion_spec.lua deleted file mode 100644 index b1b44cfa8b..0000000000 --- a/test/functional/eval/backtick_expansion_spec.lua +++ /dev/null @@ -1,50 +0,0 @@ -local lfs = require('lfs') -local helpers = require('test.functional.helpers')(after_each) -local clear, command, eval, eq = helpers.clear, helpers.command, helpers.eval, helpers.eq -local write_file = helpers.write_file - -describe("backtick expansion", function() - setup(function() - clear() - lfs.mkdir("test-backticks") - write_file("test-backticks/file1", "test file 1") - write_file("test-backticks/file2", "test file 2") - write_file("test-backticks/file3", "test file 3") - lfs.mkdir("test-backticks/subdir") - write_file("test-backticks/subdir/file4", "test file 4") - -- Long path might cause "Press ENTER" prompt; use :silent to avoid it. - command('silent cd test-backticks') - end) - - teardown(function() - helpers.rmdir('test-backticks') - end) - - it("with default 'shell'", function() - if helpers.iswin() then - command(":silent args `dir /b *2`") - else - command(":silent args `echo ***2`") - end - eq({ "file2", }, eval("argv()")) - if helpers.iswin() then - command(":silent args `dir /s/b *4`") - eq({ "subdir\\file4", }, eval("map(argv(), 'fnamemodify(v:val, \":.\")')")) - else - command(":silent args `echo */*4`") - eq({ "subdir/file4", }, eval("argv()")) - end - end) - - it("with shell=fish", function() - if eval("executable('fish')") == 0 then - pending('missing "fish" command') - return - end - command("set shell=fish") - command(":silent args `echo ***2`") - eq({ "file2", }, eval("argv()")) - command(":silent args `echo */*4`") - eq({ "subdir/file4", }, eval("argv()")) - end) -end) diff --git a/test/functional/eval/function_spec.lua b/test/functional/eval/function_spec.lua deleted file mode 100644 index ce8850fcc2..0000000000 --- a/test/functional/eval/function_spec.lua +++ /dev/null @@ -1,37 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local eq = helpers.eq -local matches = helpers.matches -local exc_exec = helpers.exc_exec -local iswin = helpers.iswin -local eval = helpers.eval - -describe('Up to MAX_FUNC_ARGS arguments are handled by', function() - local max_func_args = 20 -- from eval.h - local range = helpers.funcs.range - - before_each(clear) - - it('printf()', function() - local printf = helpers.funcs.printf - local rep = helpers.funcs['repeat'] - local expected = '2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,' - eq(expected, printf(rep('%d,', max_func_args-1), unpack(range(2, max_func_args)))) - local ret = exc_exec('call printf("", 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') - eq('Vim(call):E740: Too many arguments for function printf', ret) - end) - - it('rpcnotify()', function() - local rpcnotify = helpers.funcs.rpcnotify - local ret = rpcnotify(0, 'foo', unpack(range(3, max_func_args))) - eq(1, ret) - ret = exc_exec('call rpcnotify(0, "foo", 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') - eq('Vim(call):E740: Too many arguments for function rpcnotify', ret) - end) -end) - -it('windowsversion()', function() - clear() - matches(iswin() and '^%d+%.%d+$' or '^$', eval('windowsversion()')) -end) diff --git a/test/functional/eval/interrupt_spec.lua b/test/functional/eval/interrupt_spec.lua deleted file mode 100644 index 05b1f4ff57..0000000000 --- a/test/functional/eval/interrupt_spec.lua +++ /dev/null @@ -1,61 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) - -local command = helpers.command -local meths = helpers.meths -local clear = helpers.clear -local sleep = helpers.sleep -local poke_eventloop = helpers.poke_eventloop -local feed = helpers.feed -local eq = helpers.eq - -local dur -local min_dur = 8 -local len = 131072 - -describe('List support code', function() - if not pending('does not actually allows interrupting with just got_int', function() end) then return end - -- The following tests are confirmed to work with os_breakcheck() just before - -- `if (got_int) {break;}` in tv_list_copy and list_join_inner() and not to - -- work without. - setup(function() - clear() - dur = 0 - while true do - command(([[ - let rt = reltime() - let bl = range(%u) - let dur = reltimestr(reltime(rt)) - ]]):format(len)) - dur = tonumber(meths.get_var('dur')) - if dur >= min_dur then - -- print(('Using len %u, dur %g'):format(len, dur)) - break - else - len = len * 2 - end - end - end) - it('allows interrupting copy', function() - feed(':let t_rt = reltime():let t_bl = copy(bl)') - sleep(min_dur / 16 * 1000) - feed('') - poke_eventloop() - command('let t_dur = reltimestr(reltime(t_rt))') - local t_dur = tonumber(meths.get_var('t_dur')) - if t_dur >= dur / 8 then - eq(nil, ('Took too long to cancel: %g >= %g'):format(t_dur, dur / 8)) - end - end) - it('allows interrupting join', function() - feed(':let t_rt = reltime():let t_j = join(bl)') - sleep(min_dur / 16 * 1000) - feed('') - poke_eventloop() - command('let t_dur = reltimestr(reltime(t_rt))') - local t_dur = tonumber(meths.get_var('t_dur')) - print(('t_dur: %g'):format(t_dur)) - if t_dur >= dur / 8 then - eq(nil, ('Took too long to cancel: %g >= %g'):format(t_dur, dur / 8)) - end - end) -end) diff --git a/test/functional/insert/ctrl_o_spec.lua b/test/functional/insert/ctrl_o_spec.lua deleted file mode 100644 index 011954fa9d..0000000000 --- a/test/functional/insert/ctrl_o_spec.lua +++ /dev/null @@ -1,54 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local eq = helpers.eq -local eval = helpers.eval -local expect = helpers.expect -local feed = helpers.feed -local insert = helpers.insert -local meths = helpers.meths - -describe('insert-mode Ctrl-O', function() - before_each(clear) - - it('enters command mode for one command', function() - feed('ihello world') - feed(':let ctrlo = "test"') - feed('iii') - expect('hello worldiii') - eq(1, eval('ctrlo ==# "test"')) - end) - - it('re-enters insert mode at the end of the line when running startinsert', function() - -- #6962 - feed('ihello world') - feed(':startinsert') - feed('iii') - expect('hello worldiii') - end) - - it('re-enters insert mode at the beginning of the line when running startinsert', function() - insert('hello world') - feed('0') - feed(':startinsert') - feed('aaa') - expect('aaahello world') - end) - - it('re-enters insert mode in the middle of the line when running startinsert', function() - insert('hello world') - feed('bi') - feed(':startinsert') - feed('ooo') - expect('hello oooworld') - end) - - it("doesn't cancel Ctrl-O mode when processing event", function() - feed('iHello World') - eq({mode='niI', blocking=false}, meths.get_mode()) -- fast event - eq(2, eval('1+1')) -- causes K_EVENT key - eq({mode='niI', blocking=false}, meths.get_mode()) -- still in ctrl-o mode - feed('dd') - eq({mode='i', blocking=false}, meths.get_mode()) -- left ctrl-o mode - expect('') -- executed the command - end) -end) diff --git a/test/functional/insert/ctrl_r_spec.lua b/test/functional/insert/ctrl_r_spec.lua deleted file mode 100644 index adc3c4b406..0000000000 --- a/test/functional/insert/ctrl_r_spec.lua +++ /dev/null @@ -1,19 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed = helpers.clear, helpers.feed -local expect, command = helpers.expect, helpers.command - -describe('insert-mode Ctrl-R', function() - before_each(clear) - - it('works', function() - command("let @@ = 'test'") - feed('i"') - expect('test') - end) - - it('works with multi-byte text', function() - command("let @@ = 'påskägg'") - feed('i"') - expect('påskägg') - end) -end) diff --git a/test/functional/normal/meta_key_spec.lua b/test/functional/normal/meta_key_spec.lua deleted file mode 100644 index 9f9fad67d2..0000000000 --- a/test/functional/normal/meta_key_spec.lua +++ /dev/null @@ -1,22 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command = helpers.command -local expect = helpers.expect - -describe('meta-keys-in-normal-mode', function() - before_each(function() - clear() - end) - - it('ALT/META', function() - -- Unmapped ALT-chords behave as Esc+c - insert('hello') - feed('0') - expect('llo') - -- Mapped ALT-chord behaves as mapped. - command('nnoremap Ameta-l') - command('nnoremap Aalt-j') - feed('') - expect('lloalt-jmeta-l') - end) -end) diff --git a/test/functional/viml/function_spec.lua b/test/functional/viml/function_spec.lua deleted file mode 100644 index b8137038b1..0000000000 --- a/test/functional/viml/function_spec.lua +++ /dev/null @@ -1,216 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) - -local eq = helpers.eq -local clear = helpers.clear -local dedent = helpers.dedent -local redir_exec = helpers.redir_exec - -before_each(clear) - -local function check_func(fname, body, indent) - if type(body) == 'number' then - body = ('return %i'):format(body) - end - eq(dedent(([[ - - function %s()%s - endfunction]] - ), 3):format( - fname, - body and ('\n1' .. (' '):rep(2 + (indent or 8)) .. body) or ''), - redir_exec('function ' .. fname)) -end - -describe(':endfunction', function() - it('accepts bang', function() - eq('', redir_exec([[ - function F() - endfunction! - ]])) - check_func('F') - eq('', redir_exec([[ - function! F() - return 1 - endfunction! - ]])) - check_func('F', 1) - end) - it('accepts comments', function() - eq('', redir_exec([[ - function F1() - endfunction " Comment - ]])) - check_func('F1') - eq('', redir_exec([[ - function F2() - endfunction " }}} - ]])) - check_func('F2') - eq('', redir_exec([[ - function F3() - endfunction " F3 - ]])) - check_func('F3') - eq('', redir_exec([[ - function F4() - endfunction! " F4 - ]])) - check_func('F4') - eq('', redir_exec([[ - function! F4() - return 2 - endfunction! " F4 - ]])) - check_func('F4', 2) - end) - it('accepts function name', function() - eq('', redir_exec([[ - function F0() - endfunction F0 - ]])) - check_func('F0') - eq('', redir_exec([[ - function F1() - endfunction! F1 - ]])) - check_func('F1') - eq('', redir_exec([[ - function! F2() - endfunction! F2 - ]])) - check_func('F2') - eq('', redir_exec([[ - function! F2() - return 3 - endfunction! F2 - ]])) - check_func('F2', 3) - end) - it('accepts weird characters', function() - eq('', redir_exec([[ - function F1() - endfunction: }}} - ]])) - check_func('F1') - -- From accurev - eq('', redir_exec([[ - function F2() - endfunction :}}} - ]])) - check_func('F2') - -- From cream-vimabbrev - eq('', redir_exec([[ - function F3() - endfunction 1}}} - ]])) - check_func('F3') - -- From pyunit - eq('', redir_exec([[ - function F4() - endfunction # }}} - ]])) - check_func('F4') - -- From vim-lldb - eq('', redir_exec([[ - function F5() - endfunction() - ]])) - check_func('F5') - -- From vim-mail - eq('', redir_exec([[ - function F6() - endfunction; - ]])) - check_func('F6') - end) - it('accepts commented bar', function() - eq('', redir_exec([[ - function F1() - endfunction " F1 | echo 42 - ]])) - check_func('F1') - eq('', redir_exec([[ - function! F1() - return 42 - endfunction! " F1 | echo 42 - ]])) - check_func('F1', 42) - end) - it('accepts uncommented bar', function() - eq('\n42', redir_exec([[ - function F1() - endfunction | echo 42 - ]])) - check_func('F1') - end) - it('allows running multiple commands', function() - eq('\n2', redir_exec([[ - function F1() - echo 2 - endfunction - call F1() - ]])) - check_func('F1', 'echo 2') - eq('\n2\n3\n4', redir_exec([[ - function F2() - echo 2 - endfunction F2 - function F3() - echo 3 - endfunction " F3 - function! F4() - echo 4 - endfunction! - call F2() - call F3() - call F4() - ]])) - check_func('F2', 'echo 2') - check_func('F3', 'echo 3') - check_func('F4', 'echo 4') - end) - it('allows running multiple commands with only one character in between', - function() - eq('\n3', redir_exec(dedent([[ - function! F1() - echo 3 - endfunction! - call F1()]]))) - check_func('F1', 'echo 3', 2) - eq('\n4', redir_exec(dedent([[ - function F5() - echo 4 - endfunction - call F5()]]))) - check_func('F5', 'echo 4', 2) - eq('\n5', redir_exec(dedent([[ - function F6() - echo 5 - endfunction " TEST - call F6()]]))) - check_func('F6', 'echo 5', 2) - eq('\n6', redir_exec(dedent([[ - function F7() - echo 6 - endfunction F7 - call F7()]]))) - check_func('F7', 'echo 6', 2) - eq('\n2\n3\n4', redir_exec(dedent([[ - function F2() - echo 2 - endfunction F2 - function F3() - echo 3 - endfunction " F3 - function! F4() - echo 4 - endfunction! - call F2() - call F3() - call F4()]]))) - check_func('F2', 'echo 2', 2) - check_func('F3', 'echo 3', 2) - check_func('F4', 'echo 4', 2) - end) -end) --- vim: foldmarker=▶,▲ diff --git a/test/functional/eval/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua similarity index 100% rename from test/functional/eval/api_functions_spec.lua rename to test/functional/vimscript/api_functions_spec.lua diff --git a/test/functional/eval/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua similarity index 100% rename from test/functional/eval/buf_functions_spec.lua rename to test/functional/vimscript/buf_functions_spec.lua diff --git a/test/functional/eval/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua similarity index 100% rename from test/functional/eval/changedtick_spec.lua rename to test/functional/vimscript/changedtick_spec.lua diff --git a/test/functional/eval/container_functions_spec.lua b/test/functional/vimscript/container_functions_spec.lua similarity index 100% rename from test/functional/eval/container_functions_spec.lua rename to test/functional/vimscript/container_functions_spec.lua diff --git a/test/functional/eval/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua similarity index 100% rename from test/functional/eval/ctx_functions_spec.lua rename to test/functional/vimscript/ctx_functions_spec.lua diff --git a/test/functional/eval/environ_spec.lua b/test/functional/vimscript/environ_spec.lua similarity index 100% rename from test/functional/eval/environ_spec.lua rename to test/functional/vimscript/environ_spec.lua diff --git a/test/functional/viml/errorlist_spec.lua b/test/functional/vimscript/errorlist_spec.lua similarity index 100% rename from test/functional/viml/errorlist_spec.lua rename to test/functional/vimscript/errorlist_spec.lua diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua new file mode 100644 index 0000000000..e1459ab5b8 --- /dev/null +++ b/test/functional/vimscript/eval_spec.lua @@ -0,0 +1,146 @@ +-- Tests for core Vimscript "eval" behavior. +-- +-- See also: +-- let_spec.lua +-- null_spec.lua +-- operators_spec.lua +-- +-- Tests for the Vimscript |functions| library should live in: +-- test/functional/vimscript/_spec.lua +-- test/functional/vimscript/functions_spec.lua + +local helpers = require('test.functional.helpers')(after_each) + +local lfs = require('lfs') +local clear = helpers.clear +local eq = helpers.eq +local exc_exec = helpers.exc_exec +local eval = helpers.eval +local command = helpers.command +local write_file = helpers.write_file +local meths = helpers.meths +local sleep = helpers.sleep +local poke_eventloop = helpers.poke_eventloop +local feed = helpers.feed + +describe('Up to MAX_FUNC_ARGS arguments are handled by', function() + local max_func_args = 20 -- from eval.h + local range = helpers.funcs.range + + before_each(clear) + + it('printf()', function() + local printf = helpers.funcs.printf + local rep = helpers.funcs['repeat'] + local expected = '2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,' + eq(expected, printf(rep('%d,', max_func_args-1), unpack(range(2, max_func_args)))) + local ret = exc_exec('call printf("", 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') + eq('Vim(call):E740: Too many arguments for function printf', ret) + end) + + it('rpcnotify()', function() + local rpcnotify = helpers.funcs.rpcnotify + local ret = rpcnotify(0, 'foo', unpack(range(3, max_func_args))) + eq(1, ret) + ret = exc_exec('call rpcnotify(0, "foo", 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') + eq('Vim(call):E740: Too many arguments for function rpcnotify', ret) + end) +end) + +describe("backtick expansion", function() + setup(function() + clear() + lfs.mkdir("test-backticks") + write_file("test-backticks/file1", "test file 1") + write_file("test-backticks/file2", "test file 2") + write_file("test-backticks/file3", "test file 3") + lfs.mkdir("test-backticks/subdir") + write_file("test-backticks/subdir/file4", "test file 4") + -- Long path might cause "Press ENTER" prompt; use :silent to avoid it. + command('silent cd test-backticks') + end) + + teardown(function() + helpers.rmdir('test-backticks') + end) + + it("with default 'shell'", function() + if helpers.iswin() then + command(":silent args `dir /b *2`") + else + command(":silent args `echo ***2`") + end + eq({ "file2", }, eval("argv()")) + if helpers.iswin() then + command(":silent args `dir /s/b *4`") + eq({ "subdir\\file4", }, eval("map(argv(), 'fnamemodify(v:val, \":.\")')")) + else + command(":silent args `echo */*4`") + eq({ "subdir/file4", }, eval("argv()")) + end + end) + + it("with shell=fish", function() + if eval("executable('fish')") == 0 then + pending('missing "fish" command') + return + end + command("set shell=fish") + command(":silent args `echo ***2`") + eq({ "file2", }, eval("argv()")) + command(":silent args `echo */*4`") + eq({ "subdir/file4", }, eval("argv()")) + end) +end) + +describe('List support code', function() + local dur + local min_dur = 8 + local len = 131072 + + if not pending('does not actually allows interrupting with just got_int', function() end) then return end + -- The following tests are confirmed to work with os_breakcheck() just before + -- `if (got_int) {break;}` in tv_list_copy and list_join_inner() and not to + -- work without. + setup(function() + clear() + dur = 0 + while true do + command(([[ + let rt = reltime() + let bl = range(%u) + let dur = reltimestr(reltime(rt)) + ]]):format(len)) + dur = tonumber(meths.get_var('dur')) + if dur >= min_dur then + -- print(('Using len %u, dur %g'):format(len, dur)) + break + else + len = len * 2 + end + end + end) + it('allows interrupting copy', function() + feed(':let t_rt = reltime():let t_bl = copy(bl)') + sleep(min_dur / 16 * 1000) + feed('') + poke_eventloop() + command('let t_dur = reltimestr(reltime(t_rt))') + local t_dur = tonumber(meths.get_var('t_dur')) + if t_dur >= dur / 8 then + eq(nil, ('Took too long to cancel: %g >= %g'):format(t_dur, dur / 8)) + end + end) + it('allows interrupting join', function() + feed(':let t_rt = reltime():let t_j = join(bl)') + sleep(min_dur / 16 * 1000) + feed('') + poke_eventloop() + command('let t_dur = reltimestr(reltime(t_rt))') + local t_dur = tonumber(meths.get_var('t_dur')) + print(('t_dur: %g'):format(t_dur)) + if t_dur >= dur / 8 then + eq(nil, ('Took too long to cancel: %g >= %g'):format(t_dur, dur / 8)) + end + end) +end) diff --git a/test/functional/eval/executable_spec.lua b/test/functional/vimscript/executable_spec.lua similarity index 100% rename from test/functional/eval/executable_spec.lua rename to test/functional/vimscript/executable_spec.lua diff --git a/test/functional/eval/execute_spec.lua b/test/functional/vimscript/execute_spec.lua similarity index 100% rename from test/functional/eval/execute_spec.lua rename to test/functional/vimscript/execute_spec.lua diff --git a/test/functional/eval/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua similarity index 100% rename from test/functional/eval/exepath_spec.lua rename to test/functional/vimscript/exepath_spec.lua diff --git a/test/functional/eval/fnamemodify_spec.lua b/test/functional/vimscript/fnamemodify_spec.lua similarity index 100% rename from test/functional/eval/fnamemodify_spec.lua rename to test/functional/vimscript/fnamemodify_spec.lua diff --git a/test/functional/vimscript/functions_spec.lua b/test/functional/vimscript/functions_spec.lua new file mode 100644 index 0000000000..0ad7fd8010 --- /dev/null +++ b/test/functional/vimscript/functions_spec.lua @@ -0,0 +1,20 @@ +-- Tests for misc Vimscript |functions|. +-- +-- If a function is non-trivial, consider moving its spec to: +-- test/functional/vimscript/_spec.lua +-- +-- Core "eval" tests live in eval_spec.lua. + +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local eval = helpers.eval +local iswin = helpers.iswin +local matches = helpers.matches + +before_each(clear) + +it('windowsversion()', function() + clear() + matches(iswin() and '^%d+%.%d+$' or '^$', eval('windowsversion()')) +end) diff --git a/test/functional/eval/getline_spec.lua b/test/functional/vimscript/getline_spec.lua similarity index 100% rename from test/functional/eval/getline_spec.lua rename to test/functional/vimscript/getline_spec.lua diff --git a/test/functional/eval/glob_spec.lua b/test/functional/vimscript/glob_spec.lua similarity index 100% rename from test/functional/eval/glob_spec.lua rename to test/functional/vimscript/glob_spec.lua diff --git a/test/functional/eval/has_spec.lua b/test/functional/vimscript/has_spec.lua similarity index 100% rename from test/functional/eval/has_spec.lua rename to test/functional/vimscript/has_spec.lua diff --git a/test/functional/eval/hostname_spec.lua b/test/functional/vimscript/hostname_spec.lua similarity index 100% rename from test/functional/eval/hostname_spec.lua rename to test/functional/vimscript/hostname_spec.lua diff --git a/test/functional/eval/input_spec.lua b/test/functional/vimscript/input_spec.lua similarity index 100% rename from test/functional/eval/input_spec.lua rename to test/functional/vimscript/input_spec.lua diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua similarity index 100% rename from test/functional/eval/json_functions_spec.lua rename to test/functional/vimscript/json_functions_spec.lua diff --git a/test/functional/viml/lang_spec.lua b/test/functional/vimscript/lang_spec.lua similarity index 96% rename from test/functional/viml/lang_spec.lua rename to test/functional/vimscript/lang_spec.lua index 6d603b8822..d5254986ab 100644 --- a/test/functional/viml/lang_spec.lua +++ b/test/functional/vimscript/lang_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq local exc_exec, source = helpers.exc_exec, helpers.source -describe('viml', function() +describe('vimscript', function() before_each(clear) it('parses `` with turkish locale', function() diff --git a/test/functional/eval/let_spec.lua b/test/functional/vimscript/let_spec.lua similarity index 100% rename from test/functional/eval/let_spec.lua rename to test/functional/vimscript/let_spec.lua diff --git a/test/functional/eval/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua similarity index 100% rename from test/functional/eval/map_functions_spec.lua rename to test/functional/vimscript/map_functions_spec.lua diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/vimscript/match_functions_spec.lua similarity index 100% rename from test/functional/eval/match_functions_spec.lua rename to test/functional/vimscript/match_functions_spec.lua diff --git a/test/functional/eval/minmax_functions_spec.lua b/test/functional/vimscript/minmax_functions_spec.lua similarity index 100% rename from test/functional/eval/minmax_functions_spec.lua rename to test/functional/vimscript/minmax_functions_spec.lua diff --git a/test/functional/eval/modeline_spec.lua b/test/functional/vimscript/modeline_spec.lua similarity index 100% rename from test/functional/eval/modeline_spec.lua rename to test/functional/vimscript/modeline_spec.lua diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/vimscript/msgpack_functions_spec.lua similarity index 100% rename from test/functional/eval/msgpack_functions_spec.lua rename to test/functional/vimscript/msgpack_functions_spec.lua diff --git a/test/functional/eval/null_spec.lua b/test/functional/vimscript/null_spec.lua similarity index 100% rename from test/functional/eval/null_spec.lua rename to test/functional/vimscript/null_spec.lua diff --git a/test/functional/eval/operators_spec.lua b/test/functional/vimscript/operators_spec.lua similarity index 100% rename from test/functional/eval/operators_spec.lua rename to test/functional/vimscript/operators_spec.lua diff --git a/test/functional/eval/printf_spec.lua b/test/functional/vimscript/printf_spec.lua similarity index 100% rename from test/functional/eval/printf_spec.lua rename to test/functional/vimscript/printf_spec.lua diff --git a/test/functional/eval/reltime_spec.lua b/test/functional/vimscript/reltime_spec.lua similarity index 100% rename from test/functional/eval/reltime_spec.lua rename to test/functional/vimscript/reltime_spec.lua diff --git a/test/functional/eval/server_spec.lua b/test/functional/vimscript/server_spec.lua similarity index 100% rename from test/functional/eval/server_spec.lua rename to test/functional/vimscript/server_spec.lua diff --git a/test/functional/eval/setpos_spec.lua b/test/functional/vimscript/setpos_spec.lua similarity index 100% rename from test/functional/eval/setpos_spec.lua rename to test/functional/vimscript/setpos_spec.lua diff --git a/test/functional/eval/sort_spec.lua b/test/functional/vimscript/sort_spec.lua similarity index 100% rename from test/functional/eval/sort_spec.lua rename to test/functional/vimscript/sort_spec.lua diff --git a/test/functional/eval/special_vars_spec.lua b/test/functional/vimscript/special_vars_spec.lua similarity index 100% rename from test/functional/eval/special_vars_spec.lua rename to test/functional/vimscript/special_vars_spec.lua diff --git a/test/functional/eval/string_spec.lua b/test/functional/vimscript/string_spec.lua similarity index 100% rename from test/functional/eval/string_spec.lua rename to test/functional/vimscript/string_spec.lua diff --git a/test/functional/eval/system_spec.lua b/test/functional/vimscript/system_spec.lua similarity index 100% rename from test/functional/eval/system_spec.lua rename to test/functional/vimscript/system_spec.lua diff --git a/test/functional/eval/timer_spec.lua b/test/functional/vimscript/timer_spec.lua similarity index 100% rename from test/functional/eval/timer_spec.lua rename to test/functional/vimscript/timer_spec.lua diff --git a/test/functional/eval/uniq_spec.lua b/test/functional/vimscript/uniq_spec.lua similarity index 100% rename from test/functional/eval/uniq_spec.lua rename to test/functional/vimscript/uniq_spec.lua diff --git a/test/functional/eval/vvar_event_spec.lua b/test/functional/vimscript/vvar_event_spec.lua similarity index 100% rename from test/functional/eval/vvar_event_spec.lua rename to test/functional/vimscript/vvar_event_spec.lua diff --git a/test/functional/eval/wait_spec.lua b/test/functional/vimscript/wait_spec.lua similarity index 100% rename from test/functional/eval/wait_spec.lua rename to test/functional/vimscript/wait_spec.lua diff --git a/test/functional/eval/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua similarity index 100% rename from test/functional/eval/writefile_spec.lua rename to test/functional/vimscript/writefile_spec.lua diff --git a/test/functional/visual/meta_key_spec.lua b/test/functional/visual/meta_key_spec.lua deleted file mode 100644 index 11f7203da0..0000000000 --- a/test/functional/visual/meta_key_spec.lua +++ /dev/null @@ -1,22 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command = helpers.command -local expect = helpers.expect - -describe('meta-keys-in-visual-mode', function() - before_each(function() - clear() - end) - - it('ALT/META', function() - -- Unmapped ALT-chords behave as Esc+c - insert('peaches') - feed('viwviw') - expect('peach') - -- Mapped ALT-chord behaves as mapped. - command('vnoremap Ameta-l') - command('vnoremap Aalt-j') - feed('viwviw') - expect('peachalt-jmeta-l') - end) -end)