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