help_spec.lua (5083B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 4 local clear = n.clear 5 local command = n.command 6 local eq = t.eq 7 local fn = n.fn 8 local api = n.api 9 local mkdir = t.mkdir 10 local rmdir = n.rmdir 11 local write_file = t.write_file 12 13 describe(':help', function() 14 before_each(clear) 15 16 it('{subject}', function() 17 n.command('helptags ++t $VIMRUNTIME/doc') 18 local function check_tag(cmd, tag) 19 local cmd_ok = t.pcall(n.command, cmd) 20 local found = n.api.nvim_get_current_line():find(tag, 1, true) 21 local errmsg = (not cmd_ok and 'command failed') or (not found and 'tag not found') or '?' 22 assert( 23 cmd_ok and found, 24 string.format('Expected `:%s` to jump to tag `%s`, but %s', cmd, tag, errmsg) 25 ) 26 n.command('helpclose') 27 end 28 29 check_tag('help', '*help.txt*') 30 check_tag('help |', '*bar*') 31 check_tag('help "*', '*quotestar*') 32 check_tag('help ch??khealth', '*:checkhealth*') 33 34 check_tag([[help \\star]], [[*/\star*]]) 35 check_tag('help /*', [[*/\star*]]) 36 check_tag('help ?', '*?*') 37 check_tag('help ??', '*??*') 38 check_tag('help expr-!=?', '*expr-!=?*') 39 40 check_tag('help /<cr>', '*/<CR>*') 41 check_tag([[help %(\\)]], [[*/\%(\)*]]) 42 check_tag('help %^', [[/\%^]]) 43 check_tag('help /_^G', '/_CTRL-G') 44 check_tag([[help \0]], [[\0]]) 45 46 check_tag('help !', '*!*') 47 check_tag('help #{}', '*#{}*') 48 check_tag('help %:8', '*%:8*') 49 check_tag('help &', '*&*') 50 check_tag([[help '']], [[*''*]]) 51 check_tag([[help '(]], [[*'(*]]) 52 check_tag([[help '0]], [[*'0*]]) 53 check_tag([[help 'ac']], [[*'ac'*]]) 54 check_tag([[help '{]], [[*'{*]]) 55 check_tag('help )', '*)*') 56 check_tag('help +', '*+*') 57 58 check_tag('help +opt', '*++opt*') 59 check_tag('help --', '*--*') 60 check_tag('help -?', '*-?*') 61 check_tag('help .', '*.*') 62 check_tag('help :', '*:*') 63 check_tag([[help :'}]], [[*:'}*]]) 64 check_tag('help :,', '*:,*') 65 check_tag('help :<abuf>', '*:<abuf>*') 66 check_tag([[help :\|]], [[*:\bar*]]) 67 check_tag([[help :\\|]], [[*:\bar*]]) 68 check_tag('help _', '*_*') 69 check_tag('help `', '*`*') 70 check_tag('help `(', '*`(*') 71 check_tag([[help `:ls`.]], [[*:ls*]]) 72 73 check_tag('help [', '*[*') 74 check_tag('help [#', '*[#*') 75 check_tag([[help [']], [[*['*]]) 76 check_tag('help [(', '*[(*') 77 check_tag('help [++opt]', '*[++opt]*') 78 check_tag('help [:tab:]', '*[:tab:]*') 79 check_tag('help [count]', '*[count]*') 80 check_tag('help :[range]', '*:[range]*') 81 check_tag('help [<space>', '[<Space>') 82 check_tag('help ]_^D', ']_CTRL-D') 83 84 check_tag([[help $HOME]], [[*$HOME*]]) 85 86 check_tag('help <C-pagedown>', '*CTRL-<PageDown>*') 87 check_tag('help ^A', '*CTRL-A*') 88 check_tag('help ^W_+', '*CTRL-W_+*') 89 check_tag('help ^W<up>', '*CTRL-W_<Up>*') 90 check_tag('help ^W>', '*CTRL-W_>*') 91 check_tag('help ^W^]', '*CTRL-W_CTRL-]*') 92 check_tag('help ^W^', '*CTRL-W_^*') 93 check_tag('help ^W|', '*CTRL-W_bar*') 94 check_tag('help ^Wg<tab>', '*CTRL-W_g<Tab>*') 95 check_tag('help ^]', '*CTRL-]*') 96 check_tag('help ^{char}', 'CTRL-{char}') 97 check_tag('help [^L', '[_CTRL-L') 98 check_tag('help <C-', '*<C-*') 99 check_tag('help <S-CR>', '*<S-CR>*') 100 check_tag('help <<', '*<<*') 101 check_tag('help <>', '*<>*') 102 check_tag([[help i^x^y]], '*i_CTRL-X_CTRL-Y*') 103 check_tag([[help CTRL-\_CTRL-N]], [[*CTRL-\_CTRL-N*]]) 104 105 check_tag([[exe "help i\<C-\>\<C-G>"]], [[*i_CTRL-\_CTRL-G*]]) 106 check_tag([[exe "help \<C-V>"]], '*CTRL-V*') 107 check_tag([[exe "help! arglistid([{winnr})"]], '*arglistid()*') 108 check_tag([[exe "help! 'autoindent'."]], [[*'autoindent'*]]) 109 110 check_tag('exusage', '*:index*') 111 check_tag('viusage', '*normal-index*') 112 113 -- Test cases for removed exceptions 114 check_tag('help /\\(\\)', '*/\\(\\)*') 115 check_tag('help :s\\=', '*:s\\=*') 116 check_tag([[help expr-']], [[*expr-'*]]) 117 check_tag('help expr-barbar', '*expr-barbar*') 118 check_tag([[help s/\9]], [[*s/\9*]]) 119 check_tag([[help s/\U]], [[*s/\U*]]) 120 check_tag([[help s/\~]], [[*s/\~*]]) 121 check_tag([[help \|]], [[*/\bar*]]) 122 end) 123 124 it('window closed makes cursor return to a valid win/buf #9773', function() 125 n.add_builddir_to_rtp() 126 command('help help') 127 eq(1001, fn.win_getid()) 128 command('quit') 129 eq(1000, fn.win_getid()) 130 131 command('autocmd WinNew * wincmd p') 132 133 command('help help') 134 -- Window 1002 is opened, but the autocmd switches back to 1000 and 135 -- creates the help buffer there instead. 136 eq(1000, fn.win_getid()) 137 command('quit') 138 -- Before #9773, Nvim would crash on quitting the help window. 139 eq(1002, fn.win_getid()) 140 end) 141 142 it('multibyte help tags work #23975', function() 143 mkdir('Xhelptags') 144 finally(function() 145 rmdir('Xhelptags') 146 end) 147 mkdir('Xhelptags/doc') 148 write_file('Xhelptags/doc/Xhelptags.txt', '*…*') 149 command('helptags Xhelptags/doc') 150 command('set rtp+=Xhelptags') 151 command('help …') 152 eq('*…*', api.nvim_get_current_line()) 153 end) 154 end)