Bram Moolenaar | 343b8c0 | 2017-02-17 12:04:56 +0100 | [diff] [blame] | 1 | " Tests for :help |
| 2 | |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | 679d66c | 2022-01-30 16:42:56 +0000 | [diff] [blame] | 4 | import './vim9.vim' as v9 |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 5 | |
Bram Moolenaar | 343b8c0 | 2017-02-17 12:04:56 +0100 | [diff] [blame] | 6 | func Test_help_restore_snapshot() |
| 7 | help |
| 8 | set buftype= |
| 9 | help |
| 10 | edit x |
| 11 | help |
| 12 | helpclose |
| 13 | endfunc |
Bram Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 14 | |
LemonBoy | 2a2707d | 2022-05-04 22:13:47 +0100 | [diff] [blame] | 15 | func 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! |
| 37 | endfunc |
| 38 | |
Bram Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 39 | func Test_help_errors() |
| 40 | call assert_fails('help doesnotexist', 'E149:') |
| 41 | call assert_fails('help!', 'E478:') |
Bram Moolenaar | ea3db91 | 2020-02-02 15:32:13 +0100 | [diff] [blame] | 42 | 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 Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 54 | |
| 55 | new |
| 56 | set keywordprg=:help |
| 57 | call setline(1, " ") |
| 58 | call assert_fails('normal VK', 'E349:') |
| 59 | bwipe! |
| 60 | endfunc |
| 61 | |
Bram Moolenaar | 9ca2508 | 2019-10-05 11:30:09 +0200 | [diff] [blame] | 62 | func Test_help_expr() |
| 63 | help expr-!~? |
| 64 | call assert_equal('eval.txt', expand('%:t')) |
| 65 | close |
| 66 | endfunc |
| 67 | |
Bram Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 68 | func 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 Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 77 | endfunc |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 78 | |
| 79 | func 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-east | 0e2508d | 2022-01-03 12:53:24 +0000 | [diff] [blame] | 85 | 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 Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 117 | close |
| 118 | |
| 119 | call delete('Xruntime', 'rf') |
h-east | 0e2508d | 2022-01-03 12:53:24 +0000 | [diff] [blame] | 120 | call delete('Xruntime-ja', 'rf') |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 121 | let &rtp = rtp_save |
| 122 | endfunc |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 123 | |
| 124 | func Test_help_completion() |
| 125 | call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 126 | call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:) |
| 127 | endfunc |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 128 | |
| 129 | " Test for the :helptags command |
Bram Moolenaar | f9a6550 | 2021-03-05 20:47:44 +0100 | [diff] [blame] | 130 | " 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] | 131 | func Test_helptag_cmd() |
| 132 | call mkdir('Xdir/a/doc', 'p') |
| 133 | |
| 134 | " No help file to process in the directory |
| 135 | call assert_fails('helptags Xdir', 'E151:') |
| 136 | |
| 137 | call writefile([], 'Xdir/a/doc/sample.txt') |
| 138 | |
| 139 | " Test for ++t argument |
| 140 | helptags ++t Xdir |
| 141 | call assert_equal(["help-tags\ttags\t1"], readfile('Xdir/tags')) |
| 142 | call delete('Xdir/tags') |
| 143 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 144 | " Duplicate tags in the help file |
| 145 | call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xdir/a/doc/sample.txt') |
| 146 | call assert_fails('helptags Xdir', 'E154:') |
| 147 | |
| 148 | call delete('Xdir', 'rf') |
| 149 | endfunc |
| 150 | |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 151 | func Test_helptag_cmd_readonly() |
| 152 | CheckUnix |
| 153 | CheckNotRoot |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 154 | |
| 155 | " Read-only tags file |
| 156 | call mkdir('Xdir/doc', 'p') |
| 157 | call writefile([''], 'Xdir/doc/tags') |
| 158 | call writefile([], 'Xdir/doc/sample.txt') |
| 159 | call setfperm('Xdir/doc/tags', 'r-xr--r--') |
| 160 | call assert_fails('helptags Xdir/doc', 'E152:', getfperm('Xdir/doc/tags')) |
| 161 | |
| 162 | let rtp = &rtp |
| 163 | let &rtp = 'Xdir' |
| 164 | helptags ALL |
| 165 | let &rtp = rtp |
| 166 | |
| 167 | call delete('Xdir/doc/tags') |
| 168 | |
| 169 | " No permission to read the help file |
| 170 | call mkdir('Xdir/b/doc', 'p') |
| 171 | call writefile([], 'Xdir/b/doc/sample.txt') |
| 172 | call setfperm('Xdir/b/doc/sample.txt', '-w-------') |
| 173 | call assert_fails('helptags Xdir', 'E153:', getfperm('Xdir/b/doc/sample.txt')) |
| 174 | call delete('Xdir', 'rf') |
| 175 | endfunc |
| 176 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 177 | " Test for setting the 'helpheight' option in the help window |
| 178 | func Test_help_window_height() |
Bram Moolenaar | e4e1a1e | 2022-03-02 20:49:50 +0000 | [diff] [blame] | 179 | let &cmdheight = &lines - 23 |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 180 | set helpheight=10 |
| 181 | help |
| 182 | set helpheight=14 |
| 183 | call assert_equal(14, winheight(0)) |
| 184 | set helpheight& cmdheight=1 |
| 185 | close |
| 186 | endfunc |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 187 | |
Bram Moolenaar | bd228fd | 2021-11-25 10:50:12 +0000 | [diff] [blame] | 188 | func Test_help_long_argument() |
| 189 | try |
| 190 | exe 'help \%' .. repeat('0', 1021) |
| 191 | catch |
| 192 | call assert_match("E149:", v:exception) |
| 193 | endtry |
| 194 | endfunc |
| 195 | |
Bram Moolenaar | 679d66c | 2022-01-30 16:42:56 +0000 | [diff] [blame] | 196 | func Test_help_using_visual_match() |
| 197 | let lines =<< trim END |
| 198 | call setline(1, ' ') |
| 199 | /^ |
| 200 | exe "normal \<C-V>\<C-V>" |
| 201 | h5\%V] |
| 202 | END |
| 203 | call v9.CheckScriptFailure(lines, 'E149:') |
| 204 | endfunc |
| 205 | |
Bram Moolenaar | bd228fd | 2021-11-25 10:50:12 +0000 | [diff] [blame] | 206 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 207 | " vim: shiftwidth=2 sts=2 expandtab |