blob: 86e046b5d609c56ee68832fcafc9f90c19c5c299 [file] [log] [blame]
Bram Moolenaar292eff02017-07-11 21:46:28 +02001" Tests for maparg().
2" Also test utf8 map with a 0x80 byte.
Bram Moolenaar292eff02017-07-11 21:46:28 +02003
4function s:SID()
5 return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
6endfun
7
8function Test_maparg()
9 new
10 set cpo-=<
11 set encoding=utf8
12 " Test maparg() with a string result
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020013 let sid = s:SID()
14 let lnum = expand('<sflnum>')
Bram Moolenaar292eff02017-07-11 21:46:28 +020015 map foo<C-V> is<F4>foo
16 vnoremap <script> <buffer> <expr> <silent> bar isbar
Bram Moolenaar292eff02017-07-11 21:46:28 +020017 call assert_equal("is<F4>foo", maparg('foo<C-V>'))
18 call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020019 \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1,
20 \ 'rhs': 'is<F4>foo', 'buffer': 0},
21 \ maparg('foo<C-V>', '', 0, 1))
Bram Moolenaar292eff02017-07-11 21:46:28 +020022 call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020023 \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2,
24 \ 'rhs': 'isbar', 'buffer': 1},
Bram Moolenaar292eff02017-07-11 21:46:28 +020025 \ maparg('bar', '', 0, 1))
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020026 let lnum = expand('<sflnum>')
Bram Moolenaar292eff02017-07-11 21:46:28 +020027 map <buffer> <nowait> foo bar
28 call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020029 \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar',
30 \ 'buffer': 1},
Bram Moolenaar292eff02017-07-11 21:46:28 +020031 \ maparg('foo', '', 0, 1))
32
33 map abc x<char-114>x
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020034 call assert_equal("xrx", maparg('abc'))
Bram Moolenaar292eff02017-07-11 21:46:28 +020035 map abc y<S-char-114>y
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020036 call assert_equal("yRy", maparg('abc'))
37
38 map abc <Nop>
39 call assert_equal("<Nop>", maparg('abc'))
40 unmap abc
Bram Moolenaar292eff02017-07-11 21:46:28 +020041endfunction
42
43function Test_range_map()
44 new
45 " Outside of the range, minimum
46 inoremap <Char-0x1040> a
47 execute "normal a\u1040\<Esc>"
48 " Inside of the range, minimum
49 inoremap <Char-0x103f> b
50 execute "normal a\u103f\<Esc>"
51 " Inside of the range, maximum
52 inoremap <Char-0xf03f> c
53 execute "normal a\uf03f\<Esc>"
54 " Outside of the range, maximum
55 inoremap <Char-0xf040> d
56 execute "normal a\uf040\<Esc>"
57 call assert_equal("abcd", getline(1))
58endfunction