blob: d6b61019bb853af9855321ede4d1913fb57a5b98 [file] [log] [blame]
Bram Moolenaar292eff02017-07-11 21:46:28 +02001" Tests for maparg().
2" Also test utf8 map with a 0x80 byte.
Bram Moolenaara1449832019-09-01 20:16:52 +02003" Also test mapcheck()
Bram Moolenaar292eff02017-07-11 21:46:28 +02004
5function s:SID()
6 return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
7endfun
8
9function Test_maparg()
10 new
11 set cpo-=<
12 set encoding=utf8
13 " Test maparg() with a string result
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020014 let sid = s:SID()
15 let lnum = expand('<sflnum>')
Bram Moolenaar292eff02017-07-11 21:46:28 +020016 map foo<C-V> is<F4>foo
17 vnoremap <script> <buffer> <expr> <silent> bar isbar
Bram Moolenaar292eff02017-07-11 21:46:28 +020018 call assert_equal("is<F4>foo", maparg('foo<C-V>'))
19 call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020020 \ '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 Moolenaar292eff02017-07-11 21:46:28 +020023 call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020024 \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2,
25 \ 'rhs': 'isbar', 'buffer': 1},
Bram Moolenaara1449832019-09-01 20:16:52 +020026 \ 'bar'->maparg('', 0, 1))
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020027 let lnum = expand('<sflnum>')
Bram Moolenaar292eff02017-07-11 21:46:28 +020028 map <buffer> <nowait> foo bar
29 call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ',
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020030 \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar',
31 \ 'buffer': 1},
Bram Moolenaar292eff02017-07-11 21:46:28 +020032 \ maparg('foo', '', 0, 1))
Bram Moolenaar14371ed2019-07-27 21:05:21 +020033 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 Moolenaar292eff02017-07-11 21:46:28 +020039
40 map abc x<char-114>x
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020041 call assert_equal("xrx", maparg('abc'))
Bram Moolenaar292eff02017-07-11 21:46:28 +020042 map abc y<S-char-114>y
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020043 call assert_equal("yRy", maparg('abc'))
44
Bram Moolenaar8ba6bb72020-01-20 20:41:42 +010045 omap { w
46 let d = maparg('{', 'o', 0, 1)
47 call assert_equal(['{', 'w', 'o'], [d.lhs, d.rhs, d.mode])
48 ounmap {
49
Bram Moolenaarc2a60ae2020-01-23 16:19:54 +010050 lmap { w
51 let d = maparg('{', 'l', 0, 1)
52 call assert_equal(['{', 'w', 'l'], [d.lhs, d.rhs, d.mode])
53 lunmap {
54
55 nmap { w
56 let d = maparg('{', 'n', 0, 1)
57 call assert_equal(['{', 'w', 'n'], [d.lhs, d.rhs, d.mode])
58 nunmap {
59
60 xmap { w
61 let d = maparg('{', 'x', 0, 1)
62 call assert_equal(['{', 'w', 'x'], [d.lhs, d.rhs, d.mode])
63 xunmap {
64
65 smap { w
66 let d = maparg('{', 's', 0, 1)
67 call assert_equal(['{', 'w', 's'], [d.lhs, d.rhs, d.mode])
68 sunmap {
69
Bram Moolenaarf88a5bc2018-05-21 13:28:44 +020070 map abc <Nop>
71 call assert_equal("<Nop>", maparg('abc'))
72 unmap abc
Bram Moolenaarc2a60ae2020-01-23 16:19:54 +010073
74 call feedkeys(":abbr esc \<C-V>\<C-V>\<C-V>\<C-V>\<C-V>\<Esc>\<CR>", "xt")
75 let d = maparg('esc', 'i', 1, 1)
76 call assert_equal(['esc', "\<C-V>\<C-V>\<Esc>", '!'], [d.lhs, d.rhs, d.mode])
77 abclear
Bram Moolenaar292eff02017-07-11 21:46:28 +020078endfunction
79
Bram Moolenaara1449832019-09-01 20:16:52 +020080func Test_mapcheck()
81 call assert_equal('', mapcheck('a'))
82 call assert_equal('', mapcheck('abc'))
83 call assert_equal('', mapcheck('ax'))
84 call assert_equal('', mapcheck('b'))
85
86 map a something
87 call assert_equal('something', mapcheck('a'))
88 call assert_equal('something', mapcheck('a', 'n'))
89 call assert_equal('', mapcheck('a', 'c'))
90 call assert_equal('', mapcheck('a', 'i'))
91 call assert_equal('something', 'abc'->mapcheck())
92 call assert_equal('something', 'ax'->mapcheck())
93 call assert_equal('', mapcheck('b'))
94 unmap a
95
96 map ab foobar
97 call assert_equal('foobar', mapcheck('a'))
98 call assert_equal('foobar', mapcheck('abc'))
99 call assert_equal('', mapcheck('ax'))
100 call assert_equal('', mapcheck('b'))
101 unmap ab
102
103 map abc barfoo
104 call assert_equal('barfoo', mapcheck('a'))
105 call assert_equal('barfoo', mapcheck('a', 'n', 0))
106 call assert_equal('', mapcheck('a', 'n', 1))
107 call assert_equal('barfoo', mapcheck('abc'))
108 call assert_equal('', mapcheck('ax'))
109 call assert_equal('', mapcheck('b'))
110 unmap abc
111
112 abbr ab abbrev
113 call assert_equal('abbrev', mapcheck('a', 'i', 1))
114 call assert_equal('', mapcheck('a', 'n', 1))
115 call assert_equal('', mapcheck('a', 'i', 0))
116 unabbr ab
117endfunc
118
Bram Moolenaar292eff02017-07-11 21:46:28 +0200119function Test_range_map()
120 new
121 " Outside of the range, minimum
122 inoremap <Char-0x1040> a
123 execute "normal a\u1040\<Esc>"
124 " Inside of the range, minimum
125 inoremap <Char-0x103f> b
126 execute "normal a\u103f\<Esc>"
127 " Inside of the range, maximum
128 inoremap <Char-0xf03f> c
129 execute "normal a\uf03f\<Esc>"
130 " Outside of the range, maximum
131 inoremap <Char-0xf040> d
132 execute "normal a\uf040\<Esc>"
133 call assert_equal("abcd", getline(1))
134endfunction
Bram Moolenaar8ba6bb72020-01-20 20:41:42 +0100135
136" vim: shiftwidth=2 sts=2 expandtab