Mercurial > vim
comparison src/testdir/test_tagjump.vim @ 19055:8645b73b3645 v8.2.0088
patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Commit: https://github.com/vim/vim/commit/830c1afc9d2cd5819a05c71d4e0b1f748a8c0519
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 5 20:35:44 2020 +0100
patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Problem: Insufficient tests for tags; bug in using extra tag field when
using an ex command to position the cursor.
Solution: Fix the bug, add more tests. (Yegappan Lakshmanan, closes #5439)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 05 Jan 2020 20:45:05 +0100 |
parents | f0312cf3c792 |
children | fdc8deab9b4c |
comparison
equal
deleted
inserted
replaced
19054:ebee9e4dac40 | 19055:8645b73b3645 |
---|---|
576 call delete('Xtags') | 576 call delete('Xtags') |
577 call delete('Xtest.py') | 577 call delete('Xtest.py') |
578 set tags& | 578 set tags& |
579 endfunc | 579 endfunc |
580 | 580 |
581 " Test for expanding environment variable in a tag file name | |
582 func Test_tag_envvar() | |
583 call writefile(["Func1\t$FOO\t/^Func1/"], 'Xtags') | |
584 set tags=Xtags | |
585 | |
586 let $FOO='TagTestEnv' | |
587 | |
588 let caught_exception = v:false | |
589 try | |
590 tag Func1 | |
591 catch /E429:/ | |
592 call assert_match('E429:.*"TagTestEnv".*', v:exception) | |
593 let caught_exception = v:true | |
594 endtry | |
595 call assert_true(caught_exception) | |
596 | |
597 set tags& | |
598 call delete('Xtags') | |
599 unlet $FOO | |
600 endfunc | |
601 | |
602 " Test for :ptag | |
603 func Test_ptag() | |
604 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", | |
605 \ "second\tXfile1\t2", | |
606 \ "third\tXfile1\t3",], | |
607 \ 'Xtags') | |
608 set tags=Xtags | |
609 call writefile(['first', 'second', 'third'], 'Xfile1') | |
610 | |
611 enew | only | |
612 ptag third | |
613 call assert_equal(2, winnr()) | |
614 call assert_equal(2, winnr('$')) | |
615 call assert_equal(1, getwinvar(1, '&previewwindow')) | |
616 call assert_equal(0, getwinvar(2, '&previewwindow')) | |
617 wincmd w | |
618 call assert_equal(3, line('.')) | |
619 | |
620 " jump to the tag again | |
621 ptag third | |
622 call assert_equal(3, line('.')) | |
623 | |
624 " close the preview window | |
625 pclose | |
626 call assert_equal(1, winnr('$')) | |
627 | |
628 call delete('Xfile1') | |
629 call delete('Xtags') | |
630 set tags& | |
631 endfunc | |
632 | |
633 " Tests for guessing the tag location | |
634 func Test_tag_guess() | |
635 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", | |
636 \ "func1\tXfoo\t/^int func1(int x)/", | |
637 \ "func2\tXfoo\t/^int func2(int y)/", | |
638 \ "func3\tXfoo\t/^func3/", | |
639 \ "func4\tXfoo\t/^func4/"], | |
640 \ 'Xtags') | |
641 set tags=Xtags | |
642 let code =<< trim [CODE] | |
643 | |
644 int FUNC1 (int x) { } | |
645 int | |
646 func2 (int y) { } | |
647 int * func3 () { } | |
648 | |
649 [CODE] | |
650 call writefile(code, 'Xfoo') | |
651 | |
652 let v:statusmsg = '' | |
653 ta func1 | |
654 call assert_match('E435:', v:statusmsg) | |
655 call assert_equal(2, line('.')) | |
656 let v:statusmsg = '' | |
657 ta func2 | |
658 call assert_match('E435:', v:statusmsg) | |
659 call assert_equal(4, line('.')) | |
660 let v:statusmsg = '' | |
661 ta func3 | |
662 call assert_match('E435:', v:statusmsg) | |
663 call assert_equal(5, line('.')) | |
664 call assert_fails('ta func4', 'E434:') | |
665 | |
666 call delete('Xtags') | |
667 call delete('Xfoo') | |
668 set tags& | |
669 endfunc | |
670 | |
671 " Test for an unsorted tags file | |
672 func Test_tag_sort() | |
673 call writefile([ | |
674 \ "first\tXfoo\t1", | |
675 \ "ten\tXfoo\t3", | |
676 \ "six\tXfoo\t2"], | |
677 \ 'Xtags') | |
678 set tags=Xtags | |
679 let code =<< trim [CODE] | |
680 int first() {} | |
681 int six() {} | |
682 int ten() {} | |
683 [CODE] | |
684 call writefile(code, 'Xfoo') | |
685 | |
686 call assert_fails('tag first', 'E432:') | |
687 | |
688 call delete('Xtags') | |
689 call delete('Xfoo') | |
690 set tags& | |
691 %bwipe | |
692 endfunc | |
693 | |
694 " Test for an unsorted tags file | |
695 func Test_tag_fold() | |
696 call writefile([ | |
697 \ "!_TAG_FILE_ENCODING\tutf-8\t//", | |
698 \ "!_TAG_FILE_SORTED\t2\t/0=unsorted, 1=sorted, 2=foldcase/", | |
699 \ "first\tXfoo\t1", | |
700 \ "second\tXfoo\t2", | |
701 \ "third\tXfoo\t3"], | |
702 \ 'Xtags') | |
703 set tags=Xtags | |
704 let code =<< trim [CODE] | |
705 int first() {} | |
706 int second() {} | |
707 int third() {} | |
708 [CODE] | |
709 call writefile(code, 'Xfoo') | |
710 | |
711 enew | |
712 tag second | |
713 call assert_equal('Xfoo', bufname('')) | |
714 call assert_equal(2, line('.')) | |
715 | |
716 call delete('Xtags') | |
717 call delete('Xfoo') | |
718 set tags& | |
719 %bwipe | |
720 endfunc | |
721 | |
722 " Test for the :ltag command | |
723 func Test_ltag() | |
724 call writefile([ | |
725 \ "!_TAG_FILE_ENCODING\tutf-8\t//", | |
726 \ "first\tXfoo\t1", | |
727 \ "second\tXfoo\t/^int second() {}$/", | |
728 \ "third\tXfoo\t3"], | |
729 \ 'Xtags') | |
730 set tags=Xtags | |
731 let code =<< trim [CODE] | |
732 int first() {} | |
733 int second() {} | |
734 int third() {} | |
735 [CODE] | |
736 call writefile(code, 'Xfoo') | |
737 | |
738 enew | |
739 call setloclist(0, [], 'f') | |
740 ltag third | |
741 call assert_equal('Xfoo', bufname('')) | |
742 call assert_equal(3, line('.')) | |
743 call assert_equal([{'lnum': 3, 'bufnr': bufnr('Xfoo'), 'col': 0, | |
744 \ 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': 0, 'type': '', | |
745 \ 'module': '', 'text': 'third'}], getloclist(0)) | |
746 | |
747 ltag second | |
748 call assert_equal(2, line('.')) | |
749 call assert_equal([{'lnum': 0, 'bufnr': bufnr('Xfoo'), 'col': 0, | |
750 \ 'pattern': '^\Vint second() {}\$', 'valid': 1, 'vcol': 0, 'nr': 0, | |
751 \ 'type': '', 'module': '', 'text': 'second'}], getloclist(0)) | |
752 | |
753 call delete('Xtags') | |
754 call delete('Xfoo') | |
755 set tags& | |
756 %bwipe | |
757 endfunc | |
758 | |
759 " Test for setting the last search pattern to the tag search pattern | |
760 " when cpoptions has 't' | |
761 func Test_tag_last_search_pat() | |
762 call writefile([ | |
763 \ "!_TAG_FILE_ENCODING\tutf-8\t//", | |
764 \ "first\tXfoo\t/^int first() {}/", | |
765 \ "second\tXfoo\t/^int second() {}/", | |
766 \ "third\tXfoo\t/^int third() {}/"], | |
767 \ 'Xtags') | |
768 set tags=Xtags | |
769 let code =<< trim [CODE] | |
770 int first() {} | |
771 int second() {} | |
772 int third() {} | |
773 [CODE] | |
774 call writefile(code, 'Xfoo') | |
775 | |
776 enew | |
777 let save_cpo = &cpo | |
778 set cpo+=t | |
779 let @/ = '' | |
780 tag second | |
781 call assert_equal('^int second() {}', @/) | |
782 let &cpo = save_cpo | |
783 | |
784 call delete('Xtags') | |
785 call delete('Xfoo') | |
786 set tags& | |
787 %bwipe | |
788 endfunc | |
789 | |
790 " Test for jumping to a tag when the tag stack is full | |
791 func Test_tag_stack_full() | |
792 let l = [] | |
793 for i in range(10, 31) | |
794 let l += ["var" .. i .. "\tXfoo\t/^int var" .. i .. ";$/"] | |
795 endfor | |
796 call writefile(l, 'Xtags') | |
797 set tags=Xtags | |
798 | |
799 let l = [] | |
800 for i in range(10, 31) | |
801 let l += ["int var" .. i .. ";"] | |
802 endfor | |
803 call writefile(l, 'Xfoo') | |
804 | |
805 enew | |
806 for i in range(10, 30) | |
807 exe "tag var" .. i | |
808 endfor | |
809 let l = gettagstack() | |
810 call assert_equal(20, l.length) | |
811 call assert_equal('var11', l.items[0].tagname) | |
812 tag var31 | |
813 let l = gettagstack() | |
814 call assert_equal('var12', l.items[0].tagname) | |
815 call assert_equal('var31', l.items[19].tagname) | |
816 | |
817 " Jump from the top of the stack | |
818 call assert_fails('tag', 'E556:') | |
819 | |
820 " Pop from an unsaved buffer | |
821 enew! | |
822 call append(1, "sample text") | |
823 call assert_fails('pop', 'E37:') | |
824 call assert_equal(21, gettagstack().curidx) | |
825 enew! | |
826 | |
827 " Pop all the entries in the tag stack | |
828 call assert_fails('30pop', 'E555:') | |
829 | |
830 " Pop the tag stack when it is empty | |
831 call settagstack(1, {'items' : []}) | |
832 call assert_fails('pop', 'E73:') | |
833 | |
834 call delete('Xtags') | |
835 call delete('Xfoo') | |
836 set tags& | |
837 %bwipe | |
838 endfunc | |
839 | |
840 " Test for browsing multiple matching tags | |
841 func Test_tag_multimatch() | |
842 call writefile([ | |
843 \ "!_TAG_FILE_ENCODING\tutf-8\t//", | |
844 \ "first\tXfoo\t1", | |
845 \ "first\tXfoo\t2", | |
846 \ "first\tXfoo\t3"], | |
847 \ 'Xtags') | |
848 set tags=Xtags | |
849 let code =<< trim [CODE] | |
850 int first() {} | |
851 int first() {} | |
852 int first() {} | |
853 [CODE] | |
854 call writefile(code, 'Xfoo') | |
855 | |
856 tag first | |
857 tlast | |
858 call assert_equal(3, line('.')) | |
859 call assert_fails('tnext', 'E428:') | |
860 tfirst | |
861 call assert_equal(1, line('.')) | |
862 call assert_fails('tprev', 'E425:') | |
863 | |
864 call delete('Xtags') | |
865 call delete('Xfoo') | |
866 set tags& | |
867 %bwipe | |
868 endfunc | |
869 | |
581 " vim: shiftwidth=2 sts=2 expandtab | 870 " vim: shiftwidth=2 sts=2 expandtab |