From 805eb81ccdc6a7000926e458b6e0dd59df16a112 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Wed, 21 Apr 2021 10:29:26 +0100 Subject: oldtest: port test_prompt_buffer.vim Included from before v8.2.1588. Required for v8.2.1588. Many tests use stuff like term_sendkeys() which is N/A, so are skipped. --- src/nvim/testdir/test_prompt_buffer.vim | 159 ++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 src/nvim/testdir/test_prompt_buffer.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_prompt_buffer.vim b/src/nvim/testdir/test_prompt_buffer.vim new file mode 100644 index 0000000000..66647018b5 --- /dev/null +++ b/src/nvim/testdir/test_prompt_buffer.vim @@ -0,0 +1,159 @@ +" Tests for setting 'buftype' to "prompt" + +source check.vim +" Nvim's channel implementation differs from Vim's +" CheckFeature channel + +source shared.vim +source screendump.vim + +func CanTestPromptBuffer() + " We need to use a terminal window to be able to feed keys without leaving + " Insert mode. + " Nvim's terminal implementation differs from Vim's + " CheckFeature terminal + + " TODO: make the tests work on MS-Windows + CheckNotMSWindows +endfunc + +func WriteScript(name) + call writefile([ + \ 'func TextEntered(text)', + \ ' if a:text == "exit"', + \ ' " Reset &modified to allow the buffer to be closed.', + \ ' set nomodified', + \ ' stopinsert', + \ ' close', + \ ' else', + \ ' " Add the output above the current prompt.', + \ ' call append(line("$") - 1, "Command: \"" . a:text . "\"")', + \ ' " Reset &modified to allow the buffer to be closed.', + \ ' set nomodified', + \ ' call timer_start(20, {id -> TimerFunc(a:text)})', + \ ' endif', + \ 'endfunc', + \ '', + \ 'func TimerFunc(text)', + \ ' " Add the output above the current prompt.', + \ ' call append(line("$") - 1, "Result: \"" . a:text . "\"")', + \ ' " Reset &modified to allow the buffer to be closed.', + \ ' set nomodified', + \ 'endfunc', + \ '', + \ 'call setline(1, "other buffer")', + \ 'set nomodified', + \ 'new', + \ 'set buftype=prompt', + \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))', + \ 'eval bufnr("")->prompt_setprompt("cmd: ")', + \ 'startinsert', + \ ], a:name) +endfunc + +func Test_prompt_basic() + throw 'skipped: TODO' + call CanTestPromptBuffer() + let scriptName = 'XpromptscriptBasic' + call WriteScript(scriptName) + + let buf = RunVimInTerminal('-S ' . scriptName, {}) + call WaitForAssert({-> assert_equal('cmd:', term_getline(buf, 1))}) + + call term_sendkeys(buf, "hello\") + call WaitForAssert({-> assert_equal('cmd: hello', term_getline(buf, 1))}) + call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))}) + call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))}) + + call term_sendkeys(buf, "exit\") + call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) + + call StopVimInTerminal(buf) + call delete(scriptName) +endfunc + +func Test_prompt_editing() + throw 'skipped: TODO' + call CanTestPromptBuffer() + let scriptName = 'XpromptscriptEditing' + call WriteScript(scriptName) + + let buf = RunVimInTerminal('-S ' . scriptName, {}) + call WaitForAssert({-> assert_equal('cmd:', term_getline(buf, 1))}) + + let bs = "\" + call term_sendkeys(buf, "hello" . bs . bs) + call WaitForAssert({-> assert_equal('cmd: hel', term_getline(buf, 1))}) + + let left = "\" + call term_sendkeys(buf, left . left . left . bs . '-') + call WaitForAssert({-> assert_equal('cmd: -hel', term_getline(buf, 1))}) + + let end = "\" + call term_sendkeys(buf, end . "x") + call WaitForAssert({-> assert_equal('cmd: -helx', term_getline(buf, 1))}) + + call term_sendkeys(buf, "\exit\") + call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) + + call StopVimInTerminal(buf) + call delete(scriptName) +endfunc + +func Test_prompt_garbage_collect() + func MyPromptCallback(x, text) + " NOP + endfunc + func MyPromptInterrupt(x) + " NOP + endfunc + + new + set buftype=prompt + " Nvim doesn't support method call syntax yet. + " eval bufnr('')->prompt_setcallback(function('MyPromptCallback', [{}])) + " eval bufnr('')->prompt_setinterrupt(function('MyPromptInterrupt', [{}])) + eval prompt_setcallback(bufnr(''), function('MyPromptCallback', [{}])) + eval prompt_setinterrupt(bufnr(''), function('MyPromptInterrupt', [{}])) + call test_garbagecollect_now() + " Must not crash + call feedkeys("\\", 'xt') + call assert_true(v:true) + + call assert_fails("call prompt_setcallback(bufnr(), [])", 'E921:') + call assert_equal(0, prompt_setcallback({}, '')) + call assert_fails("call prompt_setinterrupt(bufnr(), [])", 'E921:') + call assert_equal(0, prompt_setinterrupt({}, '')) + + delfunc MyPromptCallback + bwipe! +endfunc + +" Test for editing the prompt buffer +func Test_prompt_buffer_edit() + new + set buftype=prompt + normal! i + call assert_beeps('normal! dd') + call assert_beeps('normal! ~') + call assert_beeps('normal! o') + call assert_beeps('normal! O') + call assert_beeps('normal! p') + call assert_beeps('normal! P') + call assert_beeps('normal! u') + call assert_beeps('normal! ra') + call assert_beeps('normal! s') + call assert_beeps('normal! S') + call assert_beeps("normal! \") + call assert_beeps("normal! \") + " pressing CTRL-W in the prompt buffer should trigger the window commands + call assert_equal(1, winnr()) + " In Nvim, CTRL-W commands aren't usable from insert mode in a prompt buffer + " exe "normal A\\" + " call assert_equal(2, winnr()) + " wincmd w + close! + call assert_equal(0, prompt_setprompt([], '')) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 65f35e0c7db700c25d9de9a3c8637f720c07583a Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Wed, 14 Apr 2021 20:13:22 +0100 Subject: vim-patch:8.2.1588: cannot read back the prompt of a prompt buffer Problem: Cannot read back the prompt of a prompt buffer. Solution: Add prompt_getprompt(). (Ben Jackson, closes vim/vim#6851) https://github.com/vim/vim/commit/077cc7aa0e0c431e97795612374fe17fe7c88803 Updated prompt_getprompt() doc to https://github.com/vim/vim/commit/cb80aa2d53e56d3aba3b3c439fb467f29a750c5e and removed mention of method syntax usage (not supported by Nvim). --- src/nvim/testdir/test_prompt_buffer.vim | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_prompt_buffer.vim b/src/nvim/testdir/test_prompt_buffer.vim index 66647018b5..6fc5850be3 100644 --- a/src/nvim/testdir/test_prompt_buffer.vim +++ b/src/nvim/testdir/test_prompt_buffer.vim @@ -156,4 +156,40 @@ func Test_prompt_buffer_edit() call assert_equal(0, prompt_setprompt([], '')) endfunc +func Test_prompt_buffer_getbufinfo() + new + call assert_equal('', prompt_getprompt('%')) + call assert_equal('', prompt_getprompt(bufnr('%'))) + let another_buffer = bufnr('%') + + set buftype=prompt + call assert_equal('% ', prompt_getprompt('%')) + call prompt_setprompt( bufnr( '%' ), 'This is a test: ' ) + call assert_equal('This is a test: ', prompt_getprompt('%')) + + call prompt_setprompt( bufnr( '%' ), '' ) + " Nvim doesn't support method call syntax yet. + " call assert_equal('', '%'->prompt_getprompt()) + call assert_equal('', prompt_getprompt('%')) + + call prompt_setprompt( bufnr( '%' ), 'Another: ' ) + call assert_equal('Another: ', prompt_getprompt('%')) + let another = bufnr('%') + + new + + call assert_equal('', prompt_getprompt('%')) + call assert_equal('Another: ', prompt_getprompt(another)) + + " Doesn't exist + let buffers_before = len( getbufinfo() ) + call assert_equal('', prompt_getprompt( bufnr('$') + 1)) + call assert_equal(buffers_before, len( getbufinfo())) + + " invalid type + call assert_fails('call prompt_getprompt({})', 'E728:') + + %bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From ff198bb78a34f4b388efe1b45930031b39ae5810 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Wed, 21 Apr 2021 14:27:23 +0100 Subject: fix(oldtest): fix assert_match() for :buffers t Previous pattern could cause test to fail if ":buffers t" reported "1 second ago". --- src/nvim/testdir/test_excmd.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 98a3e60368..15557056ee 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -47,7 +47,7 @@ func Test_buffers_lastused() endfor call assert_equal(['bufb', 'bufa', 'bufc'], names) - call assert_match('[0-2] seconds ago', bufs[1][1]) + call assert_match('[0-2] seconds\= ago', bufs[1][1]) bwipeout bufa bwipeout bufb -- cgit