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 |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame^] | 16 | let sid = s:SID() |
| 17 | let lnum = expand('<sflnum>') |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 18 | map foo<C-V> is<F4>foo |
| 19 | vnoremap <script> <buffer> <expr> <silent> bar isbar |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 20 | call assert_equal("is<F4>foo", maparg('foo<C-V>')) |
| 21 | call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>', |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame^] | 22 | \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, |
| 23 | \ 'rhs': 'is<F4>foo', 'buffer': 0}, |
| 24 | \ maparg('foo<C-V>', '', 0, 1)) |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 25 | call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v', |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame^] | 26 | \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2, |
| 27 | \ 'rhs': 'isbar', 'buffer': 1}, |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 28 | \ maparg('bar', '', 0, 1)) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame^] | 29 | let lnum = expand('<sflnum>') |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 30 | map <buffer> <nowait> foo bar |
| 31 | call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ', |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame^] | 32 | \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar', |
| 33 | \ 'buffer': 1}, |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 34 | \ maparg('foo', '', 0, 1)) |
| 35 | |
| 36 | map abc x<char-114>x |
Bram Moolenaar | f88a5bc | 2018-05-21 13:28:44 +0200 | [diff] [blame] | 37 | call assert_equal("xrx", maparg('abc')) |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 38 | map abc y<S-char-114>y |
Bram Moolenaar | f88a5bc | 2018-05-21 13:28:44 +0200 | [diff] [blame] | 39 | call assert_equal("yRy", maparg('abc')) |
| 40 | |
| 41 | map abc <Nop> |
| 42 | call assert_equal("<Nop>", maparg('abc')) |
| 43 | unmap abc |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 44 | endfunction |
| 45 | |
| 46 | function Test_range_map() |
| 47 | new |
| 48 | " Outside of the range, minimum |
| 49 | inoremap <Char-0x1040> a |
| 50 | execute "normal a\u1040\<Esc>" |
| 51 | " Inside of the range, minimum |
| 52 | inoremap <Char-0x103f> b |
| 53 | execute "normal a\u103f\<Esc>" |
| 54 | " Inside of the range, maximum |
| 55 | inoremap <Char-0xf03f> c |
| 56 | execute "normal a\uf03f\<Esc>" |
| 57 | " Outside of the range, maximum |
| 58 | inoremap <Char-0xf040> d |
| 59 | execute "normal a\uf040\<Esc>" |
| 60 | call assert_equal("abcd", getline(1)) |
| 61 | endfunction |