blob: c859bf5201639a6ac52d69b62e2e6e49a73a09d2 [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()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100132 call mkdir('Xtagdir/a/doc', 'p')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100133
134 " No help file to process in the directory
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100135 call assert_fails('helptags Xtagdir', 'E151:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100136
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100137 call writefile([], 'Xtagdir/a/doc/sample.txt')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100138
139 " Test for ++t argument
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100140 helptags ++t Xtagdir
141 call assert_equal(["help-tags\ttags\t1"], readfile('Xtagdir/tags'))
142 call delete('Xtagdir/tags')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100143
Carlo Teubnerddab3ce2022-07-30 12:03:16 +0100144 " Test parsing tags
145 call writefile(['*tag1*', 'Example: >', ' *notag*', 'Example end: *tag2*'],
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100146 \ 'Xtagdir/a/doc/sample.txt')
147 helptags Xtagdir
Carlo Teubnerddab3ce2022-07-30 12:03:16 +0100148 call assert_equal(["tag1\ta/doc/sample.txt\t/*tag1*",
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100149 \ "tag2\ta/doc/sample.txt\t/*tag2*"], readfile('Xtagdir/tags'))
Carlo Teubnerddab3ce2022-07-30 12:03:16 +0100150
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100151 " Duplicate tags in the help file
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100152 call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xtagdir/a/doc/sample.txt')
153 call assert_fails('helptags Xtagdir', 'E154:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100154
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100155 call delete('Xtagdir', 'rf')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100156endfunc
157
Bram Moolenaar17709e22021-03-19 14:38:12 +0100158func Test_helptag_cmd_readonly()
159 CheckUnix
160 CheckNotRoot
Bram Moolenaar17709e22021-03-19 14:38:12 +0100161
162 " Read-only tags file
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100163 call mkdir('Xrodir/doc', 'p')
164 call writefile([''], 'Xrodir/doc/tags')
165 call writefile([], 'Xrodir/doc/sample.txt')
166 call setfperm('Xrodir/doc/tags', 'r-xr--r--')
167 call assert_fails('helptags Xrodir/doc', 'E152:', getfperm('Xrodir/doc/tags'))
Bram Moolenaar17709e22021-03-19 14:38:12 +0100168
169 let rtp = &rtp
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100170 let &rtp = 'Xrodir'
Bram Moolenaar17709e22021-03-19 14:38:12 +0100171 helptags ALL
172 let &rtp = rtp
173
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100174 call delete('Xrodir/doc/tags')
Bram Moolenaar17709e22021-03-19 14:38:12 +0100175
176 " No permission to read the help file
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100177 call mkdir('Xrodir/b/doc', 'p')
178 call writefile([], 'Xrodir/b/doc/sample.txt')
179 call setfperm('Xrodir/b/doc/sample.txt', '-w-------')
180 call assert_fails('helptags Xrodir', 'E153:', getfperm('Xrodir/b/doc/sample.txt'))
181 call delete('Xrodir', 'rf')
Bram Moolenaar17709e22021-03-19 14:38:12 +0100182endfunc
183
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200184" Test for setting the 'helpheight' option in the help window
185func Test_help_window_height()
Bram Moolenaare4e1a1e2022-03-02 20:49:50 +0000186 let &cmdheight = &lines - 23
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200187 set helpheight=10
188 help
189 set helpheight=14
190 call assert_equal(14, winheight(0))
191 set helpheight& cmdheight=1
192 close
193endfunc
Bram Moolenaar17709e22021-03-19 14:38:12 +0100194
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000195func Test_help_long_argument()
196 try
197 exe 'help \%' .. repeat('0', 1021)
198 catch
199 call assert_match("E149:", v:exception)
200 endtry
201endfunc
202
Bram Moolenaar679d66c2022-01-30 16:42:56 +0000203func Test_help_using_visual_match()
204 let lines =<< trim END
205 call setline(1, ' ')
206 /^
207 exe "normal \<C-V>\<C-V>"
208 h5\%V€]
209 END
210 call v9.CheckScriptFailure(lines, 'E149:')
211endfunc
212
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000213
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100214" vim: shiftwidth=2 sts=2 expandtab