blob: ff06b0f2ab72b7a939f3662ebaf61aed4e92abf8 [file] [log] [blame]
Bram Moolenaar343b8c02017-02-17 12:04:56 +01001" Tests for :help
2
Bram Moolenaar17709e22021-03-19 14:38:12 +01003source check.vim
Bram Moolenaar679d66c2022-01-30 16:42:56 +00004import './vim9.vim' as v9
Bram Moolenaar17709e22021-03-19 14:38:12 +01005
Bram Moolenaar343b8c02017-02-17 12:04:56 +01006func Test_help_restore_snapshot()
7 help
8 set buftype=
9 help
10 edit x
11 help
12 helpclose
13endfunc
Bram Moolenaar751ba612017-03-16 22:26:44 +010014
LemonBoy2a2707d2022-05-04 22:13:47 +010015func Test_help_restore_snapshot_split()
16 " Squeeze the unnamed buffer, Xfoo and the help one side-by-side and focus
17 " the first one before calling :help.
18 let bnr = bufnr()
19 botright vsp Xfoo
20 wincmd h
21 help
22 wincmd L
23 let g:did_bufenter = v:false
24 augroup T
25 au!
26 au BufEnter Xfoo let g:did_bufenter = v:true
27 augroup END
28 helpclose
29 augroup! T
30 " We're back to the unnamed buffer.
31 call assert_equal(bnr, bufnr())
32 " No BufEnter was triggered for Xfoo.
33 call assert_equal(v:false, g:did_bufenter)
34
35 close!
36 bwipe!
37endfunc
38
Bram Moolenaar751ba612017-03-16 22:26:44 +010039func Test_help_errors()
40 call assert_fails('help doesnotexist', 'E149:')
41 call assert_fails('help!', 'E478:')
Bram Moolenaarea3db912020-02-02 15:32:13 +010042 if has('multi_lang')
43 call assert_fails('help help@xy', 'E661:')
44 endif
45
46 let save_hf = &helpfile
47 set helpfile=help_missing
48 help
49 call assert_equal(1, winnr('$'))
50 call assert_notequal('help', &buftype)
51 let &helpfile = save_hf
52
53 call assert_fails('help ' . repeat('a', 1048), 'E149:')
Bram Moolenaara4f99f52017-08-26 16:25:32 +020054
55 new
56 set keywordprg=:help
57 call setline(1, " ")
58 call assert_fails('normal VK', 'E349:')
59 bwipe!
60endfunc
61
Bram Moolenaar9ca25082019-10-05 11:30:09 +020062func Test_help_expr()
63 help expr-!~?
64 call assert_equal('eval.txt', expand('%:t'))
65 close
66endfunc
67
Bram Moolenaara4f99f52017-08-26 16:25:32 +020068func Test_help_keyword()
69 new
70 set keywordprg=:help
71 call setline(1, " Visual ")
72 normal VK
73 call assert_match('^Visual mode', getline('.'))
74 call assert_equal('help', &ft)
75 close
76 bwipe!
Bram Moolenaar751ba612017-03-16 22:26:44 +010077endfunc
Bram Moolenaar35c5e812017-12-09 21:10:13 +010078
79func Test_help_local_additions()
80 call mkdir('Xruntime/doc', 'p')
81 call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt')
82 call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt')
83 let rtp_save = &rtp
84 set rtp+=./Xruntime
h-east0e2508d2022-01-03 12:53:24 +000085 help local-additions
86 let lines = getline(line(".") + 1, search("^$") - 1)
87 call assert_equal([
88 \ '|mydoc-ext.txt| my extended awesome doc',
89 \ '|mydoc.txt| my awesome doc'
90 \ ], lines)
91 call delete('Xruntime/doc/mydoc-ext.txt')
92 close
93
94 call mkdir('Xruntime-ja/doc', 'p')
95 call writefile(["local-additions\thelp.jax\t/*local-additions*"], 'Xruntime-ja/doc/tags-ja')
96 call writefile(['*help.txt* This is jax file', '',
97 \ 'LOCAL ADDITIONS: *local-additions*', ''], 'Xruntime-ja/doc/help.jax')
98 call writefile(['*work.txt* This is jax file'], 'Xruntime-ja/doc/work.jax')
99 call writefile(['*work2.txt* This is jax file'], 'Xruntime-ja/doc/work2.jax')
100 set rtp+=./Xruntime-ja
101
102 help local-additions@en
103 let lines = getline(line(".") + 1, search("^$") - 1)
104 call assert_equal([
105 \ '|mydoc.txt| my awesome doc'
106 \ ], lines)
107 close
108
109 help local-additions@ja
110 let lines = getline(line(".") + 1, search("^$") - 1)
111 call assert_equal([
112 \ '|mydoc.txt| my awesome doc',
113 \ '|help.txt| This is jax file',
114 \ '|work.txt| This is jax file',
115 \ '|work2.txt| This is jax file',
116 \ ], lines)
Bram Moolenaar35c5e812017-12-09 21:10:13 +0100117 close
118
119 call delete('Xruntime', 'rf')
h-east0e2508d2022-01-03 12:53:24 +0000120 call delete('Xruntime-ja', 'rf')
Bram Moolenaar35c5e812017-12-09 21:10:13 +0100121 let &rtp = rtp_save
122endfunc
Bram Moolenaar297610b2019-12-27 17:20:55 +0100123
124func Test_help_completion()
125 call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx')
126 call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:)
127endfunc
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100128
129" Test for the :helptags command
Bram Moolenaarf9a65502021-03-05 20:47:44 +0100130" NOTE: if you run tests as root this will fail. Don't run tests as root!
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100131func Test_helptag_cmd()
132 call mkdir('Xdir/a/doc', 'p')
133
134 " No help file to process in the directory
135 call assert_fails('helptags Xdir', 'E151:')
136
137 call writefile([], 'Xdir/a/doc/sample.txt')
138
139 " Test for ++t argument
140 helptags ++t Xdir
141 call assert_equal(["help-tags\ttags\t1"], readfile('Xdir/tags'))
142 call delete('Xdir/tags')
143
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100144 " Duplicate tags in the help file
145 call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xdir/a/doc/sample.txt')
146 call assert_fails('helptags Xdir', 'E154:')
147
148 call delete('Xdir', 'rf')
149endfunc
150
Bram Moolenaar17709e22021-03-19 14:38:12 +0100151func Test_helptag_cmd_readonly()
152 CheckUnix
153 CheckNotRoot
Bram Moolenaar17709e22021-03-19 14:38:12 +0100154
155 " Read-only tags file
156 call mkdir('Xdir/doc', 'p')
157 call writefile([''], 'Xdir/doc/tags')
158 call writefile([], 'Xdir/doc/sample.txt')
159 call setfperm('Xdir/doc/tags', 'r-xr--r--')
160 call assert_fails('helptags Xdir/doc', 'E152:', getfperm('Xdir/doc/tags'))
161
162 let rtp = &rtp
163 let &rtp = 'Xdir'
164 helptags ALL
165 let &rtp = rtp
166
167 call delete('Xdir/doc/tags')
168
169 " No permission to read the help file
170 call mkdir('Xdir/b/doc', 'p')
171 call writefile([], 'Xdir/b/doc/sample.txt')
172 call setfperm('Xdir/b/doc/sample.txt', '-w-------')
173 call assert_fails('helptags Xdir', 'E153:', getfperm('Xdir/b/doc/sample.txt'))
174 call delete('Xdir', 'rf')
175endfunc
176
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200177" Test for setting the 'helpheight' option in the help window
178func Test_help_window_height()
Bram Moolenaare4e1a1e2022-03-02 20:49:50 +0000179 let &cmdheight = &lines - 23
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200180 set helpheight=10
181 help
182 set helpheight=14
183 call assert_equal(14, winheight(0))
184 set helpheight& cmdheight=1
185 close
186endfunc
Bram Moolenaar17709e22021-03-19 14:38:12 +0100187
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000188func Test_help_long_argument()
189 try
190 exe 'help \%' .. repeat('0', 1021)
191 catch
192 call assert_match("E149:", v:exception)
193 endtry
194endfunc
195
Bram Moolenaar679d66c2022-01-30 16:42:56 +0000196func Test_help_using_visual_match()
197 let lines =<< trim END
198 call setline(1, ' ')
199 /^
200 exe "normal \<C-V>\<C-V>"
201 h5\%V€]
202 END
203 call v9.CheckScriptFailure(lines, 'E149:')
204endfunc
205
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000206
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100207" vim: shiftwidth=2 sts=2 expandtab