vim-patch:8.1.2013: more functions can be used as methods

Problem:    More functions can be used as methods.
Solution:   Make various functions usable as a method.
f92e58cadb

Cherry-pick s:normalize_fname for tolower test from v8.1.0894 and v8.1.1417 (even though it is
unused for now).

Fix header for win_id2tabwin in eval.txt.
This commit is contained in:
Sean Dewar
2021-11-01 16:26:19 +00:00
parent 38a831e54a
commit 2ad92e9476
10 changed files with 143 additions and 46 deletions

View File

@@ -10131,6 +10131,9 @@ timer_info([{id}])
-1 means forever -1 means forever
"callback" the callback "callback" the callback
Can also be used as a |method|: >
GetTimer()->timer_info()
<
timer_pause({timer}, {paused}) *timer_pause()* timer_pause({timer}, {paused}) *timer_pause()*
Pause or unpause a timer. A paused timer does not invoke its Pause or unpause a timer. A paused timer does not invoke its
callback when its time expires. Unpausing a timer may cause callback when its time expires. Unpausing a timer may cause
@@ -10144,6 +10147,9 @@ timer_pause({timer}, {paused}) *timer_pause()*
String, then the timer is paused, otherwise it is unpaused. String, then the timer is paused, otherwise it is unpaused.
See |non-zero-arg|. See |non-zero-arg|.
Can also be used as a |method|: >
GetTimer()->timer_pause(1)
<
*timer_start()* *timer* *timers* *timer_start()* *timer* *timers*
timer_start({time}, {callback} [, {options}]) timer_start({time}, {callback} [, {options}])
Create a timer and return the timer ID. Create a timer and return the timer ID.
@@ -10171,13 +10177,19 @@ timer_start({time}, {callback} [, {options}])
\ {'repeat': 3}) \ {'repeat': 3})
< This invokes MyHandler() three times at 500 msec intervals. < This invokes MyHandler() three times at 500 msec intervals.
Not available in the |sandbox|. Can also be used as a |method|: >
GetMsec()->timer_start(callback)
< Not available in the |sandbox|.
timer_stop({timer}) *timer_stop()* timer_stop({timer}) *timer_stop()*
Stop a timer. The timer callback will no longer be invoked. Stop a timer. The timer callback will no longer be invoked.
{timer} is an ID returned by timer_start(), thus it must be a {timer} is an ID returned by timer_start(), thus it must be a
Number. If {timer} does not exist there is no error. Number. If {timer} does not exist there is no error.
Can also be used as a |method|: >
GetTimer()->timer_stop()
<
timer_stopall() *timer_stopall()* timer_stopall() *timer_stopall()*
Stop all timers. The timer callbacks will no longer be Stop all timers. The timer callbacks will no longer be
invoked. Useful if some timers is misbehaving. If there are invoked. Useful if some timers is misbehaving. If there are
@@ -10188,11 +10200,17 @@ tolower({expr}) *tolower()*
characters turned into lowercase (just like applying |gu| to characters turned into lowercase (just like applying |gu| to
the string). the string).
Can also be used as a |method|: >
GetText()->tolower()
toupper({expr}) *toupper()* toupper({expr}) *toupper()*
The result is a copy of the String given, with all lowercase The result is a copy of the String given, with all lowercase
characters turned into uppercase (just like applying |gU| to characters turned into uppercase (just like applying |gU| to
the string). the string).
Can also be used as a |method|: >
GetText()->toupper()
tr({src}, {fromstr}, {tostr}) *tr()* tr({src}, {fromstr}, {tostr}) *tr()*
The result is a copy of the {src} string with all characters The result is a copy of the {src} string with all characters
which appear in {fromstr} replaced by the character in that which appear in {fromstr} replaced by the character in that
@@ -10207,6 +10225,9 @@ tr({src}, {fromstr}, {tostr}) *tr()*
echo tr("<blob>", "<>", "{}") echo tr("<blob>", "<>", "{}")
< returns "{blob}" < returns "{blob}"
Can also be used as a |method|: >
GetText()->tr(from, to)
trim({text} [, {mask} [, {dir}]]) *trim()* trim({text} [, {mask} [, {dir}]]) *trim()*
Return {text} as a String where any character in {mask} is Return {text} as a String where any character in {mask} is
removed from the beginning and/or end of {text}. removed from the beginning and/or end of {text}.
@@ -10230,6 +10251,9 @@ trim({text} [, {mask} [, {dir}]]) *trim()*
echo trim(" vim ", " ", 2) echo trim(" vim ", " ", 2)
< returns " vim" < returns " vim"
Can also be used as a |method|: >
GetText()->trim()
trunc({expr}) *trunc()* trunc({expr}) *trunc()*
Return the largest integral value with magnitude less than or Return the largest integral value with magnitude less than or
equal to {expr} as a |Float| (truncate towards zero). equal to {expr} as a |Float| (truncate towards zero).
@@ -10286,6 +10310,9 @@ undofile({name}) *undofile()*
buffer without a file name will not write an undo file. buffer without a file name will not write an undo file.
Useful in combination with |:wundo| and |:rundo|. Useful in combination with |:wundo| and |:rundo|.
Can also be used as a |method|: >
GetFilename()->undofile()
undotree() *undotree()* undotree() *undotree()*
Return the current state of the undo tree in a dictionary with Return the current state of the undo tree in a dictionary with
the following items: the following items:
@@ -10384,8 +10411,10 @@ virtcol({expr}) *virtcol()*
all lines: > all lines: >
echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
< Can also be used as a |method|: >
GetPos()->virtcol()
visualmode([expr]) *visualmode()* visualmode([{expr}]) *visualmode()*
The result is a String, which describes the last Visual mode The result is a String, which describes the last Visual mode
used in the current buffer. Initially it returns an empty used in the current buffer. Initially it returns an empty
string, but once Visual mode has been used, it returns "v", string, but once Visual mode has been used, it returns "v",
@@ -10399,7 +10428,7 @@ visualmode([expr]) *visualmode()*
Visual mode that was used. Visual mode that was used.
If Visual mode is active, use |mode()| to get the Visual mode If Visual mode is active, use |mode()| to get the Visual mode
(e.g., in a |:vmap|). (e.g., in a |:vmap|).
If [expr] is supplied and it evaluates to a non-zero Number or If {expr} is supplied and it evaluates to a non-zero Number or
a non-empty String, then the Visual mode will be cleared and a non-empty String, then the Visual mode will be cleared and
the old value is returned. See |non-zero-arg|. the old value is returned. See |non-zero-arg|.
@@ -10438,11 +10467,18 @@ win_execute({id}, {command} [, {silent}]) *win_execute()*
have unexpected side effects. Use |:noautocmd| if needed. have unexpected side effects. Use |:noautocmd| if needed.
Example: > Example: >
call win_execute(winid, 'syntax enable') call win_execute(winid, 'syntax enable')
<
Can also be used as a |method|, the base is used for the
command: >
GetCommand()->win_execute(winid)
win_findbuf({bufnr}) *win_findbuf()* win_findbuf({bufnr}) *win_findbuf()*
Returns a |List| with |window-ID|s for windows that contain Returns a |List| with |window-ID|s for windows that contain
buffer {bufnr}. When there is none the list is empty. buffer {bufnr}. When there is none the list is empty.
Can also be used as a |method|: >
GetBufnr()->win_findbuf()
win_getid([{win} [, {tab}]]) *win_getid()* win_getid([{win} [, {tab}]]) *win_getid()*
Get the |window-ID| for the specified window. Get the |window-ID| for the specified window.
When {win} is missing use the current window. When {win} is missing use the current window.
@@ -10452,6 +10488,9 @@ win_getid([{win} [, {tab}]]) *win_getid()*
number {tab}. The first tab has number one. number {tab}. The first tab has number one.
Return zero if the window cannot be found. Return zero if the window cannot be found.
Can also be used as a |method|: >
GetWinnr()->win_getid()
win_gettype([{nr}]) *win_gettype()* win_gettype([{nr}]) *win_gettype()*
Return the type of the window: Return the type of the window:
"autocmd" autocommand window. Temporary window "autocmd" autocommand window. Temporary window
@@ -10477,15 +10516,24 @@ win_gotoid({expr}) *win_gotoid()*
tabpage. tabpage.
Return TRUE if successful, FALSE if the window cannot be found. Return TRUE if successful, FALSE if the window cannot be found.
win_id2tabwin({expr} *win_id2tabwin()* Can also be used as a |method|: >
GetWinid()->win_gotoid()
win_id2tabwin({expr}) *win_id2tabwin()*
Return a list with the tab number and window number of window Return a list with the tab number and window number of window
with ID {expr}: [tabnr, winnr]. with ID {expr}: [tabnr, winnr].
Return [0, 0] if the window cannot be found. Return [0, 0] if the window cannot be found.
Can also be used as a |method|: >
GetWinid()->win_id2tabwin()
win_id2win({expr}) *win_id2win()* win_id2win({expr}) *win_id2win()*
Return the window number of window with ID {expr}. Return the window number of window with ID {expr}.
Return 0 if the window cannot be found in the current tabpage. Return 0 if the window cannot be found in the current tabpage.
Can also be used as a |method|: >
GetWinid()->win_id2win()
win_screenpos({nr}) *win_screenpos()* win_screenpos({nr}) *win_screenpos()*
Return the screen position of window {nr} as a list with two Return the screen position of window {nr} as a list with two
numbers: [row, col]. The first window always has position numbers: [row, col]. The first window always has position
@@ -10495,6 +10543,9 @@ win_screenpos({nr}) *win_screenpos()*
Returns [0, 0] if the window cannot be found in the current Returns [0, 0] if the window cannot be found in the current
tabpage. tabpage.
Can also be used as a |method|: >
GetWinid()->win_screenpos()
<
win_splitmove({nr}, {target} [, {options}]) *win_splitmove()* win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Move the window {nr} to a new split of the window {target}. Move the window {nr} to a new split of the window {target}.
This is similar to moving to {target}, creating a new window This is similar to moving to {target}, creating a new window
@@ -10549,6 +10600,9 @@ winheight({nr}) *winheight()*
This excludes any window toolbar line. This excludes any window toolbar line.
Examples: > Examples: >
:echo "The current window has " . winheight(0) . " lines." :echo "The current window has " . winheight(0) . " lines."
< Can also be used as a |method|: >
GetWinid()->winheight()
< <
winlayout([{tabnr}]) *winlayout()* winlayout([{tabnr}]) *winlayout()*
The result is a nested List containing the layout of windows The result is a nested List containing the layout of windows
@@ -10579,6 +10633,9 @@ winlayout([{tabnr}]) *winlayout()*
:echo winlayout(2) :echo winlayout(2)
['col', [['leaf', 1002], ['row', [['leaf', 1003], ['col', [['leaf', 1002], ['row', [['leaf', 1003],
['leaf', 1001]]], ['leaf', 1000]]] ['leaf', 1001]]], ['leaf', 1000]]]
<
Can also be used as a |method|: >
GetTabnr()->winlayout()
< <
*winline()* *winline()*
winline() The result is a Number, which is the screen line of the cursor winline() The result is a Number, which is the screen line of the cursor
@@ -10614,6 +10671,9 @@ winnr([{arg}]) The result is a Number, which is the number of the current
let window_count = winnr('$') let window_count = winnr('$')
let prev_window = winnr('#') let prev_window = winnr('#')
let wnum = winnr('3k') let wnum = winnr('3k')
< Can also be used as a |method|: >
GetWinval()->winnr()
< <
*winrestcmd()* *winrestcmd()*
winrestcmd() Returns a sequence of |:resize| commands that should restore winrestcmd() Returns a sequence of |:resize| commands that should restore
@@ -10642,6 +10702,9 @@ winrestview({dict})
If you have changed the values the result is unpredictable. If you have changed the values the result is unpredictable.
If the window size changed the result won't be the same. If the window size changed the result won't be the same.
Can also be used as a |method|: >
GetView()->winrestview()
<
*winsaveview()* *winsaveview()*
winsaveview() Returns a |Dictionary| that contains information to restore winsaveview() Returns a |Dictionary| that contains information to restore
the view of the current window. Use |winrestview()| to the view of the current window. Use |winrestview()| to
@@ -10680,6 +10743,8 @@ winwidth({nr}) *winwidth()*
< For getting the terminal or screen size, see the 'columns' < For getting the terminal or screen size, see the 'columns'
option. option.
Can also be used as a |method|: >
GetWinid()->winwidth()
wordcount() *wordcount()* wordcount() *wordcount()*
The result is a dictionary of byte/chars/word statistics for The result is a dictionary of byte/chars/word statistics for
@@ -10738,6 +10803,8 @@ writefile({object}, {fname} [, {flags}])
:let fl = readfile("foo", "b") :let fl = readfile("foo", "b")
:call writefile(fl, "foocopy", "b") :call writefile(fl, "foocopy", "b")
< Can also be used as a |method|: >
GetText()->writefile("thefile")
xor({expr}, {expr}) *xor()* xor({expr}, {expr}) *xor()*
Bitwise XOR on the two arguments. The arguments are converted Bitwise XOR on the two arguments. The arguments are converted

View File

@@ -385,47 +385,47 @@ return {
termopen={args={1, 2}}, termopen={args={1, 2}},
test_garbagecollect_now={}, test_garbagecollect_now={},
test_write_list_log={args=1}, test_write_list_log={args=1},
timer_info={args={0,1}}, timer_info={args={0, 1}, base=1},
timer_pause={args=2}, timer_pause={args=2, base=1},
timer_start={args={2,3}}, timer_start={args={2, 3}, base=1},
timer_stop={args=1}, timer_stop={args=1, base=1},
timer_stopall={args=0}, timer_stopall={args=0},
tolower={args=1}, tolower={args=1, base=1},
toupper={args=1}, toupper={args=1, base=1},
tr={args=3}, tr={args=3, base=1},
trim={args={1,3}}, trim={args={1, 3}, base=1},
trunc={args=1, base=1, func="float_op_wrapper", data="&trunc"}, trunc={args=1, base=1, func="float_op_wrapper", data="&trunc"},
type={args=1, base=1}, type={args=1, base=1},
undofile={args=1}, undofile={args=1, base=1},
undotree={}, undotree={},
uniq={args={1, 3}, base=1}, uniq={args={1, 3}, base=1},
values={args=1, base=1}, values={args=1, base=1},
virtcol={args=1}, virtcol={args=1, base=1},
visualmode={args={0, 1}}, visualmode={args={0, 1}},
wait={args={2,3}}, wait={args={2,3}},
wildmenumode={}, wildmenumode={},
win_execute={args={2, 3}}, win_execute={args={2, 3}, base=2},
win_findbuf={args=1}, win_findbuf={args=1, base=1},
win_getid={args={0,2}}, win_getid={args={0, 2}, base=1},
win_gettype={args={0,1}}, win_gettype={args={0,1}},
win_gotoid={args=1}, win_gotoid={args=1, base=1},
win_id2tabwin={args=1}, win_id2tabwin={args=1, base=1},
win_id2win={args=1}, win_id2win={args=1, base=1},
win_screenpos={args=1}, win_screenpos={args=1, base=1},
win_splitmove={args={2, 3}}, win_splitmove={args={2, 3}},
winbufnr={args=1, base=1}, winbufnr={args=1, base=1},
wincol={}, wincol={},
windowsversion={}, windowsversion={},
winheight={args=1}, winheight={args=1, base=1},
winlayout={args={0, 1}}, winlayout={args={0, 1}, base=1},
winline={}, winline={},
winnr={args={0, 1}}, winnr={args={0, 1}, base=1},
winrestcmd={}, winrestcmd={},
winrestview={args=1}, winrestview={args=1, base=1},
winsaveview={}, winsaveview={},
winwidth={args=1}, winwidth={args=1, base=1},
wordcount={}, wordcount={},
writefile={args={2, 3}}, writefile={args={2, 3}, base=1},
xor={args=2, base=1}, xor={args=2, base=1},
}, },
} }

View File

@@ -82,7 +82,7 @@ func Test_screenpos()
call assert_equal({'row': winrow, call assert_equal({'row': winrow,
\ 'col': wincol + 0, \ 'col': wincol + 0,
\ 'curscol': wincol + 7, \ 'curscol': wincol + 7,
\ 'endcol': wincol + 7}, screenpos(winid, 1, 1)) \ 'endcol': wincol + 7}, winid->screenpos(1, 1))
call assert_equal({'row': winrow, call assert_equal({'row': winrow,
\ 'col': wincol + 13, \ 'col': wincol + 13,
\ 'curscol': wincol + 13, \ 'curscol': wincol + 13,

View File

@@ -99,7 +99,7 @@ func Test_win_execute()
if has('textprop') if has('textprop')
let popupwin = popup_create('the popup win', {'line': 2, 'col': 3}) let popupwin = popup_create('the popup win', {'line': 2, 'col': 3})
redraw redraw
let line = win_execute(popupwin, 'echo getline(1)') let line = 'echo getline(1)'->win_execute(popupwin)
call assert_match('the popup win', line) call assert_match('the popup win', line)
call popup_close(popupwin) call popup_close(popupwin)

View File

@@ -307,6 +307,12 @@ func Test_resolve_unix()
call assert_equal('/', resolve('/')) call assert_equal('/', resolve('/'))
endfunc endfunc
func s:normalize_fname(fname)
let ret = substitute(a:fname, '\', '/', 'g')
let ret = substitute(ret, '//', '/', 'g')
return ret->tolower()
endfunc
func Test_simplify() func Test_simplify()
call assert_equal('', simplify('')) call assert_equal('', simplify(''))
call assert_equal('/', simplify('/')) call assert_equal('/', simplify('/'))
@@ -469,7 +475,7 @@ func Test_toupper()
\ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
" Test with a few lowercase diacritics. " Test with a few lowercase diacritics.
call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả")) call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", "aàáâãäåāăąǎǟǡả"->toupper())
call assert_equal("BḂḆ", toupper("bḃḇ")) call assert_equal("BḂḆ", toupper("bḃḇ"))
call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč"))
call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ"))
@@ -532,6 +538,11 @@ func Test_toupper()
call toupper("123\xC0\x80\xC0") call toupper("123\xC0\x80\xC0")
endfunc endfunc
func Test_tr()
call assert_equal('foo', tr('bar', 'bar', 'foo'))
call assert_equal('zxy', 'cab'->tr('abc', 'xyz'))
endfunc
" Tests for the mode() function " Tests for the mode() function
let current_modes = '' let current_modes = ''
func Save_mode() func Save_mode()
@@ -1293,7 +1304,7 @@ endfunc
func Test_trim() func Test_trim()
call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B")) call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B"))
call assert_equal("Testing", trim(" \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B")) call assert_equal("Testing", " \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B"->trim())
call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t")) call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t"))
call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww")) call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww"))
call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail")) call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail"))
@@ -1560,7 +1571,7 @@ func Test_bufadd_bufload()
call assert_equal([''], getbufline(buf, 1, '$')) call assert_equal([''], getbufline(buf, 1, '$'))
let curbuf = bufnr('') let curbuf = bufnr('')
call writefile(['some', 'text'], 'XotherName') eval ['some', 'text']->writefile('XotherName')
let buf = 'XotherName'->bufadd() let buf = 'XotherName'->bufadd()
call assert_notequal(0, buf) call assert_notequal(0, buf)
eval 'XotherName'->bufexists()->assert_equal(1) eval 'XotherName'->bufexists()->assert_equal(1)

View File

@@ -25,7 +25,7 @@ func Test_listchars()
redraw! redraw!
for i in range(1, 5) for i in range(1, 5)
call cursor(i, 1) call cursor(i, 1)
call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol()))
endfor endfor
set listchars-=trail:< set listchars-=trail:<

View File

@@ -77,7 +77,7 @@ endfunc
func Test_info() func Test_info()
let id = timer_start(1000, 'MyHandler') let id = timer_start(1000, 'MyHandler')
let info = timer_info(id) let info = id->timer_info()
call assert_equal(id, info[0]['id']) call assert_equal(id, info[0]['id'])
call assert_equal(1000, info[0]['time']) call assert_equal(1000, info[0]['time'])
call assert_equal("function('MyHandler')", string(info[0]['callback'])) call assert_equal("function('MyHandler')", string(info[0]['callback']))
@@ -113,7 +113,7 @@ func Test_paused()
let info = timer_info(id) let info = timer_info(id)
call assert_equal(0, info[0]['paused']) call assert_equal(0, info[0]['paused'])
call timer_pause(id, 1) eval id->timer_pause(1)
let info = timer_info(id) let info = timer_info(id)
call assert_equal(1, info[0]['paused']) call assert_equal(1, info[0]['paused'])
sleep 200m sleep 200m
@@ -148,7 +148,7 @@ func Test_delete_myself()
endfunc endfunc
func StopTimer1(timer) func StopTimer1(timer)
let g:timer2 = timer_start(10, 'StopTimer2') let g:timer2 = 10->timer_start('StopTimer2')
" avoid maxfuncdepth error " avoid maxfuncdepth error
call timer_pause(g:timer1, 1) call timer_pause(g:timer1, 1)
sleep 40m sleep 40m
@@ -251,7 +251,7 @@ func Test_peek_and_get_char()
let intr = timer_start(100, 'Interrupt') let intr = timer_start(100, 'Interrupt')
let c = getchar() let c = getchar()
call assert_equal(char2nr('a'), c) call assert_equal(char2nr('a'), c)
call timer_stop(intr) eval intr->timer_stop()
endfunc endfunc
func Test_getchar_zero() func Test_getchar_zero()

View File

@@ -490,7 +490,7 @@ funct Test_undofile()
call delete('Xundodir', 'd') call delete('Xundodir', 'd')
" Test undofile() with 'undodir' set to a non-existing directory. " Test undofile() with 'undodir' set to a non-existing directory.
" call assert_equal('', undofile('Xundofoo')) " call assert_equal('', 'Xundofoo'->undofile())
if isdirectory('/tmp') if isdirectory('/tmp')
set undodir=/tmp set undodir=/tmp

View File

@@ -72,7 +72,7 @@ endfunc
func Test_window_quit() func Test_window_quit()
e Xa e Xa
split Xb split Xb
call assert_equal(2, winnr('$')) call assert_equal(2, '$'->winnr())
call assert_equal('Xb', bufname(winbufnr(1))) call assert_equal('Xb', bufname(winbufnr(1)))
call assert_equal('Xa', bufname(winbufnr(2))) call assert_equal('Xa', bufname(winbufnr(2)))
@@ -88,7 +88,7 @@ func Test_window_horizontal_split()
3wincmd s 3wincmd s
call assert_equal(2, winnr('$')) call assert_equal(2, winnr('$'))
call assert_equal(3, winheight(0)) call assert_equal(3, winheight(0))
call assert_equal(winwidth(1), winwidth(2)) call assert_equal(winwidth(1), 2->winwidth())
call assert_fails('botright topleft wincmd s', 'E442:') call assert_fails('botright topleft wincmd s', 'E442:')
bw bw
@@ -267,7 +267,7 @@ func Test_window_height()
wincmd + wincmd +
call assert_equal(wh1, winheight(1)) call assert_equal(wh1, winheight(1))
call assert_equal(wh2, winheight(2)) call assert_equal(wh2, 2->winheight())
2wincmd _ 2wincmd _
call assert_equal(2, winheight(1)) call assert_equal(2, winheight(1))
@@ -824,6 +824,18 @@ func Test_winnr()
only | tabonly only | tabonly
endfunc endfunc
func Test_winrestview()
split runtest.vim
normal 50%
let view = winsaveview()
close
split runtest.vim
eval view->winrestview()
call assert_equal(view, winsaveview())
bwipe!
endfunc
func Test_win_splitmove() func Test_win_splitmove()
edit a edit a
leftabove split b leftabove split b

View File

@@ -67,7 +67,7 @@ func Test_win_getid()
call win_gotoid(id2) call win_gotoid(id2)
call assert_equal("two", expand("%")) call assert_equal("two", expand("%"))
call win_gotoid(id4) eval id4->win_gotoid()
call assert_equal("four", expand("%")) call assert_equal("four", expand("%"))
call win_gotoid(id1) call win_gotoid(id1)
call assert_equal("one", expand("%")) call assert_equal("one", expand("%"))
@@ -75,17 +75,17 @@ func Test_win_getid()
call assert_equal("five", expand("%")) call assert_equal("five", expand("%"))
call assert_equal(0, win_id2win(9999)) call assert_equal(0, win_id2win(9999))
call assert_equal(nr5, win_id2win(id5)) call assert_equal(nr5, id5->win_id2win())
call assert_equal(0, win_id2win(id1)) call assert_equal(0, win_id2win(id1))
tabnext tabnext
call assert_equal(nr1, win_id2win(id1)) call assert_equal(nr1, win_id2win(id1))
call assert_equal([0, 0], win_id2tabwin(9999)) call assert_equal([0, 0], win_id2tabwin(9999))
call assert_equal([1, nr2], win_id2tabwin(id2)) call assert_equal([1, nr2], id2->win_id2tabwin())
call assert_equal([2, nr4], win_id2tabwin(id4)) call assert_equal([2, nr4], win_id2tabwin(id4))
call assert_equal([], win_findbuf(9999)) call assert_equal([], win_findbuf(9999))
call assert_equal([id2], win_findbuf(bufnr2)) call assert_equal([id2], bufnr2->win_findbuf())
call win_gotoid(id5) call win_gotoid(id5)
split split
call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5))) call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
@@ -98,7 +98,7 @@ func Test_win_getid_curtab()
tabfirst tabfirst
copen copen
only only
call assert_equal(win_getid(1), win_getid(1, 1)) call assert_equal(win_getid(1), 1->win_getid( 1))
tabclose! tabclose!
endfunc endfunc
@@ -120,4 +120,11 @@ func Test_winlayout()
call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout()) call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout())
only! only!
let w1 = win_getid()
call assert_equal(['leaf', w1], winlayout(1))
tabnew
let w2 = win_getid()
call assert_equal(['leaf', w2], 2->winlayout())
tabclose
endfunc endfunc