Bram Moolenaar | 343b8c0 | 2017-02-17 12:04:56 +0100 | [diff] [blame] | 1 | " Tests for :help |
| 2 | |
| 3 | func Test_help_restore_snapshot() |
| 4 | help |
| 5 | set buftype= |
| 6 | help |
| 7 | edit x |
| 8 | help |
| 9 | helpclose |
| 10 | endfunc |
Bram Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 11 | |
| 12 | func Test_help_errors() |
| 13 | call assert_fails('help doesnotexist', 'E149:') |
| 14 | call assert_fails('help!', 'E478:') |
Bram Moolenaar | ea3db91 | 2020-02-02 15:32:13 +0100 | [diff] [blame] | 15 | if has('multi_lang') |
| 16 | call assert_fails('help help@xy', 'E661:') |
| 17 | endif |
| 18 | |
| 19 | let save_hf = &helpfile |
| 20 | set helpfile=help_missing |
| 21 | help |
| 22 | call assert_equal(1, winnr('$')) |
| 23 | call assert_notequal('help', &buftype) |
| 24 | let &helpfile = save_hf |
| 25 | |
| 26 | call assert_fails('help ' . repeat('a', 1048), 'E149:') |
Bram Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 27 | |
| 28 | new |
| 29 | set keywordprg=:help |
| 30 | call setline(1, " ") |
| 31 | call assert_fails('normal VK', 'E349:') |
| 32 | bwipe! |
| 33 | endfunc |
| 34 | |
Bram Moolenaar | 9ca2508 | 2019-10-05 11:30:09 +0200 | [diff] [blame] | 35 | func Test_help_expr() |
| 36 | help expr-!~? |
| 37 | call assert_equal('eval.txt', expand('%:t')) |
| 38 | close |
| 39 | endfunc |
| 40 | |
Bram Moolenaar | a4f99f5 | 2017-08-26 16:25:32 +0200 | [diff] [blame] | 41 | func Test_help_keyword() |
| 42 | new |
| 43 | set keywordprg=:help |
| 44 | call setline(1, " Visual ") |
| 45 | normal VK |
| 46 | call assert_match('^Visual mode', getline('.')) |
| 47 | call assert_equal('help', &ft) |
| 48 | close |
| 49 | bwipe! |
Bram Moolenaar | 751ba61 | 2017-03-16 22:26:44 +0100 | [diff] [blame] | 50 | endfunc |
Bram Moolenaar | 35c5e81 | 2017-12-09 21:10:13 +0100 | [diff] [blame] | 51 | |
| 52 | func Test_help_local_additions() |
| 53 | call mkdir('Xruntime/doc', 'p') |
| 54 | call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt') |
| 55 | call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt') |
| 56 | let rtp_save = &rtp |
| 57 | set rtp+=./Xruntime |
| 58 | help |
| 59 | 1 |
| 60 | call search('mydoc.txt') |
| 61 | call assert_equal('|mydoc.txt| my awesome doc', getline('.')) |
| 62 | 1 |
| 63 | call search('mydoc-ext.txt') |
| 64 | call assert_equal('|mydoc-ext.txt| my extended awesome doc', getline('.')) |
| 65 | close |
| 66 | |
| 67 | call delete('Xruntime', 'rf') |
| 68 | let &rtp = rtp_save |
| 69 | endfunc |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 70 | |
| 71 | func Test_help_completion() |
| 72 | call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 73 | call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:) |
| 74 | endfunc |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 75 | |
| 76 | " Test for the :helptags command |
Bram Moolenaar | f9a6550 | 2021-03-05 20:47:44 +0100 | [diff] [blame] | 77 | " 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] | 78 | func Test_helptag_cmd() |
| 79 | call mkdir('Xdir/a/doc', 'p') |
| 80 | |
| 81 | " No help file to process in the directory |
| 82 | call assert_fails('helptags Xdir', 'E151:') |
| 83 | |
| 84 | call writefile([], 'Xdir/a/doc/sample.txt') |
| 85 | |
| 86 | " Test for ++t argument |
| 87 | helptags ++t Xdir |
| 88 | call assert_equal(["help-tags\ttags\t1"], readfile('Xdir/tags')) |
| 89 | call delete('Xdir/tags') |
| 90 | |
| 91 | " The following tests fail on FreeBSD for some reason |
| 92 | if has('unix') && !has('bsd') |
| 93 | " Read-only tags file |
Bram Moolenaar | 414b796 | 2020-02-17 22:39:35 +0100 | [diff] [blame] | 94 | call mkdir('Xdir/doc', 'p') |
| 95 | call writefile([''], 'Xdir/doc/tags') |
| 96 | call writefile([], 'Xdir/doc/sample.txt') |
| 97 | call setfperm('Xdir/doc/tags', 'r-xr--r--') |
| 98 | call assert_fails('helptags Xdir/doc', 'E152:', getfperm('Xdir/doc/tags')) |
| 99 | |
| 100 | let rtp = &rtp |
| 101 | let &rtp = 'Xdir' |
| 102 | helptags ALL |
| 103 | let &rtp = rtp |
| 104 | |
| 105 | call delete('Xdir/doc/tags') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 106 | |
| 107 | " No permission to read the help file |
| 108 | call setfperm('Xdir/a/doc/sample.txt', '-w-------') |
| 109 | call assert_fails('helptags Xdir', 'E153:', getfperm('Xdir/a/doc/sample.txt')) |
| 110 | call delete('Xdir/a/doc/sample.txt') |
| 111 | call delete('Xdir/tags') |
| 112 | endif |
| 113 | |
| 114 | " Duplicate tags in the help file |
| 115 | call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xdir/a/doc/sample.txt') |
| 116 | call assert_fails('helptags Xdir', 'E154:') |
| 117 | |
| 118 | call delete('Xdir', 'rf') |
| 119 | endfunc |
| 120 | |
| 121 | " vim: shiftwidth=2 sts=2 expandtab |