comparison src/testdir/test_mapping.vim @ 30582:72245f9c9405 v9.0.0626

patch 9.0.0626: too many delete() calls in tests Commit: https://github.com/vim/vim/commit/b152b6a40f729ed81a25d2fa541a4e73e201bec4 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 29 21:37:33 2022 +0100 patch 9.0.0626: too many delete() calls in tests Problem: Too many delete() calls in tests. Solution: Use deferred delete where possible.
author Bram Moolenaar <Bram@vim.org>
date Thu, 29 Sep 2022 22:45:04 +0200
parents 539fb427124d
children ae3970cc28cb
comparison
equal deleted inserted replaced
30581:2e1ec75a7766 30582:72245f9c9405
418 let x = [ 418 let x = [
419 endfunc 419 endfunc
420 nmap <expr> ! Func() 420 nmap <expr> ! Func()
421 set updatetime=50 421 set updatetime=50
422 [CODE] 422 [CODE]
423 call writefile(lines, 'Xtest.vim') 423 call writefile(lines, 'Xtest.vim', 'D')
424 424
425 let buf = term_start(GetVimCommandCleanTerm() .. ' -S Xtest.vim', {'term_rows': 8}) 425 let buf = term_start(GetVimCommandCleanTerm() .. ' -S Xtest.vim', {'term_rows': 8})
426 let job = term_getjob(buf) 426 let job = term_getjob(buf)
427 call WaitForAssert({-> assert_notequal('', term_getline(buf, 8))}) 427 call WaitForAssert({-> assert_notequal('', term_getline(buf, 8))})
428 428
437 call WaitFor({-> job_status(job) ==# 'dead'}) 437 call WaitFor({-> job_status(job) ==# 'dead'})
438 if has('unix') 438 if has('unix')
439 call assert_equal('', job_info(job).termsig) 439 call assert_equal('', job_info(job).termsig)
440 endif 440 endif
441 441
442 call delete('Xtest.vim')
443 exe buf .. 'bwipe!' 442 exe buf .. 'bwipe!'
444 endfunc 443 endfunc
445 444
446 func Test_list_mappings() 445 func Test_list_mappings()
447 " Remove default mappings 446 " Remove default mappings
563 func Status() 562 func Status()
564 return get(g:, 'on', 0) ? '[on]' : '' 563 return get(g:, 'on', 0) ? '[on]' : ''
565 endfunc 564 endfunc
566 set stl=%{Status()} 565 set stl=%{Status()}
567 END 566 END
568 call writefile(lines, 'XtestExprMap') 567 call writefile(lines, 'XtestExprMap', 'D')
569 let buf = RunVimInTerminal('-S XtestExprMap', #{rows: 10}) 568 let buf = RunVimInTerminal('-S XtestExprMap', #{rows: 10})
570 call term_sendkeys(buf, "\<C-B>") 569 call term_sendkeys(buf, "\<C-B>")
571 call VerifyScreenDump(buf, 'Test_map_expr_1', {}) 570 call VerifyScreenDump(buf, 'Test_map_expr_1', {})
572 571
573 " clean up 572 " clean up
574 call StopVimInTerminal(buf) 573 call StopVimInTerminal(buf)
575 call delete('XtestExprMap')
576 endfunc 574 endfunc
577 575
578 func Test_map_listing() 576 func Test_map_listing()
579 CheckScreendump 577 CheckScreendump
580 578
581 let lines =<< trim END 579 let lines =<< trim END
582 nmap a b 580 nmap a b
583 END 581 END
584 call writefile(lines, 'XtestMapList') 582 call writefile(lines, 'XtestMapList', 'D')
585 let buf = RunVimInTerminal('-S XtestMapList', #{rows: 6}) 583 let buf = RunVimInTerminal('-S XtestMapList', #{rows: 6})
586 call term_sendkeys(buf, ": nmap a\<CR>") 584 call term_sendkeys(buf, ": nmap a\<CR>")
587 call VerifyScreenDump(buf, 'Test_map_list_1', {}) 585 call VerifyScreenDump(buf, 'Test_map_list_1', {})
588 586
589 " clean up 587 " clean up
590 call StopVimInTerminal(buf) 588 call StopVimInTerminal(buf)
591 call delete('XtestMapList')
592 endfunc 589 endfunc
593 590
594 func Test_expr_map_error() 591 func Test_expr_map_error()
595 CheckScreendump 592 CheckScreendump
596 593
603 nnoremap <expr> <F2> Func() 600 nnoremap <expr> <F2> Func()
604 cnoremap <expr> <F2> Func() 601 cnoremap <expr> <F2> Func()
605 602
606 call test_override('ui_delay', 10) 603 call test_override('ui_delay', 10)
607 END 604 END
608 call writefile(lines, 'XtestExprMap') 605 call writefile(lines, 'XtestExprMap', 'D')
609 let buf = RunVimInTerminal('-S XtestExprMap', #{rows: 10}) 606 let buf = RunVimInTerminal('-S XtestExprMap', #{rows: 10})
610 call term_sendkeys(buf, "\<F2>") 607 call term_sendkeys(buf, "\<F2>")
611 call TermWait(buf) 608 call TermWait(buf)
612 call term_sendkeys(buf, "\<CR>") 609 call term_sendkeys(buf, "\<CR>")
613 call VerifyScreenDump(buf, 'Test_map_expr_2', {}) 610 call VerifyScreenDump(buf, 'Test_map_expr_2', {})
617 call term_sendkeys(buf, "\<Esc>0") 614 call term_sendkeys(buf, "\<Esc>0")
618 call VerifyScreenDump(buf, 'Test_map_expr_4', {}) 615 call VerifyScreenDump(buf, 'Test_map_expr_4', {})
619 616
620 " clean up 617 " clean up
621 call StopVimInTerminal(buf) 618 call StopVimInTerminal(buf)
622 call delete('XtestExprMap')
623 endfunc 619 endfunc
624 620
625 " Test for mapping errors 621 " Test for mapping errors
626 func Test_map_error() 622 func Test_map_error()
627 call assert_fails('unmap', 'E474:') 623 call assert_fails('unmap', 'E474:')
1079 map <F2> <Cmd>call <SID>do_it()<CR> 1075 map <F2> <Cmd>call <SID>do_it()<CR>
1080 func s:do_it() 1076 func s:do_it()
1081 let g:x = 32 1077 let g:x = 32
1082 endfunc 1078 endfunc
1083 END 1079 END
1084 call writefile(lines, 'Xscript') 1080 call writefile(lines, 'Xscript', 'D')
1085 source Xscript 1081 source Xscript
1086 call feedkeys("\<F2>", 'xt') 1082 call feedkeys("\<F2>", 'xt')
1087 call assert_equal(32, g:x) 1083 call assert_equal(32, g:x)
1088 call delete('Xscript')
1089 1084
1090 unmap <F3> 1085 unmap <F3>
1091 unmap! <F3> 1086 unmap! <F3>
1092 %bw! 1087 %bw!
1093 1088
1528 unlet b:result 1523 unlet b:result
1529 autocmd! CmdlineEnter 1524 autocmd! CmdlineEnter
1530 endfunc 1525 endfunc
1531 1526
1532 func Test_map_script_cmd_redo() 1527 func Test_map_script_cmd_redo()
1533 call mkdir('Xmapcmd') 1528 call mkdir('Xmapcmd', 'R')
1534 let lines =<< trim END 1529 let lines =<< trim END
1535 vim9script 1530 vim9script
1536 import autoload './script.vim' 1531 import autoload './script.vim'
1537 onoremap <F3> <ScriptCmd>script.Func()<CR> 1532 onoremap <F3> <ScriptCmd>script.Func()<CR>
1538 END 1533 END
1552 call feedkeys("d\<F3>j.", 'xt') 1547 call feedkeys("d\<F3>j.", 'xt')
1553 call assert_equal(['two', 'four'], getline(1, '$')) 1548 call assert_equal(['two', 'four'], getline(1, '$'))
1554 1549
1555 ounmap <F3> 1550 ounmap <F3>
1556 nunmap j 1551 nunmap j
1557 call delete('Xmapcmd', 'rf')
1558 bwipe! 1552 bwipe!
1559 endfunc 1553 endfunc
1560 1554
1561 " Test for using <script> with a map to remap characters in rhs 1555 " Test for using <script> with a map to remap characters in rhs
1562 func Test_script_local_remap() 1556 func Test_script_local_remap()
1722 let lines =<< trim END 1716 let lines =<< trim END
1723 set timeout timeoutlen=400 1717 set timeout timeoutlen=400
1724 inoremap ab TEST 1718 inoremap ab TEST
1725 inoremap a <Nop> 1719 inoremap a <Nop>
1726 END 1720 END
1727 call writefile(lines, 'Xtest_map_after_timed_out_nop') 1721 call writefile(lines, 'Xtest_map_after_timed_out_nop', 'D')
1728 let buf = RunVimInTerminal('-S Xtest_map_after_timed_out_nop', #{rows: 6}) 1722 let buf = RunVimInTerminal('-S Xtest_map_after_timed_out_nop', #{rows: 6})
1729 1723
1730 " Enter Insert mode 1724 " Enter Insert mode
1731 call term_sendkeys(buf, 'i') 1725 call term_sendkeys(buf, 'i')
1732 " Wait for the "a" mapping to timeout 1726 " Wait for the "a" mapping to timeout
1739 call term_sendkeys(buf, 'b') 1733 call term_sendkeys(buf, 'b')
1740 call WaitForAssert({-> assert_equal("TEST", term_getline(buf, 1))}) 1734 call WaitForAssert({-> assert_equal("TEST", term_getline(buf, 1))})
1741 1735
1742 " clean up 1736 " clean up
1743 call StopVimInTerminal(buf) 1737 call StopVimInTerminal(buf)
1744 call delete('Xtest_map_after_timed_out_nop')
1745 endfunc 1738 endfunc
1746 1739
1747 func Test_using_past_typeahead() 1740 func Test_using_past_typeahead()
1748 nnoremap :00 0 1741 nnoremap :00 0
1749 exe "norm :set \x80\xfb0=0\<CR>" 1742 exe "norm :set \x80\xfb0=0\<CR>"