From 9132426334a8c7e159db93ec1b08ed61ac600aae Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 9 Sep 2022 13:27:59 +0100 Subject: [PATCH] patch 9.0.0423: "for" and "while" not recognized after :vim9cmd and :legacy 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. --- src/ex_docmd.c | 5 ++++- src/testdir/Make_all.mak | 2 ++ src/testdir/test_cmdmods.vim | 35 +++++++++++++++++++++++++++++++++ src/testdir/test_eval_stuff.vim | 9 +++++++++ src/version.c | 2 ++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/testdir/test_cmdmods.vim diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 0b6b21712..0024c99c6 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -2888,7 +2888,7 @@ parse_command_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; @@ -3958,11 +3958,13 @@ static struct cmdmod {"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}, @@ -3974,6 +3976,7 @@ static struct cmdmod {"unsilent", 3, FALSE}, {"verbose", 4, TRUE}, {"vertical", 4, FALSE}, + {"vim9cmd", 4, FALSE}, }; /* diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index dbda7e15f..d7abcb5a4 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -87,6 +87,7 @@ NEW_TESTS = \ test_clientserver \ test_close_count \ test_cmdline \ + test_cmdmods \ test_cmdwin \ test_command_count \ test_comments \ @@ -346,6 +347,7 @@ NEW_TESTS_RES = \ test_clientserver.res \ test_close_count.res \ test_cmdline.res \ + test_cmdmods.res \ test_cmdwin.res \ test_command_count.res \ test_comments.res \ diff --git a/src/testdir/test_cmdmods.vim b/src/testdir/test_cmdmods.vim new file mode 100644 index 000000000..eb6dff1ce --- /dev/null +++ b/src/testdir/test_cmdmods.vim @@ -0,0 +1,35 @@ +" 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 + diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim index 0081d89a5..7d8421b72 100644 --- a/src/testdir/test_eval_stuff.vim +++ b/src/testdir/test_eval_stuff.vim @@ -146,6 +146,15 @@ func Test_for_over_null_string() 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'] diff --git a/src/version.c b/src/version.c index fe87dabfc..445ac6dde 100644 --- a/src/version.c +++ b/src/version.c @@ -703,6 +703,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 423, /**/ 422, /**/ -- 2.40.0