xref: /vim-8.2.3635/src/testdir/test_help.vim (revision e30d1025)
1" Tests for :help
2
3source check.vim
4
5func Test_help_restore_snapshot()
6  help
7  set buftype=
8  help
9  edit x
10  help
11  helpclose
12endfunc
13
14func Test_help_errors()
15  call assert_fails('help doesnotexist', 'E149:')
16  call assert_fails('help!', 'E478:')
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:')
29
30  new
31  set keywordprg=:help
32  call setline(1, "   ")
33  call assert_fails('normal VK', 'E349:')
34  bwipe!
35endfunc
36
37func Test_help_expr()
38  help expr-!~?
39  call assert_equal('eval.txt', expand('%:t'))
40  close
41endfunc
42
43func 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!
52endfunc
53
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
72
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
77
78" Test for the :helptags command
79" NOTE: if you run tests as root this will fail.  Don't run tests as root!
80func 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
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')
98endfunc
99
100func Test_helptag_cmd_readonly()
101  CheckUnix
102  CheckNotRoot
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')
124endfunc
125
126" 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
136
137" vim: shiftwidth=2 sts=2 expandtab
138