robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesfeat(help): super K (":help!") guesses tag at cursor #3620516f7440cc7

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