blob: c9e440edc092a77eefe2855a20356dec9799aa4b [file] [log] [blame]
Bram Moolenaar292eff02017-07-11 21:46:28 +02001" Tests for maparg().
2" Also test utf8 map with a 0x80 byte.
3if !has("multi_byte")
4 finish
5endif
6
7function s:SID()
8 return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
9endfun
10
11function Test_maparg()
12 new
13 set cpo-=<
14 set encoding=utf8
15 " Test maparg() with a string result
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020016 let sid = s:SID()
17 let lnum = expand('<sflnum>')
Bram Moolenaar292eff02017-07-11 21:46:28 +020018 map foo<C-V> is<F4>foo
19 vnoremap <script> <buffer> <expr> <silent> bar isbar
Bram Moolenaar292eff02017-07-11 21:46:28 +020020 call assert_equal("is<F4>foo", maparg('foo<C-V>'))
21 call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020022 \ '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 Moolenaar292eff02017-07-11 21:46:28 +020025 call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020026 \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2,
27 \ 'rhs': 'isbar', 'buffer': 1},
Bram Moolenaar292eff02017-07-11 21:46:28 +020028 \ maparg('bar', '', 0, 1))
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020029 let lnum = expand('<sflnum>')
Bram Moolenaar292eff02017-07-11 21:46:28 +020030 map <buffer> <nowait> foo bar
31 call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020032 \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar',
33 \ 'buffer': 1},
Bram Moolenaar292eff02017-07-11 21:46:28 +020034 \ maparg('foo', '', 0, 1))
35
36 map abc x<char-114>x
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020037 call assert_equal("xrx", maparg('abc'))
Bram Moolenaar292eff02017-07-11 21:46:28 +020038 map abc y<S-char-114>y
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020039 call assert_equal("yRy", maparg('abc'))
40
41 map abc <Nop>
42 call assert_equal("<Nop>", maparg('abc'))
43 unmap abc
Bram Moolenaar292eff02017-07-11 21:46:28 +020044endfunction
45
46function 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))
61endfunction