Mercurial > vim
comparison src/testdir/test_visual.vim @ 19738:0208534b8a84 v8.2.0425
patch 8.2.0425: code for modeless selection not sufficiently tested
Commit: https://github.com/vim/vim/commit/515545e11f523d14343b1e588dc0b9bd3d362bc2
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 22 14:08:59 2020 +0100
patch 8.2.0425: code for modeless selection not sufficiently tested
Problem: Code for modeless selection not sufficiently tested.
Solution: Add tests. Move mouse code functionality to a common script file.
(Yegappan Lakshmanan, closes #5821)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 22 Mar 2020 14:15:04 +0100 |
parents | f70a3c1000bb |
children | 12518b40c161 |
comparison
equal
deleted
inserted
replaced
19737:5591829276ff | 19738:0208534b8a84 |
---|---|
616 call assert_equal(['', 'a', ''], getline(1, '$')) | 616 call assert_equal(['', 'a', ''], getline(1, '$')) |
617 | 617 |
618 bwipe! | 618 bwipe! |
619 endfunc | 619 endfunc |
620 | 620 |
621 func Test_characterwise_select_mode() | |
622 new | |
623 | |
624 " Select mode maps | |
625 snoremap <lt>End> <End> | |
626 snoremap <lt>Down> <Down> | |
627 snoremap <lt>Del> <Del> | |
628 | |
629 " characterwise select mode: delete middle line | |
630 call deletebufline('', 1, '$') | |
631 call append('$', ['a', 'b', 'c']) | |
632 exe "normal Gkkgh\<End>\<Del>" | |
633 call assert_equal(['', 'b', 'c'], getline(1, '$')) | |
634 | |
635 " characterwise select mode: delete middle two lines | |
636 call deletebufline('', 1, '$') | |
637 call append('$', ['a', 'b', 'c']) | |
638 exe "normal Gkkgh\<Down>\<End>\<Del>" | |
639 call assert_equal(['', 'c'], getline(1, '$')) | |
640 | |
641 " characterwise select mode: delete last line | |
642 call deletebufline('', 1, '$') | |
643 call append('$', ['a', 'b', 'c']) | |
644 exe "normal Ggh\<End>\<Del>" | |
645 call assert_equal(['', 'a', 'b', ''], getline(1, '$')) | |
646 | |
647 " characterwise select mode: delete last two lines | |
648 call deletebufline('', 1, '$') | |
649 call append('$', ['a', 'b', 'c']) | |
650 exe "normal Gkgh\<Down>\<End>\<Del>" | |
651 call assert_equal(['', 'a', ''], getline(1, '$')) | |
652 | |
653 " CTRL-H in select mode behaves like 'x' | |
654 call setline(1, 'abcdef') | |
655 exe "normal! gggh\<Right>\<Right>\<Right>\<C-H>" | |
656 call assert_equal('ef', getline(1)) | |
657 | |
658 " CTRL-O in select mode switches to visual mode for one command | |
659 call setline(1, 'abcdef') | |
660 exe "normal! gggh\<C-O>3lm" | |
661 call assert_equal('mef', getline(1)) | |
662 | |
663 sunmap <lt>End> | |
664 sunmap <lt>Down> | |
665 sunmap <lt>Del> | |
666 bwipe! | |
667 endfunc | |
668 | |
669 func Test_linewise_select_mode() | |
670 new | |
671 | |
672 " linewise select mode: delete middle line | |
673 call append('$', ['a', 'b', 'c']) | |
674 exe "normal GkkgH\<Del>" | |
675 call assert_equal(['', 'b', 'c'], getline(1, '$')) | |
676 | |
677 " linewise select mode: delete middle two lines | |
678 call deletebufline('', 1, '$') | |
679 call append('$', ['a', 'b', 'c']) | |
680 exe "normal GkkgH\<Down>\<Del>" | |
681 call assert_equal(['', 'c'], getline(1, '$')) | |
682 | |
683 " linewise select mode: delete last line | |
684 call deletebufline('', 1, '$') | |
685 call append('$', ['a', 'b', 'c']) | |
686 exe "normal GgH\<Del>" | |
687 call assert_equal(['', 'a', 'b'], getline(1, '$')) | |
688 | |
689 " linewise select mode: delete last two lines | |
690 call deletebufline('', 1, '$') | |
691 call append('$', ['a', 'b', 'c']) | |
692 exe "normal GkgH\<Down>\<Del>" | |
693 call assert_equal(['', 'a'], getline(1, '$')) | |
694 | |
695 bwipe! | |
696 endfunc | |
697 | |
698 " Test for blockwise select mode (g CTRL-H) | |
699 func Test_blockwise_select_mode() | |
700 new | |
701 call setline(1, ['foo', 'bar']) | |
702 call feedkeys("g\<BS>\<Right>\<Down>mm", 'xt') | |
703 call assert_equal(['mmo', 'mmr'], getline(1, '$')) | |
704 close! | |
705 endfunc | |
706 | |
707 func Test_visual_mode_put() | 621 func Test_visual_mode_put() |
708 new | 622 new |
709 | 623 |
710 " v_p: replace last character with line register at middle line | 624 " v_p: replace last character with line register at middle line |
711 call append('$', ['aaa', 'bbb', 'ccc']) | 625 call append('$', ['aaa', 'bbb', 'ccc']) |
741 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) | 655 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$')) |
742 | 656 |
743 bwipe! | 657 bwipe! |
744 endfunc | 658 endfunc |
745 | 659 |
746 func Test_select_mode_gv() | 660 func Test_gv_with_exclusive_selection() |
747 new | 661 new |
748 | 662 |
749 " gv in exclusive select mode after operation | 663 " gv with exclusive selection after an operation |
750 call append('$', ['zzz ', 'äà ']) | 664 call append('$', ['zzz ', 'äà ']) |
751 set selection=exclusive | 665 set selection=exclusive |
752 normal Gkv3lyjv3lpgvcxxx | 666 normal Gkv3lyjv3lpgvcxxx |
753 call assert_equal(['', 'zzz ', 'xxx '], getline(1, '$')) | 667 call assert_equal(['', 'zzz ', 'xxx '], getline(1, '$')) |
754 | 668 |
755 " gv in exclusive select mode without operation | 669 " gv with exclusive selection without an operation |
756 call deletebufline('', 1, '$') | 670 call deletebufline('', 1, '$') |
757 call append('$', 'zzz ') | 671 call append('$', 'zzz ') |
758 set selection=exclusive | 672 set selection=exclusive |
759 exe "normal G0v3l\<Esc>gvcxxx" | 673 exe "normal G0v3l\<Esc>gvcxxx" |
760 call assert_equal(['', 'xxx '], getline(1, '$')) | 674 call assert_equal(['', 'xxx '], getline(1, '$')) |
938 delmarks < > | 852 delmarks < > |
939 call assert_fails('*yank', 'E20:') | 853 call assert_fails('*yank', 'E20:') |
940 close! | 854 close! |
941 endfunc | 855 endfunc |
942 | 856 |
943 " Test for using visual mode maps in select mode | |
944 func Test_select_mode_map() | |
945 new | |
946 vmap <buffer> <F2> 3l | |
947 call setline(1, 'Test line') | |
948 call feedkeys("gh\<F2>map", 'xt') | |
949 call assert_equal('map line', getline(1)) | |
950 | |
951 vmap <buffer> <F2> ygV | |
952 call feedkeys("0gh\<Right>\<Right>\<F2>cwabc", 'xt') | |
953 call assert_equal('abc line', getline(1)) | |
954 | |
955 vmap <buffer> <F2> :<C-U>let v=100<CR> | |
956 call feedkeys("gggh\<Right>\<Right>\<F2>foo", 'xt') | |
957 call assert_equal('foo line', getline(1)) | |
958 | |
959 " reselect the select mode using gv from a visual mode map | |
960 vmap <buffer> <F2> gv | |
961 set selectmode=cmd | |
962 call feedkeys("0gh\<F2>map", 'xt') | |
963 call assert_equal('map line', getline(1)) | |
964 set selectmode& | |
965 | |
966 close! | |
967 endfunc | |
968 | |
969 " Test for changing text in visual mode with 'exclusive' selection | 857 " Test for changing text in visual mode with 'exclusive' selection |
970 func Test_exclusive_selection() | 858 func Test_exclusive_selection() |
971 new | 859 new |
972 call setline(1, ['one', 'two']) | 860 call setline(1, ['one', 'two']) |
973 set selection=exclusive | 861 set selection=exclusive |