blob: 15cc642d1734d9a163e3a16fcbf42c87001eaddc [file] [log] [blame]
Bram Moolenaar343b8c02017-02-17 12:04:56 +01001" Tests for :help
2
Bram Moolenaar17709e22021-03-19 14:38:12 +01003source check.vim
4
Bram Moolenaar343b8c02017-02-17 12:04:56 +01005func Test_help_restore_snapshot()
6 help
7 set buftype=
8 help
9 edit x
10 help
11 helpclose
12endfunc
Bram Moolenaar751ba612017-03-16 22:26:44 +010013
14func Test_help_errors()
15 call assert_fails('help doesnotexist', 'E149:')
16 call assert_fails('help!', 'E478:')
Bram Moolenaarea3db912020-02-02 15:32:13 +010017 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 Moolenaara4f99f52017-08-26 16:25:32 +020029
30 new
31 set keywordprg=:help
32 call setline(1, " ")
33 call assert_fails('normal VK', 'E349:')
34 bwipe!
35endfunc
36
Bram Moolenaar9ca25082019-10-05 11:30:09 +020037func Test_help_expr()
38 help expr-!~?
39 call assert_equal('eval.txt', expand('%:t'))
40 close
41endfunc
42
Bram Moolenaara4f99f52017-08-26 16:25:32 +020043func 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 Moolenaar751ba612017-03-16 22:26:44 +010052endfunc
Bram Moolenaar35c5e812017-12-09 21:10:13 +010053
54func 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
71endfunc
Bram Moolenaar297610b2019-12-27 17:20:55 +010072
73func Test_help_completion()
74 call feedkeys(":help :undo\<C-A>\<C-B>\"\<CR>", 'tx')
75 call assert_equal('"help :undo :undoj :undol :undojoin :undolist', @:)
76endfunc
Bram Moolenaare20b9ec2020-02-03 21:40:04 +010077
78" Test for the :helptags command
Bram Moolenaarf9a65502021-03-05 20:47:44 +010079" NOTE: if you run tests as root this will fail. Don't run tests as root!
Bram Moolenaare20b9ec2020-02-03 21:40:04 +010080func 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 Moolenaare20b9ec2020-02-03 21:40:04 +010093 " 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')
98endfunc
99
Bram Moolenaar17709e22021-03-19 14:38:12 +0100100func Test_helptag_cmd_readonly()
101 CheckUnix
102 CheckNotRoot
Bram Moolenaar17709e22021-03-19 14:38:12 +0100103
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')
124endfunc
125
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200126" Test for setting the 'helpheight' option in the help window
127func 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
135endfunc
Bram Moolenaar17709e22021-03-19 14:38:12 +0100136
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100137" vim: shiftwidth=2 sts=2 expandtab