" Tests for editing the command line. source check.vim source screendump.vim source view_util.vim source shared.vim func SetUp() func SaveLastScreenLine() let g:Sline = Screenline(&lines - 1) return '' endfunc cnoremap SaveLastScreenLine() endfunc func TearDown() delfunc SaveLastScreenLine cunmap endfunc func Test_complete_tab() call writefile(['testfile'], 'Xtestfile') call feedkeys(":e Xtest\t\r", "tx") call assert_equal('testfile', getline(1)) " Pressing after '%' completes the current file, also on MS-Windows call feedkeys(":e %\t\r", "tx") call assert_equal('e Xtestfile', @:) call delete('Xtestfile') endfunc func Test_complete_list() " We can't see the output, but at least we check the code runs properly. call feedkeys(":e test\\r", "tx") call assert_equal('test', expand('%:t')) " If a command doesn't support completion, then CTRL-D should be literally " used. call feedkeys(":chistory \\\"\", 'xt') call assert_equal("\"chistory \", @:) " Test for displaying the tail of the completion matches set wildmode=longest,full call mkdir('Xtest') call writefile([], 'Xtest/a.c') call writefile([], 'Xtest/a.h') let g:Sline = '' call feedkeys(":e Xtest/\\\\"\", 'xt') call assert_equal('a.c a.h', g:Sline) call assert_equal('"e Xtest/', @:) if has('win32') " Test for 'completeslash' set completeslash=backslash call feedkeys(":e Xtest\\\"\", 'xt') call assert_equal('"e Xtest\', @:) call feedkeys(":e Xtest/\\\"\", 'xt') call assert_equal('"e Xtest\a.', @:) set completeslash=slash call feedkeys(":e Xtest\\\"\", 'xt') call assert_equal('"e Xtest/', @:) call feedkeys(":e Xtest\\\\\"\", 'xt') call assert_equal('"e Xtest/a.', @:) set completeslash& endif " Test for displaying the tail with wildcards let g:Sline = '' call feedkeys(":e Xtes?/\\\\"\", 'xt') call assert_equal('Xtest/a.c Xtest/a.h', g:Sline) call assert_equal('"e Xtes?/', @:) let g:Sline = '' call feedkeys(":e Xtes*/\\\\"\", 'xt') call assert_equal('Xtest/a.c Xtest/a.h', g:Sline) call assert_equal('"e Xtes*/', @:) let g:Sline = '' call feedkeys(":e Xtes[/\\\\"\", 'xt') call assert_equal(':e Xtes[/', g:Sline) call assert_equal('"e Xtes[/', @:) call delete('Xtest', 'rf') set wildmode& endfunc func Test_complete_wildmenu() call mkdir('Xwilddir1/Xdir2', 'pR') call writefile(['testfile1'], 'Xwilddir1/Xtestfile1') call writefile(['testfile2'], 'Xwilddir1/Xtestfile2') call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3') call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4') set wildmenu " Pressing completes, and moves to next files when pressing again. call feedkeys(":e Xwilddir1/\\\", 'tx') call assert_equal('testfile1', getline(1)) call feedkeys(":e Xwilddir1/\\\\", 'tx') call assert_equal('testfile2', getline(1)) " is like but begin with the last match and then go to " previous. call feedkeys(":e Xwilddir1/Xtest\\", 'tx') call assert_equal('testfile2', getline(1)) call feedkeys(":e Xwilddir1/Xtest\\\", 'tx') call assert_equal('testfile1', getline(1)) " / to move to previous/next file. call feedkeys(":e Xwilddir1/\\\", 'tx') call assert_equal('testfile1', getline(1)) call feedkeys(":e Xwilddir1/\\\\", 'tx') call assert_equal('testfile2', getline(1)) call feedkeys(":e Xwilddir1/\\\\\", 'tx') call assert_equal('testfile1', getline(1)) " / to go up/down directories. call feedkeys(":e Xwilddir1/\\\", 'tx') call assert_equal('testfile3', getline(1)) call feedkeys(":e Xwilddir1/\\\\\", 'tx') call assert_equal('testfile1', getline(1)) " this fails in some Unix GUIs, not sure why if !has('unix') || !has('gui_running') " / mappings to go up/down directories when 'wildcharm' is " different than 'wildchar'. set wildcharm= cnoremap cnoremap call feedkeys(":e Xwilddir1/\\\", 'tx') call assert_equal('testfile3', getline(1)) call feedkeys(":e Xwilddir1/\\\\", 'tx') call assert_equal('testfile1', getline(1)) set wildcharm=0 cunmap cunmap endif " Test for canceling the wild menu by adding a character redrawstatus call feedkeys(":e Xwilddir1/\x\\"\", 'xt') call assert_equal('"e Xwilddir1/Xdir2/x', @:) " Completion using a relative path cd Xwilddir1/Xdir2 call feedkeys(":e ../\\\\\\"\", 'tx') call assert_equal('"e Xtestfile3 Xtestfile4', @:) cd - " test for wildmenumode() cnoremap wildmenumode() call feedkeys(":cd Xwilddir\\\\"\", 'tx') call assert_equal('"cd Xwilddir1/0', @:) call feedkeys(":e Xwilddir1/\\\\"\", 'tx') call assert_equal('"e Xwilddir1/Xdir2/1', @:) cunmap " Test for canceling the wild menu by pressing or . " After this pressing or should not change the selection. call feedkeys(":sign \\\\\\\"\", 'tx') call assert_equal('"sign define', @:) call histadd('cmd', 'TestWildMenu') call feedkeys(":sign \\\\\\\"\", 'tx') call assert_equal('"TestWildMenu', @:) " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match call feedkeys(":sign un zz\\\\\ yy\\"\", 'tx') call assert_equal('"sign un yy zz', @:) call feedkeys(":sign un zz\\\\\\ yy\\"\", 'tx') call assert_equal('"sign unplace yy zz', @:) " cleanup %bwipe set nowildmenu endfunc func Test_wildmenu_screendump() CheckScreendump let lines =<< trim [SCRIPT] set wildmenu hlsearch [SCRIPT] call writefile(lines, 'XTest_wildmenu', 'D') " Test simple wildmenu let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8}) call term_sendkeys(buf, ":vim\") call VerifyScreenDump(buf, 'Test_wildmenu_1', {}) call term_sendkeys(buf, "\") call VerifyScreenDump(buf, 'Test_wildmenu_2', {}) call term_sendkeys(buf, "\") call VerifyScreenDump(buf, 'Test_wildmenu_3', {}) " Looped back to the original value call term_sendkeys(buf, "\\") call VerifyScreenDump(buf, 'Test_wildmenu_4', {}) " Test that the wild menu is cleared properly call term_sendkeys(buf, " ") call VerifyScreenDump(buf, 'Test_wildmenu_5', {}) " Test that a different wildchar still works call term_sendkeys(buf, "\:set wildchar=\") call term_sendkeys(buf, ":vim\") call VerifyScreenDump(buf, 'Test_wildmenu_1', {}) " Double- is a hard-coded method to escape while wildchar=. Make " sure clean up is properly done in edge case like this. call term_sendkeys(buf, "\") call VerifyScreenDump(buf, 'Test_wildmenu_6', {}) " clean up call StopVimInTerminal(buf) endfunc func Test_redraw_in_autocmd() CheckScreendump let lines =<< trim END set cmdheight=2 autocmd CmdlineChanged * redraw END call writefile(lines, 'XTest_redraw', 'D') let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8}) call term_sendkeys(buf, ":for i in range(3)\") call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {}) call term_sendkeys(buf, "let i =") call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {}) " clean up call term_sendkeys(buf, "\") call StopVimInTerminal(buf) endfunc func Test_redrawstatus_in_autocmd() CheckScreendump let lines =<< trim END set laststatus=2 set statusline=%=:%{getcmdline()} autocmd CmdlineChanged * redrawstatus END call writefile(lines, 'XTest_redrawstatus', 'D') let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8}) " :redrawstatus is postponed if messages have scrolled call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\") call term_sendkeys(buf, ":foobar") call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {}) " it is not postponed if messages have not scrolled call term_sendkeys(buf, "\:for in in range(3)") call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {}) " with cmdheight=1 messages have scrolled when typing :endfor call term_sendkeys(buf, "\:endfor") call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {}) call term_sendkeys(buf, "\:set cmdheight=2\") " with cmdheight=2 messages haven't scrolled when typing :for or :endfor call term_sendkeys(buf, ":for in in range(3)") call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {}) call term_sendkeys(buf, "\:endfor") call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {}) " clean up call term_sendkeys(buf, "\") call StopVimInTerminal(buf) endfunc func Test_changing_cmdheight() CheckScreendump let lines =<< trim END set cmdheight=1 laststatus=2 func EchoTwo() set laststatus=2 set cmdheight=5 echo 'foo' echo 'bar' set cmdheight=1 endfunc END call writefile(lines, 'XTest_cmdheight', 'D') let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8}) call term_sendkeys(buf, ":resize -3\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {}) " using the space available doesn't change the status line call term_sendkeys(buf, ":set cmdheight+=3\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {}) " using more space moves the status line up call term_sendkeys(buf, ":set cmdheight+=1\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {}) " reducing cmdheight moves status line down call term_sendkeys(buf, ":set cmdheight-=2\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {}) " reducing window size and then setting cmdheight call term_sendkeys(buf, ":resize -1\") call term_sendkeys(buf, ":set cmdheight=1\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {}) " setting 'cmdheight' works after outputting two messages call term_sendkeys(buf, ":call EchoTwo()\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {}) " clean up call StopVimInTerminal(buf) endfunc func Test_cmdheight_tabline() CheckScreendump let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6}) call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {}) " clean up call StopVimInTerminal(buf) endfunc func Test_map_completion() call feedkeys(":map \\"\", 'xt') call assert_equal('"map ', getreg(':')) call feedkeys(":map