Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 1 | " Tests for maparg(). |
| 2 | " Also test utf8 map with a 0x80 byte. |
| 3 | if !has("multi_byte") |
| 4 | finish |
| 5 | endif |
| 6 | |
| 7 | function s:SID() |
| 8 | return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')) |
| 9 | endfun |
| 10 | |
| 11 | function Test_maparg() |
| 12 | new |
| 13 | set cpo-=< |
| 14 | set encoding=utf8 |
| 15 | " Test maparg() with a string result |
| 16 | map foo<C-V> is<F4>foo |
| 17 | vnoremap <script> <buffer> <expr> <silent> bar isbar |
| 18 | let sid = s:SID() |
| 19 | call assert_equal("is<F4>foo", maparg('foo<C-V>')) |
| 20 | call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>', |
| 21 | \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'rhs': 'is<F4>foo', |
| 22 | \ 'buffer': 0}, maparg('foo<C-V>', '', 0, 1)) |
| 23 | call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v', |
| 24 | \ 'nowait': 0, 'expr': 1, 'sid': sid, 'rhs': 'isbar', 'buffer': 1}, |
| 25 | \ maparg('bar', '', 0, 1)) |
| 26 | map <buffer> <nowait> foo bar |
| 27 | call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ', |
| 28 | \ 'nowait': 1, 'expr': 0, 'sid': sid, 'rhs': 'bar', 'buffer': 1}, |
| 29 | \ maparg('foo', '', 0, 1)) |
| 30 | |
| 31 | map abc x<char-114>x |
| 32 | call assert_equal(maparg('abc'), "xrx") |
| 33 | map abc y<S-char-114>y |
| 34 | call assert_equal(maparg('abc'), "yRy") |
| 35 | endfunction |
| 36 | |
| 37 | function Test_range_map() |
| 38 | new |
| 39 | " Outside of the range, minimum |
| 40 | inoremap <Char-0x1040> a |
| 41 | execute "normal a\u1040\<Esc>" |
| 42 | " Inside of the range, minimum |
| 43 | inoremap <Char-0x103f> b |
| 44 | execute "normal a\u103f\<Esc>" |
| 45 | " Inside of the range, maximum |
| 46 | inoremap <Char-0xf03f> c |
| 47 | execute "normal a\uf03f\<Esc>" |
| 48 | " Outside of the range, maximum |
| 49 | inoremap <Char-0xf040> d |
| 50 | execute "normal a\uf040\<Esc>" |
| 51 | call assert_equal("abcd", getline(1)) |
| 52 | endfunction |