neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_help.vim (8821B)


      1 " Tests for :help
      2 
      3 source check.vim
      4 source vim9.vim
      5 
      6 func SetUp()
      7  let s:vimruntime = $VIMRUNTIME
      8  let s:runtimepath = &runtimepath
      9  " Set $VIMRUNTIME to $BUILD_DIR/runtime and remove the original $VIMRUNTIME
     10  " path from &runtimepath so that ":h local-additions" won't pick up builtin
     11  " help files.
     12  let $VIMRUNTIME = expand($BUILD_DIR) .. '/runtime'
     13  set runtimepath-=../../../runtime
     14 endfunc
     15 
     16 func TearDown()
     17  let $VIMRUNTIME = s:vimruntime
     18  let &runtimepath = s:runtimepath
     19 endfunc
     20 
     21 func Test_help_restore_snapshot()
     22  help
     23  set buftype=
     24  help
     25  edit x
     26  help
     27  helpclose
     28 endfunc
     29 
     30 func Test_help_restore_snapshot_split()
     31  " Squeeze the unnamed buffer, Xfoo and the help one side-by-side and focus
     32  " the first one before calling :help.
     33  let bnr = bufnr()
     34  botright vsp Xfoo
     35  wincmd h
     36  help
     37  wincmd L
     38  let g:did_bufenter = v:false
     39  augroup T
     40    au!
     41    au BufEnter Xfoo let g:did_bufenter = v:true
     42  augroup END
     43  helpclose
     44  augroup! T
     45  " We're back to the unnamed buffer.
     46  call assert_equal(bnr, bufnr())
     47  " No BufEnter was triggered for Xfoo.
     48  call assert_equal(v:false, g:did_bufenter)
     49 
     50  close!
     51  bwipe!
     52 endfunc
     53 
     54 func Test_help_errors()
     55  call assert_fails('help doesnotexist', 'E149:')
     56  call assert_fails('help!', 'E478:')
     57  if has('multi_lang')
     58    call assert_fails('help help@xy', 'E661:')
     59  endif
     60 
     61  let save_hf = &helpfile
     62  set helpfile=help_missing
     63  help
     64  call assert_equal(1, winnr('$'))
     65  call assert_notequal('help', &buftype)
     66  let &helpfile = save_hf
     67 
     68  call assert_fails('help ' . repeat('a', 1048), 'E149:')
     69 
     70  new
     71  set keywordprg=:help
     72  call setline(1, "   ")
     73  call assert_fails('normal VK', 'E349:')
     74  bwipe!
     75 endfunc
     76 
     77 func Test_helpclose_errors()
     78  call assert_fails('42helpclose', 'E481:')
     79  call assert_fails('helpclose 42', 'E488:')
     80  call assert_fails('helpclose foo', 'E488:')
     81  call assert_fails('helpclose!', 'E477:')
     82 endfunc
     83 
     84 func Test_help_expr()
     85  help expr-!~?
     86  call assert_equal('vimeval.txt', expand('%:t'))
     87  close
     88 endfunc
     89 
     90 func Test_help_keyword()
     91  new
     92  set keywordprg=:help
     93  call setline(1, "  Visual ")
     94  normal VK
     95  call assert_match('^Visual mode', getline('.'))
     96  call assert_equal('help', &ft)
     97  close
     98  bwipe!
     99 endfunc
    100 
    101 func Test_help_local_additions()
    102  call mkdir('Xruntime/doc', 'p')
    103  call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt')
    104  call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt')
    105  let rtp_save = &rtp
    106  set rtp+=./Xruntime
    107  help local-additions
    108  let lines = getline(line(".") + 1, search("^$") - 1)
    109  call assert_equal([
    110  \ '|mydoc.txt|                                                     my awesome doc',
    111  \ '|mydoc-ext.txt|                                        my extended awesome doc'
    112  \ ], lines)
    113  call delete('Xruntime/doc/mydoc-ext.txt')
    114  close
    115 
    116  call mkdir('Xruntime-ja/doc', 'p')
    117  call writefile(["local-additions\thelp.jax\t/*local-additions*"], 'Xruntime-ja/doc/tags-ja')
    118  call writefile(['*help.txt* This is jax file', '',
    119  \ 'LOCAL ADDITIONS: *local-additions*', ''], 'Xruntime-ja/doc/help.jax')
    120  call writefile(['*work.txt* This is jax file'], 'Xruntime-ja/doc/work.jax')
    121  call writefile(['*work2.txt* This is jax file'], 'Xruntime-ja/doc/work2.jax')
    122  set rtp+=./Xruntime-ja
    123 
    124  help local-additions@en
    125  let lines = getline(line(".") + 1, search("^$") - 1)
    126  call assert_equal([
    127  \ '|mydoc.txt|                                                     my awesome doc'
    128  \ ], lines)
    129  close
    130 
    131  help local-additions@ja
    132  let lines = getline(line(".") + 1, search("^$") - 1)
    133  call assert_equal([
    134  \ '|help.txt|                                                    This is jax file',
    135  \ '|mydoc.txt|                                                     my awesome doc',
    136  \ '|work.txt|                                                    This is jax file',
    137  \ '|work2.txt|                                                   This is jax file',
    138  \ ], lines)
    139  close
    140 
    141  call delete('Xruntime', 'rf')
    142  call delete('Xruntime-ja', 'rf')
    143  let &rtp = rtp_save
    144 endfunc
    145 
    146 func Test_help_completion()
    147  call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx')
    148  call assert_equal('"help :undo :undoj :undol :undojoin :undolist :Undotree', @:)
    149 endfunc
    150 
    151 " Test for the :helptags command
    152 " NOTE: if you run tests as root this will fail.  Don't run tests as root!
    153 func Test_helptag_cmd()
    154  call mkdir('Xtagdir/a/doc', 'p')
    155 
    156  " No help file to process in the directory
    157  call assert_fails('helptags Xtagdir', 'E151:')
    158 
    159  call writefile([], 'Xtagdir/a/doc/sample.txt')
    160 
    161  " Test for ++t argument
    162  helptags ++t Xtagdir
    163  call assert_equal(["help-tags\ttags\t1"], readfile('Xtagdir/tags'))
    164  call delete('Xtagdir/tags')
    165 
    166  " Test parsing tags
    167  call writefile(['*tag1*', 'Example: >', '  *notag1*', 'Example end: *tag2*',
    168                \ '>', '  *notag2*', '<',
    169                \ '*tag3*', 'Code: >vim', '  *notag3*', 'Code end: *tag4*',
    170                \ '>i3config', '  *notag4*', '<'],
    171    \ 'Xtagdir/a/doc/sample.txt')
    172  helptags Xtagdir
    173  call assert_equal(["tag1\ta/doc/sample.txt\t/*tag1*",
    174                   \ "tag2\ta/doc/sample.txt\t/*tag2*",
    175                   \ "tag3\ta/doc/sample.txt\t/*tag3*",
    176                   \ "tag4\ta/doc/sample.txt\t/*tag4*"],
    177    \ readfile('Xtagdir/tags'))
    178 
    179  " Duplicate tags in the help file
    180  call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xtagdir/a/doc/sample.txt')
    181  call assert_fails('helptags Xtagdir', 'E154:')
    182 
    183  call delete('Xtagdir', 'rf')
    184 endfunc
    185 
    186 func Test_helptag_cmd_readonly()
    187  CheckUnix
    188  CheckNotRoot
    189 
    190  " Read-only tags file
    191  call mkdir('Xrodir/doc', 'p')
    192  call writefile([''], 'Xrodir/doc/tags')
    193  call writefile([], 'Xrodir/doc/sample.txt')
    194  call setfperm('Xrodir/doc/tags', 'r-xr--r--')
    195  call assert_fails('helptags Xrodir/doc', 'E152:', getfperm('Xrodir/doc/tags'))
    196 
    197  let rtp = &rtp
    198  let &rtp = 'Xrodir'
    199  helptags ALL
    200  let &rtp = rtp
    201 
    202  call delete('Xrodir/doc/tags')
    203 
    204  " No permission to read the help file
    205  call mkdir('Xrodir/b/doc', 'p')
    206  call writefile([], 'Xrodir/b/doc/sample.txt')
    207  call setfperm('Xrodir/b/doc/sample.txt', '-w-------')
    208  call assert_fails('helptags Xrodir', 'E153:', getfperm('Xrodir/b/doc/sample.txt'))
    209  call delete('Xrodir', 'rf')
    210 endfunc
    211 
    212 " Test for setting the 'helpheight' option in the help window
    213 func Test_help_window_height()
    214  let &cmdheight = &lines - 23
    215  set helpheight=10
    216  help
    217  set helpheight=14
    218  call assert_equal(14, winheight(0))
    219  set helpheight& cmdheight=1
    220  close
    221 endfunc
    222 
    223 func Test_help_long_argument()
    224  try
    225    exe 'help \%' .. repeat('0', 1021)
    226  catch
    227    call assert_match("E149:", v:exception)
    228  endtry
    229 endfunc
    230 
    231 func Test_help_using_visual_match()
    232  let lines =<< trim END
    233      call setline(1, ' ')
    234      /^
    235      exe "normal \<C-V>\<C-V>"
    236      h5\%V€]
    237  END
    238  call CheckScriptFailure(lines, 'E149:')
    239 endfunc
    240 
    241 func Test_helptag_navigation()
    242  let helpdir = tempname()
    243  let tempfile = helpdir . '/test.txt'
    244  call mkdir(helpdir, 'pR')
    245  call writefile(['', '*[tag*', '', '|[tag|'], tempfile)
    246  exe 'helptags' helpdir
    247  exe 'sp' tempfile
    248  exe 'lcd' helpdir
    249  setl ft=help
    250  let &l:iskeyword='!-~,^*,^|,^",192-255'
    251  call cursor(4, 2)
    252  " Vim must not escape `[` when expanding the tag
    253  exe "normal! \<C-]>"
    254  call assert_equal(2, line('.'))
    255  bw
    256 endfunc
    257 
    258 func Test_help_command_termination()
    259  " :help {arg}
    260  call execute('help |')
    261  call assert_match('*bar\*', getline('.'))
    262 
    263  " :help {arg}
    264  call execute('help ||')
    265  call assert_match('*expr-barbar\*', getline('.'))
    266 
    267  " :help | <whitespace> <empty-command>
    268  call execute('help | ')
    269  call assert_match('*help.txt\*', getline('.'))
    270 
    271  " :help {arg} | <whitespace> <empty-command>
    272  call execute('help || ')
    273  call assert_match('*bar\*', getline('.'))
    274 
    275  " :help {arg}
    276  call assert_fails('help |||', 'E149:')
    277  " :help {arg} | <whitespace> <empty-command>
    278  call execute('help ||| ')
    279  call assert_match('*expr-barbar\*', getline('.'))
    280 
    281  " :help {invalid-arg}
    282  call assert_fails('help ||||', 'E149:')
    283  " :help {invalid-arg} | <whitespace> <empty-command>
    284  "   (aborted command sequence)
    285  call assert_fails('help |||| ', 'E149:')
    286 
    287  call assert_equal("nextcmd",
    288        \ execute("help |     echo 'nextcmd'")->split("\n")[-1])
    289  call assert_equal("nextcmd",
    290        \ execute("help ||    echo 'nextcmd'")->split("\n")[-1])
    291  call assert_equal("nextcmd",
    292        \ execute("help \<NL> echo 'nextcmd'")->split("\n")[-1])
    293  call assert_equal("nextcmd",
    294        \ execute("help \<CR> echo 'nextcmd'")->split("\n")[-1])
    295 
    296  helpclose
    297 endfunc
    298 
    299 " This caused a buffer overflow
    300 func Test_helpfile_overflow()
    301  let _helpfile = &helpfile
    302  let &helpfile = repeat('A', 5000)
    303  help
    304  helpclose
    305  for i in range(4089, 4096)
    306    let &helpfile = repeat('A', i) .. '/A'
    307    help
    308    helpclose
    309  endfor
    310  let &helpfile = _helpfile
    311 endfunc
    312 
    313 " vim: shiftwidth=2 sts=2 expandtab