To: vim_dev@googlegroups.com Subject: Patch 8.2.3590 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3590 Problem: Test for v:colornames sometimes fails. (Dominique Pellé) Solution: Check features. Clear v:colornames between tests. (Drew Vogel, closes #9105, closes #9073) Files: runtime/doc/eval.txt, src/highlight.c, src/proto/highlight.pro, src/testdir/test_highlight.vim *** ../vim-8.2.3589/runtime/doc/eval.txt 2021-11-03 21:56:41.218795250 +0000 --- runtime/doc/eval.txt 2021-11-13 10:47:51.434124364 +0000 *************** *** 1852,1866 **** \ 'mauve': '#915f6d, \ }, 'keep') < ! Using |extend| with the 'keep' option updates each color only if it did not exist in |v:colornames|. Doing so allows the user to choose the precise color value for a common name by setting it in their |.vimrc|. It is possible to remove entries from this dictionary but ! doing so is *NOT* recommended. Doing so is disruptive to other scripts. It is also unlikely to achieve the desired ! result because the |colorscheme| and |highlight| commands will both automatically load all `colors/lists/default.vim` color scripts. --- 1865,1879 ---- \ 'mauve': '#915f6d, \ }, 'keep') < ! Using |extend()| with the 'keep' option updates each color only if it did not exist in |v:colornames|. Doing so allows the user to choose the precise color value for a common name by setting it in their |.vimrc|. It is possible to remove entries from this dictionary but ! doing so is NOT recommended, because it is disruptive to other scripts. It is also unlikely to achieve the desired ! result because the |:colorscheme| and |:highlight| commands will both automatically load all `colors/lists/default.vim` color scripts. *** ../vim-8.2.3589/src/highlight.c 2021-11-03 21:56:41.218795250 +0000 --- src/highlight.c 2021-11-13 10:44:34.954469929 +0000 *************** *** 2332,2370 **** return INVALCOLOR; } - // Maps the given name to the given color value, overwriting any current - // mapping. If allocation fails the named color will no longer exist in the - // table and the user will receive an error message. - void - save_colorname_hexstr(int r, int g, int b, char_u *name) - { - int result; - dict_T *colornames_table; - dictitem_T *existing; - char_u hexstr[8]; - - if (vim_snprintf((char *)hexstr, sizeof(hexstr), - "#%02x%02x%02x", r, g, b) < 0) - { - semsg(_(e_cannot_allocate_color_str), name); - return; - } - - colornames_table = get_vim_var_dict(VV_COLORNAMES); - // The colornames_table dict is safe to use here because it is allocated at - // startup in evalvars.c - existing = dict_find(colornames_table, name, -1); - if (existing != NULL) - { - dictitem_remove(colornames_table, existing); - existing = NULL; // dictitem_remove freed the item - } - - result = dict_add_string(colornames_table, (char *)name, hexstr); - if (result == FAIL) - semsg(_(e_cannot_allocate_color_str), name); - } - /* * Load a default color list. Intended to support legacy color names but allows * the user to override the color values. Only loaded once. --- 2332,2337 ---- *** ../vim-8.2.3589/src/proto/highlight.pro 2021-11-03 21:56:41.218795250 +0000 --- src/proto/highlight.pro 2021-11-13 10:48:10.334090493 +0000 *************** *** 16,22 **** guicolor_T color_name2handle(char_u *name); guicolor_T decode_hex_color(char_u *hex); guicolor_T colorname2rgb(char_u *name); - void save_colorname_hexstr(int r, int g, int b, char_u *name); void load_default_colors_lists(void); guicolor_T gui_get_color_cmn(char_u *name); guicolor_T gui_get_rgb_color_cmn(int r, int g, int b); --- 16,21 ---- *** ../vim-8.2.3589/src/testdir/test_highlight.vim 2021-11-03 21:56:41.218795250 +0000 --- src/testdir/test_highlight.vim 2021-11-13 10:44:34.958469922 +0000 *************** *** 6,11 **** --- 6,17 ---- source script_util.vim source vim9.vim + func ClearDict(d) + for k in keys(a:d) + call remove(a:d, k) + endfor + endfunc + func Test_highlight() " basic test if ":highlight" doesn't crash highlight *************** *** 936,954 **** --- 942,971 ---- endfunc func Test_colornames_assignment_and_lookup() + CheckAnyOf Feature:gui_running Feature:termguicolors + " Ensure highlight command can find custom color. let v:colornames['a redish white'] = '#ffeedd' highlight Normal guifg='a redish white' highlight clear + call ClearDict(v:colornames) endfunc func Test_colornames_default_list() + CheckAnyOf Feature:gui_running Feature:termguicolors + " Ensure default lists are loaded automatically and can be used for all gui fields. + call assert_equal(0, len(v:colornames)) highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple' + call assert_notequal(0, len(v:colornames)) + echo v:colornames['rebecca purple'] highlight clear + call ClearDict(v:colornames) endfunc func Test_colornames_overwrite_default() + CheckAnyOf Feature:gui_running Feature:termguicolors + " Ensure entries in v:colornames can be overwritten. " Load default color scheme to trigger default color list loading. colorscheme default *************** *** 961,966 **** --- 978,987 ---- endfunc func Test_colornames_assignment_and_unassignment() + " No feature check is needed for this test because the v:colornames dict + " always exists with +eval. The feature checks are only required for + " commands that do color lookup. + " Ensure we cannot overwrite the v:colornames dict. call assert_fails("let v:colornames = {}", 'E46:') *** ../vim-8.2.3589/src/version.c 2021-11-13 10:27:34.387764064 +0000 --- src/version.c 2021-11-13 10:47:18.558183062 +0000 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 3590, /**/ -- ARTHUR: Well, it doesn't matter. Will you go and tell your master that Arthur from the Court of Camelot is here. GUARD #1: Listen, in order to maintain air-speed velocity, a swallow needs to beat its wings 43 times every second, right? ARTHUR: Please! The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///