Merge pull request #21102 from zeertzjq/vim-8.2.4512

vim-patch:8.2.{4512,4518,4538,4543,4544}: find_tags_in_file() function is too long
This commit is contained in:
zeertzjq 2022-11-18 20:01:09 +08:00 committed by GitHub
commit cf759c7429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 947 additions and 629 deletions

File diff suppressed because it is too large Load Diff

View File

@ -231,15 +231,13 @@ func Test_tag_symbolic()
endfunc
" Tests for tag search with !_TAG_FILE_ENCODING.
" Depends on the test83-tags2 and test83-tags3 files.
func Test_tag_file_encoding()
throw 'skipped: Nvim removed test83-tags2, test83-tags3'
if has('vms')
return
throw 'Skipped: does not work on VMS'
endif
if !has('iconv') || iconv("\x82\x60", "cp932", "utf-8") != "\uff21"
return
throw 'Skipped: iconv does not work'
endif
let save_enc = &encoding
@ -264,18 +262,31 @@ func Test_tag_file_encoding()
" case2:
new
set tags=test83-tags2
let content = ['!_TAG_FILE_ENCODING cp932 //',
\ "\x82`\x82a\x82b Xtags2.txt /\x82`\x82a\x82b"]
call writefile(content, 'Xtags')
set tags=Xtags
tag /.
call assert_equal('Xtags2.txt', expand('%:t'))
call assert_equal('', getline('.'))
call delete('Xtags')
close
" case3:
new
set tags=test83-tags3
let contents = [
\ "!_TAG_FILE_SORTED 1 //",
\ "!_TAG_FILE_ENCODING cp932 //"]
for i in range(1, 100)
call add(contents, 'abc' .. i
\ .. " Xtags3.txt /\x82`\x82a\x82b")
endfor
call writefile(contents, 'Xtags')
set tags=Xtags
tag abc50
call assert_equal('Xtags3.txt', expand('%:t'))
call assert_equal('', getline('.'))
call delete('Xtags')
close
set tags&
@ -327,6 +338,7 @@ func Test_tagjump_etags()
\ ], 'Xtags2')
tag main
call assert_equal(2, line('.'))
call assert_fails('tag bar', 'E426:')
" corrupted tag line
call writefile([
@ -352,6 +364,27 @@ func Test_tagjump_etags()
\ ], 'Xtags')
call assert_fails('tag foo', 'E431:')
" end of file after a CTRL-L line
call writefile([
\ "\x0c",
\ "Xmain.c,64",
\ "void foo() {}\x7ffoo\x011,0",
\ "\x0c",
\ ], 'Xtags')
call assert_fails('tag main', 'E426:')
" error in an included tags file
call writefile([
\ "\x0c",
\ "Xtags2,include"
\ ], 'Xtags')
call writefile([
\ "\x0c",
\ "Xmain.c,64",
\ "void foo() {}",
\ ], 'Xtags2')
call assert_fails('tag foo', 'E431:')
call delete('Xtags')
call delete('Xtags2')
call delete('Xmain.c')
@ -772,11 +805,11 @@ endfunc
" Test for an unsorted tags file
func Test_tag_sort()
call writefile([
let l = [
\ "first\tXfoo\t1",
\ "ten\tXfoo\t3",
\ "six\tXfoo\t2"],
\ 'Xtags')
\ "six\tXfoo\t2"]
call writefile(l, 'Xtags')
set tags=Xtags
let code =<< trim [CODE]
int first() {}
@ -787,7 +820,14 @@ func Test_tag_sort()
call assert_fails('tag first', 'E432:')
" When multiple tag files are not sorted, then message should be displayed
" multiple times
call writefile(l, 'Xtags2')
set tags=Xtags,Xtags2
call assert_fails('tag first', ['E432:', 'E432:'])
call delete('Xtags')
call delete('Xtags2')
call delete('Xfoo')
set tags&
%bwipe
@ -1453,6 +1493,11 @@ func Test_tagfile_errors()
\ "foo Xfile 1"], 'Xtags')
call assert_fails('tag foo', 'E431:')
" file name and search pattern are not separated by a tab
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "foo\tXfile 1;"], 'Xtags')
call assert_fails('tag foo', 'E431:')
call delete('Xtags')
call delete('Xfile')
set tags&
@ -1485,4 +1530,86 @@ func Test_stag_close_window_on_error()
set tags&
endfunc
" Test for 'tagbsearch' (binary search)
func Test_tagbsearch()
" If a tags file header says the tags are sorted, but the tags are actually
" unsorted, then binary search should fail and linear search should work.
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted, 2=foldcase/",
\ "third\tXfoo\t3",
\ "second\tXfoo\t2",
\ "first\tXfoo\t1"],
\ 'Xtags')
set tags=Xtags
let code =<< trim [CODE]
int first() {}
int second() {}
int third() {}
[CODE]
call writefile(code, 'Xfoo')
enew
set tagbsearch
call assert_fails('tag first', 'E426:')
call assert_equal('', bufname())
call assert_fails('tag second', 'E426:')
call assert_equal('', bufname())
tag third
call assert_equal('Xfoo', bufname())
call assert_equal(3, line('.'))
%bw!
set notagbsearch
tag first
call assert_equal('Xfoo', bufname())
call assert_equal(1, line('.'))
enew
tag second
call assert_equal('Xfoo', bufname())
call assert_equal(2, line('.'))
enew
tag third
call assert_equal('Xfoo', bufname())
call assert_equal(3, line('.'))
%bw!
" If a tags file header says the tags are unsorted, but the tags are
" actually sorted, then binary search should work.
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted, 2=foldcase/",
\ "first\tXfoo\t1",
\ "second\tXfoo\t2",
\ "third\tXfoo\t3"],
\ 'Xtags')
set tagbsearch
tag first
call assert_equal('Xfoo', bufname())
call assert_equal(1, line('.'))
enew
tag second
call assert_equal('Xfoo', bufname())
call assert_equal(2, line('.'))
enew
tag third
call assert_equal('Xfoo', bufname())
call assert_equal(3, line('.'))
%bw!
" Binary search fails on EOF
call writefile([
\ "!_TAG_FILE_ENCODING\tutf-8\t//",
\ "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted, 2=foldcase/",
\ "bar\tXfoo\t1",
\ "foo\tXfoo\t2"],
\ 'Xtags')
call assert_fails('tag bbb', 'E426:')
call delete('Xtags')
call delete('Xfoo')
set tags& tagbsearch&
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -36,6 +36,12 @@ func Test_taglist()
call assert_equal('d', cmd[0]['kind'])
call assert_equal('call cursor(3, 4)', cmd[0]['cmd'])
" Use characters with value > 127 in the tag extra field.
call writefile([
\ "vFoo\tXfoo\t4" .. ';"' .. "\ttypename:int\ta£££\tv",
\ ], 'Xtags')
call assert_equal('v', taglist('vFoo')[0].kind)
call assert_fails("let l=taglist([])", 'E730:')
call delete('Xtags')
@ -221,6 +227,11 @@ func Test_format_error()
endtry
call assert_true(caught_exception)
" no field after the filename for a tag
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "foo\tXfile"], 'Xtags')
call assert_fails("echo taglist('foo')", 'E431:')
set tags&
call delete('Xtags')
endfunc