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 |
| 60 | help |
| 61 | 1 |
| 62 | call search('mydoc.txt') |
| 63 | call assert_equal('|mydoc.txt| my awesome doc', getline('.')) |
| 64 | 1 |
| 65 | call search('mydoc-ext.txt') |
| 66 | call assert_equal('|mydoc-ext.txt| my extended awesome doc', getline('.')) |
| 67 | close |
| 68 | |
| 69 | call delete('Xruntime', 'rf') |
| 70 | let &rtp = rtp_save |
| 71 | endfunc |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 72 | |
| 73 | func Test_help_completion() |
| 74 | call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 75 | call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:) |
| 76 | endfunc |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 77 | |
| 78 | " Test for the :helptags command |
Bram Moolenaar | f9a6550 | 2021-03-05 20:47:44 +0100 | [diff] [blame] | 79 | " 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] | 80 | func Test_helptag_cmd() |
| 81 | call mkdir('Xdir/a/doc', 'p') |
| 82 | |
| 83 | " No help file to process in the directory |
| 84 | call assert_fails('helptags Xdir', 'E151:') |
| 85 | |
| 86 | call writefile([], 'Xdir/a/doc/sample.txt') |
| 87 | |
| 88 | " Test for ++t argument |
| 89 | helptags ++t Xdir |
| 90 | call assert_equal(["help-tags\ttags\t1"], readfile('Xdir/tags')) |
| 91 | call delete('Xdir/tags') |
| 92 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 93 | " Duplicate tags in the help file |
| 94 | call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xdir/a/doc/sample.txt') |
| 95 | call assert_fails('helptags Xdir', 'E154:') |
| 96 | |
| 97 | call delete('Xdir', 'rf') |
| 98 | endfunc |
| 99 | |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 100 | func Test_helptag_cmd_readonly() |
| 101 | CheckUnix |
| 102 | CheckNotRoot |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 103 | |
| 104 | " Read-only tags file |
| 105 | call mkdir('Xdir/doc', 'p') |
| 106 | call writefile([''], 'Xdir/doc/tags') |
| 107 | call writefile([], 'Xdir/doc/sample.txt') |
| 108 | call setfperm('Xdir/doc/tags', 'r-xr--r--') |
| 109 | call assert_fails('helptags Xdir/doc', 'E152:', getfperm('Xdir/doc/tags')) |
| 110 | |
| 111 | let rtp = &rtp |
| 112 | let &rtp = 'Xdir' |
| 113 | helptags ALL |
| 114 | let &rtp = rtp |
| 115 | |
| 116 | call delete('Xdir/doc/tags') |
| 117 | |
| 118 | " No permission to read the help file |
| 119 | call mkdir('Xdir/b/doc', 'p') |
| 120 | call writefile([], 'Xdir/b/doc/sample.txt') |
| 121 | call setfperm('Xdir/b/doc/sample.txt', '-w-------') |
| 122 | call assert_fails('helptags Xdir', 'E153:', getfperm('Xdir/b/doc/sample.txt')) |
| 123 | call delete('Xdir', 'rf') |
| 124 | endfunc |
| 125 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 126 | " Test for setting the 'helpheight' option in the help window |
| 127 | func Test_help_window_height() |
| 128 | let &cmdheight = &lines - 24 |
| 129 | set helpheight=10 |
| 130 | help |
| 131 | set helpheight=14 |
| 132 | call assert_equal(14, winheight(0)) |
| 133 | set helpheight& cmdheight=1 |
| 134 | close |
| 135 | endfunc |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 136 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 137 | " vim: shiftwidth=2 sts=2 expandtab |