annotate src/testdir/test_map_functions.vim @ 28614:9ae2c32841fb v8.2.4831

patch 8.2.4831: crash when using maparg() and unmapping simplified keys Commit: https://github.com/vim/vim/commit/2c8a7ebdad9da017bfb6dc8a0f46acea77ec2e17 Author: zeertzjq <zeertzjq@outlook.com> Date: Tue Apr 26 21:36:21 2022 +0100 patch 8.2.4831: crash when using maparg() and unmapping simplified keys Problem: Crash when using maparg() and unmapping simplified keys. Solution: Do not keep a mapblock pointer. (closes https://github.com/vim/vim/issues/10294)
author Bram Moolenaar <Bram@vim.org>
date Tue, 26 Apr 2022 22:45:03 +0200
parents 398c5b3211f9
children 38f7a132bba3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
1 " Tests for maparg(), mapcheck(), mapset(), maplist()
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Also test utf8 map with a 0x80 byte.
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3
20506
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
4 func s:SID()
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
20506
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
6 endfunc
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
20516
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
8 func Test_maparg()
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 new
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 set cpo-=<
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 set encoding=utf8
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " Test maparg() with a string result
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 13986
diff changeset
13 let sid = s:SID()
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 13986
diff changeset
14 let lnum = expand('<sflnum>')
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 map foo<C-V> is<F4>foo
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 vnoremap <script> <buffer> <expr> <silent> bar isbar
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_equal("is<F4>foo", maparg('foo<C-V>'))
19870
658248b68f7c patch 8.2.0491: cannot recognize a <script> mapping using maparg()
Bram Moolenaar <Bram@vim.org>
parents: 19170
diff changeset
18 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo<C-V>',
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
19 \ 'lhsraw': "foo\x80\xfc\x04V", 'lhsrawalt': "foo\x16",
27223
ea2b4cb4515b patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents: 24529
diff changeset
20 \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'scriptversion': 1,
ea2b4cb4515b patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents: 24529
diff changeset
21 \ 'lnum': lnum + 1,
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
22 \ 'rhs': 'is<F4>foo', 'buffer': 0},
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 13986
diff changeset
23 \ maparg('foo<C-V>', '', 0, 1))
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
24 call assert_equal({'silent': 1, 'noremap': 1, 'script': 1, 'lhs': 'bar',
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
25 \ 'lhsraw': 'bar', 'mode': 'v',
27223
ea2b4cb4515b patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents: 24529
diff changeset
26 \ 'nowait': 0, 'expr': 1, 'sid': sid, 'scriptversion': 1,
ea2b4cb4515b patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents: 24529
diff changeset
27 \ 'lnum': lnum + 2,
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
28 \ 'rhs': 'isbar', 'buffer': 1},
17930
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
29 \ 'bar'->maparg('', 0, 1))
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 13986
diff changeset
30 let lnum = expand('<sflnum>')
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 map <buffer> <nowait> foo bar
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
32 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo',
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
33 \ 'lhsraw': 'foo', 'mode': ' ',
27223
ea2b4cb4515b patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents: 24529
diff changeset
34 \ 'nowait': 1, 'expr': 0, 'sid': sid, 'scriptversion': 1,
ea2b4cb4515b patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents: 24529
diff changeset
35 \ 'lnum': lnum + 1, 'rhs': 'bar',
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
36 \ 'buffer': 1},
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 \ maparg('foo', '', 0, 1))
17522
e17cbc3e545d patch 8.1.1759: no mode char for terminal mapping from maparg()
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
38 let lnum = expand('<sflnum>')
e17cbc3e545d patch 8.1.1759: no mode char for terminal mapping from maparg()
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
39 tmap baz foo
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
40 call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'baz',
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
41 \ 'lhsraw': 'baz', 'mode': 't',
27223
ea2b4cb4515b patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents: 24529
diff changeset
42 \ 'nowait': 0, 'expr': 0, 'sid': sid, 'scriptversion': 1,
ea2b4cb4515b patch 8.2.4140: maparg() does not indicate the type of script
Bram Moolenaar <Bram@vim.org>
parents: 24529
diff changeset
43 \ 'lnum': lnum + 1, 'rhs': 'foo',
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
44 \ 'buffer': 0},
17522
e17cbc3e545d patch 8.1.1759: no mode char for terminal mapping from maparg()
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
45 \ maparg('baz', 't', 0, 1))
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 map abc x<char-114>x
13986
4a41a169e5ea patch 8.1.0011: maparg() and mapcheck() confuse empty and non-existing
Christian Brabandt <cb@256bit.org>
parents: 11651
diff changeset
48 call assert_equal("xrx", maparg('abc'))
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 map abc y<S-char-114>y
13986
4a41a169e5ea patch 8.1.0011: maparg() and mapcheck() confuse empty and non-existing
Christian Brabandt <cb@256bit.org>
parents: 11651
diff changeset
50 call assert_equal("yRy", maparg('abc'))
4a41a169e5ea patch 8.1.0011: maparg() and mapcheck() confuse empty and non-existing
Christian Brabandt <cb@256bit.org>
parents: 11651
diff changeset
51
19149
643c6c3c0da4 patch 8.2.0134: some map functionality not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 17930
diff changeset
52 omap { w
643c6c3c0da4 patch 8.2.0134: some map functionality not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 17930
diff changeset
53 let d = maparg('{', 'o', 0, 1)
643c6c3c0da4 patch 8.2.0134: some map functionality not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 17930
diff changeset
54 call assert_equal(['{', 'w', 'o'], [d.lhs, d.rhs, d.mode])
643c6c3c0da4 patch 8.2.0134: some map functionality not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 17930
diff changeset
55 ounmap {
643c6c3c0da4 patch 8.2.0134: some map functionality not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 17930
diff changeset
56
19170
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
57 lmap { w
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
58 let d = maparg('{', 'l', 0, 1)
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
59 call assert_equal(['{', 'w', 'l'], [d.lhs, d.rhs, d.mode])
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
60 lunmap {
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
61
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
62 nmap { w
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
63 let d = maparg('{', 'n', 0, 1)
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
64 call assert_equal(['{', 'w', 'n'], [d.lhs, d.rhs, d.mode])
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
65 nunmap {
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
66
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
67 xmap { w
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
68 let d = maparg('{', 'x', 0, 1)
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
69 call assert_equal(['{', 'w', 'x'], [d.lhs, d.rhs, d.mode])
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
70 xunmap {
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
71
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
72 smap { w
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
73 let d = maparg('{', 's', 0, 1)
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
74 call assert_equal(['{', 'w', 's'], [d.lhs, d.rhs, d.mode])
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
75 sunmap {
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
76
28614
9ae2c32841fb patch 8.2.4831: crash when using maparg() and unmapping simplified keys
Bram Moolenaar <Bram@vim.org>
parents: 28602
diff changeset
77 map <C-I> foo
9ae2c32841fb patch 8.2.4831: crash when using maparg() and unmapping simplified keys
Bram Moolenaar <Bram@vim.org>
parents: 28602
diff changeset
78 unmap <Tab>
9ae2c32841fb patch 8.2.4831: crash when using maparg() and unmapping simplified keys
Bram Moolenaar <Bram@vim.org>
parents: 28602
diff changeset
79 " This used to cause a segfault
9ae2c32841fb patch 8.2.4831: crash when using maparg() and unmapping simplified keys
Bram Moolenaar <Bram@vim.org>
parents: 28602
diff changeset
80 call maparg('<C-I>', '', 0, 1)
9ae2c32841fb patch 8.2.4831: crash when using maparg() and unmapping simplified keys
Bram Moolenaar <Bram@vim.org>
parents: 28602
diff changeset
81 unmap <C-I>
9ae2c32841fb patch 8.2.4831: crash when using maparg() and unmapping simplified keys
Bram Moolenaar <Bram@vim.org>
parents: 28602
diff changeset
82
13986
4a41a169e5ea patch 8.1.0011: maparg() and mapcheck() confuse empty and non-existing
Christian Brabandt <cb@256bit.org>
parents: 11651
diff changeset
83 map abc <Nop>
4a41a169e5ea patch 8.1.0011: maparg() and mapcheck() confuse empty and non-existing
Christian Brabandt <cb@256bit.org>
parents: 11651
diff changeset
84 call assert_equal("<Nop>", maparg('abc'))
4a41a169e5ea patch 8.1.0011: maparg() and mapcheck() confuse empty and non-existing
Christian Brabandt <cb@256bit.org>
parents: 11651
diff changeset
85 unmap abc
19170
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
86
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
87 call feedkeys(":abbr esc \<C-V>\<C-V>\<C-V>\<C-V>\<C-V>\<Esc>\<CR>", "xt")
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
88 let d = maparg('esc', 'i', 1, 1)
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
89 call assert_equal(['esc', "\<C-V>\<C-V>\<Esc>", '!'], [d.lhs, d.rhs, d.mode])
ad40333f2ec0 patch 8.2.0144: some mapping code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 19149
diff changeset
90 abclear
28614
9ae2c32841fb patch 8.2.4831: crash when using maparg() and unmapping simplified keys
Bram Moolenaar <Bram@vim.org>
parents: 28602
diff changeset
91 unlet d
20506
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
92 endfunc
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93
21695
f27187782dc6 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Bram Moolenaar <Bram@vim.org>
parents: 20522
diff changeset
94 def Test_vim9_maparg()
f27187782dc6 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Bram Moolenaar <Bram@vim.org>
parents: 20522
diff changeset
95 nmap { w
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22147
diff changeset
96 var one: string = maparg('{')
21695
f27187782dc6 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Bram Moolenaar <Bram@vim.org>
parents: 20522
diff changeset
97 assert_equal('w', one)
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22147
diff changeset
98 var two: string = maparg('{', 'n')
21695
f27187782dc6 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Bram Moolenaar <Bram@vim.org>
parents: 20522
diff changeset
99 assert_equal('w', two)
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22147
diff changeset
100 var three: string = maparg('{', 'n', 0)
21695
f27187782dc6 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Bram Moolenaar <Bram@vim.org>
parents: 20522
diff changeset
101 assert_equal('w', three)
22435
166a0f17b05e patch 8.2.1766: Vim9: Some tests are still using :let
Bram Moolenaar <Bram@vim.org>
parents: 22147
diff changeset
102 var four: dict<any> = maparg('{', 'n', 0, 1)
22147
d55008685870 patch 8.2.1623: Vim9: using :call where it is not needed
Bram Moolenaar <Bram@vim.org>
parents: 21695
diff changeset
103 assert_equal(['{', 'w', 'n'], [four.lhs, four.rhs, four.mode])
21695
f27187782dc6 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Bram Moolenaar <Bram@vim.org>
parents: 20522
diff changeset
104 nunmap {
f27187782dc6 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Bram Moolenaar <Bram@vim.org>
parents: 20522
diff changeset
105 enddef
f27187782dc6 patch 8.2.1397: Vim9: return type of maparg() not adjusted for fourth arg
Bram Moolenaar <Bram@vim.org>
parents: 20522
diff changeset
106
17930
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
107 func Test_mapcheck()
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
108 call assert_equal('', mapcheck('a'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
109 call assert_equal('', mapcheck('abc'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
110 call assert_equal('', mapcheck('ax'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
111 call assert_equal('', mapcheck('b'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
112
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
113 map a something
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
114 call assert_equal('something', mapcheck('a'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
115 call assert_equal('something', mapcheck('a', 'n'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
116 call assert_equal('', mapcheck('a', 'c'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
117 call assert_equal('', mapcheck('a', 'i'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
118 call assert_equal('something', 'abc'->mapcheck())
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
119 call assert_equal('something', 'ax'->mapcheck())
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
120 call assert_equal('', mapcheck('b'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
121 unmap a
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
122
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
123 map ab foobar
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
124 call assert_equal('foobar', mapcheck('a'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
125 call assert_equal('foobar', mapcheck('abc'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
126 call assert_equal('', mapcheck('ax'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
127 call assert_equal('', mapcheck('b'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
128 unmap ab
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
129
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
130 map abc barfoo
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
131 call assert_equal('barfoo', mapcheck('a'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
132 call assert_equal('barfoo', mapcheck('a', 'n', 0))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
133 call assert_equal('', mapcheck('a', 'n', 1))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
134 call assert_equal('barfoo', mapcheck('abc'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
135 call assert_equal('', mapcheck('ax'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
136 call assert_equal('', mapcheck('b'))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
137 unmap abc
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
138
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
139 abbr ab abbrev
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
140 call assert_equal('abbrev', mapcheck('a', 'i', 1))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
141 call assert_equal('', mapcheck('a', 'n', 1))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
142 call assert_equal('', mapcheck('a', 'i', 0))
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
143 unabbr ab
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
144 endfunc
0cdb6ac20748 patch 8.1.1961: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17522
diff changeset
145
20506
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
146 func Test_range_map()
11651
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 new
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 " Outside of the range, minimum
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 inoremap <Char-0x1040> a
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 execute "normal a\u1040\<Esc>"
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 " Inside of the range, minimum
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152 inoremap <Char-0x103f> b
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 execute "normal a\u103f\<Esc>"
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 " Inside of the range, maximum
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 inoremap <Char-0xf03f> c
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 execute "normal a\uf03f\<Esc>"
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 " Outside of the range, maximum
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 inoremap <Char-0xf040> d
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 execute "normal a\uf040\<Esc>"
140d51d5b5c3 patch 8.0.0708: some tests are old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160 call assert_equal("abcd", getline(1))
20506
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
161 endfunc
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
162
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
163 func One_mapset_test(keys)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
164 exe 'nnoremap ' .. a:keys .. ' original<CR>'
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
165 let orig = maparg(a:keys, 'n', 0, 1)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
166 call assert_equal(a:keys, orig.lhs)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
167 call assert_equal('original<CR>', orig.rhs)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
168 call assert_equal('n', orig.mode)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
169
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
170 exe 'nunmap ' .. a:keys
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
171 let d = maparg(a:keys, 'n', 0, 1)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
172 call assert_equal({}, d)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
173
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
174 call mapset('n', 0, orig)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
175 let d = maparg(a:keys, 'n', 0, 1)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
176 call assert_equal(a:keys, d.lhs)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
177 call assert_equal('original<CR>', d.rhs)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
178 call assert_equal('n', d.mode)
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
179
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
180 exe 'nunmap ' .. a:keys
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
181 endfunc
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
182
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
183 func Test_mapset()
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
184 call One_mapset_test('K')
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
185 call One_mapset_test('<F3>')
20516
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
186
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
187 " Check <> key conversion
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
188 new
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
189 inoremap K one<Left>x
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
190 call feedkeys("iK\<Esc>", 'xt')
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
191 call assert_equal('onxe', getline(1))
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
192
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
193 let orig = maparg('K', 'i', 0, 1)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
194 call assert_equal('K', orig.lhs)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
195 call assert_equal('one<Left>x', orig.rhs)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
196 call assert_equal('i', orig.mode)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
197
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
198 iunmap K
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
199 let d = maparg('K', 'i', 0, 1)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
200 call assert_equal({}, d)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
201
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
202 call mapset('i', 0, orig)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
203 call feedkeys("SK\<Esc>", 'xt')
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
204 call assert_equal('onxe', getline(1))
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
205
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
206 iunmap K
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
207
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
208 " Test literal <CR> using a backslash
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
209 let cpo_save = &cpo
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
210 set cpo-=B
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
211 inoremap K one\<CR>two
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
212 call feedkeys("SK\<Esc>", 'xt')
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
213 call assert_equal('one<CR>two', getline(1))
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
214
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
215 let orig = maparg('K', 'i', 0, 1)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
216 call assert_equal('K', orig.lhs)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
217 call assert_equal('one\<CR>two', orig.rhs)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
218 call assert_equal('i', orig.mode)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
219
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
220 iunmap K
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
221 let d = maparg('K', 'i', 0, 1)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
222 call assert_equal({}, d)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
223
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
224 call mapset('i', 0, orig)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
225 call feedkeys("SK\<Esc>", 'xt')
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
226 call assert_equal('one<CR>two', getline(1))
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
227
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
228 iunmap K
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
229
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
230 " Test literal <CR> using CTRL-V
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
231 inoremap K one<CR>two
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
232 call feedkeys("SK\<Esc>", 'xt')
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
233 call assert_equal('one<CR>two', getline(1))
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
234
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
235 let orig = maparg('K', 'i', 0, 1)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
236 call assert_equal('K', orig.lhs)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
237 call assert_equal("one\x16<CR>two", orig.rhs)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
238 call assert_equal('i', orig.mode)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
239
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
240 iunmap K
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
241 let d = maparg('K', 'i', 0, 1)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
242 call assert_equal({}, d)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
243
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
244 call mapset('i', 0, orig)
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
245 call feedkeys("SK\<Esc>", 'xt')
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
246 call assert_equal('one<CR>two', getline(1))
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
247
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
248 iunmap K
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
249 let &cpo = cpo_save
d9e3fdf26cb9 patch 8.2.0812: mapset() does not properly handle <> notation
Bram Moolenaar <Bram@vim.org>
parents: 20506
diff changeset
250 bwipe!
22450
9b09676b9e0e patch 8.2.1773: crash when calling mapset() with a list as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
251
9b09676b9e0e patch 8.2.1773: crash when calling mapset() with a list as first argument
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
252 call assert_fails('call mapset([], v:false, {})', 'E730:')
23984
e27b5529dc6a patch 8.2.2534: missing test coverage
Bram Moolenaar <Bram@vim.org>
parents: 22450
diff changeset
253 call assert_fails('call mapset("i", 0, "")', 'E716:')
e27b5529dc6a patch 8.2.2534: missing test coverage
Bram Moolenaar <Bram@vim.org>
parents: 22450
diff changeset
254 call assert_fails('call mapset("i", 0, {})', 'E460:')
20506
aee0b72ca6d6 patch 8.2.0807: cannot easily restore a mapping
Bram Moolenaar <Bram@vim.org>
parents: 19870
diff changeset
255 endfunc
19149
643c6c3c0da4 patch 8.2.0134: some map functionality not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 17930
diff changeset
256
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
257 func Check_ctrlb_map(d, check_alt)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
258 call assert_equal('<C-B>', a:d.lhs)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
259 if a:check_alt
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
260 call assert_equal("\x80\xfc\x04B", a:d.lhsraw)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
261 call assert_equal("\x02", a:d.lhsrawalt)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
262 else
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
263 call assert_equal("\x02", a:d.lhsraw)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
264 endif
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
265 endfunc
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
266
24529
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
267 func Test_map_local()
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
268 nmap a global
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
269 nmap <buffer>a local
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
270
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
271 let prev_map_list = split(execute('nmap a'), "\n")
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
272 call assert_match('n\s*a\s*@local', prev_map_list[0])
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
273 call assert_match('n\s*a\s*global', prev_map_list[1])
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
274
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
275 let mapping = maparg('a', 'n', 0, 1)
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
276 call assert_equal(1, mapping.buffer)
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
277 let mapping.rhs = 'new_local'
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
278 call mapset('n', 0, mapping)
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
279
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
280 " Check that the global mapping is left untouched.
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
281 let map_list = split(execute('nmap a'), "\n")
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
282 call assert_match('n\s*a\s*@new_local', map_list[0])
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
283 call assert_match('n\s*a\s*global', map_list[1])
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
284
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
285 nunmap a
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
286 endfunc
db2b4e867d06 patch 8.2.2804: setting buffer local mapping with mapset() changes global
Bram Moolenaar <Bram@vim.org>
parents: 23984
diff changeset
287
20522
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
288 func Test_map_restore()
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
289 " Test restoring map with alternate keycode
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
290 nmap <C-B> back
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
291 let d = maparg('<C-B>', 'n', 0, 1)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
292 call Check_ctrlb_map(d, 1)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
293 let dsimp = maparg("\x02", 'n', 0, 1)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
294 call Check_ctrlb_map(dsimp, 0)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
295 nunmap <C-B>
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
296 call mapset('n', 0, d)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
297 let d = maparg('<C-B>', 'n', 0, 1)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
298 call Check_ctrlb_map(d, 1)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
299 let dsimp = maparg("\x02", 'n', 0, 1)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
300 call Check_ctrlb_map(dsimp, 0)
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
301
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
302 nunmap <C-B>
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
303
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
304 endfunc
729853a754ea patch 8.2.0815: maparg() does not provide enough information for mapset()
Bram Moolenaar <Bram@vim.org>
parents: 20516
diff changeset
305
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
306 def Test_maplist()
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
307 new
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
308 def ClearMappingsAbbreviations()
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
309 mapclear | nmapclear | vmapclear | xmapclear | smapclear | omapclear
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
310 mapclear! | imapclear | lmapclear | cmapclear | tmapclear
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
311 mapclear <buffer> | nmapclear <buffer> | vmapclear <buffer>
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
312 xmapclear <buffer> | smapclear <buffer> | omapclear <buffer>
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
313 mapclear! <buffer> | imapclear <buffer> | lmapclear <buffer>
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
314 cmapclear <buffer> | tmapclear <buffer>
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
315 abclear | abclear <buffer>
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
316 enddef
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
317
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
318 def AddMaps(new: list<string>, accum: list<string>)
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
319 if len(new) > 0 && new[0] != "No mapping found"
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
320 accum->extend(new)
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
321 endif
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
322 enddef
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
323
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
324 ClearMappingsAbbreviations()
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
325 assert_equal(0, len(maplist()))
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
326 assert_equal(0, len(maplist(true)))
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
327
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
328 # Set up some mappings.
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
329 map dup bar
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
330 map <buffer> dup bufbar
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
331 map foo<C-V> is<F4>foo
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
332 vnoremap <script> <buffer> <expr> <silent> bar isbar
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
333 tmap baz foo
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
334 omap h w
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
335 lmap i w
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
336 nmap j w
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
337 xmap k w
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
338 smap l w
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
339 map abc <Nop>
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
340 nmap <M-j> x
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
341 nmap <M-Space> y
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
342 # And abbreviations
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
343 abbreviate xy he
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
344 abbreviate xx she
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
345 abbreviate <buffer> x they
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
346
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
347 # Get a list of the mappings with the ':map' commands.
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
348 # Check maplist() return a list of the same size.
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
349 assert_equal(13, len(maplist()))
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
350 assert_equal(3, len(maplist(true)))
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
351 assert_equal(13, len(maplist(false)))
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
352
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
353 # collect all the current maps using :map commands
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
354 var maps_command: list<string>
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
355 AddMaps(split(execute('map'), '\n'), maps_command)
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
356 AddMaps(split(execute('map!'), '\n'), maps_command)
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
357 AddMaps(split(execute('tmap'), '\n'), maps_command)
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
358 AddMaps(split(execute('lmap'), '\n'), maps_command)
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
359
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
360 # Use maplist to get all the maps
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
361 var maps_maplist = maplist()
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
362 assert_equal(len(maps_command), len(maps_maplist))
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
363
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
364 # make sure all the mode-lhs are unique, no duplicates
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
365 var map_set: dict<number>
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
366 for d in maps_maplist
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
367 map_set[d.mode .. "-" .. d.lhs .. "-" .. d.buffer] = 0
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
368 endfor
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
369 assert_equal(len(maps_maplist), len(map_set))
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
370
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
371 # For everything returned by maplist, should be the same as from maparg.
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
372 # Except for "map dup", bacause maparg returns the <buffer> version
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
373 for d in maps_maplist
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
374 if d.lhs == 'dup' && d.buffer == 0
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
375 continue
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
376 endif
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
377 var d_maparg = maparg(d.lhs, d.mode, false, true)
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
378 assert_equal(d_maparg, d)
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
379 endfor
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
380
28602
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
381 # Check abbr matches maparg
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
382 for d in maplist(true)
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
383 # Note, d.mode is '!', but can't use that with maparg
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
384 var d_maparg = maparg(d.lhs, 'i', true, true)
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
385 assert_equal(d_maparg, d)
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
386 endfor
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
387
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
388 ClearMappingsAbbreviations()
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
389 assert_equal(0, len(maplist()))
398c5b3211f9 patch 8.2.4825: can only get a list of mappings
Bram Moolenaar <Bram@vim.org>
parents: 28592
diff changeset
390 assert_equal(0, len(maplist(true)))
28592
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
391 enddef
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
392
d3c966c0cdf7 patch 8.2.4820: not simple programmatic way to find a specific mapping
Bram Moolenaar <Bram@vim.org>
parents: 27223
diff changeset
393
19149
643c6c3c0da4 patch 8.2.0134: some map functionality not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 17930
diff changeset
394 " vim: shiftwidth=2 sts=2 expandtab