Skip to content

Commit ce90e36

Browse files
committed
patch 8.1.2011: more functions can be used as methods
Problem: More functions can be used as methods. Solution: Make various functions usable as a method. Make the window command test faster.
1 parent 9490b9a commit ce90e36

15 files changed

Lines changed: 116 additions & 85 deletions

runtime/doc/eval.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9606,6 +9606,8 @@ tabpagebuflist([{arg}]) *tabpagebuflist()*
96069606
endfor
96079607
< Note that a buffer may appear in more than one window.
96089608

9609+
Can also be used as a |method|: >
9610+
GetTabpage()->tabpagebuflist()
96099611
96109612
tabpagenr([{arg}]) *tabpagenr()*
96119613
The result is a Number, which is the number of the current
@@ -9628,6 +9630,9 @@ tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
96289630
tabpagewinnr(4, '$') " number of windows in tab page 4
96299631
< When {tabarg} is invalid zero is returned.
96309632

9633+
Can also be used as a |method|: >
9634+
GetTabpage()->tabpagewinnr()
9635+
<
96319636
*tagfiles()*
96329637
tagfiles() Returns a |List| with the file names used to search for tags
96339638
for the current buffer. This is the 'tags' option expanded.
@@ -9676,6 +9681,9 @@ taglist({expr} [, {filename}]) *taglist()*
96769681
located by Vim. Refer to |tags-file-format| for the format of
96779682
the tags file generated by the different ctags tools.
96789683

9684+
Can also be used as a |method|: >
9685+
GetTagpattern()->taglist()
9686+
96799687
tan({expr}) *tan()*
96809688
Return the tangent of {expr}, measured in radians, as a |Float|
96819689
in the range [-inf, inf].

runtime/doc/testing.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ test_alloc_fail({id}, {countdown}, {repeat}) *test_alloc_fail()*
4444
let memory allocation fail {repeat} times. When {repeat} is
4545
smaller than one it fails one time.
4646

47+
Can also be used as a |method|: >
48+
GetAllocId()->test_alloc_fail()
4749
4850
test_autochdir() *test_autochdir()*
4951
Set a flag to enable the effect of 'autochdir' before Vim
@@ -55,6 +57,8 @@ test_feedinput({string}) *test_feedinput()*
5557
were typed by the user. This uses a low level input buffer.
5658
This function works only when with |+unix| or GUI is running.
5759

60+
Can also be used as a |method|: >
61+
GetText()->test_feedinput()
5862
5963
test_garbagecollect_now() *test_garbagecollect_now()*
6064
Like garbagecollect(), but executed right away. This must
@@ -73,6 +77,8 @@ test_getvalue({name}) *test_getvalue()*
7377
{name} are supported:
7478
need_fileinfo
7579

80+
Can also be used as a |method|: >
81+
GetName()->test_getvalue()
7682
7783
test_ignore_error({expr}) *test_ignore_error()*
7884
Ignore any error containing {expr}. A normal message is given
@@ -84,6 +90,8 @@ test_ignore_error({expr}) *test_ignore_error()*
8490
When the {expr} is the string "RESET" then the list of ignored
8591
errors is made empty.
8692

93+
Can also be used as a |method|: >
94+
GetErrorText()->test_ignore_error()
8795
8896
test_null_blob() *test_null_blob()*
8997
Return a |Blob| that is null. Only useful for testing.
@@ -124,6 +132,9 @@ test_option_not_set({name}) *test_option_not_set()*
124132
even though the value is "double".
125133
Only to be used for testing!
126134

135+
Can also be used as a |method|: >
136+
GetOptionName()->test_option_not_set()
137+
127138
128139
test_override({name}, {val}) *test_override()*
129140
Overrides certain parts of Vim's internal processing to be able
@@ -155,12 +166,17 @@ test_override({name}, {val}) *test_override()*
155166
< The value of "starting" is saved. It is restored by: >
156167
call test_override('starting', 0)
157168
169+
< Can also be used as a |method|: >
170+
GetOverrideVal()-> test_override('starting')
158171
159172
test_refcount({expr}) *test_refcount()*
160173
Return the reference count of {expr}. When {expr} is of a
161174
type that does not have a reference count, returns -1. Only
162175
to be used for testing.
163176

177+
Can also be used as a |method|: >
178+
GetVarname()->test_refcount()
179+
164180
165181
test_scrollbar({which}, {value}, {dragging}) *test_scrollbar()*
166182
Pretend using scrollbar {which} to move it to position
@@ -179,6 +195,8 @@ test_scrollbar({which}, {value}, {dragging}) *test_scrollbar()*
179195
Only works when the {which} scrollbar actually exists,
180196
obviously only when using the GUI.
181197

198+
Can also be used as a |method|: >
199+
GetValue()->test_scrollbar('right', 0)
182200
183201
test_setmouse({row}, {col}) *test_setmouse()*
184202
Set the mouse position to be used for the next mouse action.
@@ -197,6 +215,9 @@ test_settime({expr}) *test_settime()*
197215
{expr} must evaluate to a number. When the value is zero the
198216
normal behavior is restored.
199217

218+
Can also be used as a |method|: >
219+
GetTime()->test_settime()
220+
200221
==============================================================================
201222
3. Assert functions *assert-functions-details*
202223

src/evalfunc.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,11 @@ static funcentry_T global_functions[] =
754754
{"synstack", 2, 2, 0, f_synstack},
755755
{"system", 1, 2, FEARG_1, f_system},
756756
{"systemlist", 1, 2, FEARG_1, f_systemlist},
757-
{"tabpagebuflist", 0, 1, 0, f_tabpagebuflist},
757+
{"tabpagebuflist", 0, 1, FEARG_1, f_tabpagebuflist},
758758
{"tabpagenr", 0, 1, 0, f_tabpagenr},
759-
{"tabpagewinnr", 1, 2, 0, f_tabpagewinnr},
759+
{"tabpagewinnr", 1, 2, FEARG_1, f_tabpagewinnr},
760760
{"tagfiles", 0, 0, 0, f_tagfiles},
761-
{"taglist", 1, 2, 0, f_taglist},
761+
{"taglist", 1, 2, FEARG_1, f_taglist},
762762
#ifdef FEAT_FLOAT
763763
{"tan", 1, 1, FEARG_1, f_tan},
764764
{"tanh", 1, 1, FEARG_1, f_tanh},
@@ -793,13 +793,13 @@ static funcentry_T global_functions[] =
793793
{"term_start", 1, 2, 0, f_term_start},
794794
{"term_wait", 1, 2, 0, f_term_wait},
795795
#endif
796-
{"test_alloc_fail", 3, 3, 0, f_test_alloc_fail},
796+
{"test_alloc_fail", 3, 3, FEARG_1, f_test_alloc_fail},
797797
{"test_autochdir", 0, 0, 0, f_test_autochdir},
798-
{"test_feedinput", 1, 1, 0, f_test_feedinput},
799-
{"test_garbagecollect_now", 0, 0, 0, f_test_garbagecollect_now},
800-
{"test_garbagecollect_soon", 0, 0, 0, f_test_garbagecollect_soon},
801-
{"test_getvalue", 1, 1, 0, f_test_getvalue},
802-
{"test_ignore_error", 1, 1, 0, f_test_ignore_error},
798+
{"test_feedinput", 1, 1, FEARG_1, f_test_feedinput},
799+
{"test_garbagecollect_now", 0, 0, 0, f_test_garbagecollect_now},
800+
{"test_garbagecollect_soon", 0, 0, 0, f_test_garbagecollect_soon},
801+
{"test_getvalue", 1, 1, FEARG_1, f_test_getvalue},
802+
{"test_ignore_error", 1, 1, FEARG_1, f_test_ignore_error},
803803
{"test_null_blob", 0, 0, 0, f_test_null_blob},
804804
#ifdef FEAT_JOB_CHANNEL
805805
{"test_null_channel", 0, 0, 0, f_test_null_channel},
@@ -811,16 +811,16 @@ static funcentry_T global_functions[] =
811811
{"test_null_list", 0, 0, 0, f_test_null_list},
812812
{"test_null_partial", 0, 0, 0, f_test_null_partial},
813813
{"test_null_string", 0, 0, 0, f_test_null_string},
814-
{"test_option_not_set", 1, 1, 0, f_test_option_not_set},
815-
{"test_override", 2, 2, 0, f_test_override},
816-
{"test_refcount", 1, 1, 0, f_test_refcount},
814+
{"test_option_not_set", 1, 1, FEARG_1, f_test_option_not_set},
815+
{"test_override", 2, 2, FEARG_2, f_test_override},
816+
{"test_refcount", 1, 1, FEARG_1, f_test_refcount},
817817
#ifdef FEAT_GUI
818-
{"test_scrollbar", 3, 3, 0, f_test_scrollbar},
818+
{"test_scrollbar", 3, 3, FEARG_2, f_test_scrollbar},
819819
#endif
820820
#ifdef FEAT_MOUSE
821821
{"test_setmouse", 2, 2, 0, f_test_setmouse},
822822
#endif
823-
{"test_settime", 1, 1, 0, f_test_settime},
823+
{"test_settime", 1, 1, FEARG_1, f_test_settime},
824824
#ifdef FEAT_TIMERS
825825
{"timer_info", 0, 1, 0, f_timer_info},
826826
{"timer_pause", 2, 2, 0, f_timer_pause},

src/testdir/test_assert.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ endfunc
259259

260260
func Test_override()
261261
call test_override('char_avail', 1)
262-
call test_override('redraw', 1)
262+
eval 1->test_override('redraw')
263263
call test_override('ALL', 0)
264264
call assert_fails("call test_override('xxx', 1)", 'E475')
265265
call assert_fails("call test_override('redraw', 'yes')", 'E474')

src/testdir/test_gui.vim

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -398,72 +398,69 @@ func Test_set_guifont()
398398
endfunc
399399

400400
func Test_set_guifontset()
401+
CheckFeature xfontset
401402
let skipped = ''
402403

403-
if !has('xfontset')
404-
let skipped = g:not_supported . 'xfontset'
405-
else
406-
let ctype_saved = v:ctype
407-
408-
" First, since XCreateFontSet(3) is very sensitive to locale, fonts must
409-
" be chosen meticulously.
410-
let font_head = '-misc-fixed-medium-r-normal--14'
411-
412-
let font_aw70 = font_head . '-130-75-75-c-70'
413-
let font_aw140 = font_head . '-130-75-75-c-140'
414-
415-
let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
416-
let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
417-
418-
let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
419-
let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
420-
let singleton = font_head . '-*'
421-
let aliases = 'k14,r14'
422-
423-
" Second, among 'locales', look up such a locale that gets 'set
424-
" guifontset=' to work successfully with every fontset specified with
425-
" 'fontsets'.
426-
let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
427-
let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
428-
429-
let feasible = 0
430-
for locale in locales
404+
let ctype_saved = v:ctype
405+
406+
" First, since XCreateFontSet(3) is very sensitive to locale, fonts must
407+
" be chosen meticulously.
408+
let font_head = '-misc-fixed-medium-r-normal--14'
409+
410+
let font_aw70 = font_head . '-130-75-75-c-70'
411+
let font_aw140 = font_head . '-130-75-75-c-140'
412+
413+
let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
414+
let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
415+
416+
let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
417+
let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
418+
let singleton = font_head . '-*'
419+
let aliases = 'k14,r14'
420+
421+
" Second, among 'locales', look up such a locale that gets 'set
422+
" guifontset=' to work successfully with every fontset specified with
423+
" 'fontsets'.
424+
let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
425+
let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
426+
427+
let feasible = 0
428+
for locale in locales
429+
try
430+
exec 'language ctype' locale
431+
catch /^Vim\%((\a\+)\)\=:E197/
432+
continue
433+
endtry
434+
let done = 0
435+
for fontset in fontsets
431436
try
432-
exec 'language ctype' locale
433-
catch /^Vim\%((\a\+)\)\=:E197/
434-
continue
437+
exec 'set guifontset=' . fontset
438+
catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
439+
break
435440
endtry
436-
let done = 0
437-
for fontset in fontsets
438-
try
439-
exec 'set guifontset=' . fontset
440-
catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
441-
break
442-
endtry
443-
let done += 1
444-
endfor
445-
if done == len(fontsets)
446-
let feasible = 1
447-
break
448-
endif
441+
let done += 1
449442
endfor
450-
451-
" Third, give a set of tests if it is found feasible.
452-
if !feasible
453-
let skipped = g:not_hosted
454-
else
455-
" N.B. 'v:ctype' has already been set to an appropriate value in the
456-
" previous loop.
457-
for fontset in fontsets
458-
exec 'set guifontset=' . fontset
459-
call assert_equal(fontset, &guifontset)
460-
endfor
443+
if done == len(fontsets)
444+
let feasible = 1
445+
break
461446
endif
447+
endfor
462448

463-
" Finally, restore ctype.
464-
exec 'language ctype' ctype_saved
449+
" Third, give a set of tests if it is found feasible.
450+
if !feasible
451+
let skipped = g:not_hosted
452+
else
453+
" N.B. 'v:ctype' has already been set to an appropriate value in the
454+
" previous loop.
455+
for fontset in fontsets
456+
exec 'set guifontset=' . fontset
457+
call assert_equal(fontset, &guifontset)
458+
endfor
465459
endif
466460

461+
" Finally, restore ctype.
462+
exec 'language ctype' ctype_saved
463+
467464
if !empty(skipped)
468465
throw skipped
469466
endif
@@ -677,7 +674,7 @@ func Test_scrollbars()
677674
set guioptions+=rlb
678675

679676
" scroll to move line 11 at top, moves the cursor there
680-
call test_scrollbar('left', 10, 0)
677+
eval 10->test_scrollbar('left', 0)
681678
redraw
682679
call assert_equal(1, winline())
683680
call assert_equal(11, line('.'))

src/testdir/test_messages.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func Test_echoerr()
9090
if has('float')
9191
call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"'))
9292
endif
93-
call test_ignore_error('<lambda>')
93+
eval '<lambda>'->test_ignore_error()
9494
call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}'))
9595
call test_ignore_error('RESET')
9696
endfunc

src/testdir/test_options.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func Test_shortmess_F2()
510510
call assert_true(empty(execute('bn', '')))
511511
call assert_false(test_getvalue('need_fileinfo'))
512512
call assert_true(empty(execute('bn', '')))
513-
call assert_false(test_getvalue('need_fileinfo'))
513+
call assert_false('need_fileinfo'->test_getvalue())
514514
set hidden
515515
call assert_true(empty(execute('bn', '')))
516516
call assert_false(test_getvalue('need_fileinfo'))

src/testdir/test_quickfix.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func Test_nomem()
517517
call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
518518
call assert_fails('vimgrep vim runtest.vim', 'E342:')
519519

520-
call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
520+
call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0)
521521
call assert_fails('vimgrep vim runtest.vim', 'E342:')
522522

523523
call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)

src/testdir/test_taglist.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func Test_taglist()
1313
split Xtext
1414

1515
call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo"), {i, v -> v.name}))
16-
call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xtext"), {i, v -> v.name}))
16+
call assert_equal(['FFoo', 'BFoo'], map("Foo"->taglist("Xtext"), {i, v -> v.name}))
1717
call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xfoo"), {i, v -> v.name}))
1818
call assert_equal(['BFoo', 'FFoo'], map(taglist("Foo", "Xbar"), {i, v -> v.name}))
1919

src/testdir/test_termcodes.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ func Test_term_rgb_response()
646646

647647
" response to t_RB, 4 digits, dark
648648
set background=light
649-
call test_option_not_set('background')
649+
eval 'background'->test_option_not_set()
650650
let red = 0x29
651651
let green = 0x4a
652652
let blue = 0x6b

0 commit comments

Comments
 (0)