blob: f7524f56d995d78b22f5bd3b4998339e9fd92d52 [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))
Bram Moolenaar14371ed2019-07-27 21:05:21 +020032 let lnum = expand('<sflnum>')
33 tmap baz foo
34 call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'baz', 'mode': 't',
35 \ 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'foo',
36 \ 'buffer': 0},
37 \ maparg('baz', 't', 0, 1))
Bram Moolenaar292eff02017-07-11 21:46:28 +020038
39 map abc x<char-114>x
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020040 call assert_equal("xrx", maparg('abc'))
Bram Moolenaar292eff02017-07-11 21:46:28 +020041 map abc y<S-char-114>y
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020042 call assert_equal("yRy", maparg('abc'))
43
44 map abc <Nop>
45 call assert_equal("<Nop>", maparg('abc'))
46 unmap abc
Bram Moolenaar292eff02017-07-11 21:46:28 +020047endfunction
48
49function Test_range_map()
50 new
51 " Outside of the range, minimum
52 inoremap <Char-0x1040> a
53 execute "normal a\u1040\<Esc>"
54 " Inside of the range, minimum
55 inoremap <Char-0x103f> b
56 execute "normal a\u103f\<Esc>"
57 " Inside of the range, maximum
58 inoremap <Char-0xf03f> c
59 execute "normal a\uf03f\<Esc>"
60 " Outside of the range, maximum
61 inoremap <Char-0xf040> d
62 execute "normal a\uf040\<Esc>"
63 call assert_equal("abcd", getline(1))
64endfunction