comparison src/testdir/test_maparg.vim @ 20506:aee0b72ca6d6 v8.2.0807

patch 8.2.0807: cannot easily restore a mapping Commit: https://github.com/vim/vim/commit/4c9243f9fb708c9010867d3cc8e928f36b58509a Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 22 13:10:44 2020 +0200 patch 8.2.0807: cannot easily restore a mapping Problem: Cannot easily restore a mapping. Solution: Add mapset().
author Bram Moolenaar <Bram@vim.org>
date Fri, 22 May 2020 13:15:04 +0200
parents 658248b68f7c
children d9e3fdf26cb9
comparison
equal deleted inserted replaced
20505:af5d9cf7e7a1 20506:aee0b72ca6d6
1 " Tests for maparg(). 1 " Tests for maparg(), mapcheck() and mapset().
2 " Also test utf8 map with a 0x80 byte. 2 " Also test utf8 map with a 0x80 byte.
3 " Also test mapcheck() 3 " Also test mapcheck()
4 4
5 function s:SID() 5 func s:SID()
6 return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')) 6 return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
7 endfun 7 endfunc
8 8
9 function Test_maparg() 9 funct Test_maparg()
10 new 10 new
11 set cpo-=< 11 set cpo-=<
12 set encoding=utf8 12 set encoding=utf8
13 " Test maparg() with a string result 13 " Test maparg() with a string result
14 let sid = s:SID() 14 let sid = s:SID()
16 map foo<C-V> is<F4>foo 16 map foo<C-V> is<F4>foo
17 vnoremap <script> <buffer> <expr> <silent> bar isbar 17 vnoremap <script> <buffer> <expr> <silent> bar isbar
18 call assert_equal("is<F4>foo", maparg('foo<C-V>')) 18 call assert_equal("is<F4>foo", maparg('foo<C-V>'))
19 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo<C-V>', 19 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo<C-V>',
20 \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 20 \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1,
21 \ 'rhs': 'is<F4>foo', 'buffer': 0}, 21 \ 'simplified': 1, 'rhs': 'is<F4>foo', 'buffer': 0},
22 \ maparg('foo<C-V>', '', 0, 1)) 22 \ maparg('foo<C-V>', '', 0, 1))
23 call assert_equal({'silent': 1, 'noremap': 1, 'script': 1, 'lhs': 'bar', 'mode': 'v', 23 call assert_equal({'silent': 1, 'noremap': 1, 'script': 1, 'lhs': 'bar', 'mode': 'v',
24 \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2, 24 \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2,
25 \ 'rhs': 'isbar', 'buffer': 1}, 25 \ 'simplified': 0, 'rhs': 'isbar', 'buffer': 1},
26 \ 'bar'->maparg('', 0, 1)) 26 \ 'bar'->maparg('', 0, 1))
27 let lnum = expand('<sflnum>') 27 let lnum = expand('<sflnum>')
28 map <buffer> <nowait> foo bar 28 map <buffer> <nowait> foo bar
29 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo', 'mode': ' ', 29 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo', 'mode': ' ',
30 \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar', 30 \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar',
31 \ 'buffer': 1}, 31 \ 'simplified': 0, 'buffer': 1},
32 \ maparg('foo', '', 0, 1)) 32 \ maparg('foo', '', 0, 1))
33 let lnum = expand('<sflnum>') 33 let lnum = expand('<sflnum>')
34 tmap baz foo 34 tmap baz foo
35 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'baz', 'mode': 't', 35 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'baz', 'mode': 't',
36 \ 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'foo', 36 \ 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'foo',
37 \ 'buffer': 0}, 37 \ 'simplified': 0, 'buffer': 0},
38 \ maparg('baz', 't', 0, 1)) 38 \ maparg('baz', 't', 0, 1))
39 39
40 map abc x<char-114>x 40 map abc x<char-114>x
41 call assert_equal("xrx", maparg('abc')) 41 call assert_equal("xrx", maparg('abc'))
42 map abc y<S-char-114>y 42 map abc y<S-char-114>y
73 73
74 call feedkeys(":abbr esc \<C-V>\<C-V>\<C-V>\<C-V>\<C-V>\<Esc>\<CR>", "xt") 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) 75 let d = maparg('esc', 'i', 1, 1)
76 call assert_equal(['esc', "\<C-V>\<C-V>\<Esc>", '!'], [d.lhs, d.rhs, d.mode]) 76 call assert_equal(['esc', "\<C-V>\<C-V>\<Esc>", '!'], [d.lhs, d.rhs, d.mode])
77 abclear 77 abclear
78 endfunction 78 endfunc
79 79
80 func Test_mapcheck() 80 func Test_mapcheck()
81 call assert_equal('', mapcheck('a')) 81 call assert_equal('', mapcheck('a'))
82 call assert_equal('', mapcheck('abc')) 82 call assert_equal('', mapcheck('abc'))
83 call assert_equal('', mapcheck('ax')) 83 call assert_equal('', mapcheck('ax'))
114 call assert_equal('', mapcheck('a', 'n', 1)) 114 call assert_equal('', mapcheck('a', 'n', 1))
115 call assert_equal('', mapcheck('a', 'i', 0)) 115 call assert_equal('', mapcheck('a', 'i', 0))
116 unabbr ab 116 unabbr ab
117 endfunc 117 endfunc
118 118
119 function Test_range_map() 119 func Test_range_map()
120 new 120 new
121 " Outside of the range, minimum 121 " Outside of the range, minimum
122 inoremap <Char-0x1040> a 122 inoremap <Char-0x1040> a
123 execute "normal a\u1040\<Esc>" 123 execute "normal a\u1040\<Esc>"
124 " Inside of the range, minimum 124 " Inside of the range, minimum
129 execute "normal a\uf03f\<Esc>" 129 execute "normal a\uf03f\<Esc>"
130 " Outside of the range, maximum 130 " Outside of the range, maximum
131 inoremap <Char-0xf040> d 131 inoremap <Char-0xf040> d
132 execute "normal a\uf040\<Esc>" 132 execute "normal a\uf040\<Esc>"
133 call assert_equal("abcd", getline(1)) 133 call assert_equal("abcd", getline(1))
134 endfunction 134 endfunc
135
136 func One_mapset_test(keys)
137 exe 'nnoremap ' .. a:keys .. ' original<CR>'
138 let orig = maparg(a:keys, 'n', 0, 1)
139 call assert_equal(a:keys, orig.lhs)
140 call assert_equal('original<CR>', orig.rhs)
141 call assert_equal('n', orig.mode)
142
143 exe 'nunmap ' .. a:keys
144 let d = maparg(a:keys, 'n', 0, 1)
145 call assert_equal({}, d)
146
147 call mapset('n', 0, orig)
148 let d = maparg(a:keys, 'n', 0, 1)
149 call assert_equal(a:keys, d.lhs)
150 call assert_equal('original<CR>', d.rhs)
151 call assert_equal('n', d.mode)
152
153 exe 'nunmap ' .. a:keys
154 endfunc
155
156 func Test_mapset()
157 call One_mapset_test('K')
158 call One_mapset_test('<F3>')
159 endfunc
135 160
136 " vim: shiftwidth=2 sts=2 expandtab 161 " vim: shiftwidth=2 sts=2 expandtab