2017-02-17 12:04:56 +01:00
|
|
|
|
" Tests for :help
|
|
|
|
|
|
2021-03-19 14:38:12 +01:00
|
|
|
|
source check.vim
|
2022-01-30 16:42:56 +00:00
|
|
|
|
import './vim9.vim' as v9
|
2021-03-19 14:38:12 +01:00
|
|
|
|
|
2017-02-17 12:04:56 +01:00
|
|
|
|
func Test_help_restore_snapshot()
|
|
|
|
|
help
|
|
|
|
|
set buftype=
|
|
|
|
|
help
|
|
|
|
|
edit x
|
|
|
|
|
help
|
|
|
|
|
helpclose
|
|
|
|
|
endfunc
|
2017-03-16 22:26:44 +01:00
|
|
|
|
|
2022-05-04 22:13:47 +01:00
|
|
|
|
func Test_help_restore_snapshot_split()
|
|
|
|
|
" Squeeze the unnamed buffer, Xfoo and the help one side-by-side and focus
|
|
|
|
|
" the first one before calling :help.
|
|
|
|
|
let bnr = bufnr()
|
|
|
|
|
botright vsp Xfoo
|
|
|
|
|
wincmd h
|
|
|
|
|
help
|
|
|
|
|
wincmd L
|
|
|
|
|
let g:did_bufenter = v:false
|
|
|
|
|
augroup T
|
|
|
|
|
au!
|
|
|
|
|
au BufEnter Xfoo let g:did_bufenter = v:true
|
|
|
|
|
augroup END
|
|
|
|
|
helpclose
|
|
|
|
|
augroup! T
|
|
|
|
|
" We're back to the unnamed buffer.
|
|
|
|
|
call assert_equal(bnr, bufnr())
|
|
|
|
|
" No BufEnter was triggered for Xfoo.
|
|
|
|
|
call assert_equal(v:false, g:did_bufenter)
|
|
|
|
|
|
|
|
|
|
close!
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2017-03-16 22:26:44 +01:00
|
|
|
|
func Test_help_errors()
|
|
|
|
|
call assert_fails('help doesnotexist', 'E149:')
|
|
|
|
|
call assert_fails('help!', 'E478:')
|
2020-02-02 15:32:13 +01:00
|
|
|
|
if has('multi_lang')
|
|
|
|
|
call assert_fails('help help@xy', 'E661:')
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
let save_hf = &helpfile
|
|
|
|
|
set helpfile=help_missing
|
|
|
|
|
help
|
|
|
|
|
call assert_equal(1, winnr('$'))
|
|
|
|
|
call assert_notequal('help', &buftype)
|
|
|
|
|
let &helpfile = save_hf
|
|
|
|
|
|
|
|
|
|
call assert_fails('help ' . repeat('a', 1048), 'E149:')
|
2017-08-26 16:25:32 +02:00
|
|
|
|
|
|
|
|
|
new
|
|
|
|
|
set keywordprg=:help
|
|
|
|
|
call setline(1, " ")
|
|
|
|
|
call assert_fails('normal VK', 'E349:')
|
|
|
|
|
bwipe!
|
|
|
|
|
endfunc
|
|
|
|
|
|
2019-10-05 11:30:09 +02:00
|
|
|
|
func Test_help_expr()
|
|
|
|
|
help expr-!~?
|
|
|
|
|
call assert_equal('eval.txt', expand('%:t'))
|
|
|
|
|
close
|
|
|
|
|
endfunc
|
|
|
|
|
|
2017-08-26 16:25:32 +02:00
|
|
|
|
func Test_help_keyword()
|
|
|
|
|
new
|
|
|
|
|
set keywordprg=:help
|
|
|
|
|
call setline(1, " Visual ")
|
|
|
|
|
normal VK
|
|
|
|
|
call assert_match('^Visual mode', getline('.'))
|
|
|
|
|
call assert_equal('help', &ft)
|
|
|
|
|
close
|
|
|
|
|
bwipe!
|
2017-03-16 22:26:44 +01:00
|
|
|
|
endfunc
|
2017-12-09 21:10:13 +01:00
|
|
|
|
|
|
|
|
|
func Test_help_local_additions()
|
2022-09-28 21:07:03 +01:00
|
|
|
|
call mkdir('Xruntime/doc', 'pR')
|
2017-12-09 21:10:13 +01:00
|
|
|
|
call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt')
|
|
|
|
|
call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt')
|
|
|
|
|
let rtp_save = &rtp
|
|
|
|
|
set rtp+=./Xruntime
|
2022-01-03 12:53:24 +00:00
|
|
|
|
help local-additions
|
|
|
|
|
let lines = getline(line(".") + 1, search("^$") - 1)
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ '|mydoc-ext.txt| my extended awesome doc',
|
|
|
|
|
\ '|mydoc.txt| my awesome doc'
|
|
|
|
|
\ ], lines)
|
|
|
|
|
call delete('Xruntime/doc/mydoc-ext.txt')
|
|
|
|
|
close
|
|
|
|
|
|
2022-09-28 21:07:03 +01:00
|
|
|
|
call mkdir('Xruntime-ja/doc', 'pR')
|
2022-01-03 12:53:24 +00:00
|
|
|
|
call writefile(["local-additions\thelp.jax\t/*local-additions*"], 'Xruntime-ja/doc/tags-ja')
|
|
|
|
|
call writefile(['*help.txt* This is jax file', '',
|
|
|
|
|
\ 'LOCAL ADDITIONS: *local-additions*', ''], 'Xruntime-ja/doc/help.jax')
|
|
|
|
|
call writefile(['*work.txt* This is jax file'], 'Xruntime-ja/doc/work.jax')
|
|
|
|
|
call writefile(['*work2.txt* This is jax file'], 'Xruntime-ja/doc/work2.jax')
|
|
|
|
|
set rtp+=./Xruntime-ja
|
|
|
|
|
|
|
|
|
|
help local-additions@en
|
|
|
|
|
let lines = getline(line(".") + 1, search("^$") - 1)
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ '|mydoc.txt| my awesome doc'
|
|
|
|
|
\ ], lines)
|
|
|
|
|
close
|
|
|
|
|
|
|
|
|
|
help local-additions@ja
|
|
|
|
|
let lines = getline(line(".") + 1, search("^$") - 1)
|
|
|
|
|
call assert_equal([
|
|
|
|
|
\ '|mydoc.txt| my awesome doc',
|
|
|
|
|
\ '|help.txt| This is jax file',
|
|
|
|
|
\ '|work.txt| This is jax file',
|
|
|
|
|
\ '|work2.txt| This is jax file',
|
|
|
|
|
\ ], lines)
|
2017-12-09 21:10:13 +01:00
|
|
|
|
close
|
|
|
|
|
|
|
|
|
|
let &rtp = rtp_save
|
|
|
|
|
endfunc
|
2019-12-27 17:20:55 +01:00
|
|
|
|
|
|
|
|
|
func Test_help_completion()
|
|
|
|
|
call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx')
|
|
|
|
|
call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:)
|
|
|
|
|
endfunc
|
2020-02-03 21:40:04 +01:00
|
|
|
|
|
|
|
|
|
" Test for the :helptags command
|
2021-03-05 20:47:44 +01:00
|
|
|
|
" NOTE: if you run tests as root this will fail. Don't run tests as root!
|
2020-02-03 21:40:04 +01:00
|
|
|
|
func Test_helptag_cmd()
|
2022-09-28 21:07:03 +01:00
|
|
|
|
call mkdir('Xtagdir/a/doc', 'pR')
|
2020-02-03 21:40:04 +01:00
|
|
|
|
|
|
|
|
|
" No help file to process in the directory
|
2022-08-29 22:31:20 +01:00
|
|
|
|
call assert_fails('helptags Xtagdir', 'E151:')
|
2020-02-03 21:40:04 +01:00
|
|
|
|
|
2022-08-29 22:31:20 +01:00
|
|
|
|
call writefile([], 'Xtagdir/a/doc/sample.txt')
|
2020-02-03 21:40:04 +01:00
|
|
|
|
|
|
|
|
|
" Test for ++t argument
|
2022-08-29 22:31:20 +01:00
|
|
|
|
helptags ++t Xtagdir
|
|
|
|
|
call assert_equal(["help-tags\ttags\t1"], readfile('Xtagdir/tags'))
|
|
|
|
|
call delete('Xtagdir/tags')
|
2020-02-03 21:40:04 +01:00
|
|
|
|
|
2022-07-30 12:03:16 +01:00
|
|
|
|
" Test parsing tags
|
|
|
|
|
call writefile(['*tag1*', 'Example: >', ' *notag*', 'Example end: *tag2*'],
|
2022-08-29 22:31:20 +01:00
|
|
|
|
\ 'Xtagdir/a/doc/sample.txt')
|
|
|
|
|
helptags Xtagdir
|
2022-07-30 12:03:16 +01:00
|
|
|
|
call assert_equal(["tag1\ta/doc/sample.txt\t/*tag1*",
|
2022-08-29 22:31:20 +01:00
|
|
|
|
\ "tag2\ta/doc/sample.txt\t/*tag2*"], readfile('Xtagdir/tags'))
|
2022-07-30 12:03:16 +01:00
|
|
|
|
|
2020-02-03 21:40:04 +01:00
|
|
|
|
" Duplicate tags in the help file
|
2022-08-29 22:31:20 +01:00
|
|
|
|
call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xtagdir/a/doc/sample.txt')
|
|
|
|
|
call assert_fails('helptags Xtagdir', 'E154:')
|
2020-02-03 21:40:04 +01:00
|
|
|
|
endfunc
|
|
|
|
|
|
2021-03-19 14:38:12 +01:00
|
|
|
|
func Test_helptag_cmd_readonly()
|
|
|
|
|
CheckUnix
|
|
|
|
|
CheckNotRoot
|
|
|
|
|
|
|
|
|
|
" Read-only tags file
|
2022-09-28 21:07:03 +01:00
|
|
|
|
call mkdir('Xrodir/doc', 'pR')
|
2022-08-29 22:31:20 +01:00
|
|
|
|
call writefile([''], 'Xrodir/doc/tags')
|
|
|
|
|
call writefile([], 'Xrodir/doc/sample.txt')
|
|
|
|
|
call setfperm('Xrodir/doc/tags', 'r-xr--r--')
|
|
|
|
|
call assert_fails('helptags Xrodir/doc', 'E152:', getfperm('Xrodir/doc/tags'))
|
2021-03-19 14:38:12 +01:00
|
|
|
|
|
|
|
|
|
let rtp = &rtp
|
2022-08-29 22:31:20 +01:00
|
|
|
|
let &rtp = 'Xrodir'
|
2021-03-19 14:38:12 +01:00
|
|
|
|
helptags ALL
|
|
|
|
|
let &rtp = rtp
|
|
|
|
|
|
2022-08-29 22:31:20 +01:00
|
|
|
|
call delete('Xrodir/doc/tags')
|
2021-03-19 14:38:12 +01:00
|
|
|
|
|
|
|
|
|
" No permission to read the help file
|
2022-08-29 22:31:20 +01:00
|
|
|
|
call mkdir('Xrodir/b/doc', 'p')
|
|
|
|
|
call writefile([], 'Xrodir/b/doc/sample.txt')
|
|
|
|
|
call setfperm('Xrodir/b/doc/sample.txt', '-w-------')
|
|
|
|
|
call assert_fails('helptags Xrodir', 'E153:', getfperm('Xrodir/b/doc/sample.txt'))
|
2021-03-19 14:38:12 +01:00
|
|
|
|
endfunc
|
|
|
|
|
|
2021-06-12 13:46:41 +02:00
|
|
|
|
" Test for setting the 'helpheight' option in the help window
|
|
|
|
|
func Test_help_window_height()
|
2022-03-02 20:49:50 +00:00
|
|
|
|
let &cmdheight = &lines - 23
|
2021-06-12 13:46:41 +02:00
|
|
|
|
set helpheight=10
|
|
|
|
|
help
|
|
|
|
|
set helpheight=14
|
|
|
|
|
call assert_equal(14, winheight(0))
|
|
|
|
|
set helpheight& cmdheight=1
|
|
|
|
|
close
|
|
|
|
|
endfunc
|
2021-03-19 14:38:12 +01:00
|
|
|
|
|
2021-11-25 10:50:12 +00:00
|
|
|
|
func Test_help_long_argument()
|
|
|
|
|
try
|
|
|
|
|
exe 'help \%' .. repeat('0', 1021)
|
|
|
|
|
catch
|
|
|
|
|
call assert_match("E149:", v:exception)
|
|
|
|
|
endtry
|
|
|
|
|
endfunc
|
|
|
|
|
|
2022-01-30 16:42:56 +00:00
|
|
|
|
func Test_help_using_visual_match()
|
|
|
|
|
let lines =<< trim END
|
|
|
|
|
call setline(1, ' ')
|
|
|
|
|
/^
|
|
|
|
|
exe "normal \<C-V>\<C-V>"
|
|
|
|
|
h5\%V]
|
|
|
|
|
END
|
|
|
|
|
call v9.CheckScriptFailure(lines, 'E149:')
|
|
|
|
|
endfunc
|
|
|
|
|
|
2021-11-25 10:50:12 +00:00
|
|
|
|
|
2020-02-03 21:40:04 +01:00
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|