comparison src/testdir/test_cmdline.vim @ 29369:b1f345ec827e v9.0.0027

patch 9.0.0027: the command line test is getting quite big Commit: https://github.com/vim/vim/commit/2d2950198231a31bf87c1cd4322099cc36b0bb93 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 2 16:29:34 2022 +0100 patch 9.0.0027: the command line test is getting quite big Problem: The command line test is getting quite big. Solution: Move command line window tests to a separate file.
author Bram Moolenaar <Bram@vim.org>
date Sat, 02 Jul 2022 17:30:02 +0200
parents 98de9a961a64
children 5c390aa28f44
comparison
equal deleted inserted replaced
29368:8828385b55da 29369:b1f345ec827e
1320 cunmap <F6> 1320 cunmap <F6>
1321 1321
1322 call assert_equal('', getcmdline()) 1322 call assert_equal('', getcmdline())
1323 endfunc 1323 endfunc
1324 1324
1325 func Test_getcmdwintype()
1326 CheckFeature cmdwin
1327
1328 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1329 call assert_equal('/', a)
1330
1331 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1332 call assert_equal('?', a)
1333
1334 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1335 call assert_equal(':', a)
1336
1337 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
1338 call assert_equal(':', a)
1339
1340 call assert_equal('', getcmdwintype())
1341 endfunc
1342
1343 func Test_getcmdwin_autocmd()
1344 CheckFeature cmdwin
1345
1346 let s:seq = []
1347 augroup CmdWin
1348 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
1349 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
1350 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
1351 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
1352 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
1353 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
1354
1355 let org_winid = win_getid()
1356 let org_bufnr = bufnr()
1357 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
1358 call assert_equal(':', a)
1359 call assert_equal([
1360 \ 'WinLeave ' .. org_winid,
1361 \ 'WinEnter ' .. s:cmd_winid,
1362 \ 'BufLeave ' .. org_bufnr,
1363 \ 'BufEnter ' .. s:cmd_bufnr,
1364 \ 'CmdWinEnter ' .. s:cmd_winid,
1365 \ 'CmdWinLeave ' .. s:cmd_winid,
1366 \ 'BufLeave ' .. s:cmd_bufnr,
1367 \ 'WinLeave ' .. s:cmd_winid,
1368 \ 'WinEnter ' .. org_winid,
1369 \ 'BufEnter ' .. org_bufnr,
1370 \ ], s:seq)
1371
1372 au!
1373 augroup END
1374 endfunc
1375
1376 func Test_verbosefile() 1325 func Test_verbosefile()
1377 set verbosefile=Xlog 1326 set verbosefile=Xlog
1378 echomsg 'foo' 1327 echomsg 'foo'
1379 echomsg 'bar' 1328 echomsg 'bar'
1380 set verbosefile= 1329 set verbosefile=
1450 " Test overstrike with multi-byte characters. 1399 " Test overstrike with multi-byte characters.
1451 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1400 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
1452 call assert_equal('"テabキcdエディタ', @:, e) 1401 call assert_equal('"テabキcdエディタ', @:, e)
1453 1402
1454 let &encoding = encoding_save 1403 let &encoding = encoding_save
1455 endfunc
1456
1457 func Test_cmdwin_bug()
1458 CheckFeature cmdwin
1459
1460 let winid = win_getid()
1461 sp
1462 try
1463 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
1464 catch /^Vim\%((\a\+)\)\=:E11/
1465 endtry
1466 bw!
1467 endfunc
1468
1469 func Test_cmdwin_restore()
1470 CheckFeature cmdwin
1471 CheckScreendump
1472
1473 let lines =<< trim [SCRIPT]
1474 augroup vimHints | au! | augroup END
1475 call setline(1, range(30))
1476 2split
1477 [SCRIPT]
1478 call writefile(lines, 'XTest_restore')
1479
1480 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
1481 call TermWait(buf, 50)
1482 call term_sendkeys(buf, "q:")
1483 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
1484
1485 " normal restore
1486 call term_sendkeys(buf, ":q\<CR>")
1487 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
1488
1489 " restore after setting 'lines' with one window
1490 call term_sendkeys(buf, ":close\<CR>")
1491 call term_sendkeys(buf, "q:")
1492 call term_sendkeys(buf, ":set lines=18\<CR>")
1493 call term_sendkeys(buf, ":q\<CR>")
1494 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
1495
1496 " clean up
1497 call StopVimInTerminal(buf)
1498 call delete('XTest_restore')
1499 endfunc
1500
1501 func Test_cmdwin_no_terminal()
1502 CheckFeature cmdwin
1503 CheckFeature terminal
1504 CheckNotMSWindows
1505
1506 let buf = RunVimInTerminal('', {'rows': 12})
1507 call TermWait(buf, 50)
1508 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
1509 call term_sendkeys(buf, "q:")
1510 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
1511 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
1512 call term_sendkeys(buf, ":q\<CR>")
1513 call StopVimInTerminal(buf)
1514 endfunc 1404 endfunc
1515 1405
1516 func Test_buffers_lastused() 1406 func Test_buffers_lastused()
1517 " check that buffers are sorted by time when wildmode has lastused 1407 " check that buffers are sorted by time when wildmode has lastused
1518 call test_settime(1550020000) " middle 1408 call test_settime(1550020000) " middle
1556 bwipeout bufa 1446 bwipeout bufa
1557 bwipeout bufb 1447 bwipeout bufb
1558 bwipeout bufc 1448 bwipeout bufc
1559 endfunc 1449 endfunc
1560 1450
1561 func Test_cmdwin_feedkeys()
1562 CheckFeature cmdwin
1563
1564 " This should not generate E488
1565 call feedkeys("q:\<CR>", 'x')
1566 " Using feedkeys with q: only should automatically close the cmd window
1567 call feedkeys('q:', 'xt')
1568 call assert_equal(1, winnr('$'))
1569 call assert_equal('', getcmdwintype())
1570 endfunc
1571
1572 " Tests for the issues fixed in 7.4.441.
1573 " When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
1574 func Test_cmdwin_cedit()
1575 CheckFeature cmdwin
1576
1577 exe "set cedit=\<C-c>"
1578 normal! :
1579 call assert_equal(1, winnr('$'))
1580
1581 let g:cmd_wintype = ''
1582 func CmdWinType()
1583 let g:cmd_wintype = getcmdwintype()
1584 let g:wintype = win_gettype()
1585 return ''
1586 endfunc
1587
1588 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
1589 echo input('')
1590 call assert_equal('@', g:cmd_wintype)
1591 call assert_equal('command', g:wintype)
1592
1593 set cedit&vim
1594 delfunc CmdWinType
1595 endfunc
1596
1597 " Test for CmdwinEnter autocmd
1598 func Test_cmdwin_autocmd()
1599 CheckFeature cmdwin
1600
1601 augroup CmdWin
1602 au!
1603 autocmd BufLeave * if &buftype == '' | update | endif
1604 autocmd CmdwinEnter * startinsert
1605 augroup END
1606
1607 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
1608 call assert_equal('xyz', @:)
1609
1610 augroup CmdWin
1611 au!
1612 augroup END
1613 augroup! CmdWin
1614 endfunc
1615
1616 func Test_cmdlineclear_tabenter() 1451 func Test_cmdlineclear_tabenter()
1617 CheckScreendump 1452 CheckScreendump
1618 1453
1619 let lines =<< trim [SCRIPT] 1454 let lines =<< trim [SCRIPT]
1620 call setline(1, range(30)) 1455 call setline(1, range(30))
1645 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt') 1480 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
1646 call assert_equal('"e Xfile.cpp Xfile.java', @:) 1481 call assert_equal('"e Xfile.cpp Xfile.java', @:)
1647 close 1482 close
1648 call delete('Xfile.cpp') 1483 call delete('Xfile.cpp')
1649 call delete('Xfile.java') 1484 call delete('Xfile.java')
1650 endfunc
1651
1652 func Test_cmdwin_jump_to_win()
1653 CheckFeature cmdwin
1654
1655 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
1656 new
1657 set modified
1658 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
1659 close!
1660 call feedkeys("q/:close\<CR>", "xt")
1661 call assert_equal(1, winnr('$'))
1662 call feedkeys("q/:exit\<CR>", "xt")
1663 call assert_equal(1, winnr('$'))
1664
1665 " opening command window twice should fail
1666 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
1667 call assert_equal(1, winnr('$'))
1668 endfunc
1669
1670 func Test_cmdwin_tabpage()
1671 tabedit
1672 call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
1673 tabclose!
1674 endfunc
1675
1676 func Test_cmdwin_interrupted()
1677 CheckFeature cmdwin
1678 CheckScreendump
1679
1680 " aborting the :smile output caused the cmdline window to use the current
1681 " buffer.
1682 let lines =<< trim [SCRIPT]
1683 au WinNew * smile
1684 [SCRIPT]
1685 call writefile(lines, 'XTest_cmdwin')
1686
1687 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
1688 " open cmdwin
1689 call term_sendkeys(buf, "q:")
1690 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
1691 " quit more prompt for :smile command
1692 call term_sendkeys(buf, "q")
1693 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
1694 " execute a simple command
1695 call term_sendkeys(buf, "aecho 'done'\<CR>")
1696 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
1697
1698 " clean up
1699 call StopVimInTerminal(buf)
1700 call delete('XTest_cmdwin')
1701 endfunc 1485 endfunc
1702 1486
1703 " Test for backtick expression in the command line 1487 " Test for backtick expression in the command line
1704 func Test_cmd_backtick() 1488 func Test_cmd_backtick()
1705 %argd 1489 %argd
2031 1815
2032 set imcmdline& 1816 set imcmdline&
2033 %bwipe! 1817 %bwipe!
2034 endfunc 1818 endfunc
2035 1819
2036 " Test for recursively getting multiple command line inputs
2037 func Test_cmdwin_multi_input()
2038 CheckFeature cmdwin
2039
2040 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
2041 call assert_equal('"cyan', @:)
2042 endfunc
2043
2044 " Test for using CTRL-_ in the command line with 'allowrevins' 1820 " Test for using CTRL-_ in the command line with 'allowrevins'
2045 func Test_cmdline_revins() 1821 func Test_cmdline_revins()
2046 CheckNotMSWindows 1822 CheckNotMSWindows
2047 CheckFeature rightleft 1823 CheckFeature rightleft
2048 call feedkeys(":\"abc\<c-_>\<cr>", 'xt') 1824 call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
2055 1831
2056 " Test for typing UTF-8 composing characters in the command line 1832 " Test for typing UTF-8 composing characters in the command line
2057 func Test_cmdline_composing_chars() 1833 func Test_cmdline_composing_chars()
2058 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt') 1834 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
2059 call assert_equal('"ゔ', @:) 1835 call assert_equal('"ゔ', @:)
2060 endfunc
2061
2062 " Test for normal mode commands not supported in the cmd window
2063 func Test_cmdwin_blocked_commands()
2064 CheckFeature cmdwin
2065
2066 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
2067 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
2068 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
2069 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
2070 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
2071 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
2072 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
2073 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
2074 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
2075 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
2076 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
2077 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
2078 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
2079 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
2080 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
2081 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
2082 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
2083 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
2084 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
2085 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
2086 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
2087 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
2088 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
2089 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
2090 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
2091 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
2092 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
2093 endfunc
2094
2095 " Close the Cmd-line window in insert mode using CTRL-C
2096 func Test_cmdwin_insert_mode_close()
2097 CheckFeature cmdwin
2098
2099 %bw!
2100 let s = ''
2101 exe "normal q:a\<C-C>let s='Hello'\<CR>"
2102 call assert_equal('Hello', s)
2103 call assert_equal(1, winnr('$'))
2104 endfunc
2105
2106 func Test_cmdwin_ex_mode_with_modifier()
2107 " this was accessing memory after allocated text in Ex mode
2108 new
2109 call setline(1, ['some', 'text', 'lines'])
2110 silent! call feedkeys("gQnormal vq:atopleft\<C-V>\<CR>\<CR>", 'xt')
2111 bwipe!
2112 endfunc 1836 endfunc
2113 1837
2114 " test that ";" works to find a match at the start of the first line 1838 " test that ";" works to find a match at the start of the first line
2115 func Test_zero_line_search() 1839 func Test_zero_line_search()
2116 new 1840 new