blob: 3e358d6bbbf90baff28d31820e4166b61721b56e [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
4
Bram Moolenaar343b8c02017-02-17 12:04:56 +01005func Test_help_restore_snapshot()
6 help
7 set buftype=
8 help
9 edit x
10 help
11 helpclose
12endfunc
Bram Moolenaar751ba612017-03-16 22:26:44 +010013
14func Test_help_errors()
15 call assert_fails('help doesnotexist', 'E149:')
16 call assert_fails('help!', 'E478:')
Bram Moolenaarea3db912020-02-02 15:32:13 +010017 if has('multi_lang')
18 call assert_fails('help help@xy', 'E661:')
19 endif
20
21 let save_hf = &helpfile
22 set helpfile=help_missing
23 help
24 call assert_equal(1, winnr('$'))
25 call assert_notequal('help', &buftype)
26 let &helpfile = save_hf
27
28 call assert_fails('help ' . repeat('a', 1048), 'E149:')
Bram Moolenaara4f99f52017-08-26 16:25:32 +020029
30 new
31 set keywordprg=:help
32 call setline(1, " ")
33 call assert_fails('normal VK', 'E349:')
34 bwipe!
35endfunc
36
Bram Moolenaar9ca25082019-10-05 11:30:09 +020037func Test_help_expr()
38 help expr-!~?
39 call assert_equal('eval.txt', expand('%:t'))
40 close
41endfunc
42
Bram Moolenaara4f99f52017-08-26 16:25:32 +020043func Test_help_keyword()
44 new
45 set keywordprg=:help
46 call setline(1, " Visual ")
47 normal VK
48 call assert_match('^Visual mode', getline('.'))
49 call assert_equal('help', &ft)
50 close
51 bwipe!
Bram Moolenaar751ba612017-03-16 22:26:44 +010052endfunc
Bram Moolenaar35c5e812017-12-09 21:10:13 +010053
54func Test_help_local_additions()
55 call mkdir('Xruntime/doc', 'p')
56 call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt')
57 call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt')
58 let rtp_save = &rtp
59 set rtp+=./Xruntime
h-east0e2508d2022-01-03 12:53:24 +000060 help local-additions
61 let lines = getline(line(".") + 1, search("^$") - 1)
62 call assert_equal([
63 \ '|mydoc-ext.txt| my extended awesome doc',
64 \ '|mydoc.txt| my awesome doc'
65 \ ], lines)
66 call delete('Xruntime/doc/mydoc-ext.txt')
67 close
68
69 call mkdir('Xruntime-ja/doc', 'p')
70 call writefile(["local-additions\thelp.jax\t/*local-additions*"], 'Xruntime-ja/doc/tags-ja')
71 call writefile(['*help.txt* This is jax file', '',
72 \ 'LOCAL ADDITIONS: *local-additions*', ''], 'Xruntime-ja/doc/help.jax')
73 call writefile(['*work.txt* This is jax file'], 'Xruntime-ja/doc/work.jax')
74 call writefile(['*work2.txt* This is jax file'], 'Xruntime-ja/doc/work2.jax')
75 set rtp+=./Xruntime-ja
76
77 help local-additions@en
78 let lines = getline(line(".") + 1, search("^$") - 1)
79 call assert_equal([
80 \ '|mydoc.txt| my awesome doc'
81 \ ], lines)
82 close
83
84 help local-additions@ja
85 let lines = getline(line(".") + 1, search("^$") - 1)
86 call assert_equal([
87 \ '|mydoc.txt| my awesome doc',
88 \ '|help.txt| This is jax file',
89 \ '|work.txt| This is jax file',
90 \ '|work2.txt| This is jax file',
91 \ ], lines)
Bram Moolenaar35c5e812017-12-09 21:10:13 +010092 close
93
94 call delete('Xruntime', 'rf')
h-east0e2508d2022-01-03 12:53:24 +000095 call delete('Xruntime-ja', 'rf')
Bram Moolenaar35c5e812017-12-09 21:10:13 +010096 let &rtp = rtp_save
97endfunc
Bram Moolenaar297610b2019-12-27 17:20:55 +010098
99func Test_help_completion()
100 call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx')
101 call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:)
102endfunc
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100103
104" Test for the :helptags command
Bram Moolenaarf9a65502021-03-05 20:47:44 +0100105" NOTE: if you run tests as root this will fail. Don't run tests as root!
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100106func Test_helptag_cmd()
107 call mkdir('Xdir/a/doc', 'p')
108
109 " No help file to process in the directory
110 call assert_fails('helptags Xdir', 'E151:')
111
112 call writefile([], 'Xdir/a/doc/sample.txt')
113
114 " Test for ++t argument
115 helptags ++t Xdir
116 call assert_equal(["help-tags\ttags\t1"], readfile('Xdir/tags'))
117 call delete('Xdir/tags')
118
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100119 " Duplicate tags in the help file
120 call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xdir/a/doc/sample.txt')
121 call assert_fails('helptags Xdir', 'E154:')
122
123 call delete('Xdir', 'rf')
124endfunc
125
Bram Moolenaar17709e22021-03-19 14:38:12 +0100126func Test_helptag_cmd_readonly()
127 CheckUnix
128 CheckNotRoot
Bram Moolenaar17709e22021-03-19 14:38:12 +0100129
130 " Read-only tags file
131 call mkdir('Xdir/doc', 'p')
132 call writefile([''], 'Xdir/doc/tags')
133 call writefile([], 'Xdir/doc/sample.txt')
134 call setfperm('Xdir/doc/tags', 'r-xr--r--')
135 call assert_fails('helptags Xdir/doc', 'E152:', getfperm('Xdir/doc/tags'))
136
137 let rtp = &rtp
138 let &rtp = 'Xdir'
139 helptags ALL
140 let &rtp = rtp
141
142 call delete('Xdir/doc/tags')
143
144 " No permission to read the help file
145 call mkdir('Xdir/b/doc', 'p')
146 call writefile([], 'Xdir/b/doc/sample.txt')
147 call setfperm('Xdir/b/doc/sample.txt', '-w-------')
148 call assert_fails('helptags Xdir', 'E153:', getfperm('Xdir/b/doc/sample.txt'))
149 call delete('Xdir', 'rf')
150endfunc
151
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200152" Test for setting the 'helpheight' option in the help window
153func Test_help_window_height()
154 let &cmdheight = &lines - 24
155 set helpheight=10
156 help
157 set helpheight=14
158 call assert_equal(14, winheight(0))
159 set helpheight& cmdheight=1
160 close
161endfunc
Bram Moolenaar17709e22021-03-19 14:38:12 +0100162
Bram Moolenaarbd228fd2021-11-25 10:50:12 +0000163func Test_help_long_argument()
164 try
165 exe 'help \%' .. repeat('0', 1021)
166 catch
167 call assert_match("E149:", v:exception)
168 endtry
169endfunc
170
171
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100172" vim: shiftwidth=2 sts=2 expandtab