To: vim_dev@googlegroups.com Subject: Patch 8.1.2011 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2011 Problem: More functions can be used as methods. Solution: Make various functions usable as a method. Make the window command test faster. Files: runtime/doc/eval.txt, runtime/doc/testing.txt, src/evalfunc.c, src/testdir/test_assert.vim, src/testdir/test_gui.vim, src/testdir/test_messages.vim, src/testdir/test_options.vim, src/testdir/test_quickfix.vim, src/testdir/test_taglist.vim, src/testdir/test_termcodes.vim, src/testdir/test_timers.vim, src/testdir/test_vimscript.vim, src/testdir/test_viminfo.vim, src/testdir/test_window_cmd.vim *** ../vim-8.1.2010/runtime/doc/eval.txt 2019-09-07 19:05:02.337280945 +0200 --- runtime/doc/eval.txt 2019-09-08 18:08:51.365820297 +0200 *************** *** 9592,9597 **** --- 9606,9613 ---- endfor < Note that a buffer may appear in more than one window. + Can also be used as a |method|: > + GetTabpage()->tabpagebuflist() tabpagenr([{arg}]) *tabpagenr()* The result is a Number, which is the number of the current *************** *** 9614,9619 **** --- 9630,9638 ---- tabpagewinnr(4, '$') " number of windows in tab page 4 < When {tabarg} is invalid zero is returned. + Can also be used as a |method|: > + GetTabpage()->tabpagewinnr() + < *tagfiles()* tagfiles() Returns a |List| with the file names used to search for tags for the current buffer. This is the 'tags' option expanded. *************** *** 9662,9667 **** --- 9681,9689 ---- located by Vim. Refer to |tags-file-format| for the format of the tags file generated by the different ctags tools. + Can also be used as a |method|: > + GetTagpattern()->taglist() + tan({expr}) *tan()* Return the tangent of {expr}, measured in radians, as a |Float| in the range [-inf, inf]. *** ../vim-8.1.2010/runtime/doc/testing.txt 2019-08-21 22:49:48.107267870 +0200 --- runtime/doc/testing.txt 2019-09-08 18:52:46.278846067 +0200 *************** *** 44,49 **** --- 44,51 ---- let memory allocation fail {repeat} times. When {repeat} is smaller than one it fails one time. + Can also be used as a |method|: > + GetAllocId()->test_alloc_fail() test_autochdir() *test_autochdir()* Set a flag to enable the effect of 'autochdir' before Vim *************** *** 55,60 **** --- 57,64 ---- were typed by the user. This uses a low level input buffer. This function works only when with |+unix| or GUI is running. + Can also be used as a |method|: > + GetText()->test_feedinput() test_garbagecollect_now() *test_garbagecollect_now()* Like garbagecollect(), but executed right away. This must *************** *** 73,78 **** --- 77,84 ---- {name} are supported: need_fileinfo + Can also be used as a |method|: > + GetName()->test_getvalue() test_ignore_error({expr}) *test_ignore_error()* Ignore any error containing {expr}. A normal message is given *************** *** 84,89 **** --- 90,97 ---- When the {expr} is the string "RESET" then the list of ignored errors is made empty. + Can also be used as a |method|: > + GetErrorText()->test_ignore_error() test_null_blob() *test_null_blob()* Return a |Blob| that is null. Only useful for testing. *************** *** 124,129 **** --- 132,140 ---- even though the value is "double". Only to be used for testing! + Can also be used as a |method|: > + GetOptionName()->test_option_not_set() + test_override({name}, {val}) *test_override()* Overrides certain parts of Vim's internal processing to be able *************** *** 155,166 **** --- 166,182 ---- < The value of "starting" is saved. It is restored by: > call test_override('starting', 0) + < Can also be used as a |method|: > + GetOverrideVal()-> test_override('starting') test_refcount({expr}) *test_refcount()* Return the reference count of {expr}. When {expr} is of a type that does not have a reference count, returns -1. Only to be used for testing. + Can also be used as a |method|: > + GetVarname()->test_refcount() + test_scrollbar({which}, {value}, {dragging}) *test_scrollbar()* Pretend using scrollbar {which} to move it to position *************** *** 179,184 **** --- 195,202 ---- Only works when the {which} scrollbar actually exists, obviously only when using the GUI. + Can also be used as a |method|: > + GetValue()->test_scrollbar('right', 0) test_setmouse({row}, {col}) *test_setmouse()* Set the mouse position to be used for the next mouse action. *************** *** 197,202 **** --- 215,223 ---- {expr} must evaluate to a number. When the value is zero the normal behavior is restored. + Can also be used as a |method|: > + GetTime()->test_settime() + ============================================================================== 3. Assert functions *assert-functions-details* *** ../vim-8.1.2010/src/evalfunc.c 2019-09-07 19:05:02.337280945 +0200 --- src/evalfunc.c 2019-09-08 18:53:37.714736302 +0200 *************** *** 754,764 **** {"synstack", 2, 2, 0, f_synstack}, {"system", 1, 2, FEARG_1, f_system}, {"systemlist", 1, 2, FEARG_1, f_systemlist}, ! {"tabpagebuflist", 0, 1, 0, f_tabpagebuflist}, {"tabpagenr", 0, 1, 0, f_tabpagenr}, ! {"tabpagewinnr", 1, 2, 0, f_tabpagewinnr}, {"tagfiles", 0, 0, 0, f_tagfiles}, ! {"taglist", 1, 2, 0, f_taglist}, #ifdef FEAT_FLOAT {"tan", 1, 1, FEARG_1, f_tan}, {"tanh", 1, 1, FEARG_1, f_tanh}, --- 754,764 ---- {"synstack", 2, 2, 0, f_synstack}, {"system", 1, 2, FEARG_1, f_system}, {"systemlist", 1, 2, FEARG_1, f_systemlist}, ! {"tabpagebuflist", 0, 1, FEARG_1, f_tabpagebuflist}, {"tabpagenr", 0, 1, 0, f_tabpagenr}, ! {"tabpagewinnr", 1, 2, FEARG_1, f_tabpagewinnr}, {"tagfiles", 0, 0, 0, f_tagfiles}, ! {"taglist", 1, 2, FEARG_1, f_taglist}, #ifdef FEAT_FLOAT {"tan", 1, 1, FEARG_1, f_tan}, {"tanh", 1, 1, FEARG_1, f_tanh}, *************** *** 793,805 **** {"term_start", 1, 2, 0, f_term_start}, {"term_wait", 1, 2, 0, f_term_wait}, #endif ! {"test_alloc_fail", 3, 3, 0, f_test_alloc_fail}, {"test_autochdir", 0, 0, 0, f_test_autochdir}, ! {"test_feedinput", 1, 1, 0, f_test_feedinput}, ! {"test_garbagecollect_now", 0, 0, 0, f_test_garbagecollect_now}, ! {"test_garbagecollect_soon", 0, 0, 0, f_test_garbagecollect_soon}, ! {"test_getvalue", 1, 1, 0, f_test_getvalue}, ! {"test_ignore_error", 1, 1, 0, f_test_ignore_error}, {"test_null_blob", 0, 0, 0, f_test_null_blob}, #ifdef FEAT_JOB_CHANNEL {"test_null_channel", 0, 0, 0, f_test_null_channel}, --- 793,805 ---- {"term_start", 1, 2, 0, f_term_start}, {"term_wait", 1, 2, 0, f_term_wait}, #endif ! {"test_alloc_fail", 3, 3, FEARG_1, f_test_alloc_fail}, {"test_autochdir", 0, 0, 0, f_test_autochdir}, ! {"test_feedinput", 1, 1, FEARG_1, f_test_feedinput}, ! {"test_garbagecollect_now", 0, 0, 0, f_test_garbagecollect_now}, ! {"test_garbagecollect_soon", 0, 0, 0, f_test_garbagecollect_soon}, ! {"test_getvalue", 1, 1, FEARG_1, f_test_getvalue}, ! {"test_ignore_error", 1, 1, FEARG_1, f_test_ignore_error}, {"test_null_blob", 0, 0, 0, f_test_null_blob}, #ifdef FEAT_JOB_CHANNEL {"test_null_channel", 0, 0, 0, f_test_null_channel}, *************** *** 811,826 **** {"test_null_list", 0, 0, 0, f_test_null_list}, {"test_null_partial", 0, 0, 0, f_test_null_partial}, {"test_null_string", 0, 0, 0, f_test_null_string}, ! {"test_option_not_set", 1, 1, 0, f_test_option_not_set}, ! {"test_override", 2, 2, 0, f_test_override}, ! {"test_refcount", 1, 1, 0, f_test_refcount}, #ifdef FEAT_GUI ! {"test_scrollbar", 3, 3, 0, f_test_scrollbar}, #endif #ifdef FEAT_MOUSE {"test_setmouse", 2, 2, 0, f_test_setmouse}, #endif ! {"test_settime", 1, 1, 0, f_test_settime}, #ifdef FEAT_TIMERS {"timer_info", 0, 1, 0, f_timer_info}, {"timer_pause", 2, 2, 0, f_timer_pause}, --- 811,826 ---- {"test_null_list", 0, 0, 0, f_test_null_list}, {"test_null_partial", 0, 0, 0, f_test_null_partial}, {"test_null_string", 0, 0, 0, f_test_null_string}, ! {"test_option_not_set", 1, 1, FEARG_1, f_test_option_not_set}, ! {"test_override", 2, 2, FEARG_2, f_test_override}, ! {"test_refcount", 1, 1, FEARG_1, f_test_refcount}, #ifdef FEAT_GUI ! {"test_scrollbar", 3, 3, FEARG_2, f_test_scrollbar}, #endif #ifdef FEAT_MOUSE {"test_setmouse", 2, 2, 0, f_test_setmouse}, #endif ! {"test_settime", 1, 1, FEARG_1, f_test_settime}, #ifdef FEAT_TIMERS {"timer_info", 0, 1, 0, f_timer_info}, {"timer_pause", 2, 2, 0, f_timer_pause}, *** ../vim-8.1.2010/src/testdir/test_assert.vim 2019-08-21 22:49:48.111267837 +0200 --- src/testdir/test_assert.vim 2019-09-08 18:25:36.785499555 +0200 *************** *** 259,265 **** func Test_override() call test_override('char_avail', 1) ! call test_override('redraw', 1) call test_override('ALL', 0) call assert_fails("call test_override('xxx', 1)", 'E475') call assert_fails("call test_override('redraw', 'yes')", 'E474') --- 259,265 ---- func Test_override() call test_override('char_avail', 1) ! eval 1->test_override('redraw') call test_override('ALL', 0) call assert_fails("call test_override('xxx', 1)", 'E475') call assert_fails("call test_override('redraw', 'yes')", 'E474') *** ../vim-8.1.2010/src/testdir/test_gui.vim 2019-08-14 21:12:00.977833219 +0200 --- src/testdir/test_gui.vim 2019-09-08 18:48:40.159772811 +0200 *************** *** 398,469 **** endfunc func Test_set_guifontset() let skipped = '' ! if !has('xfontset') ! let skipped = g:not_supported . 'xfontset' ! else ! let ctype_saved = v:ctype ! ! " First, since XCreateFontSet(3) is very sensitive to locale, fonts must ! " be chosen meticulously. ! let font_head = '-misc-fixed-medium-r-normal--14' ! ! let font_aw70 = font_head . '-130-75-75-c-70' ! let font_aw140 = font_head . '-130-75-75-c-140' ! ! let font_jisx0201 = font_aw70 . '-jisx0201.1976-0' ! let font_jisx0208 = font_aw140 . '-jisx0208.1983-0' ! ! let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',') ! let short_XLFDs = join([ font_aw140, font_aw70 ], ',') ! let singleton = font_head . '-*' ! let aliases = 'k14,r14' ! ! " Second, among 'locales', look up such a locale that gets 'set ! " guifontset=' to work successfully with every fontset specified with ! " 'fontsets'. ! let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ] ! let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ] ! let feasible = 0 ! for locale in locales try ! exec 'language ctype' locale ! catch /^Vim\%((\a\+)\)\=:E197/ ! continue endtry ! let done = 0 ! for fontset in fontsets ! try ! exec 'set guifontset=' . fontset ! catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/ ! break ! endtry ! let done += 1 ! endfor ! if done == len(fontsets) ! let feasible = 1 ! break ! endif endfor ! ! " Third, give a set of tests if it is found feasible. ! if !feasible ! let skipped = g:not_hosted ! else ! " N.B. 'v:ctype' has already been set to an appropriate value in the ! " previous loop. ! for fontset in fontsets ! exec 'set guifontset=' . fontset ! call assert_equal(fontset, &guifontset) ! endfor endif ! " Finally, restore ctype. ! exec 'language ctype' ctype_saved endif if !empty(skipped) throw skipped endif --- 398,466 ---- endfunc func Test_set_guifontset() + CheckFeature xfontset let skipped = '' ! let ctype_saved = v:ctype ! " First, since XCreateFontSet(3) is very sensitive to locale, fonts must ! " be chosen meticulously. ! let font_head = '-misc-fixed-medium-r-normal--14' ! ! let font_aw70 = font_head . '-130-75-75-c-70' ! let font_aw140 = font_head . '-130-75-75-c-140' ! ! let font_jisx0201 = font_aw70 . '-jisx0201.1976-0' ! let font_jisx0208 = font_aw140 . '-jisx0208.1983-0' ! ! let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',') ! let short_XLFDs = join([ font_aw140, font_aw70 ], ',') ! let singleton = font_head . '-*' ! let aliases = 'k14,r14' ! ! " Second, among 'locales', look up such a locale that gets 'set ! " guifontset=' to work successfully with every fontset specified with ! " 'fontsets'. ! let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ] ! let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ] ! ! let feasible = 0 ! for locale in locales ! try ! exec 'language ctype' locale ! catch /^Vim\%((\a\+)\)\=:E197/ ! continue ! endtry ! let done = 0 ! for fontset in fontsets try ! exec 'set guifontset=' . fontset ! catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/ ! break endtry ! let done += 1 endfor ! if done == len(fontsets) ! let feasible = 1 ! break endif + endfor ! " Third, give a set of tests if it is found feasible. ! if !feasible ! let skipped = g:not_hosted ! else ! " N.B. 'v:ctype' has already been set to an appropriate value in the ! " previous loop. ! for fontset in fontsets ! exec 'set guifontset=' . fontset ! call assert_equal(fontset, &guifontset) ! endfor endif + " Finally, restore ctype. + exec 'language ctype' ctype_saved + if !empty(skipped) throw skipped endif *************** *** 677,683 **** set guioptions+=rlb " scroll to move line 11 at top, moves the cursor there ! call test_scrollbar('left', 10, 0) redraw call assert_equal(1, winline()) call assert_equal(11, line('.')) --- 674,680 ---- set guioptions+=rlb " scroll to move line 11 at top, moves the cursor there ! eval 10->test_scrollbar('left', 0) redraw call assert_equal(1, winline()) call assert_equal(11, line('.')) *** ../vim-8.1.2010/src/testdir/test_messages.vim 2019-08-23 20:58:42.024375479 +0200 --- src/testdir/test_messages.vim 2019-09-08 18:18:30.291489775 +0200 *************** *** 90,96 **** if has('float') call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) endif ! call test_ignore_error('') call assert_match("function('\\d*')", execute(':echoerr {-> 1234}')) call test_ignore_error('RESET') endfunc --- 90,96 ---- if has('float') call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) endif ! eval ''->test_ignore_error() call assert_match("function('\\d*')", execute(':echoerr {-> 1234}')) call test_ignore_error('RESET') endfunc *** ../vim-8.1.2010/src/testdir/test_options.vim 2019-08-07 23:07:03.960858821 +0200 --- src/testdir/test_options.vim 2019-09-08 18:16:18.312030761 +0200 *************** *** 510,516 **** call assert_true(empty(execute('bn', ''))) call assert_false(test_getvalue('need_fileinfo')) call assert_true(empty(execute('bn', ''))) ! call assert_false(test_getvalue('need_fileinfo')) set hidden call assert_true(empty(execute('bn', ''))) call assert_false(test_getvalue('need_fileinfo')) --- 510,516 ---- call assert_true(empty(execute('bn', ''))) call assert_false(test_getvalue('need_fileinfo')) call assert_true(empty(execute('bn', ''))) ! call assert_false('need_fileinfo'->test_getvalue()) set hidden call assert_true(empty(execute('bn', ''))) call assert_false(test_getvalue('need_fileinfo')) *** ../vim-8.1.2010/src/testdir/test_quickfix.vim 2019-09-06 22:45:47.578271556 +0200 --- src/testdir/test_quickfix.vim 2019-09-08 18:12:44.464876952 +0200 *************** *** 517,523 **** call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) call assert_fails('vimgrep vim runtest.vim', 'E342:') ! call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0) call assert_fails('vimgrep vim runtest.vim', 'E342:') call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0) --- 517,523 ---- call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) call assert_fails('vimgrep vim runtest.vim', 'E342:') ! call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0) call assert_fails('vimgrep vim runtest.vim', 'E342:') call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0) *** ../vim-8.1.2010/src/testdir/test_taglist.vim 2019-06-15 18:40:11.044368488 +0200 --- src/testdir/test_taglist.vim 2019-09-08 18:09:15.237722397 +0200 *************** *** 13,19 **** split Xtext call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo"), {i, v -> v.name})) ! call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xtext"), {i, v -> v.name})) call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xfoo"), {i, v -> v.name})) call assert_equal(['BFoo', 'FFoo'], map(taglist("Foo", "Xbar"), {i, v -> v.name})) --- 13,19 ---- split Xtext call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo"), {i, v -> v.name})) ! call assert_equal(['FFoo', 'BFoo'], map("Foo"->taglist("Xtext"), {i, v -> v.name})) call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xfoo"), {i, v -> v.name})) call assert_equal(['BFoo', 'FFoo'], map(taglist("Foo", "Xbar"), {i, v -> v.name})) *** ../vim-8.1.2010/src/testdir/test_termcodes.vim 2019-08-31 21:17:35.594131454 +0200 --- src/testdir/test_termcodes.vim 2019-09-08 18:22:51.330244463 +0200 *************** *** 646,652 **** " response to t_RB, 4 digits, dark set background=light ! call test_option_not_set('background') let red = 0x29 let green = 0x4a let blue = 0x6b --- 646,652 ---- " response to t_RB, 4 digits, dark set background=light ! eval 'background'->test_option_not_set() let red = 0x29 let green = 0x4a let blue = 0x6b *** ../vim-8.1.2010/src/testdir/test_timers.vim 2019-08-17 13:18:12.638746868 +0200 --- src/testdir/test_timers.vim 2019-09-08 18:14:26.916469726 +0200 *************** *** 251,257 **** endfunc func Interrupt(timer) ! call test_feedinput("\") endfunc func Test_timer_peek_and_get_char() --- 251,257 ---- endfunc func Interrupt(timer) ! eval "\"->test_feedinput() endfunc func Test_timer_peek_and_get_char() *** ../vim-8.1.2010/src/testdir/test_vimscript.vim 2019-08-24 20:49:58.829320278 +0200 --- src/testdir/test_vimscript.vim 2019-09-08 18:26:57.353145777 +0200 *************** *** 1596,1602 **** call assert_equal(1, test_refcount(x)) let x = {} ! call assert_equal(1, test_refcount(x)) let x = 0zff call assert_equal(1, test_refcount(x)) --- 1596,1602 ---- call assert_equal(1, test_refcount(x)) let x = {} ! call assert_equal(1, x->test_refcount()) let x = 0zff call assert_equal(1, test_refcount(x)) *** ../vim-8.1.2010/src/testdir/test_viminfo.vim 2019-07-27 23:27:48.758769385 +0200 --- src/testdir/test_viminfo.vim 2019-09-08 18:53:16.082783512 +0200 *************** *** 171,177 **** call histdel(':') " items go before and after ! call test_settime(8) call histadd(':', "echo '8'") call test_settime(39) call histadd(':', "echo '39'") --- 171,177 ---- call histdel(':') " items go before and after ! eval 8->test_settime() call histadd(':', "echo '8'") call test_settime(39) call histadd(':', "echo '39'") *** ../vim-8.1.2010/src/testdir/test_window_cmd.vim 2019-08-17 15:07:56.919054146 +0200 --- src/testdir/test_window_cmd.vim 2019-09-08 18:07:43.342101312 +0200 *************** *** 485,491 **** wincmd T call assert_equal(2, tabpagenr('$')) call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) ! call assert_equal(['Xc' ], map(tabpagebuflist(2), 'bufname(v:val)')) %bw! endfunc --- 485,491 ---- wincmd T call assert_equal(2, tabpagenr('$')) call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) ! call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)')) %bw! endfunc *************** *** 598,605 **** func Fun_RenewFile() " Need to wait a bit for the timestamp to be older. ! sleep 2 ! silent execute '!echo "1" > tmp.txt' sp wincmd p edit! tmp.txt --- 598,608 ---- func Fun_RenewFile() " Need to wait a bit for the timestamp to be older. ! let old_ftime = getftime("tmp.txt") ! while getftime("tmp.txt") == old_ftime ! sleep 100m ! silent execute '!echo "1" > tmp.txt' ! endwhile sp wincmd p edit! tmp.txt *************** *** 835,841 **** tabnew call assert_equal(8, tabpagewinnr(1, 'j')) ! call assert_equal(2, tabpagewinnr(1, 'k')) call assert_equal(4, tabpagewinnr(1, 'h')) call assert_equal(6, tabpagewinnr(1, 'l')) --- 838,844 ---- tabnew call assert_equal(8, tabpagewinnr(1, 'j')) ! call assert_equal(2, 1->tabpagewinnr('k')) call assert_equal(4, tabpagewinnr(1, 'h')) call assert_equal(6, tabpagewinnr(1, 'l')) *** ../vim-8.1.2010/src/version.c 2019-09-08 17:20:05.882203752 +0200 --- src/version.c 2019-09-08 18:57:41.590118449 +0200 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 2011, /**/ -- hundred-and-one symptoms of being an internet addict: 220. Your wife asks for sex and you tell her where to find you on IRC. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///