test_map_functions.vim (19170B)
1 " Tests for maparg(), mapcheck(), mapset(), maplist() 2 " Also test utf8 map with a 0x80 byte. 3 4 source shared.vim 5 6 func s:SID() 7 return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')) 8 endfunc 9 10 func Test_maparg() 11 new 12 set cpo-=< 13 set encoding=utf8 14 let sid = s:SID() 15 16 let lnum = expand('<sflnum>') 17 map foo<C-V> is<F4>foo 18 vnoremap <script> <buffer> <expr> <silent> bar isbar 19 call assert_equal("is<F4>foo", maparg('foo<C-V>')) " maparg() string result 20 call assert_equal({'mode': ' ', 'mode_bits': 0x47, 'abbr': 0, 'buffer': 0, 21 \ 'noremap': 0, 'script': 0, 'expr': 0, 'nowait': 0, 'silent': 0, 22 "\ Nvim-specific field "replace_keycodes" 23 \ 'replace_keycodes': 0, 24 \ 'lhs': 'foo<C-V>', 'lhsraw': "foo\x80\xfc\x04V", 'rhs': 'is<F4>foo', 25 \ 'lhsrawalt': "foo\x16", 26 \ 'sid': sid, 'scriptversion': 1, 'lnum': lnum + 1}, 27 \ maparg('foo<C-V>', '', 0, 1)) 28 call assert_equal({'mode': 'v', 'mode_bits': 0x42, 'abbr': 0, 'buffer': 1, 29 \ 'noremap': 1, 'script': 1, 'expr': 1, 'nowait': 0, 'silent': 1, 30 "\ Nvim-specific field "replace_keycodes" 31 \ 'replace_keycodes': 0, 32 \ 'lhs': 'bar', 'lhsraw': 'bar', 'rhs': 'isbar', 33 \ 'sid': sid, 'scriptversion': 1, 'lnum': lnum + 2}, 34 \ 'bar'->maparg('', 0, 1)) 35 unmap foo<C-V> 36 vunmap <buffer> bar 37 38 let lnum = expand('<sflnum>') 39 map <buffer> <nowait> foo bar 40 call assert_equal({'mode': ' ', 'mode_bits': 0x47, 'abbr': 0, 'buffer': 1, 41 \ 'noremap': 0, 'script': 0, 'expr': 0, 'nowait': 1, 'silent': 0, 42 "\ Nvim-specific field "replace_keycodes" 43 \ 'replace_keycodes': 0, 44 \ 'lhs': 'foo', 'lhsraw': 'foo', 'rhs': 'bar', 45 \ 'sid': sid, 'scriptversion': 1, 'lnum': lnum + 1}, 46 \ maparg('foo', '', 0, 1)) 47 unmap <buffer> foo 48 49 let lnum = expand('<sflnum>') 50 tmap baz foo 51 call assert_equal({'mode': 't', 'mode_bits': 0x80, 'abbr': 0, 'buffer': 0, 52 \ 'noremap': 0, 'script': 0, 'expr': 0, 'nowait': 0, 'silent': 0, 53 "\ Nvim-specific field "replace_keycodes" 54 \ 'replace_keycodes': 0, 55 \ 'lhs': 'baz', 'lhsraw': 'baz', 'rhs': 'foo', 56 \ 'sid': sid, 'scriptversion': 1, 'lnum': lnum + 1}, 57 \ maparg('baz', 't', 0, 1)) 58 tunmap baz 59 60 let lnum = expand('<sflnum>') 61 iab A B 62 call assert_equal({'mode': 'i', 'mode_bits': 0x10, 'abbr': 1, 'buffer': 0, 63 \ 'noremap': 0, 'script': 0, 'expr': 0, 'nowait': 0, 'silent': 0, 64 "\ Nvim-specific field "replace_keycodes" 65 \ 'replace_keycodes': 0, 66 \ 'lhs': 'A', 'lhsraw': 'A', 'rhs': 'B', 67 \ 'sid': sid, 'scriptversion': 1, 'lnum': lnum + 1}, 68 \ maparg('A', 'i', 1, 1)) 69 iuna A 70 71 map abc x<char-114>x 72 call assert_equal("xrx", maparg('abc')) 73 map abc y<S-char-114>y 74 call assert_equal("yRy", maparg('abc')) 75 76 " character with K_SPECIAL byte 77 nmap abc … 78 call assert_equal('…', maparg('abc')) 79 80 " modified character with K_SPECIAL byte 81 nmap abc <M-…> 82 call assert_equal('<M-…>', maparg('abc')) 83 84 " illegal bytes 85 let str = ":\x7f:\x80:\x90:\xd0:" 86 exe 'nmap abc ' .. str 87 call assert_equal(str, maparg('abc')) 88 unlet str 89 90 omap { w 91 let d = maparg('{', 'o', 0, 1) 92 call assert_equal(['{', 'w', 'o'], [d.lhs, d.rhs, d.mode]) 93 ounmap { 94 95 lmap { w 96 let d = maparg('{', 'l', 0, 1) 97 call assert_equal(['{', 'w', 'l'], [d.lhs, d.rhs, d.mode]) 98 lunmap { 99 100 nmap { w 101 let d = maparg('{', 'n', 0, 1) 102 call assert_equal(['{', 'w', 'n'], [d.lhs, d.rhs, d.mode]) 103 nunmap { 104 105 xmap { w 106 let d = maparg('{', 'x', 0, 1) 107 call assert_equal(['{', 'w', 'x'], [d.lhs, d.rhs, d.mode]) 108 xunmap { 109 110 smap { w 111 let d = maparg('{', 's', 0, 1) 112 call assert_equal(['{', 'w', 's'], [d.lhs, d.rhs, d.mode]) 113 sunmap { 114 115 map <C-I> foo 116 unmap <Tab> 117 " This used to cause a segfault 118 call maparg('<C-I>', '', 0, 1) 119 unmap <C-I> 120 121 map abc <Nop> 122 call assert_equal("<Nop>", maparg('abc')) 123 unmap abc 124 125 call feedkeys(":abbr esc \<C-V>\<C-V>\<C-V>\<C-V>\<C-V>\<Esc>\<CR>", "xt") 126 let d = maparg('esc', 'i', 1, 1) 127 call assert_equal(['esc', "\<C-V>\<C-V>\<Esc>", '!'], [d.lhs, d.rhs, d.mode]) 128 abclear 129 unlet d 130 endfunc 131 132 " def Test_vim9_maparg() 133 " nmap { w 134 " var one: string = maparg('{') 135 " assert_equal('w', one) 136 " var two: string = maparg('{', 'n') 137 " assert_equal('w', two) 138 " var three: string = maparg('{', 'n', 0) 139 " assert_equal('w', three) 140 " var four: dict<any> = maparg('{', 'n', 0, 1) 141 " assert_equal(['{', 'w', 'n'], [four.lhs, four.rhs, four.mode]) 142 " nunmap { 143 " enddef 144 145 func Test_mapcheck() 146 call assert_equal('', mapcheck('a')) 147 call assert_equal('', mapcheck('abc')) 148 call assert_equal('', mapcheck('ax')) 149 call assert_equal('', mapcheck('b')) 150 151 map a something 152 call assert_equal('something', mapcheck('a')) 153 call assert_equal('something', mapcheck('a', 'n')) 154 call assert_equal('', mapcheck('a', 'c')) 155 call assert_equal('', mapcheck('a', 'i')) 156 call assert_equal('something', 'abc'->mapcheck()) 157 call assert_equal('something', 'ax'->mapcheck()) 158 call assert_equal('', mapcheck('b')) 159 unmap a 160 161 map ab foobar 162 call assert_equal('foobar', mapcheck('a')) 163 call assert_equal('foobar', mapcheck('abc')) 164 call assert_equal('', mapcheck('ax')) 165 call assert_equal('', mapcheck('b')) 166 unmap ab 167 168 map abc barfoo 169 call assert_equal('barfoo', mapcheck('a')) 170 call assert_equal('barfoo', mapcheck('a', 'n', 0)) 171 call assert_equal('', mapcheck('a', 'n', 1)) 172 call assert_equal('barfoo', mapcheck('abc')) 173 call assert_equal('', mapcheck('ax')) 174 call assert_equal('', mapcheck('b')) 175 unmap abc 176 177 abbr ab abbrev 178 call assert_equal('abbrev', mapcheck('a', 'i', 1)) 179 call assert_equal('', mapcheck('a', 'n', 1)) 180 call assert_equal('', mapcheck('a', 'i', 0)) 181 unabbr ab 182 endfunc 183 184 func Test_range_map() 185 new 186 " Outside of the range, minimum 187 inoremap <Char-0x1040> a 188 execute "normal a\u1040\<Esc>" 189 " Inside of the range, minimum 190 inoremap <Char-0x103f> b 191 execute "normal a\u103f\<Esc>" 192 " Inside of the range, maximum 193 inoremap <Char-0xf03f> c 194 execute "normal a\uf03f\<Esc>" 195 " Outside of the range, maximum 196 inoremap <Char-0xf040> d 197 execute "normal a\uf040\<Esc>" 198 call assert_equal("abcd", getline(1)) 199 endfunc 200 201 func One_mapset_test(keys, rhs) 202 exe 'nnoremap ' .. a:keys .. ' ' .. a:rhs 203 let orig = maparg(a:keys, 'n', 0, 1) 204 call assert_equal(a:keys, orig.lhs) 205 call assert_equal(a:rhs, orig.rhs) 206 call assert_equal('n', orig.mode) 207 208 exe 'nunmap ' .. a:keys 209 let d = maparg(a:keys, 'n', 0, 1) 210 call assert_equal({}, d) 211 212 call mapset('n', 0, orig) 213 let d = maparg(a:keys, 'n', 0, 1) 214 call assert_equal(a:keys, d.lhs) 215 call assert_equal(a:rhs, d.rhs) 216 call assert_equal('n', d.mode) 217 218 exe 'nunmap ' .. a:keys 219 endfunc 220 221 func Test_mapset() 222 call One_mapset_test('K', 'original<CR>') 223 call One_mapset_test('<F3>', 'original<CR>') 224 call One_mapset_test('<F3>', '<lt>Nop>') 225 226 " Check <> key conversion 227 new 228 inoremap K one<Left>x 229 call feedkeys("iK\<Esc>", 'xt') 230 call assert_equal('onxe', getline(1)) 231 232 let orig = maparg('K', 'i', 0, 1) 233 call assert_equal('K', orig.lhs) 234 call assert_equal('one<Left>x', orig.rhs) 235 call assert_equal('i', orig.mode) 236 237 iunmap K 238 let d = maparg('K', 'i', 0, 1) 239 call assert_equal({}, d) 240 241 call mapset('i', 0, orig) 242 call feedkeys("SK\<Esc>", 'xt') 243 call assert_equal('onxe', getline(1)) 244 245 iunmap K 246 247 " Test that <Nop> is restored properly 248 inoremap K <Nop> 249 call feedkeys("SK\<Esc>", 'xt') 250 call assert_equal('', getline(1)) 251 252 let orig = maparg('K', 'i', 0, 1) 253 call assert_equal('K', orig.lhs) 254 call assert_equal('<Nop>', orig.rhs) 255 call assert_equal('i', orig.mode) 256 257 inoremap K foo 258 call feedkeys("SK\<Esc>", 'xt') 259 call assert_equal('foo', getline(1)) 260 261 call mapset('i', 0, orig) 262 call feedkeys("SK\<Esc>", 'xt') 263 call assert_equal('', getline(1)) 264 265 iunmap K 266 267 " Test literal <CR> using a backslash 268 let cpo_save = &cpo 269 set cpo-=B 270 inoremap K one\<CR>two 271 call feedkeys("SK\<Esc>", 'xt') 272 call assert_equal('one<CR>two', getline(1)) 273 274 let orig = maparg('K', 'i', 0, 1) 275 call assert_equal('K', orig.lhs) 276 call assert_equal('one\<CR>two', orig.rhs) 277 call assert_equal('i', orig.mode) 278 279 iunmap K 280 let d = maparg('K', 'i', 0, 1) 281 call assert_equal({}, d) 282 283 call mapset('i', 0, orig) 284 call feedkeys("SK\<Esc>", 'xt') 285 call assert_equal('one<CR>two', getline(1)) 286 287 iunmap K 288 289 " Test literal <CR> using CTRL-V 290 inoremap K one<CR>two 291 call feedkeys("SK\<Esc>", 'xt') 292 call assert_equal('one<CR>two', getline(1)) 293 294 let orig = maparg('K', 'i', 0, 1) 295 call assert_equal('K', orig.lhs) 296 call assert_equal("one\x16<CR>two", orig.rhs) 297 call assert_equal('i', orig.mode) 298 299 iunmap K 300 let d = maparg('K', 'i', 0, 1) 301 call assert_equal({}, d) 302 303 call mapset('i', 0, orig) 304 call feedkeys("SK\<Esc>", 'xt') 305 call assert_equal('one<CR>two', getline(1)) 306 307 iunmap K 308 let &cpo = cpo_save 309 bwipe! 310 311 call assert_fails('call mapset([], v:false, {})', 'E730:') 312 call assert_fails('call mapset("i", 0, "")', 'E1206:') 313 call assert_fails('call mapset("i", 0, {})', 'E460:') 314 endfunc 315 316 func Test_mapset_arg1_dir() 317 " This test is mostly about get_map_mode_string. 318 " Once the code gets past that, it's common with the 3 arg mapset. 319 320 " GetModes() return list of modes for 'XZ' lhs using maplist. 321 " There is one list item per mapping 322 func s:GetModes(abbr = v:false) 323 return maplist(a:abbr)->filter({_, m -> m.lhs == 'XZ'}) 324 \ ->mapnew({_, m -> m.mode}) 325 endfunc 326 327 func s:UnmapAll(lhs) 328 const unmap_cmds = [ 'unmap', 'unmap!', 'tunmap', 'lunmap' ] 329 for cmd in unmap_cmds 330 try | call execute(cmd .. ' ' .. a:lhs) | catch /E31/ | endtry 331 endfor 332 endfunc 333 334 let tmap = {} 335 336 " some mapset(mode, abbr, dict) tests using get_map_mode_str 337 map XZ x 338 let tmap = maplist()->filter({_, m -> m.lhs == 'XZ'})[0]->copy() 339 " this splits the mapping into 2 mappings 340 call mapset('ox', v:false, tmap) 341 call assert_equal(2, len(s:GetModes())) 342 call mapset('o', v:false, tmap) 343 call assert_equal(3, len(s:GetModes())) 344 " test that '' acts like ' ', and that the 3 mappings become 1 345 call mapset('', v:false, tmap) 346 call assert_equal([' '], s:GetModes()) 347 " dict's mode/abbr are ignored 348 call s:UnmapAll('XZ') 349 let tmap.mode = '!' 350 let tmap.abbr = v:true 351 call mapset('o', v:false, tmap) 352 call assert_equal(['o'], s:GetModes()) 353 354 " test the 3 arg version handles bad mode string, dict not used 355 call assert_fails("call mapset('vi', v:false, {})", 'E1276:') 356 357 358 " get the abbreviations out of the way 359 abbreviate XZ ZX 360 let tmap = maplist(v:true)->filter({_, m -> m.lhs == 'XZ'})[0]->copy() 361 362 abclear 363 " 'ic' is the default ab command, shows up as '!' 364 let tmap.mode = 'ic' 365 call mapset(tmap) 366 call assert_equal(['!'], s:GetModes(v:true)) 367 368 abclear 369 let tmap.mode = 'i' 370 call mapset(tmap) 371 call assert_equal(['i'], s:GetModes(v:true)) 372 373 abclear 374 let tmap.mode = 'c' 375 call mapset(tmap) 376 call assert_equal(['c'], s:GetModes(v:true)) 377 378 abclear 379 let tmap.mode = '!' 380 call mapset(tmap) 381 call assert_equal(['!'], s:GetModes(v:true)) 382 383 call assert_fails("call mapset(#{mode: ' !', abbr: 1})", 'E1276:') 384 call assert_fails("call mapset(#{mode: 'cl', abbr: 1})", 'E1276:') 385 call assert_fails("call mapset(#{mode: 'in', abbr: 1})", 'E1276:') 386 387 " the map commands 388 map XZ x 389 let tmap = maplist()->filter({_, m -> m.lhs == 'XZ'})[0]->copy() 390 391 " try the combos 392 call s:UnmapAll('XZ') 393 " 'nxso' is ' ', the unadorned :map 394 let tmap.mode = 'nxso' 395 call mapset(tmap) 396 call assert_equal([' '], s:GetModes()) 397 398 cal s:UnmapAll('XZ') 399 " 'ic' is '!' 400 let tmap.mode = 'ic' 401 call mapset(tmap) 402 call assert_equal(['!'], s:GetModes()) 403 404 call s:UnmapAll('XZ') 405 " 'xs' is really 'v' 406 let tmap.mode = 'xs' 407 call mapset(tmap) 408 call assert_equal(['v'], s:GetModes()) 409 410 " try the individual modes 411 call s:UnmapAll('XZ') 412 let tmap.mode = 'n' 413 call mapset(tmap) 414 call assert_equal(['n'], s:GetModes()) 415 416 call s:UnmapAll('XZ') 417 let tmap.mode = 'x' 418 call mapset(tmap) 419 call assert_equal(['x'], s:GetModes()) 420 421 call s:UnmapAll('XZ') 422 let tmap.mode = 's' 423 call mapset(tmap) 424 call assert_equal(['s'], s:GetModes()) 425 426 call s:UnmapAll('XZ') 427 let tmap.mode = 'o' 428 call mapset(tmap) 429 call assert_equal(['o'], s:GetModes()) 430 431 call s:UnmapAll('XZ') 432 let tmap.mode = 'i' 433 call mapset(tmap) 434 call assert_equal(['i'], s:GetModes()) 435 436 call s:UnmapAll('XZ') 437 let tmap.mode = 'c' 438 call mapset(tmap) 439 call assert_equal(['c'], s:GetModes()) 440 441 call s:UnmapAll('XZ') 442 let tmap.mode = 't' 443 call mapset(tmap) 444 call assert_equal(['t'], s:GetModes()) 445 446 call s:UnmapAll('XZ') 447 let tmap.mode = 'l' 448 call mapset(tmap) 449 call assert_equal(['l'], s:GetModes()) 450 451 call s:UnmapAll('XZ') 452 453 " get errors for modes that can't be in one mapping 454 call assert_fails("call mapset(#{mode: 'nxsoi', abbr: 0})", 'E1276:') 455 call assert_fails("call mapset(#{mode: ' !', abbr: 0})", 'E1276:') 456 call assert_fails("call mapset(#{mode: 'ix', abbr: 0})", 'E1276:') 457 call assert_fails("call mapset(#{mode: 'tl', abbr: 0})", 'E1276:') 458 call assert_fails("call mapset(#{mode: ' l', abbr: 0})", 'E1276:') 459 call assert_fails("call mapset(#{mode: ' t', abbr: 0})", 'E1276:') 460 endfunc 461 462 func Check_ctrlb_map(d, check_alt) 463 call assert_equal('<C-B>', a:d.lhs) 464 if a:check_alt 465 call assert_equal("\x80\xfc\x04B", a:d.lhsraw) 466 call assert_equal("\x02", a:d.lhsrawalt) 467 else 468 call assert_equal("\x02", a:d.lhsraw) 469 endif 470 endfunc 471 472 func Test_map_local() 473 nmap a global 474 nmap <buffer>a local 475 476 let prev_map_list = split(execute('nmap a'), "\n") 477 call assert_match('n\s*a\s*@local', prev_map_list[0]) 478 call assert_match('n\s*a\s*global', prev_map_list[1]) 479 480 let mapping = maparg('a', 'n', 0, 1) 481 call assert_equal(1, mapping.buffer) 482 let mapping.rhs = 'new_local' 483 call mapset('n', 0, mapping) 484 485 " Check that the global mapping is left untouched. 486 let map_list = split(execute('nmap a'), "\n") 487 call assert_match('n\s*a\s*@new_local', map_list[0]) 488 call assert_match('n\s*a\s*global', map_list[1]) 489 490 nunmap a 491 endfunc 492 493 func Test_map_restore() 494 " Test restoring map with alternate keycode 495 nmap <C-B> back 496 let d = maparg('<C-B>', 'n', 0, 1) 497 call Check_ctrlb_map(d, 1) 498 let dsimp = maparg("\x02", 'n', 0, 1) 499 call Check_ctrlb_map(dsimp, 0) 500 nunmap <C-B> 501 call mapset('n', 0, d) 502 let d = maparg('<C-B>', 'n', 0, 1) 503 call Check_ctrlb_map(d, 1) 504 let dsimp = maparg("\x02", 'n', 0, 1) 505 call Check_ctrlb_map(dsimp, 0) 506 507 nunmap <C-B> 508 endfunc 509 510 " Test restoring an <SID> mapping 511 func Test_map_restore_sid() 512 func RestoreMap() 513 const d = maparg('<CR>', 'i', v:false, v:true) 514 iunmap <buffer> <CR> 515 call mapset('i', v:false, d) 516 endfunc 517 518 let mapscript =<< trim [CODE] 519 inoremap <silent><buffer> <SID>Return <C-R>=42<CR> 520 inoremap <script><buffer> <CR> <CR><SID>Return 521 [CODE] 522 call writefile(mapscript, 'Xmapscript', 'D') 523 524 new 525 source Xmapscript 526 inoremap <buffer> <C-B> <Cmd>call RestoreMap()<CR> 527 call feedkeys("i\<CR>\<*C-B>\<CR>", 'xt') 528 call assert_equal(['', '42', '42'], getline(1, '$')) 529 530 bwipe! 531 delfunc RestoreMap 532 endfunc 533 534 " Test restoring a mapping with a negative script ID 535 func Test_map_restore_negative_sid() 536 let after =<< trim [CODE] 537 call assert_equal("\tLast set from --cmd argument", 538 \ execute('verbose nmap ,n')->trim()->split("\n")[-1]) 539 let d = maparg(',n', 'n', 0, 1) 540 nunmap ,n 541 call assert_equal('No mapping found', 542 \ execute('verbose nmap ,n')->trim()->split("\n")[-1]) 543 call mapset('n', 0, d) 544 call assert_equal("\tLast set from --cmd argument", 545 \ execute('verbose nmap ,n')->trim()->split("\n")[-1]) 546 call writefile(v:errors, 'Xresult') 547 qall! 548 [CODE] 549 550 if RunVim([], after, '--clean --cmd "nmap ,n <Nop>"') 551 call assert_equal([], readfile('Xresult')) 552 endif 553 call delete('Xresult') 554 endfunc 555 556 " Check that restoring a mapping doesn't remove a mapping whose {rhs} matches 557 " the restored mapping's {lhs}. 558 func Test_map_restore_with_rhs_match_lhs() 559 nnoremap <F2> <F3> 560 nnoremap <F3> <F4> 561 call assert_equal('<F3>', maparg('<F2>', 'n')) 562 call assert_equal('<F4>', maparg('<F3>', 'n')) 563 let d = maparg('<F3>', 'n', v:false, v:true) 564 nunmap <F3> 565 call assert_equal('<F3>', maparg('<F2>', 'n')) 566 call assert_equal('', maparg('<F3>', 'n')) 567 call mapset(d) 568 call assert_equal('<F3>', maparg('<F2>', 'n')) 569 call assert_equal('<F4>', maparg('<F3>', 'n')) 570 571 nunmap <F2> 572 nunmap <F3> 573 endfunc 574 575 func Test_maplist() 576 new 577 func s:ClearMappingsAbbreviations() 578 mapclear | nmapclear | vmapclear | xmapclear | smapclear | omapclear 579 mapclear! | imapclear | lmapclear | cmapclear | tmapclear 580 mapclear <buffer> | nmapclear <buffer> | vmapclear <buffer> 581 xmapclear <buffer> | smapclear <buffer> | omapclear <buffer> 582 mapclear! <buffer> | imapclear <buffer> | lmapclear <buffer> 583 cmapclear <buffer> | tmapclear <buffer> 584 abclear | abclear <buffer> 585 endfunc 586 587 func s:AddMaps(new, accum) 588 if len(a:new) > 0 && a:new[0] != "No mapping found" 589 eval a:accum->extend(a:new) 590 endif 591 endfunc 592 593 call s:ClearMappingsAbbreviations() 594 call assert_equal(0, len(maplist())) 595 call assert_equal(0, len(maplist(v:true))) 596 597 " Set up some mappings. 598 map dup bar 599 map <buffer> dup bufbar 600 map foo<C-V> is<F4>foo 601 vnoremap <script> <buffer> <expr> <silent> bar isbar 602 tmap baz foo 603 omap h w 604 lmap i w 605 nmap j w 606 xmap k w 607 smap l w 608 map abc <Nop> 609 nmap <M-j> x 610 nmap <M-Space> y 611 " And abbreviations 612 abbreviate xy he 613 abbreviate xx she 614 abbreviate <buffer> x they 615 616 " Get a list of the mappings with the ':map' commands. 617 " Check maplist() return a list of the same size. 618 call assert_equal(13, len(maplist())) 619 call assert_equal(3, len(maplist(v:true))) 620 call assert_equal(13, len(maplist(v:false))) 621 622 " collect all the current maps using :map commands 623 let maps_command = [] 624 call s:AddMaps(split(execute('map'), '\n'), maps_command) 625 call s:AddMaps(split(execute('map!'), '\n'), maps_command) 626 call s:AddMaps(split(execute('tmap'), '\n'), maps_command) 627 call s:AddMaps(split(execute('lmap'), '\n'), maps_command) 628 629 " Use maplist to get all the maps 630 let maps_maplist = maplist() 631 call assert_equal(len(maps_command), len(maps_maplist)) 632 633 " make sure all the mode-lhs are unique, no duplicates 634 let map_set = {} 635 for d in maps_maplist 636 let map_set[d.mode .. "-" .. d.lhs .. "-" .. d.buffer] = 0 637 endfor 638 call assert_equal(len(maps_maplist), len(map_set)) 639 640 " For everything returned by maplist, should be the same as from maparg. 641 " Except for "map dup", because maparg returns the <buffer> version 642 for d in maps_maplist 643 if d.lhs == 'dup' && d.buffer == 0 644 continue 645 endif 646 let d_maparg = maparg(d.lhs, d.mode, v:false, v:true) 647 call assert_equal(d_maparg, d) 648 endfor 649 650 " Check abbr matches maparg 651 for d in maplist(v:true) 652 " Note, d.mode is '!', but can't use that with maparg 653 let d_maparg = maparg(d.lhs, 'i', v:true, v:true) 654 call assert_equal(d_maparg, d) 655 endfor 656 657 call s:ClearMappingsAbbreviations() 658 call assert_equal(0, len(maplist())) 659 call assert_equal(0, len(maplist(v:true))) 660 endfunc 661 662 663 " vim: shiftwidth=2 sts=2 expandtab