Mercurial > vim
comparison src/testdir/test_functions.vim @ 18143:2416e1a887ca
patch 8.1.2066: no tests for state()
Commit: https://github.com/vim/vim/commit/c2585490321854ca3df115efcf0b40986901d96c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 22 21:29:53 2019 +0200
patch 8.1.2066: no tests for state()
Problem: No tests for state().
Solution: Add tests. Clean up some feature checks. Make "a" flag work.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 22 Sep 2019 21:30:04 +0200 |
parents | 609b351cb58f |
children | 9a7bbad64376 |
comparison
equal
deleted
inserted
replaced
18142:6243a1690929 | 18143:2416e1a887ca |
---|---|
1 " Tests for various functions. | 1 " Tests for various functions. |
2 source shared.vim | 2 source shared.vim |
3 source check.vim | 3 source check.vim |
4 source term_util.vim | |
4 | 5 |
5 " Must be done first, since the alternate buffer must be unset. | 6 " Must be done first, since the alternate buffer must be unset. |
6 func Test_00_bufexists() | 7 func Test_00_bufexists() |
7 call assert_equal(0, bufexists('does_not_exist')) | 8 call assert_equal(0, bufexists('does_not_exist')) |
8 call assert_equal(1, bufexists(bufnr('%'))) | 9 call assert_equal(1, bufexists(bufnr('%'))) |
1657 bwipe someName | 1658 bwipe someName |
1658 bwipe XotherName | 1659 bwipe XotherName |
1659 call assert_equal(0, bufexists('someName')) | 1660 call assert_equal(0, bufexists('someName')) |
1660 call delete('XotherName') | 1661 call delete('XotherName') |
1661 endfunc | 1662 endfunc |
1663 | |
1664 func Test_state() | |
1665 CheckRunVimInTerminal | |
1666 | |
1667 let lines =<< trim END | |
1668 call setline(1, ['one', 'two', 'three']) | |
1669 map ;; gg | |
1670 func RunTimer() | |
1671 call timer_start(10, {id -> execute('let g:state = state()') .. execute('let g:mode = mode()')}) | |
1672 endfunc | |
1673 au Filetype foobar let g:state = state()|let g:mode = mode() | |
1674 END | |
1675 call writefile(lines, 'XState') | |
1676 let buf = RunVimInTerminal('-S XState', #{rows: 6}) | |
1677 | |
1678 " Using a ":" command Vim is busy, thus "S" is returned | |
1679 call term_sendkeys(buf, ":echo 'state: ' .. state() .. '; mode: ' .. mode()\<CR>") | |
1680 call WaitForAssert({-> assert_match('state: S; mode: n', term_getline(buf, 6))}, 1000) | |
1681 call term_sendkeys(buf, ":\<CR>") | |
1682 | |
1683 " Using a timer callback | |
1684 call term_sendkeys(buf, ":call RunTimer()\<CR>") | |
1685 call term_wait(buf, 50) | |
1686 let getstate = ":echo 'state: ' .. g:state .. '; mode: ' .. g:mode\<CR>" | |
1687 call term_sendkeys(buf, getstate) | |
1688 call WaitForAssert({-> assert_match('state: c; mode: n', term_getline(buf, 6))}, 1000) | |
1689 | |
1690 " Halfway a mapping | |
1691 call term_sendkeys(buf, ":call RunTimer()\<CR>;") | |
1692 call term_wait(buf, 50) | |
1693 call term_sendkeys(buf, ";") | |
1694 call term_sendkeys(buf, getstate) | |
1695 call WaitForAssert({-> assert_match('state: mSc; mode: n', term_getline(buf, 6))}, 1000) | |
1696 | |
1697 " Insert mode completion | |
1698 call term_sendkeys(buf, ":call RunTimer()\<CR>Got\<C-N>") | |
1699 call term_wait(buf, 50) | |
1700 call term_sendkeys(buf, "\<Esc>") | |
1701 call term_sendkeys(buf, getstate) | |
1702 call WaitForAssert({-> assert_match('state: aSc; mode: i', term_getline(buf, 6))}, 1000) | |
1703 | |
1704 " Autocommand executing | |
1705 call term_sendkeys(buf, ":set filetype=foobar\<CR>") | |
1706 call term_wait(buf, 50) | |
1707 call term_sendkeys(buf, getstate) | |
1708 call WaitForAssert({-> assert_match('state: xS; mode: n', term_getline(buf, 6))}, 1000) | |
1709 | |
1710 " Todo: "w" - waiting for ch_evalexpr() | |
1711 | |
1712 " messages scrolled | |
1713 call term_sendkeys(buf, ":call RunTimer()\<CR>:echo \"one\\ntwo\\nthree\"\<CR>") | |
1714 call term_wait(buf, 50) | |
1715 call term_sendkeys(buf, "\<CR>") | |
1716 call term_sendkeys(buf, getstate) | |
1717 call WaitForAssert({-> assert_match('state: Scs; mode: r', term_getline(buf, 6))}, 1000) | |
1718 | |
1719 call StopVimInTerminal(buf) | |
1720 call delete('XState') | |
1721 endfunc |