Bram Moolenaar | 343b8c0 | 2017-02-17 12:04:56 +0100 | [diff] [blame] | 1 | " Tests for :help |
| 2 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 3 | import './util/vim9.vim' as v9 |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 4 | |
Bram Moolenaar | 343b8c0 | 2017-02-17 12:04:56 +0100 | [diff] [blame] | 5 | func Test_help_restore_snapshot() |
| 6 | help |
| 7 | set buftype= |
| 8 | help |
| 9 | edit x |
| 10 | help |
| 11 | helpclose |
| 12 | endfunc |
Bram Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 13 | |
LemonBoy | 2a2707d | 2022-05-04 22:13:47 +0100 | [diff] [blame] | 14 | func Test_help_restore_snapshot_split() |
| 15 | " Squeeze the unnamed buffer, Xfoo and the help one side-by-side and focus |
| 16 | " the first one before calling :help. |
| 17 | let bnr = bufnr() |
| 18 | botright vsp Xfoo |
| 19 | wincmd h |
| 20 | help |
| 21 | wincmd L |
| 22 | let g:did_bufenter = v:false |
| 23 | augroup T |
| 24 | au! |
| 25 | au BufEnter Xfoo let g:did_bufenter = v:true |
| 26 | augroup END |
| 27 | helpclose |
| 28 | augroup! T |
| 29 | " We're back to the unnamed buffer. |
| 30 | call assert_equal(bnr, bufnr()) |
| 31 | " No BufEnter was triggered for Xfoo. |
| 32 | call assert_equal(v:false, g:did_bufenter) |
| 33 | |
| 34 | close! |
| 35 | bwipe! |
| 36 | endfunc |
| 37 | |
Bram Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 38 | func Test_help_errors() |
| 39 | call assert_fails('help doesnotexist', 'E149:') |
| 40 | call assert_fails('help!', 'E478:') |
Bram Moolenaar | ea3db91 | 2020-02-02 15:32:13 +0100 | [diff] [blame] | 41 | if has('multi_lang') |
| 42 | call assert_fails('help help@xy', 'E661:') |
| 43 | endif |
| 44 | |
| 45 | let save_hf = &helpfile |
| 46 | set helpfile=help_missing |
| 47 | help |
| 48 | call assert_equal(1, winnr('$')) |
| 49 | call assert_notequal('help', &buftype) |
| 50 | let &helpfile = save_hf |
| 51 | |
| 52 | call assert_fails('help ' . repeat('a', 1048), 'E149:') |
Bram Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 53 | |
| 54 | new |
| 55 | set keywordprg=:help |
| 56 | call setline(1, " ") |
| 57 | call assert_fails('normal VK', 'E349:') |
| 58 | bwipe! |
| 59 | endfunc |
| 60 | |
Bram Moolenaar | 9ca2508 | 2019-10-05 11:30:09 +0200 | [diff] [blame] | 61 | func Test_help_expr() |
| 62 | help expr-!~? |
| 63 | call assert_equal('eval.txt', expand('%:t')) |
| 64 | close |
| 65 | endfunc |
| 66 | |
Bram Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 67 | func Test_help_keyword() |
| 68 | new |
| 69 | set keywordprg=:help |
| 70 | call setline(1, " Visual ") |
| 71 | normal VK |
| 72 | call assert_match('^Visual mode', getline('.')) |
| 73 | call assert_equal('help', &ft) |
| 74 | close |
| 75 | bwipe! |
Bram Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 76 | endfunc |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 77 | |
| 78 | func Test_help_local_additions() |
Bram Moolenaar | 572a443 | 2022-09-28 21:07:03 +0100 | [diff] [blame] | 79 | call mkdir('Xruntime/doc', 'pR') |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 80 | call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt') |
| 81 | call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt') |
| 82 | let rtp_save = &rtp |
| 83 | set rtp+=./Xruntime |
h-east | 0e2508d | 2022-01-03 12:53:24 +0000 | [diff] [blame] | 84 | help local-additions |
| 85 | let lines = getline(line(".") + 1, search("^$") - 1) |
| 86 | call assert_equal([ |
| 87 | \ '|mydoc-ext.txt| my extended awesome doc', |
| 88 | \ '|mydoc.txt| my awesome doc' |
| 89 | \ ], lines) |
| 90 | call delete('Xruntime/doc/mydoc-ext.txt') |
| 91 | close |
| 92 | |
Bram Moolenaar | 572a443 | 2022-09-28 21:07:03 +0100 | [diff] [blame] | 93 | call mkdir('Xruntime-ja/doc', 'pR') |
h-east | 0e2508d | 2022-01-03 12:53:24 +0000 | [diff] [blame] | 94 | call writefile(["local-additions\thelp.jax\t/*local-additions*"], 'Xruntime-ja/doc/tags-ja') |
| 95 | call writefile(['*help.txt* This is jax file', '', |
| 96 | \ 'LOCAL ADDITIONS: *local-additions*', ''], 'Xruntime-ja/doc/help.jax') |
| 97 | call writefile(['*work.txt* This is jax file'], 'Xruntime-ja/doc/work.jax') |
| 98 | call writefile(['*work2.txt* This is jax file'], 'Xruntime-ja/doc/work2.jax') |
| 99 | set rtp+=./Xruntime-ja |
| 100 | |
| 101 | help local-additions@en |
| 102 | let lines = getline(line(".") + 1, search("^$") - 1) |
| 103 | call assert_equal([ |
| 104 | \ '|mydoc.txt| my awesome doc' |
| 105 | \ ], lines) |
| 106 | close |
| 107 | |
| 108 | help local-additions@ja |
| 109 | let lines = getline(line(".") + 1, search("^$") - 1) |
| 110 | call assert_equal([ |
| 111 | \ '|mydoc.txt| my awesome doc', |
| 112 | \ '|help.txt| This is jax file', |
| 113 | \ '|work.txt| This is jax file', |
| 114 | \ '|work2.txt| This is jax file', |
| 115 | \ ], lines) |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 116 | close |
| 117 | |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 118 | let &rtp = rtp_save |
| 119 | endfunc |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 120 | |
| 121 | func Test_help_completion() |
| 122 | call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 123 | call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:) |
| 124 | endfunc |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 125 | |
| 126 | " Test for the :helptags command |
Bram Moolenaar | f9a6550 | 2021-03-05 20:47:44 +0100 | [diff] [blame] | 127 | " NOTE: if you run tests as root this will fail. Don't run tests as root! |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 128 | func Test_helptag_cmd() |
Bram Moolenaar | 572a443 | 2022-09-28 21:07:03 +0100 | [diff] [blame] | 129 | call mkdir('Xtagdir/a/doc', 'pR') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 130 | |
| 131 | " No help file to process in the directory |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 132 | call assert_fails('helptags Xtagdir', 'E151:') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 133 | |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 134 | call writefile([], 'Xtagdir/a/doc/sample.txt') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 135 | |
| 136 | " Test for ++t argument |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 137 | helptags ++t Xtagdir |
| 138 | call assert_equal(["help-tags\ttags\t1"], readfile('Xtagdir/tags')) |
| 139 | call delete('Xtagdir/tags') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 140 | |
Carlo Teubner | ddab3ce | 2022-07-30 12:03:16 +0100 | [diff] [blame] | 141 | " Test parsing tags |
| 142 | call writefile(['*tag1*', 'Example: >', ' *notag*', 'Example end: *tag2*'], |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 143 | \ 'Xtagdir/a/doc/sample.txt') |
| 144 | helptags Xtagdir |
Carlo Teubner | ddab3ce | 2022-07-30 12:03:16 +0100 | [diff] [blame] | 145 | call assert_equal(["tag1\ta/doc/sample.txt\t/*tag1*", |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 146 | \ "tag2\ta/doc/sample.txt\t/*tag2*"], readfile('Xtagdir/tags')) |
Carlo Teubner | ddab3ce | 2022-07-30 12:03:16 +0100 | [diff] [blame] | 147 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 148 | " Duplicate tags in the help file |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 149 | call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xtagdir/a/doc/sample.txt') |
| 150 | call assert_fails('helptags Xtagdir', 'E154:') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 151 | endfunc |
| 152 | |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 153 | func Test_helptag_cmd_readonly() |
| 154 | CheckUnix |
| 155 | CheckNotRoot |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 156 | |
| 157 | " Read-only tags file |
Bram Moolenaar | 572a443 | 2022-09-28 21:07:03 +0100 | [diff] [blame] | 158 | call mkdir('Xrodir/doc', 'pR') |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 159 | call writefile([''], 'Xrodir/doc/tags') |
| 160 | call writefile([], 'Xrodir/doc/sample.txt') |
| 161 | call setfperm('Xrodir/doc/tags', 'r-xr--r--') |
| 162 | call assert_fails('helptags Xrodir/doc', 'E152:', getfperm('Xrodir/doc/tags')) |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 163 | |
| 164 | let rtp = &rtp |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 165 | let &rtp = 'Xrodir' |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 166 | helptags ALL |
| 167 | let &rtp = rtp |
| 168 | |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 169 | call delete('Xrodir/doc/tags') |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 170 | |
| 171 | " No permission to read the help file |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 172 | call mkdir('Xrodir/b/doc', 'p') |
| 173 | call writefile([], 'Xrodir/b/doc/sample.txt') |
| 174 | call setfperm('Xrodir/b/doc/sample.txt', '-w-------') |
| 175 | call assert_fails('helptags Xrodir', 'E153:', getfperm('Xrodir/b/doc/sample.txt')) |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 176 | endfunc |
| 177 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 178 | " Test for setting the 'helpheight' option in the help window |
| 179 | func Test_help_window_height() |
Bram Moolenaar | e4e1a1e | 2022-03-02 20:49:50 +0000 | [diff] [blame] | 180 | let &cmdheight = &lines - 23 |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 181 | set helpheight=10 |
| 182 | help |
| 183 | set helpheight=14 |
| 184 | call assert_equal(14, winheight(0)) |
| 185 | set helpheight& cmdheight=1 |
| 186 | close |
| 187 | endfunc |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 188 | |
Bram Moolenaar | bd228fd | 2021-11-25 10:50:12 +0000 | [diff] [blame] | 189 | func Test_help_long_argument() |
| 190 | try |
| 191 | exe 'help \%' .. repeat('0', 1021) |
| 192 | catch |
| 193 | call assert_match("E149:", v:exception) |
| 194 | endtry |
| 195 | endfunc |
| 196 | |
Bram Moolenaar | 679d66c | 2022-01-30 16:42:56 +0000 | [diff] [blame] | 197 | func Test_help_using_visual_match() |
| 198 | let lines =<< trim END |
| 199 | call setline(1, ' ') |
| 200 | /^ |
| 201 | exe "normal \<C-V>\<C-V>" |
| 202 | h5\%V] |
| 203 | END |
| 204 | call v9.CheckScriptFailure(lines, 'E149:') |
| 205 | endfunc |
| 206 | |
Phạm Bình An | 6af20a9 | 2025-05-01 17:30:58 +0200 | [diff] [blame] | 207 | func Test_helptag_navigation() |
| 208 | let helpdir = tempname() |
| 209 | let tempfile = helpdir . '/test.txt' |
| 210 | call mkdir(helpdir, 'pR') |
| 211 | call writefile(['', '*[tag*', '', '|[tag|'], tempfile) |
| 212 | exe 'helptags' helpdir |
| 213 | exe 'sp' tempfile |
| 214 | exe 'lcd' helpdir |
| 215 | setl ft=help |
| 216 | let &l:iskeyword='!-~,^*,^|,^",192-255' |
| 217 | call cursor(4, 2) |
| 218 | " Vim must not escape `[` when expanding the tag |
| 219 | exe "normal! \<C-]>" |
| 220 | call assert_equal(2, line('.')) |
| 221 | bw |
| 222 | endfunc |
| 223 | |
Bram Moolenaar | bd228fd | 2021-11-25 10:50:12 +0000 | [diff] [blame] | 224 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 225 | " vim: shiftwidth=2 sts=2 expandtab |