blob: 77ae85ea2c3de984c9066818956bdd648139526c [file] [log] [blame]
Yee Cheng Chinb77bdce2022-10-15 10:22:19 +01001" Test to verify that the cmd list in runtime/doc/index.txt contains all of
2" the commands in src/ex_cmds.h. It doesn't map the other way round because
3" index.txt contains some shorthands like :!! which are useful to list, but
4" they don't exist as an independent entry in src/ex_cmds.h.
5"
6" Currently this just checks for existence, and we aren't checking for whether
7" they are sorted in the index, or whether the substring needed (e.g.
8" 'defc[ompile]') is correct or not.
9
10func Test_cmd_lists()
11
12 " Create a list of the commands in ex_cmds.h:CMD_index.
13 enew!
14 read ../ex_cmds.h
15 1,/^enum CMD_index$/d
16 call search('^};$')
17 .,$d
18 v/^EXCMD/d
19 %s/^.*"\(\S\+\)".*$/\1/
20 " Special case ':*' because it's represented as ':star'
21 %s/^\*$/star/
22 sort u
23 let l:command_list = getline(1, '$')
24
25 " Verify that the ':help ex-cmd-index' list contains all known commands.
26 enew!
27 if filereadable('../../doc/index.txt')
28 " unpacked MS-Windows zip archive
29 read ../../doc/index.txt
30 else
31 read ../../runtime/doc/index.txt
32 endif
33 call search('\*ex-cmd-index\*')
34 1,.d
35 v/^|:/d
36 %s/^|:\(\S*\)|.*/\1/
37 sort u
38 norm gg
39 let l:missing_cmds = []
40 for cmd in l:command_list
41 " Reserved Vim 9 commands or other script-only syntax aren't useful to
42 " document as Ex commands.
43 let l:vim9cmds = [
44 \ 'abstract',
45 \ 'class',
46 \ 'endclass',
47 \ 'endenum',
48 \ 'endinterface',
49 \ 'enum',
50 \ 'interface',
Bram Moolenaar9163efb2022-12-04 21:09:48 +000051 \ 'public',
Yee Cheng Chinb77bdce2022-10-15 10:22:19 +010052 \ 'static',
Bram Moolenaar94722c52023-01-28 19:19:03 +000053 \ 'this',
Yee Cheng Chinb77bdce2022-10-15 10:22:19 +010054 \ 'type',
55 \ '++',
56 \ '--',
57 \ '{',
58 \ '}']
59 if index(l:vim9cmds, cmd) != -1
60 continue
61 endif
62
63 if search('^\V' .. cmd .. '\v$', 'cW') == 0
64 call add(l:missing_cmds, ':' .. cmd)
65 endif
66 endfor
67 call assert_equal(0, len(l:missing_cmds), "Missing commands from `:help ex-cmd-index`: " .. string(l:missing_cmds))
68endfunc
69
70" vim: shiftwidth=2 sts=2 expandtab