blob: 6c8b3ab3971ca6ea6a39cc8366cc04087ff58401 [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()
Bram Moolenaar572a4432022-09-28 21:07:03 +010080 call mkdir('Xruntime/doc', 'pR')
Bram Moolenaar35c5e812017-12-09 21:10:13 +010081 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
Bram Moolenaar572a4432022-09-28 21:07:03 +010094 call mkdir('Xruntime-ja/doc', 'pR')
h-east0e2508d2022-01-03 12:53:24 +000095 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
Bram Moolenaar35c5e812017-12-09 21:10:13 +0100119 let &rtp = rtp_save
120endfunc
Bram Moolenaar297610b2019-12-27 17:20:55 +0100121
122func Test_help_completion()
123 call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx')
124 call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:)
125endfunc
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100126
127" Test for the :helptags command
Bram Moolenaarf9a65502021-03-05 20:47:44 +0100128" NOTE: if you run tests as root this will fail. Don't run tests as root!
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100129func Test_helptag_cmd()
Bram Moolenaar572a4432022-09-28 21:07:03 +0100130 call mkdir('Xtagdir/a/doc', 'pR')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100131
132 " No help file to process in the directory
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100133 call assert_fails('helptags Xtagdir', 'E151:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100134
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100135 call writefile([], 'Xtagdir/a/doc/sample.txt')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100136
137 " Test for ++t argument
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100138 helptags ++t Xtagdir
139 call assert_equal(["help-tags\ttags\t1"], readfile('Xtagdir/tags'))
140 call delete('Xtagdir/tags')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100141
Carlo Teubnerddab3ce2022-07-30 12:03:16 +0100142 " Test parsing tags
143 call writefile(['*tag1*', 'Example: >', ' *notag*', 'Example end: *tag2*'],
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100144 \ 'Xtagdir/a/doc/sample.txt')
145 helptags Xtagdir
Carlo Teubnerddab3ce2022-07-30 12:03:16 +0100146 call assert_equal(["tag1\ta/doc/sample.txt\t/*tag1*",
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100147 \ "tag2\ta/doc/sample.txt\t/*tag2*"], readfile('Xtagdir/tags'))
Carlo Teubnerddab3ce2022-07-30 12:03:16 +0100148
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100149 " Duplicate tags in the help file
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100150 call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xtagdir/a/doc/sample.txt')
151 call assert_fails('helptags Xtagdir', 'E154:')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100152endfunc
153
Bram Moolenaar17709e22021-03-19 14:38:12 +0100154func Test_helptag_cmd_readonly()
155 CheckUnix
156 CheckNotRoot
Bram Moolenaar17709e22021-03-19 14:38:12 +0100157
158 " Read-only tags file
Bram Moolenaar572a4432022-09-28 21:07:03 +0100159 call mkdir('Xrodir/doc', 'pR')
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100160 call writefile([''], 'Xrodir/doc/tags')
161 call writefile([], 'Xrodir/doc/sample.txt')
162 call setfperm('Xrodir/doc/tags', 'r-xr--r--')
163 call assert_fails('helptags Xrodir/doc', 'E152:', getfperm('Xrodir/doc/tags'))
Bram Moolenaar17709e22021-03-19 14:38:12 +0100164
165 let rtp = &rtp
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100166 let &rtp = 'Xrodir'
Bram Moolenaar17709e22021-03-19 14:38:12 +0100167 helptags ALL
168 let &rtp = rtp
169
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100170 call delete('Xrodir/doc/tags')
Bram Moolenaar17709e22021-03-19 14:38:12 +0100171
172 " No permission to read the help file
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100173 call mkdir('Xrodir/b/doc', 'p')
174 call writefile([], 'Xrodir/b/doc/sample.txt')
175 call setfperm('Xrodir/b/doc/sample.txt', '-w-------')
176 call assert_fails('helptags Xrodir', 'E153:', getfperm('Xrodir/b/doc/sample.txt'))
Bram Moolenaar17709e22021-03-19 14:38:12 +0100177endfunc
178
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200179" Test for setting the 'helpheight' option in the help window
180func Test_help_window_height()
Bram Moolenaare4e1a1e2022-03-02 20:49:50 +0000181 let &cmdheight = &lines - 23
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200182 set helpheight=10
183 help
184 set helpheight=14
185 call assert_equal(14, winheight(0))
186 set helpheight& cmdheight=1
187 close
188endfunc
Bram Moolenaar17709e22021-03-19 14:38:12 +0100189
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000190func Test_help_long_argument()
191 try
192 exe 'help \%' .. repeat('0', 1021)
193 catch
194 call assert_match("E149:", v:exception)
195 endtry
196endfunc
197
Bram Moolenaar679d66c2022-01-30 16:42:56 +0000198func Test_help_using_visual_match()
199 let lines =<< trim END
200 call setline(1, ' ')
201 /^
202 exe "normal \<C-V>\<C-V>"
203 h5\%V€]
204 END
205 call v9.CheckScriptFailure(lines, 'E149:')
206endfunc
207
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000208
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100209" vim: shiftwidth=2 sts=2 expandtab