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 |
| 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 | |
| 14 | func Test_help_errors() |
| 15 | call assert_fails('help doesnotexist', 'E149:') |
| 16 | call assert_fails('help!', 'E478:') |
Bram Moolenaar | ea3db91 | 2020-02-02 15:32:13 +0100 | [diff] [blame] | 17 | 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 Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 29 | |
| 30 | new |
| 31 | set keywordprg=:help |
| 32 | call setline(1, " ") |
| 33 | call assert_fails('normal VK', 'E349:') |
| 34 | bwipe! |
| 35 | endfunc |
| 36 | |
Bram Moolenaar | 9ca2508 | 2019-10-05 11:30:09 +0200 | [diff] [blame] | 37 | func Test_help_expr() |
| 38 | help expr-!~? |
| 39 | call assert_equal('eval.txt', expand('%:t')) |
| 40 | close |
| 41 | endfunc |
| 42 | |
Bram Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 43 | func 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 Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 52 | endfunc |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 53 | |
| 54 | func 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-east | 0e2508d | 2022-01-03 12:53:24 +0000 | [diff] [blame] | 60 | 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 Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 92 | close |
| 93 | |
| 94 | call delete('Xruntime', 'rf') |
h-east | 0e2508d | 2022-01-03 12:53:24 +0000 | [diff] [blame] | 95 | call delete('Xruntime-ja', 'rf') |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 96 | let &rtp = rtp_save |
| 97 | endfunc |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 98 | |
| 99 | func Test_help_completion() |
| 100 | call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 101 | call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:) |
| 102 | endfunc |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 103 | |
| 104 | " Test for the :helptags command |
Bram Moolenaar | f9a6550 | 2021-03-05 20:47:44 +0100 | [diff] [blame] | 105 | " 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] | 106 | func 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 Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 119 | " 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') |
| 124 | endfunc |
| 125 | |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 126 | func Test_helptag_cmd_readonly() |
| 127 | CheckUnix |
| 128 | CheckNotRoot |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 129 | |
| 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') |
| 150 | endfunc |
| 151 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 152 | " Test for setting the 'helpheight' option in the help window |
| 153 | func 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 |
| 161 | endfunc |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 162 | |
Bram Moolenaar | bd228fd | 2021-11-25 10:50:12 +0000 | [diff] [blame] | 163 | func Test_help_long_argument() |
| 164 | try |
| 165 | exe 'help \%' .. repeat('0', 1021) |
| 166 | catch |
| 167 | call assert_match("E149:", v:exception) |
| 168 | endtry |
| 169 | endfunc |
| 170 | |
| 171 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 172 | " vim: shiftwidth=2 sts=2 expandtab |