comparison src/testdir/test_tagjump.vim @ 19063:fdc8deab9b4c v8.2.0092

patch 8.2.0092: tags functionality insufficiently tested Commit: https://github.com/vim/vim/commit/a1353b5352f0797fc651a0dd363876f1c2fa60c5 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 6 20:09:13 2020 +0100 patch 8.2.0092: tags functionality insufficiently tested Problem: Tags functionality insufficiently tested. Solution: Add more tags tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5446)
author Bram Moolenaar <Bram@vim.org>
date Mon, 06 Jan 2020 20:15:04 +0100
parents 8645b73b3645
children 67fbe280a502
comparison
equal deleted inserted replaced
19062:1eefc5cb7f1a 19063:fdc8deab9b4c
598 call delete('Xtags') 598 call delete('Xtags')
599 unlet $FOO 599 unlet $FOO
600 endfunc 600 endfunc
601 601
602 " Test for :ptag 602 " Test for :ptag
603 func Test_ptag() 603 func Test_tag_preview()
604 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", 604 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
605 \ "second\tXfile1\t2", 605 \ "second\tXfile1\t2",
606 \ "third\tXfile1\t3",], 606 \ "third\tXfile1\t3",],
607 \ 'Xtags') 607 \ 'Xtags')
608 set tags=Xtags 608 set tags=Xtags
612 ptag third 612 ptag third
613 call assert_equal(2, winnr()) 613 call assert_equal(2, winnr())
614 call assert_equal(2, winnr('$')) 614 call assert_equal(2, winnr('$'))
615 call assert_equal(1, getwinvar(1, '&previewwindow')) 615 call assert_equal(1, getwinvar(1, '&previewwindow'))
616 call assert_equal(0, getwinvar(2, '&previewwindow')) 616 call assert_equal(0, getwinvar(2, '&previewwindow'))
617 wincmd P
618 call assert_equal(3, line('.'))
619
620 " jump to the tag again
617 wincmd w 621 wincmd w
622 ptag third
623 wincmd P
618 call assert_equal(3, line('.')) 624 call assert_equal(3, line('.'))
619 625
620 " jump to the tag again 626 " jump to the newer tag
621 ptag third 627 wincmd w
628 ptag
629 wincmd P
622 call assert_equal(3, line('.')) 630 call assert_equal(3, line('.'))
623 631
624 " close the preview window 632 " close the preview window
625 pclose 633 pclose
626 call assert_equal(1, winnr('$')) 634 call assert_equal(1, winnr('$'))
785 call delete('Xfoo') 793 call delete('Xfoo')
786 set tags& 794 set tags&
787 %bwipe 795 %bwipe
788 endfunc 796 endfunc
789 797
790 " Test for jumping to a tag when the tag stack is full 798 " Tag stack tests
791 func Test_tag_stack_full() 799 func Test_tag_stack()
792 let l = [] 800 let l = []
793 for i in range(10, 31) 801 for i in range(10, 31)
794 let l += ["var" .. i .. "\tXfoo\t/^int var" .. i .. ";$/"] 802 let l += ["var" .. i .. "\tXfoo\t/^int var" .. i .. ";$/"]
795 endfor 803 endfor
796 call writefile(l, 'Xtags') 804 call writefile(l, 'Xtags')
800 for i in range(10, 31) 808 for i in range(10, 31)
801 let l += ["int var" .. i .. ";"] 809 let l += ["int var" .. i .. ";"]
802 endfor 810 endfor
803 call writefile(l, 'Xfoo') 811 call writefile(l, 'Xfoo')
804 812
813 " Jump to a tag when the tag stack is full. Oldest entry should be removed.
805 enew 814 enew
806 for i in range(10, 30) 815 for i in range(10, 30)
807 exe "tag var" .. i 816 exe "tag var" .. i
808 endfor 817 endfor
809 let l = gettagstack() 818 let l = gettagstack()
812 tag var31 821 tag var31
813 let l = gettagstack() 822 let l = gettagstack()
814 call assert_equal('var12', l.items[0].tagname) 823 call assert_equal('var12', l.items[0].tagname)
815 call assert_equal('var31', l.items[19].tagname) 824 call assert_equal('var31', l.items[19].tagname)
816 825
817 " Jump from the top of the stack 826 " Use tnext with a single match
827 call assert_fails('tnext', 'E427:')
828
829 " Jump to newest entry from the top of the stack
818 call assert_fails('tag', 'E556:') 830 call assert_fails('tag', 'E556:')
831
832 " Pop with zero count from the top of the stack
833 call assert_fails('0pop', 'E556:')
819 834
820 " Pop from an unsaved buffer 835 " Pop from an unsaved buffer
821 enew! 836 enew!
822 call append(1, "sample text") 837 call append(1, "sample text")
823 call assert_fails('pop', 'E37:') 838 call assert_fails('pop', 'E37:')
825 enew! 840 enew!
826 841
827 " Pop all the entries in the tag stack 842 " Pop all the entries in the tag stack
828 call assert_fails('30pop', 'E555:') 843 call assert_fails('30pop', 'E555:')
829 844
845 " Pop with a count when already at the bottom of the stack
846 call assert_fails('exe "normal 4\<C-T>"', 'E555:')
847 call assert_equal(1, gettagstack().curidx)
848
849 " Jump to newest entry from the bottom of the stack with zero count
850 call assert_fails('0tag', 'E555:')
851
830 " Pop the tag stack when it is empty 852 " Pop the tag stack when it is empty
831 call settagstack(1, {'items' : []}) 853 call settagstack(1, {'items' : []})
832 call assert_fails('pop', 'E73:') 854 call assert_fails('pop', 'E73:')
833 855
834 call delete('Xtags') 856 call delete('Xtags')
851 int first() {} 873 int first() {}
852 int first() {} 874 int first() {}
853 [CODE] 875 [CODE]
854 call writefile(code, 'Xfoo') 876 call writefile(code, 'Xfoo')
855 877
878 call settagstack(1, {'items' : []})
856 tag first 879 tag first
857 tlast 880 tlast
858 call assert_equal(3, line('.')) 881 call assert_equal(3, line('.'))
859 call assert_fails('tnext', 'E428:') 882 call assert_fails('tnext', 'E428:')
860 tfirst 883 tfirst
861 call assert_equal(1, line('.')) 884 call assert_equal(1, line('.'))
862 call assert_fails('tprev', 'E425:') 885 call assert_fails('tprev', 'E425:')
863 886
887 tlast
888 call feedkeys("5\<CR>", 't')
889 tselect first
890 call assert_equal(2, gettagstack().curidx)
891
892 set ignorecase
893 tag FIRST
894 tnext
895 call assert_equal(2, line('.'))
896 set ignorecase&
897
864 call delete('Xtags') 898 call delete('Xtags')
865 call delete('Xfoo') 899 call delete('Xfoo')
866 set tags& 900 set tags&
867 %bwipe 901 %bwipe
868 endfunc 902 endfunc
869 903
904 " Test for previewing multiple matching tags
905 func Test_preview_tag_multimatch()
906 call writefile([
907 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
908 \ "first\tXfoo\t1",
909 \ "first\tXfoo\t2",
910 \ "first\tXfoo\t3"],
911 \ 'Xtags')
912 set tags=Xtags
913 let code =<< trim [CODE]
914 int first() {}
915 int first() {}
916 int first() {}
917 [CODE]
918 call writefile(code, 'Xfoo')
919
920 enew | only
921 ptag first
922 ptlast
923 wincmd P
924 call assert_equal(3, line('.'))
925 wincmd w
926 call assert_fails('ptnext', 'E428:')
927 ptprev
928 wincmd P
929 call assert_equal(2, line('.'))
930 wincmd w
931 ptfirst
932 wincmd P
933 call assert_equal(1, line('.'))
934 wincmd w
935 call assert_fails('ptprev', 'E425:')
936 ptnext
937 wincmd P
938 call assert_equal(2, line('.'))
939 wincmd w
940 ptlast
941 call feedkeys("5\<CR>", 't')
942 ptselect first
943 wincmd P
944 call assert_equal(3, line('.'))
945
946 pclose
947
948 call delete('Xtags')
949 call delete('Xfoo')
950 set tags&
951 %bwipe
952 endfunc
953
954 " Test for jumping to multiple matching tags across multiple :tags commands
955 func Test_tnext_multimatch()
956 call writefile([
957 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
958 \ "first\tXfoo1\t1",
959 \ "first\tXfoo2\t1",
960 \ "first\tXfoo3\t1"],
961 \ 'Xtags')
962 set tags=Xtags
963 let code =<< trim [CODE]
964 int first() {}
965 [CODE]
966 call writefile(code, 'Xfoo1')
967 call writefile(code, 'Xfoo2')
968 call writefile(code, 'Xfoo3')
969
970 tag first
971 tag first
972 pop
973 tnext
974 tnext
975 call assert_fails('tnext', 'E428:')
976
977 call delete('Xtags')
978 call delete('Xfoo1')
979 call delete('Xfoo2')
980 call delete('Xfoo3')
981 set tags&
982 %bwipe
983 endfunc
984
985 " Test for jumping to multiple matching tags in non-existing files
986 func Test_multimatch_non_existing_files()
987 call writefile([
988 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
989 \ "first\tXfoo1\t1",
990 \ "first\tXfoo2\t1",
991 \ "first\tXfoo3\t1"],
992 \ 'Xtags')
993 set tags=Xtags
994
995 call settagstack(1, {'items' : []})
996 call assert_fails('tag first', 'E429:')
997 call assert_equal(3, gettagstack().items[0].matchnr)
998
999 call delete('Xtags')
1000 set tags&
1001 %bwipe
1002 endfunc
1003
1004 func Test_tselect_listing()
1005 call writefile([
1006 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
1007 \ "first\tXfoo\t1" .. ';"' .. "\tv\ttyperef:typename:int\tfile:",
1008 \ "first\tXfoo\t2" .. ';"' .. "\tv\ttyperef:typename:char\tfile:"],
1009 \ 'Xtags')
1010 set tags=Xtags
1011
1012 let code =<< trim [CODE]
1013 static int first;
1014 static char first;
1015 [CODE]
1016 call writefile(code, 'Xfoo')
1017
1018 call feedkeys("\<CR>", "t")
1019 let l = split(execute("tselect first"), "\n")
1020 let expected =<< [DATA]
1021 # pri kind tag file
1022 1 FS v first Xfoo
1023 typeref:typename:int
1024 1
1025 2 FS v first Xfoo
1026 typeref:typename:char
1027 2
1028 Type number and <Enter> (empty cancels):
1029 [DATA]
1030 call assert_equal(expected, l)
1031
1032 call delete('Xtags')
1033 call delete('Xfoo')
1034 set tags&
1035 %bwipe
1036 endfunc
1037
870 " vim: shiftwidth=2 sts=2 expandtab 1038 " vim: shiftwidth=2 sts=2 expandtab