]> granicus.if.org Git - vim/commitdiff
patch 8.1.2011: more functions can be used as methods v8.1.2011
authorBram Moolenaar <Bram@vim.org>
Sun, 8 Sep 2019 16:58:44 +0000 (18:58 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 8 Sep 2019 16:58:44 +0000 (18:58 +0200)
Problem:    More functions can be used as methods.
Solution:   Make various functions usable as a method.  Make the window
            command test faster.

15 files changed:
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_viminfo.vim
src/testdir/test_vimscript.vim
src/testdir/test_window_cmd.vim
src/version.c

index 772fd1d7ae59fd4ac61182851cf39e6df0c25d5f..339a01eb94aa3d332471d8ce5bddd5ebfc26c3a7 100644 (file)
@@ -9606,6 +9606,8 @@ tabpagebuflist([{arg}])                                   *tabpagebuflist()*
                        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
@@ -9628,6 +9630,9 @@ tabpagewinnr({tabarg} [, {arg}])                  *tabpagewinnr()*
                    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.
@@ -9676,6 +9681,9 @@ taglist({expr} [, {filename}])                            *taglist()*
                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].
index e29921aa66968f600d8f4c6a4b8aed9156a573de..82fe64e7a12416829ae0bab256384b035f521f73 100644 (file)
@@ -44,6 +44,8 @@ test_alloc_fail({id}, {countdown}, {repeat})          *test_alloc_fail()*
                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,6 +57,8 @@ test_feedinput({string})                              *test_feedinput()*
                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,6 +77,8 @@ test_getvalue({name})                                 *test_getvalue()*
                {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,6 +90,8 @@ test_ignore_error({expr})                      *test_ignore_error()*
                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,6 +132,9 @@ test_option_not_set({name})                         *test_option_not_set()*
                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,12 +166,17 @@ test_override({name}, {val})                              *test_override()*
 <              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,6 +195,8 @@ test_scrollbar({which}, {value}, {dragging})                *test_scrollbar()*
                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,6 +215,9 @@ test_settime({expr})                                        *test_settime()*
                {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*
 
index 19922da79ac89f1b6a6e8bea6d6474c0817d110b..d9381253c68754cc0948cfb05d3d0c09a3a6b479 100644 (file)
@@ -754,11 +754,11 @@ static funcentry_T global_functions[] =
     {"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},
+    {"tabpagebuflist", 0, 1, FEARG_1,    f_tabpagebuflist},
     {"tabpagenr",      0, 1, 0,          f_tabpagenr},
-    {"tabpagewinnr",   1, 2, 0,          f_tabpagewinnr},
+    {"tabpagewinnr",   1, 2, FEARG_1,    f_tabpagewinnr},
     {"tagfiles",       0, 0, 0,          f_tagfiles},
-    {"taglist",                1, 2, 0,          f_taglist},
+    {"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,13 +793,13 @@ static funcentry_T global_functions[] =
     {"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_alloc_fail",        3, 3, FEARG_1,    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_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,16 +811,16 @@ static funcentry_T global_functions[] =
     {"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},
+    {"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, 0,          f_test_scrollbar},
+    {"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, 0,          f_test_settime},
+    {"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},
index d89bd983a26ade86c254d4abca71ed44b546552b..1b1f9e5151149ac340df43e21a69a17123ec3083 100644 (file)
@@ -259,7 +259,7 @@ endfunc
 
 func Test_override()
   call test_override('char_avail', 1)
-  call test_override('redraw', 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')
index e80e85f277eba233ed01ebb5dc2a6c994df77a07..f2d82e4a6d006ddfe2f37367d1060d713f75d120 100644 (file)
@@ -398,72 +398,69 @@ func Test_set_guifont()
 endfunc
 
 func Test_set_guifontset()
+  CheckFeature xfontset
   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
+  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 'language ctype' locale
-      catch /^Vim\%((\a\+)\)\=:E197/
-        continue
+       exec 'set guifontset=' . fontset
+      catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
+       break
       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
+      let done += 1
     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
+    if done == len(fontsets)
+      let feasible = 1
+      break
     endif
+  endfor
 
-    " Finally, restore ctype.
-    exec 'language ctype' ctype_saved
+  " 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,7 +674,7 @@ func Test_scrollbars()
   set guioptions+=rlb
 
   " scroll to move line 11 at top, moves the cursor there
-  call test_scrollbar('left', 10, 0)
+  eval 10->test_scrollbar('left', 0)
   redraw
   call assert_equal(1, winline())
   call assert_equal(11, line('.'))
index f122917ba7e33ef510e0ad9b792282a7b63641f0..bcfcdd2401282c681ec74496907218d15b0c42a0 100644 (file)
@@ -90,7 +90,7 @@ func Test_echoerr()
   if has('float')
     call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"'))
   endif
-  call test_ignore_error('<lambda>')
+  eval '<lambda>'->test_ignore_error()
   call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}'))
   call test_ignore_error('RESET')
 endfunc
index 5d5723cca664f4210eb2132beefd1a76fad8e1f7..3a43356504f900fec880c8d85ce5be60534ac7f0 100644 (file)
@@ -510,7 +510,7 @@ func Test_shortmess_F2()
   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'))
+  call assert_false('need_fileinfo'->test_getvalue())
   set hidden
   call assert_true(empty(execute('bn', '')))
   call assert_false(test_getvalue('need_fileinfo'))
index 402a96dc53b4e2a87f880a660f6649be1cdc5138..f2403986bf56a2cdf357c4805b69de488920d5cb 100644 (file)
@@ -517,7 +517,7 @@ func Test_nomem()
   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 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)
index 9ddefc5153b02477525c6ab0558ca27dda878745..824adc013bc5b46cb975faf56f2d33abbbb579ef 100644 (file)
@@ -13,7 +13,7 @@ func Test_taglist()
   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("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}))
 
index 7b71d60ae9aea70aec1ffbbbd4a74ef340de4ab6..e8b36f40ea517d6d936a65cdad3615f0e0e3f3d8 100644 (file)
@@ -646,7 +646,7 @@ func Test_term_rgb_response()
 
   " response to t_RB, 4 digits, dark
   set background=light
-  call test_option_not_set('background')
+  eval 'background'->test_option_not_set()
   let red = 0x29
   let green = 0x4a
   let blue = 0x6b
index 3eebad66c3bd759d309ab00bbbc9fa18a4a5ea61..261be278dddcc9959078c78f7713250bcd276c41 100644 (file)
@@ -251,7 +251,7 @@ func FeedAndPeek(timer)
 endfunc
 
 func Interrupt(timer)
-  call test_feedinput("\<C-C>")
+  eval "\<C-C>"->test_feedinput()
 endfunc
 
 func Test_timer_peek_and_get_char()
index 306f54d602d7464a670d7c3988f333a143ba5145..048ebacd305f781d1692fe1f66326e3e3d635416 100644 (file)
@@ -171,7 +171,7 @@ func Test_cmdline_history_order()
 
   call histdel(':')
   " items go before and after
-  call test_settime(8)
+  eval 8->test_settime()
   call histadd(':', "echo '8'")
   call test_settime(39)
   call histadd(':', "echo '39'")
index 8dc00f2334eb4c7cb9cb6fd33c8070be1c5ac6c4..18790d24ca09c63ed2150f250f0833203b7fb900 100644 (file)
@@ -1596,7 +1596,7 @@ func Test_refcount()
     call assert_equal(1, test_refcount(x))
 
     let x = {}
-    call assert_equal(1, test_refcount(x))
+    call assert_equal(1, x->test_refcount())
 
     let x = 0zff
     call assert_equal(1, test_refcount(x))
index 9927e27576e37868d569843744453107c384cbf6..f2a9f1797a976bd1247bfdccf99f670ed68a48e7 100644 (file)
@@ -485,7 +485,7 @@ func Test_window_newtab()
   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)'))
+  call assert_equal(['Xc'      ], map(2->tabpagebuflist(), 'bufname(v:val)'))
 
   %bw!
 endfunc
@@ -598,8 +598,11 @@ endfunc
 
 func Fun_RenewFile()
   " Need to wait a bit for the timestamp to be older.
-  sleep 2
-  silent execute '!echo "1" > tmp.txt'
+  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,7 +838,7 @@ func Test_winnr()
 
   tabnew
   call assert_equal(8, tabpagewinnr(1, 'j'))
-  call assert_equal(2, tabpagewinnr(1, 'k'))
+  call assert_equal(2, 1->tabpagewinnr('k'))
   call assert_equal(4, tabpagewinnr(1, 'h'))
   call assert_equal(6, tabpagewinnr(1, 'l'))
 
index 2dbd141267464cf15a2b4a6c9fdeaaba15ca235e..0e58772bd24286bf0f6803cd7facb15edc61d28a 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2011,
 /**/
     2010,
 /**/