comparison src/testdir/test_cpoptions.vim @ 20848:d3fa0d29fa9a v8.2.0976

patch 8.2.0976: some 'cpoptions' not tested Commit: https://github.com/vim/vim/commit/df7df59d85e7e56a796912dc865488a75d3f0e53 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 14 13:50:55 2020 +0200 patch 8.2.0976: some 'cpoptions' not tested Problem: Some 'cpoptions' not tested. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6253)
author Bram Moolenaar <Bram@vim.org>
date Sun, 14 Jun 2020 14:00:03 +0200
parents 045442aa392b
children 505d97ea54da
comparison
equal deleted inserted replaced
20847:4e1017c5fbb5 20848:d3fa0d29fa9a
1 " Test for various 'cpoptions' (cpo) flags 1 " Test for the various 'cpoptions' (cpo) flags
2 2
3 source check.vim 3 source check.vim
4 source shared.vim
4 source view_util.vim 5 source view_util.vim
5 6
6 " Test for the 'a' flag in 'cpo'. Reading a file should set the alternate 7 " Test for the 'a' flag in 'cpo'. Reading a file should set the alternate
7 " file name. 8 " file name.
8 func Test_cpo_a() 9 func Test_cpo_a()
58 set cpo-=b 59 set cpo-=b
59 nnoremap <F5> :pwd\<CR>\|let i = 1 60 nnoremap <F5> :pwd\<CR>\|let i = 1
60 call assert_equal(':pwd\<CR>|let i = 1', maparg('<F5>')) 61 call assert_equal(':pwd\<CR>|let i = 1', maparg('<F5>'))
61 let &cpo = save_cpo 62 let &cpo = save_cpo
62 nunmap <F5> 63 nunmap <F5>
64 endfunc
65
66 " Test for the 'B' flag in 'cpo'. A backslash in mappings, abbreviations, user
67 " commands and menu commands has no special meaning.
68 func Test_cpo_B()
69 let save_cpo = &cpo
70 new
71 set cpo-=B
72 iabbr <buffer> abc ab\<BS>d
73 exe "normal iabc "
74 call assert_equal('ab<BS>d ', getline(1))
75 %d
76 set cpo+=B
77 iabbr <buffer> abc ab\<BS>d
78 exe "normal iabc "
79 call assert_equal('abd ', getline(1))
80 close!
81 let &cpo = save_cpo
63 endfunc 82 endfunc
64 83
65 " Test for the 'c' flag in 'cpo'. 84 " Test for the 'c' flag in 'cpo'.
66 func Test_cpo_c() 85 func Test_cpo_c()
67 let save_cpo = &cpo 86 let save_cpo = &cpo
224 call assert_equal(' a ', getline(1)) 243 call assert_equal(' a ', getline(1))
225 close! 244 close!
226 let &cpo = save_cpo 245 let &cpo = save_cpo
227 endfunc 246 endfunc
228 247
248 " TODO: Add a test for the 'i' flag in 'cpo'
249
229 " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys) 250 " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys)
230 func Test_cpo_I() 251 func Test_cpo_I()
231 let save_cpo = &cpo 252 let save_cpo = &cpo
232 new 253 new
233 setlocal autoindent 254 setlocal autoindent
239 exe "normal i one\<CR>\<Up>" 260 exe "normal i one\<CR>\<Up>"
240 call assert_equal('', getline(2)) 261 call assert_equal('', getline(2))
241 close! 262 close!
242 let &cpo = save_cpo 263 let &cpo = save_cpo
243 endfunc 264 endfunc
265
266 " Test for the 'j' flag in 'cpo' is in the test_join.vim file.
244 267
245 " Test for the 'J' flag in 'cpo' (two spaces after a sentence) 268 " Test for the 'J' flag in 'cpo' (two spaces after a sentence)
246 func Test_cpo_J() 269 func Test_cpo_J()
247 let save_cpo = &cpo 270 let save_cpo = &cpo
248 new 271 new
269 endfor 292 endfor
270 close! 293 close!
271 let &cpo = save_cpo 294 let &cpo = save_cpo
272 endfunc 295 endfunc
273 296
274 " TODO: Add a test for 'k' in 'cpo' 297 " TODO: Add a test for the 'k' flag in 'cpo'
275 298
276 " TODO: Add a test for 'K' in 'cpo' 299 " TODO: Add a test for the 'K' flag in 'cpo'
277 300
278 " Test for the 'l' flag in 'cpo' (backslash in a [] range) 301 " Test for the 'l' flag in 'cpo' (backslash in a [] range)
279 func Test_cpo_l() 302 func Test_cpo_l()
280 let save_cpo = &cpo 303 let save_cpo = &cpo
281 new 304 new
309 call assert_equal("\<Tab>ijklmnopqr", getline(1)) 332 call assert_equal("\<Tab>ijklmnopqr", getline(1))
310 close! 333 close!
311 let &cpo = save_cpo 334 let &cpo = save_cpo
312 endfunc 335 endfunc
313 336
314 " TODO: This test doesn't work. 337 " TODO: Add a test for the 'm' flag in 'cpo'
315 338
316 " Test for the 'M' flag in 'cpo' (% with escape parenthesis) 339 " Test for the 'M' flag in 'cpo' (% with escape parenthesis)
317 func Test_cpo_M() 340 func Test_cpo_M()
318 let save_cpo = &cpo 341 let save_cpo = &cpo
319 new 342 new
393 call assert_equal(['one'], readfile('Xfile')) 416 call assert_equal(['one'], readfile('Xfile'))
394 close! 417 close!
395 call delete('Xfile') 418 call delete('Xfile')
396 let &cpo = save_cpo 419 let &cpo = save_cpo
397 endfunc 420 endfunc
421
422 " Test for the 'p' flag in 'cpo' is in the test_lispwords.vim file.
398 423
399 " Test for the 'P' flag in 'cpo' (appending to a file sets the current file 424 " Test for the 'P' flag in 'cpo' (appending to a file sets the current file
400 " name) 425 " name)
401 func Test_cpo_P() 426 func Test_cpo_P()
402 let save_cpo = &cpo 427 let save_cpo = &cpo
470 %!sort 495 %!sort
471 call assert_equal(0, line("'r")) 496 call assert_equal(0, line("'r"))
472 close! 497 close!
473 let &cpo = save_cpo 498 let &cpo = save_cpo
474 endfunc 499 endfunc
500
501 " TODO: Add a test for the 's' flag in 'cpo'
475 502
476 " Test for the 'S' flag in 'cpo' (copying buffer options) 503 " Test for the 'S' flag in 'cpo' (copying buffer options)
477 func Test_cpo_S() 504 func Test_cpo_S()
478 let save_cpo = &cpo 505 let save_cpo = &cpo
479 new Xfile1 506 new Xfile1
495 close! 522 close!
496 close! 523 close!
497 let &cpo = save_cpo 524 let &cpo = save_cpo
498 endfunc 525 endfunc
499 526
527 " Test for the 't' flag in 'cpo' is in the test_tagjump.vim file.
528
500 " Test for the 'u' flag in 'cpo' (Vi-compatible undo) 529 " Test for the 'u' flag in 'cpo' (Vi-compatible undo)
501 func Test_cpo_u() 530 func Test_cpo_u()
502 let save_cpo = &cpo 531 let save_cpo = &cpo
503 new 532 new
504 set cpo-=u 533 set cpo-=u
511 normal uu 540 normal uu
512 call assert_equal('abcdefghi', getline(1)) 541 call assert_equal('abcdefghi', getline(1))
513 close! 542 close!
514 let &cpo = save_cpo 543 let &cpo = save_cpo
515 endfunc 544 endfunc
545
546 " TODO: Add a test for the 'v' flag in 'cpo' (backspace doesn't remove
547 " characters from the screen)
548
549 " Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one
550 " character)
551 func Test_cpo_w()
552 let save_cpo = &cpo
553 new
554 set cpo+=w
555 call setline(1, 'here are some words')
556 norm! 1gg0elcwZZZ
557 call assert_equal('hereZZZ are some words', getline('.'))
558 norm! 1gg2elcWYYY
559 call assert_equal('hereZZZ areYYY some words', getline('.'))
560 set cpo-=w
561 call setline(1, 'here are some words')
562 norm! 1gg0elcwZZZ
563 call assert_equal('hereZZZare some words', getline('.'))
564 norm! 1gg2elcWYYY
565 call assert_equal('hereZZZare someYYYwords', getline('.'))
566 close!
567 let &cpo = save_cpo
568 endfunc
569
570 " Test for the 'W' flag in 'cpo' is in the test_writefile.vim file
516 571
517 " Test for the 'x' flag in 'cpo' (Esc on command-line executes command) 572 " Test for the 'x' flag in 'cpo' (Esc on command-line executes command)
518 func Test_cpo_x() 573 func Test_cpo_x()
519 let save_cpo = &cpo 574 let save_cpo = &cpo
520 set cpo-=x 575 set cpo-=x
584 close! 639 close!
585 call delete('Xfile') 640 call delete('Xfile')
586 let &cpo = save_cpo 641 let &cpo = save_cpo
587 endfunc 642 endfunc
588 643
589 " Test for cursor movement with '-' in 'cpoptions' 644 " Test for the '!' flag in 'cpo' is in the test_normal.vim file
590 func Test_cpo_minus()
591 new
592 call setline(1, ['foo', 'bar', 'baz'])
593 let save_cpo = &cpo
594 set cpo+=-
595 call assert_beeps('normal 10j')
596 call assert_equal(1, line('.'))
597 normal G
598 call assert_beeps('normal 10k')
599 call assert_equal(3, line('.'))
600 call assert_fails(10, 'E16:')
601 let &cpo = save_cpo
602 close!
603 endfunc
604 645
605 " Test for displaying dollar when changing text ('$' flag in 'cpoptions') 646 " Test for displaying dollar when changing text ('$' flag in 'cpoptions')
606 func Test_cpo_dollar() 647 func Test_cpo_dollar()
607 new 648 new
608 let g:Line = '' 649 let g:Line = ''
622 call test_override('ALL', 0) 663 call test_override('ALL', 0)
623 delfunc SaveFirstLine 664 delfunc SaveFirstLine
624 %bw! 665 %bw!
625 endfunc 666 endfunc
626 667
668 " Test for the '%' flag in 'cpo' (parenthesis matching inside strings)
669 func Test_cpo_percent()
670 let save_cpo = &cpo
671 new
672 call setline(1, ' if (strcmp("ab)cd(", s))')
673 set cpo-=%
674 normal 8|%
675 call assert_equal(28, col('.'))
676 normal 15|%
677 call assert_equal(27, col('.'))
678 normal 27|%
679 call assert_equal(15, col('.'))
680 call assert_beeps("normal 19|%")
681 call assert_beeps("normal 22|%")
682 set cpo+=%
683 normal 8|%
684 call assert_equal(28, col('.'))
685 normal 15|%
686 call assert_equal(19, col('.'))
687 normal 27|%
688 call assert_equal(22, col('.'))
689 normal 19|%
690 call assert_equal(15, col('.'))
691 normal 22|%
692 call assert_equal(27, col('.'))
693 close!
694 let &cpo = save_cpo
695 endfunc
696
697 " Test for cursor movement with '-' in 'cpoptions'
698 func Test_cpo_minus()
699 new
700 call setline(1, ['foo', 'bar', 'baz'])
701 let save_cpo = &cpo
702 set cpo+=-
703 call assert_beeps('normal 10j')
704 call assert_equal(1, line('.'))
705 normal G
706 call assert_beeps('normal 10k')
707 call assert_equal(3, line('.'))
708 call assert_fails(10, 'E16:')
709 close!
710 let &cpo = save_cpo
711 endfunc
712
713 " Test for the '+' flag in 'cpo' ('write file' command resets the 'modified'
714 " flag)
715 func Test_cpo_plus()
716 let save_cpo = &cpo
717 call writefile([], 'Xfile')
718 new Xfile
719 call setline(1, 'foo')
720 write X1
721 call assert_equal(1, &modified)
722 set cpo+=+
723 write X2
724 call assert_equal(0, &modified)
725 close!
726 call delete('Xfile')
727 call delete('X1')
728 call delete('X2')
729 let &cpo = save_cpo
730 endfunc
731
732 " Test for the '*' flag in 'cpo' (':*' is same as ':@')
733 func Test_cpo_star()
734 let save_cpo = &cpo
735 let x = 0
736 new
737 set cpo-=*
738 let @a = 'let x += 1'
739 call assert_fails('*a', 'E20:')
740 set cpo+=*
741 *a
742 call assert_equal(1, x)
743 close!
744 let &cpo = save_cpo
745 endfunc
746
747 " Test for the '<' flag in 'cpo' is in the test_mapping.vim file
748
749 " Test for the '>' flag in 'cpo' (use a new line when appending to a register)
750 func Test_cpo_gt()
751 let save_cpo = &cpo
752 new
753 call setline(1, 'one two')
754 set cpo-=>
755 let @r = ''
756 normal gg"Rye
757 normal "Rye
758 call assert_equal("oneone", @r)
759 set cpo+=>
760 let @r = ''
761 normal gg"Rye
762 normal "Rye
763 call assert_equal("\none\none", @r)
764 close!
765 let &cpo = save_cpo
766 endfunc
767
768 " Test for the ';' flag in 'cpo'
769 " Test for t,f,F,T movement commands and 'cpo-;' setting
770 func Test_cpo_semicolon()
771 let save_cpo = &cpo
772 new
773 call append(0, ["aaa two three four", " zzz", "yyy ",
774 \ "bbb yee yoo four", "ccc two three four",
775 \ "ddd yee yoo four"])
776 set cpo-=;
777 1
778 normal! 0tt;D
779 2
780 normal! 0fz;D
781 3
782 normal! $Fy;D
783 4
784 normal! $Ty;D
785 set cpo+=;
786 5
787 normal! 0tt;;D
788 6
789 normal! $Ty;;D
790
791 call assert_equal('aaa two', getline(1))
792 call assert_equal(' z', getline(2))
793 call assert_equal('y', getline(3))
794 call assert_equal('bbb y', getline(4))
795 call assert_equal('ccc', getline(5))
796 call assert_equal('ddd yee y', getline(6))
797 close!
798 let &cpo = save_cpo
799 endfunc
800
801 " Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators)
802 func Test_cpo_hash()
803 let save_cpo = &cpo
804 new
805 set cpo-=#
806 call setline(1, ['one', 'two', 'three'])
807 normal gg2D
808 call assert_equal(['three'], getline(1, '$'))
809 normal gg2ofour
810 call assert_equal(['three', 'four', 'four'], getline(1, '$'))
811 normal gg2Otwo
812 call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$'))
813 %d
814 set cpo+=#
815 call setline(1, ['one', 'two', 'three'])
816 normal gg2D
817 call assert_equal(['', 'two', 'three'], getline(1, '$'))
818 normal gg2oone
819 call assert_equal(['', 'one', 'two', 'three'], getline(1, '$'))
820 normal gg2Ozero
821 call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$'))
822 close!
823 let &cpo = save_cpo
824 endfunc
825
826 " Test for the '&' flag in 'cpo'. The swap file is kept when a buffer is still
827 " loaded and ':preserve' is used.
828 func Test_cpo_ampersand()
829 call writefile(['one'], 'Xfile')
830 let after =<< trim [CODE]
831 set cpo+=&
832 preserve
833 qall
834 [CODE]
835 if RunVim([], after, 'Xfile')
836 call assert_equal(1, filereadable('.Xfile.swp'))
837 call delete('.Xfile.swp')
838 endif
839 call delete('Xfile')
840 endfunc
841
842 " Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern)
843 func Test_cpo_backslash()
844 let save_cpo = &cpo
845 new
846 call setline(1, ['', " \\-string"])
847 set cpo-=\
848 exe 'normal gg/[ \-]' .. "\<CR>n"
849 call assert_equal(3, col('.'))
850 set cpo+=\
851 exe 'normal gg/[ \-]' .. "\<CR>n"
852 call assert_equal(2, col('.'))
853 close!
854 let &cpo = save_cpo
855 endfunc
856
857 " Test for the '/' flag in 'cpo' is in the test_substitute.vim file
858
859 " Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a {
860 " character at the start of a line)
861 func Test_cpo_brace()
862 let save_cpo = &cpo
863 new
864 call setline(1, ['', '{', ' int i;', '}', ''])
865 set cpo-={
866 normal gg}
867 call assert_equal(5, line('.'))
868 normal G{
869 call assert_equal(1, line('.'))
870 set cpo+={
871 normal gg}
872 call assert_equal(2, line('.'))
873 normal G{
874 call assert_equal(2, line('.'))
875 close!
876 let &cpo = save_cpo
877 endfunc
878
879 " Test for the '.' flag in 'cpo' (:cd command fails if the current buffer is
880 " modified)
881 func Test_cpo_dot()
882 let save_cpo = &cpo
883 new Xfoo
884 call setline(1, 'foo')
885 let save_dir = getcwd()
886 set cpo+=.
887
888 " :cd should fail when buffer is modified and 'cpo' contains dot.
889 call assert_fails('cd ..', 'E747:')
890 call assert_equal(save_dir, getcwd())
891
892 " :cd with exclamation mark should succeed.
893 cd! ..
894 call assert_notequal(save_dir, getcwd())
895
896 " :cd should succeed when buffer has been written.
897 w!
898 exe 'cd ' .. fnameescape(save_dir)
899 call assert_equal(save_dir, getcwd())
900
901 call delete('Xfoo')
902 set cpo&
903 close!
904 let &cpo = save_cpo
905 endfunc
906
627 " vim: shiftwidth=2 sts=2 expandtab 907 " vim: shiftwidth=2 sts=2 expandtab