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. |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 3 | " Also test mapcheck() |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 4 | |
| 5 | function s:SID() |
| 6 | return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')) |
| 7 | endfun |
| 8 | |
| 9 | function Test_maparg() |
| 10 | new |
| 11 | set cpo-=< |
| 12 | set encoding=utf8 |
| 13 | " Test maparg() with a string result |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 14 | let sid = s:SID() |
| 15 | let lnum = expand('<sflnum>') |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 16 | map foo<C-V> is<F4>foo |
| 17 | vnoremap <script> <buffer> <expr> <silent> bar isbar |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 18 | call assert_equal("is<F4>foo", maparg('foo<C-V>')) |
| 19 | call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>', |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 20 | \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, |
| 21 | \ 'rhs': 'is<F4>foo', 'buffer': 0}, |
| 22 | \ maparg('foo<C-V>', '', 0, 1)) |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 23 | call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v', |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 24 | \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2, |
| 25 | \ 'rhs': 'isbar', 'buffer': 1}, |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 26 | \ 'bar'->maparg('', 0, 1)) |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 27 | let lnum = expand('<sflnum>') |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 28 | map <buffer> <nowait> foo bar |
| 29 | call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ', |
Bram Moolenaar | f29c1c6 | 2018-09-10 21:05:02 +0200 | [diff] [blame] | 30 | \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar', |
| 31 | \ 'buffer': 1}, |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 32 | \ maparg('foo', '', 0, 1)) |
Bram Moolenaar | 14371ed | 2019-07-27 21:05:21 +0200 | [diff] [blame] | 33 | let lnum = expand('<sflnum>') |
| 34 | tmap baz foo |
| 35 | call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'baz', 'mode': 't', |
| 36 | \ 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'foo', |
| 37 | \ 'buffer': 0}, |
| 38 | \ maparg('baz', 't', 0, 1)) |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 39 | |
| 40 | map abc x<char-114>x |
Bram Moolenaar | f88a5bc | 2018-05-21 13:28:44 +0200 | [diff] [blame] | 41 | call assert_equal("xrx", maparg('abc')) |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 42 | map abc y<S-char-114>y |
Bram Moolenaar | f88a5bc | 2018-05-21 13:28:44 +0200 | [diff] [blame] | 43 | call assert_equal("yRy", maparg('abc')) |
| 44 | |
| 45 | map abc <Nop> |
| 46 | call assert_equal("<Nop>", maparg('abc')) |
| 47 | unmap abc |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 48 | endfunction |
| 49 | |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 50 | func Test_mapcheck() |
| 51 | call assert_equal('', mapcheck('a')) |
| 52 | call assert_equal('', mapcheck('abc')) |
| 53 | call assert_equal('', mapcheck('ax')) |
| 54 | call assert_equal('', mapcheck('b')) |
| 55 | |
| 56 | map a something |
| 57 | call assert_equal('something', mapcheck('a')) |
| 58 | call assert_equal('something', mapcheck('a', 'n')) |
| 59 | call assert_equal('', mapcheck('a', 'c')) |
| 60 | call assert_equal('', mapcheck('a', 'i')) |
| 61 | call assert_equal('something', 'abc'->mapcheck()) |
| 62 | call assert_equal('something', 'ax'->mapcheck()) |
| 63 | call assert_equal('', mapcheck('b')) |
| 64 | unmap a |
| 65 | |
| 66 | map ab foobar |
| 67 | call assert_equal('foobar', mapcheck('a')) |
| 68 | call assert_equal('foobar', mapcheck('abc')) |
| 69 | call assert_equal('', mapcheck('ax')) |
| 70 | call assert_equal('', mapcheck('b')) |
| 71 | unmap ab |
| 72 | |
| 73 | map abc barfoo |
| 74 | call assert_equal('barfoo', mapcheck('a')) |
| 75 | call assert_equal('barfoo', mapcheck('a', 'n', 0)) |
| 76 | call assert_equal('', mapcheck('a', 'n', 1)) |
| 77 | call assert_equal('barfoo', mapcheck('abc')) |
| 78 | call assert_equal('', mapcheck('ax')) |
| 79 | call assert_equal('', mapcheck('b')) |
| 80 | unmap abc |
| 81 | |
| 82 | abbr ab abbrev |
| 83 | call assert_equal('abbrev', mapcheck('a', 'i', 1)) |
| 84 | call assert_equal('', mapcheck('a', 'n', 1)) |
| 85 | call assert_equal('', mapcheck('a', 'i', 0)) |
| 86 | unabbr ab |
| 87 | endfunc |
| 88 | |
Bram Moolenaar | 292eff0 | 2017-07-11 21:46:28 +0200 | [diff] [blame] | 89 | function Test_range_map() |
| 90 | new |
| 91 | " Outside of the range, minimum |
| 92 | inoremap <Char-0x1040> a |
| 93 | execute "normal a\u1040\<Esc>" |
| 94 | " Inside of the range, minimum |
| 95 | inoremap <Char-0x103f> b |
| 96 | execute "normal a\u103f\<Esc>" |
| 97 | " Inside of the range, maximum |
| 98 | inoremap <Char-0xf03f> c |
| 99 | execute "normal a\uf03f\<Esc>" |
| 100 | " Outside of the range, maximum |
| 101 | inoremap <Char-0xf040> d |
| 102 | execute "normal a\uf040\<Esc>" |
| 103 | call assert_equal("abcd", getline(1)) |
| 104 | endfunction |