Problem: "for" and "while" not recognized after :vim9cmd and :legacy.
(Emanuele Torre)
Solution: Recognize all the command modifiers. (closes #11087)
Add a test to check the list of modifiers.
switch (*p)
{
- // When adding an entry, also modify cmd_exists().
+ // When adding an entry, also modify cmdmods[].
case 'a': if (!checkforcmd_noparen(&eap->cmd, "aboveleft", 3))
break;
cmod->cmod_split |= WSP_ABOVE;
{"confirm", 4, FALSE},
{"filter", 4, FALSE},
{"hide", 3, FALSE},
+ {"horizontal", 3, FALSE},
{"keepalt", 5, FALSE},
{"keepjumps", 5, FALSE},
{"keepmarks", 3, FALSE},
{"keeppatterns", 5, FALSE},
{"leftabove", 5, FALSE},
+ {"legacy", 3, FALSE},
{"lockmarks", 3, FALSE},
{"noautocmd", 3, FALSE},
{"noswapfile", 3, FALSE},
{"unsilent", 3, FALSE},
{"verbose", 4, TRUE},
{"vertical", 4, FALSE},
+ {"vim9cmd", 4, FALSE},
};
/*
test_clientserver \
test_close_count \
test_cmdline \
+ test_cmdmods \
test_cmdwin \
test_command_count \
test_comments \
test_clientserver.res \
test_close_count.res \
test_cmdline.res \
+ test_cmdmods.res \
test_cmdwin.res \
test_command_count.res \
test_comments.res \
--- /dev/null
+" Test for all comand modifiers in
+
+def Test_cmdmods_array()
+ # Get all the command modifiers from ex_cmds.h.
+ var lines = readfile('../ex_cmds.h')->filter((_, l) => l =~ 'ex_wrongmodifier,')
+ var cmds = lines->map((_, v) => substitute(v, '.*"\(\k*\)".*', '\1', ''))
+
+ # :hide is both a command and a modifier
+ cmds->extend(['hide'])
+
+ # Get the entries of cmdmods[] in ex_docmd.c
+ edit ../ex_docmd.c
+ var top = search('^} cmdmods[') + 1
+ var bot = search('^};') - 1
+ lines = getline(top, bot)
+ var mods = lines->map((_, v) => substitute(v, '.*"\(\k*\)".*', '\1', ''))
+
+ # Check the lists are equal. Convert them to a dict to get a clearer error
+ # message.
+ var cmds_dict = {}
+ for v in cmds
+ cmds_dict[v] = 1
+ endfor
+ var mods_dict = {}
+ for v in mods
+ mods_dict[v] = 1
+ endfor
+ assert_equal(cmds_dict, mods_dict)
+
+ bwipe!
+enddef
+
+
+" vim: shiftwidth=2 sts=2 expandtab
+
let &enc = save_enc
endfunc
+func Test_for_with_modifier()
+ " this checks has_loop_cmd() works with a modifier
+ let result = []
+ vim9cmd for i in range(3)
+ call extend(result, [i])
+ endfor
+ call assert_equal([0, 1, 2], result)
+endfunc
+
func Test_for_invalid_line_count()
let lines =<< trim END
111111111111111111111111 for line in ['one']
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 423,
/**/
422,
/**/