diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-08-07 17:53:43 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-08-12 22:35:24 +0100 |
commit | 7925f0b6330c18c9391d02f844cd17b41fbb3d2e (patch) | |
tree | 17519697c8de6e7a8c0154c9a16333c282f219da | |
parent | 5fbc1a49c719c0c93fa73277ac30d17f797d096d (diff) | |
download | rneovim-7925f0b6330c18c9391d02f844cd17b41fbb3d2e.tar.gz rneovim-7925f0b6330c18c9391d02f844cd17b41fbb3d2e.tar.bz2 rneovim-7925f0b6330c18c9391d02f844cd17b41fbb3d2e.zip |
vim-patch:8.1.1909: more functions can be used as methods
Problem: More functions can be used as methods.
Solution: Make a few more functions usable as a method.
https://github.com/vim/vim/commit/e49fbff384e45dd17fed72321c26937edf6de16b
-rw-r--r-- | runtime/doc/eval.txt | 17 | ||||
-rw-r--r-- | runtime/doc/testing.txt | 8 | ||||
-rw-r--r-- | src/nvim/eval.lua | 10 | ||||
-rw-r--r-- | src/nvim/testdir/test_assert.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_bufline.vim | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_bufwintabinfo.vim | 2 | ||||
-rw-r--r-- | test/functional/legacy/assert_spec.lua | 7 |
7 files changed, 37 insertions, 15 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 511d072366..5754742c6d 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2929,18 +2929,22 @@ bufwinid({expr}) *bufwinid()* < Only deals with the current tab page. + Can also be used as a |method|: > + FindBuffer()->bufwinid() + bufwinnr({expr}) *bufwinnr()* - The result is a Number, which is the number of the first - window associated with buffer {expr}. For the use of {expr}, - see |bufname()| above. If buffer {expr} doesn't exist or - there is no such window, -1 is returned. Example: > + Like |bufwinid()| but return the window number instead of the + |window-ID|. + If buffer {expr} doesn't exist or there is no such window, -1 + is returned. Example: > echo "A window containing buffer 1 is " . (bufwinnr(1)) < The number can be used with |CTRL-W_w| and ":wincmd w" |:wincmd|. - Only deals with the current tab page. + Can also be used as a |method|: > + FindBuffer()->bufwinnr() byte2line({byte}) *byte2line()* Return the line number that contains the character at byte @@ -9619,6 +9623,9 @@ winbufnr({nr}) The result is a Number, which is the number of the buffer Example: > :echo "The file in the current window is " . bufname(winbufnr(0)) < + Can also be used as a |method|: > + FindWindow()->winbufnr()->bufname() +< *wincol()* wincol() The result is a Number, which is the virtual column of the cursor in the window. This is counting screen cells from the diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt index fc841dfc9c..3b59dfa908 100644 --- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -83,6 +83,9 @@ assert_equalfile({fname-one}, {fname-two}) When {fname-one} or {fname-two} does not exist the error will mention that. + Can also be used as a |method|: > + GetLog()->assert_equalfile('expected.log') + assert_exception({error} [, {msg}]) *assert_exception()* When v:exception does not contain the string {error} an error message is added to |v:errors|. Also see |assert-return|. @@ -172,10 +175,15 @@ assert_notmatch({pattern}, {actual} [, {msg}]) Can also be used as a |method|: > getFile()->assert_notmatch('bar.*') + assert_report({msg}) *assert_report()* Report a test failure directly, using {msg}. Always returns one. + Can also be used as a |method|: > + GetMessage()->assert_report() + + assert_true({actual} [, {msg}]) *assert_true()* When {actual} is not true an error message is added to |v:errors|, like with |assert_equal()|. diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 6f8645c806..722f413d82 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -35,7 +35,7 @@ return { asin={args=1, base=1, func="float_op_wrapper", data="&asin"}, -- WJMc assert_beeps={args={1}, base=1}, assert_equal={args={2, 3}, base=2}, - assert_equalfile={args={2, 3}}, + assert_equalfile={args={2, 3}, base=1}, assert_exception={args={1, 2}}, assert_fails={args={1, 3}, base=1}, assert_false={args={1, 2}, base=1}, @@ -44,7 +44,7 @@ return { assert_nobeep={args={1}}, assert_notequal={args={2, 3}, base=2}, assert_notmatch={args={2, 3}, base=2}, - assert_report={args=1}, + assert_report={args=1, base=1}, assert_true={args={1, 2}, base=1}, atan={args=1, base=1, func="float_op_wrapper", data="&atan"}, atan2={args=2, base=1}, @@ -60,8 +60,8 @@ return { bufloaded={args=1, base=1}, bufname={args={0, 1}, base=1}, bufnr={args={0, 2}, base=1}, - bufwinid={args=1}, - bufwinnr={args=1}, + bufwinid={args=1, base=1}, + bufwinnr={args=1, base=1}, byte2line={args=1}, byteidx={args=2}, byteidxcomp={args=2}, @@ -408,7 +408,7 @@ return { win_id2win={args=1}, win_screenpos={args=1}, win_splitmove={args={2, 3}}, - winbufnr={args=1}, + winbufnr={args=1, base=1}, wincol={}, windowsversion={}, winheight={args=1}, diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim index 1d114221dc..52f243aaea 100644 --- a/src/nvim/testdir/test_assert.vim +++ b/src/nvim/testdir/test_assert.vim @@ -7,7 +7,7 @@ func Test_assert_equalfile() let goodtext = ["one", "two", "three"] call writefile(goodtext, 'Xone') - call assert_equal(1, assert_equalfile('Xone', 'xyzxyz')) + call assert_equal(1, 'Xone'->assert_equalfile('xyzxyz')) call assert_match("E485: Can't read file xyzxyz", v:errors[0]) call remove(v:errors, 0) diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index e038bce08e..2a8c6915e2 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -131,11 +131,11 @@ func Test_appendbufline_redraw() endif let lines =<< trim END new foo - let winnr=bufwinnr('foo') - let buf=bufnr('foo') + let winnr = 'foo'->bufwinnr() + let buf = bufnr('foo') wincmd p call appendbufline(buf, '$', range(1,200)) - exe winnr. 'wincmd w' + exe winnr .. 'wincmd w' norm! G wincmd p call deletebufline(buf, 1, '$') diff --git a/src/nvim/testdir/test_bufwintabinfo.vim b/src/nvim/testdir/test_bufwintabinfo.vim index cb7ab44798..4b5b55e6bf 100644 --- a/src/nvim/testdir/test_bufwintabinfo.vim +++ b/src/nvim/testdir/test_bufwintabinfo.vim @@ -18,7 +18,7 @@ function Test_getbufwintabinfo() let l = getbufinfo('%') call assert_equal(bufnr('%'), l[0].bufnr) call assert_equal('vim', l[0].variables.editor) - call assert_notequal(-1, index(l[0].windows, bufwinid('%'))) + call assert_notequal(-1, index(l[0].windows, '%'->bufwinid())) " Test for getbufinfo() with 'bufmodified' call assert_equal(0, len(getbufinfo({'bufmodified' : 1}))) diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua index 40050f6ce8..c2b22472bf 100644 --- a/test/functional/legacy/assert_spec.lua +++ b/test/functional/legacy/assert_spec.lua @@ -360,6 +360,13 @@ describe('assert function:', function() command('call remove(v:errors, 0)') expected_empty() end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(1, 'also wrong'->assert_report()) + ]] + expected_errors({tmpname .. ' line 1: also wrong'}) + end) end) -- assert_exception({cmd}, [, {error}]) |