blob: b8b9bbc78bd77d93c413678b3171b1b7450940bb [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
15func Test_help_errors()
16 call assert_fails('help doesnotexist', 'E149:')
17 call assert_fails('help!', 'E478:')
Bram Moolenaarea3db912020-02-02 15:32:13 +010018 if has('multi_lang')
19 call assert_fails('help help@xy', 'E661:')
20 endif
21
22 let save_hf = &helpfile
23 set helpfile=help_missing
24 help
25 call assert_equal(1, winnr('$'))
26 call assert_notequal('help', &buftype)
27 let &helpfile = save_hf
28
29 call assert_fails('help ' . repeat('a', 1048), 'E149:')
Bram Moolenaara4f99f52017-08-26 16:25:32 +020030
31 new
32 set keywordprg=:help
33 call setline(1, " ")
34 call assert_fails('normal VK', 'E349:')
35 bwipe!
36endfunc
37
Bram Moolenaar9ca25082019-10-05 11:30:09 +020038func Test_help_expr()
39 help expr-!~?
40 call assert_equal('eval.txt', expand('%:t'))
41 close
42endfunc
43
Bram Moolenaara4f99f52017-08-26 16:25:32 +020044func Test_help_keyword()
45 new
46 set keywordprg=:help
47 call setline(1, " Visual ")
48 normal VK
49 call assert_match('^Visual mode', getline('.'))
50 call assert_equal('help', &ft)
51 close
52 bwipe!
Bram Moolenaar751ba612017-03-16 22:26:44 +010053endfunc
Bram Moolenaar35c5e812017-12-09 21:10:13 +010054
55func Test_help_local_additions()
56 call mkdir('Xruntime/doc', 'p')
57 call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt')
58 call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt')
59 let rtp_save = &rtp
60 set rtp+=./Xruntime
h-east0e2508d2022-01-03 12:53:24 +000061 help local-additions
62 let lines = getline(line(".") + 1, search("^$") - 1)
63 call assert_equal([
64 \ '|mydoc-ext.txt| my extended awesome doc',
65 \ '|mydoc.txt| my awesome doc'
66 \ ], lines)
67 call delete('Xruntime/doc/mydoc-ext.txt')
68 close
69
70 call mkdir('Xruntime-ja/doc', 'p')
71 call writefile(["local-additions\thelp.jax\t/*local-additions*"], 'Xruntime-ja/doc/tags-ja')
72 call writefile(['*help.txt* This is jax file', '',
73 \ 'LOCAL ADDITIONS: *local-additions*', ''], 'Xruntime-ja/doc/help.jax')
74 call writefile(['*work.txt* This is jax file'], 'Xruntime-ja/doc/work.jax')
75 call writefile(['*work2.txt* This is jax file'], 'Xruntime-ja/doc/work2.jax')
76 set rtp+=./Xruntime-ja
77
78 help local-additions@en
79 let lines = getline(line(".") + 1, search("^$") - 1)
80 call assert_equal([
81 \ '|mydoc.txt| my awesome doc'
82 \ ], lines)
83 close
84
85 help local-additions@ja
86 let lines = getline(line(".") + 1, search("^$") - 1)
87 call assert_equal([
88 \ '|mydoc.txt| my awesome doc',
89 \ '|help.txt| This is jax file',
90 \ '|work.txt| This is jax file',
91 \ '|work2.txt| This is jax file',
92 \ ], lines)
Bram Moolenaar35c5e812017-12-09 21:10:13 +010093 close
94
95 call delete('Xruntime', 'rf')
h-east0e2508d2022-01-03 12:53:24 +000096 call delete('Xruntime-ja', 'rf')
Bram Moolenaar35c5e812017-12-09 21:10:13 +010097 let &rtp = rtp_save
98endfunc
Bram Moolenaar297610b2019-12-27 17:20:55 +010099
100func Test_help_completion()
101 call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx')
102 call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:)
103endfunc
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100104
105" Test for the :helptags command
Bram Moolenaarf9a65502021-03-05 20:47:44 +0100106" NOTE: if you run tests as root this will fail. Don't run tests as root!
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100107func Test_helptag_cmd()
108 call mkdir('Xdir/a/doc', 'p')
109
110 " No help file to process in the directory
111 call assert_fails('helptags Xdir', 'E151:')
112
113 call writefile([], 'Xdir/a/doc/sample.txt')
114
115 " Test for ++t argument
116 helptags ++t Xdir
117 call assert_equal(["help-tags\ttags\t1"], readfile('Xdir/tags'))
118 call delete('Xdir/tags')
119
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100120 " Duplicate tags in the help file
121 call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xdir/a/doc/sample.txt')
122 call assert_fails('helptags Xdir', 'E154:')
123
124 call delete('Xdir', 'rf')
125endfunc
126
Bram Moolenaar17709e22021-03-19 14:38:12 +0100127func Test_helptag_cmd_readonly()
128 CheckUnix
129 CheckNotRoot
Bram Moolenaar17709e22021-03-19 14:38:12 +0100130
131 " Read-only tags file
132 call mkdir('Xdir/doc', 'p')
133 call writefile([''], 'Xdir/doc/tags')
134 call writefile([], 'Xdir/doc/sample.txt')
135 call setfperm('Xdir/doc/tags', 'r-xr--r--')
136 call assert_fails('helptags Xdir/doc', 'E152:', getfperm('Xdir/doc/tags'))
137
138 let rtp = &rtp
139 let &rtp = 'Xdir'
140 helptags ALL
141 let &rtp = rtp
142
143 call delete('Xdir/doc/tags')
144
145 " No permission to read the help file
146 call mkdir('Xdir/b/doc', 'p')
147 call writefile([], 'Xdir/b/doc/sample.txt')
148 call setfperm('Xdir/b/doc/sample.txt', '-w-------')
149 call assert_fails('helptags Xdir', 'E153:', getfperm('Xdir/b/doc/sample.txt'))
150 call delete('Xdir', 'rf')
151endfunc
152
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200153" Test for setting the 'helpheight' option in the help window
154func Test_help_window_height()
155 let &cmdheight = &lines - 24
156 set helpheight=10
157 help
158 set helpheight=14
159 call assert_equal(14, winheight(0))
160 set helpheight& cmdheight=1
161 close
162endfunc
Bram Moolenaar17709e22021-03-19 14:38:12 +0100163
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000164func Test_help_long_argument()
165 try
166 exe 'help \%' .. repeat('0', 1021)
167 catch
168 call assert_match("E149:", v:exception)
169 endtry
170endfunc
171
Bram Moolenaar679d66c2022-01-30 16:42:56 +0000172func Test_help_using_visual_match()
173 let lines =<< trim END
174 call setline(1, ' ')
175 /^
176 exe "normal \<C-V>\<C-V>"
177 h5\%V€]
178 END
179 call v9.CheckScriptFailure(lines, 'E149:')
180endfunc
181
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000182
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100183" vim: shiftwidth=2 sts=2 expandtab