0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 9.0.0449: there is no easy way to translate a key code into a string

Problem:    There is no easy way to translate a string with a key code into a
            readable string.
Solution:   Add the keytrans() function. (closes #11114)
This commit is contained in:
zeertzjq
2022-09-12 13:38:41 +01:00
committed by Bram Moolenaar
parent 5a4eb55122
commit cdc839353f
9 changed files with 83 additions and 15 deletions

View File

@@ -2764,6 +2764,32 @@ func Test_eval()
call assert_fails("call eval('5 a')", 'E488:')
endfunc
" Test for the keytrans() function
func Test_keytrans()
call assert_equal('<Space>', keytrans(' '))
call assert_equal('<lt>', keytrans('<'))
call assert_equal('<lt>Tab>', keytrans('<Tab>'))
call assert_equal('<Tab>', keytrans("\<Tab>"))
call assert_equal('<C-V>', keytrans("\<C-V>"))
call assert_equal('<BS>', keytrans("\<BS>"))
call assert_equal('<Home>', keytrans("\<Home>"))
call assert_equal('<C-Home>', keytrans("\<C-Home>"))
call assert_equal('<M-Home>', keytrans("\<M-Home>"))
call assert_equal('<C-Space>', keytrans("\<C-Space>"))
call assert_equal('<M-Space>', keytrans("\<*M-Space>"))
call assert_equal('<M-x>', "\<*M-x>"->keytrans())
call assert_equal('<C-I>', "\<*C-I>"->keytrans())
call assert_equal('<S-3>', "\<*S-3>"->keytrans())
call assert_equal('π', 'π'->keytrans())
call assert_equal('<M-π>', "\<M-π>"->keytrans())
call assert_equal('ě', 'ě'->keytrans())
call assert_equal('<M-ě>', "\<M-ě>"->keytrans())
call assert_equal('', ''->keytrans())
call assert_equal('', test_null_string()->keytrans())
call assert_fails('call keytrans(1)', 'E1174:')
call assert_fails('call keytrans()', 'E119:')
endfunc
" Test for the nr2char() function
func Test_nr2char()
set encoding=latin1