diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-08-31 22:51:29 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-10-03 20:06:32 +0100 |
commit | 59c8a1fd5158886cb13b56070ebf15259d12eba2 (patch) | |
tree | 9f38ebf07476c8d4f3e9baa5801ed787ff197a04 | |
parent | 8b7615c735325245cff20907fbd7e0470a0d00d0 (diff) | |
download | rneovim-59c8a1fd5158886cb13b56070ebf15259d12eba2.tar.gz rneovim-59c8a1fd5158886cb13b56070ebf15259d12eba2.tar.bz2 rneovim-59c8a1fd5158886cb13b56070ebf15259d12eba2.zip |
feat(eval/method): partially port v8.1.1953
Adds method call support for all functions in the patch, but it cannot
be fully ported due to missing tests for:
- index(): requires Blobs from v8.1.0735.
Note that index() was already added as a method in v8.1.1803;
this patch only adds a test.
- iconv(): requires v8.1.1136 for test_termcodes.vim.
Nvim deprecated inputdialog(), so it no longer has an eval.txt entry.
Keep the test for hlexists() commented-out, just like previously. (Nvim
always defines the Number group, so it always returns 1 instead)
Cannot include both changes to test_syn_attr.vim as Nvim doesn't support
":hi term=..."; however, both test the same ->hlID() syntax anyway.
-rw-r--r-- | runtime/doc/eval.txt | 47 | ||||
-rw-r--r-- | src/nvim/eval.lua | 36 | ||||
-rw-r--r-- | src/nvim/testdir/test_breakindent.vim | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 25 | ||||
-rw-r--r-- | src/nvim/testdir/test_getcwd.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_history.vim | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_listdict.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_syn_attr.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_true_false.vim | 2 | ||||
-rw-r--r-- | test/functional/legacy/delete_spec.lua | 2 |
10 files changed, 99 insertions, 33 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index ffc6221818..f998c5750a 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -5763,6 +5763,9 @@ haslocaldir([{winnr}[, {tabnr}]]) *haslocaldir()* {winnr} can be the window number or the |window-ID|. If {winnr} is -1 it is ignored, only the tab is resolved. + Can also be used as a |method|: > + GetWinnr()->haslocaldir() + hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* The result is a Number, which is TRUE if there is a mapping that contains {what} in somewhere in the rhs (what it is @@ -5792,6 +5795,9 @@ hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* < This installs the mapping to "\ABCdoit" only if there isn't already a mapping to "\ABCdoit". + Can also be used as a |method|: > + GetRHS()->hasmapto() + histadd({history}, {item}) *histadd()* Add the String {item} to the history {history} which can be one of: *hist-names* @@ -5813,6 +5819,10 @@ histadd({history}, {item}) *histadd()* :let date=input("Enter date: ") < This function is not available in the |sandbox|. + Can also be used as a |method|, the base is used for the + second argument: > + GetPattern()->histadd('search') + histdel({history} [, {item}]) *histdel()* Clear {history}, i.e. delete all its entries. See |hist-names| for the possible values of {history}. @@ -5844,6 +5854,9 @@ histdel({history} [, {item}]) *histdel()* the "n" command and 'hlsearch': > :call histdel("search", -1) :let @/ = histget("search", -1) +< + Can also be used as a |method|: > + GetHistory()->histdel() histget({history} [, {index}]) *histget()* The result is a String, the entry with Number {index} from @@ -5860,6 +5873,9 @@ histget({history} [, {index}]) *histget()* the {num}th entry from the output of |:history|. > :command -nargs=1 H execute histget("cmd", 0+<args>) < + Can also be used as a |method|: > + GetHistory()->histget() + histnr({history}) *histnr()* The result is the Number of the current entry in {history}. See |hist-names| for the possible values of {history}. @@ -5867,6 +5883,9 @@ histnr({history}) *histnr()* Example: > :let inp_index = histnr("expr") + +< Can also be used as a |method|: > + GetHistory()->histnr() < hlexists({name}) *hlexists()* The result is a Number, which is TRUE if a highlight group @@ -5875,6 +5894,9 @@ hlexists({name}) *hlexists()* been defined for it, it may also have been used for a syntax item. + Can also be used as a |method|: > + GetName()->hlexists() +< *hlID()* hlID({name}) The result is a Number, which is the ID of the highlight group with name {name}. When the highlight group doesn't exist, @@ -5883,6 +5905,9 @@ hlID({name}) The result is a Number, which is the ID of the highlight group group. For example, to get the background color of the "Comment" group: > :echo synIDattr(synIDtrans(hlID("Comment")), "bg") +< + Can also be used as a |method|: > + GetName()->hlID() hostname() *hostname()* The result is a String, which is the name of the machine on @@ -5901,6 +5926,9 @@ iconv({string}, {from}, {to}) *iconv()* from/to UCS-2 is automatically changed to use UTF-8. You cannot use UCS-2 in a string anyway, because of the NUL bytes. + Can also be used as a |method|: > + GetText()->iconv('latin1', 'utf-8') +< *indent()* indent({lnum}) The result is a Number, which is indent of line {lnum} in the current buffer. The indent is counted in spaces, the value @@ -5908,6 +5936,8 @@ indent({lnum}) The result is a Number, which is indent of line {lnum} in the |getline()|. When {lnum} is invalid -1 is returned. + Can also be used as a |method|: > + GetLnum()->indent() index({object}, {expr} [, {start} [, {ic}]]) *index()* If {object} is a |List| return the lowest index where the item @@ -5928,6 +5958,8 @@ index({object}, {expr} [, {start} [, {ic}]]) *index()* :let idx = index(words, "the") :if index(numbers, 123) >= 0 +< Can also be used as a |method|: > + GetObject()->index(what) input({prompt} [, {text} [, {completion}]]) *input()* input({opts}) @@ -6040,6 +6072,9 @@ input({opts}) : call inputrestore() :endfunction +< Can also be used as a |method|: > + GetPrompt()->input() + inputlist({textlist}) *inputlist()* {textlist} must be a |List| of strings. This |List| is displayed, one string per line. The user will be prompted to @@ -6057,6 +6092,9 @@ inputlist({textlist}) *inputlist()* let color = inputlist(['Select color:', '1. red', \ '2. green', '3. blue']) +< Can also be used as a |method|: > + GetChoices()->inputlist() + inputrestore() *inputrestore()* Restore typeahead that was saved with a previous |inputsave()|. Should be called the same number of times inputsave() is @@ -6082,6 +6120,9 @@ inputsecret({prompt} [, {text}]) *inputsecret()* typed on the command-line in response to the issued prompt. NOTE: Command-line completion is not supported. + Can also be used as a |method|: > + GetPrompt()->inputsecret() + insert({object}, {item} [, {idx}]) *insert()* When {object} is a |List| or a |Blob| insert {item} at the start of it. @@ -6128,6 +6169,9 @@ isdirectory({directory}) *isdirectory()* exist, or isn't a directory, the result is |FALSE|. {directory} is any expression, which is used as a String. + Can also be used as a |method|: > + GetName()->isdirectory() + isinf({expr}) *isinf()* Return 1 if {expr} is a positive infinity, or -1 a negative infinity, otherwise 0. > @@ -6153,6 +6197,9 @@ islocked({expr}) *islocked()* *E786* < When {expr} is a variable that does not exist you get an error message. Use |exists()| to check for existence. + Can also be used as a |method|: > + GetName()->islocked() + id({expr}) *id()* Returns a |String| which is a unique identifier of the container type (|List|, |Dict|, |Blob| and |Partial|). It is diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index cc38a0734e..f600b4ce06 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -183,32 +183,32 @@ return { globpath={args={2, 5}, base=2}, has={args=1}, has_key={args=2, base=1}, - haslocaldir={args={0,2}}, - hasmapto={args={1, 3}}, - highlightID={args=1, func='f_hlID'}, -- obsolete - highlight_exists={args=1, func='f_hlexists'}, -- obsolete - histadd={args=2}, - histdel={args={1, 2}}, - histget={args={1, 2}}, - histnr={args=1}, - hlID={args=1}, - hlexists={args=1}, + haslocaldir={args={0, 2}, base=1}, + hasmapto={args={1, 3}, base=1}, + highlightID={args=1, base=1, func='f_hlID'}, -- obsolete + highlight_exists={args=1, base=1, func='f_hlexists'}, -- obsolete + histadd={args=2, base=2}, + histdel={args={1, 2}, base=1}, + histget={args={1, 2}, base=1}, + histnr={args=1, base=1}, + hlID={args=1, base=1}, + hlexists={args=1, base=1}, hostname={}, - iconv={args=3}, - indent={args=1}, + iconv={args=3, base=1}, + indent={args=1, base=1}, index={args={2, 4}, base=1}, - input={args={1, 3}}, - inputdialog={args={1, 3}}, - inputlist={args=1}, + input={args={1, 3}, base=1}, + inputdialog={args={1, 3}, base=1}, + inputlist={args=1, base=1}, inputrestore={}, inputsave={}, - inputsecret={args={1, 2}}, + inputsecret={args={1, 2}, base=1}, insert={args={2, 3}, base=1}, interrupt={args=0}, invert={args=1, base=1}, - isdirectory={args=1}, + isdirectory={args=1, base=1}, isinf={args=1, base=1}, - islocked={args=1}, + islocked={args=1, base=1}, isnan={args=1, base=1}, id={args=1}, items={args=1, base=1}, diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index 97b570e64f..277050876e 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -418,8 +418,8 @@ endfunc func Test_breakindent11() " test strdisplaywidth() call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4') - let text=getline(2) - let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times + let text = getline(2) + let width = strlen(text[1:]) + indent(2) + strlen(&sbr) * 3 " text wraps 3 times call assert_equal(width, strdisplaywidth(text)) call s:close_windows('set sbr=') endfunc @@ -431,7 +431,7 @@ func Test_breakindent11_vartabs() " test strdisplaywidth() call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4') let text = getline(2) - let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times + let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times call assert_equal(width, strdisplaywidth(text)) call s:close_windows('set sbr= vts&') endfunc diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index e3a80be6d5..90732549de 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1127,7 +1127,7 @@ endfunc func Test_hlexists() call assert_equal(0, hlexists('does_not_exist')) - " call assert_equal(0, hlexists('Number')) + " call assert_equal(0, 'Number'->hlexists()) call assert_equal(0, highlight_exists('does_not_exist')) " call assert_equal(0, highlight_exists('Number')) syntax on @@ -1160,7 +1160,7 @@ endfunc func Test_inputlist() call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx') call assert_equal(1, c) - call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>2\<cr>", 'tx') + call feedkeys(":let c = ['Select color:', '1. red', '2. green', '3. blue']->inputlist()\<cr>2\<cr>", 'tx') call assert_equal(2, c) call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx') call assert_equal(3, c) @@ -1413,7 +1413,7 @@ func Test_reg_executing_and_recording() let g:regs = [] func TestFunc() abort let g:regs += [reg_executing()] - let g:typed = input('?') + let g:typed = '?'->input() let g:regs += [reg_executing()] endfunc call feedkeys("@qy\<CR>", 'xt') @@ -1429,6 +1429,25 @@ func Test_reg_executing_and_recording() unlet s:reg_stat endfunc +func Test_inputsecret() + map W :call TestFunc()<CR> + let @q = "W" + let g:typed1 = '' + let g:typed2 = '' + let g:regs = [] + func TestFunc() abort + let g:typed1 = '?'->inputsecret() + let g:typed2 = inputsecret('password: ') + endfunc + call feedkeys("@qsomething\<CR>else\<CR>", 'xt') + call assert_equal("something", g:typed1) + call assert_equal("else", g:typed2) + delfunc TestFunc + unmap W + unlet g:typed1 + unlet g:typed2 +endfunc + func Test_getchar() call feedkeys('a', '') call assert_equal(char2nr('a'), getchar()) diff --git a/src/nvim/testdir/test_getcwd.vim b/src/nvim/testdir/test_getcwd.vim index ca098781e4..b9343b1daa 100644 --- a/src/nvim/testdir/test_getcwd.vim +++ b/src/nvim/testdir/test_getcwd.vim @@ -17,7 +17,7 @@ func GetCwdInfo(win, tab) let lflag = haslocaldir(a:win) else let dirname = fnamemodify(getcwd(a:win, a:tab), mod) - let lflag = haslocaldir(a:win, a:tab) + let lflag = a:win->haslocaldir(a:tab) endif return bufname . ' ' . dirname . ' ' . lflag endfunc diff --git a/src/nvim/testdir/test_history.vim b/src/nvim/testdir/test_history.vim index 16aad9889e..2f0dc2dae1 100644 --- a/src/nvim/testdir/test_history.vim +++ b/src/nvim/testdir/test_history.vim @@ -13,7 +13,7 @@ function History_Tests(hist) call assert_equal(-1, histnr(a:hist)) call assert_equal('', histget(a:hist)) - call assert_true(histadd(a:hist, 'ls')) + call assert_true('ls'->histadd(a:hist)) call assert_true(histadd(a:hist, 'buffers')) call assert_equal('buffers', histget(a:hist)) call assert_equal('ls', histget(a:hist, -2)) @@ -22,14 +22,14 @@ function History_Tests(hist) call assert_equal('', histget(a:hist, -5)) call assert_equal(2, histnr(a:hist)) call assert_true(histdel(a:hist, 2)) - call assert_false(histdel(a:hist, 7)) + call assert_false(a:hist->histdel(7)) call assert_equal(1, histnr(a:hist)) call assert_equal('ls', histget(a:hist, -1)) call assert_true(histadd(a:hist, 'buffers')) call assert_true(histadd(a:hist, 'ls')) - call assert_equal('ls', histget(a:hist, -1)) - call assert_equal(4, histnr(a:hist)) + call assert_equal('ls', a:hist->histget(-1)) + call assert_equal(4, a:hist->histnr()) let a=execute('history ' . a:hist) call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a) diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index ae035fa519..f6c404d390 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -573,7 +573,7 @@ func Test_lockvar_script_autoload() set rtp+=./sautest lockvar g:footest#x unlockvar g:footest#x - call assert_equal(-1, islocked('g:footest#x')) + call assert_equal(-1, 'g:footest#x'->islocked()) call assert_equal(0, exists('g:footest#x')) call assert_equal(1, g:footest#x) let &rtp = old_rtp diff --git a/src/nvim/testdir/test_syn_attr.vim b/src/nvim/testdir/test_syn_attr.vim index 353054fec8..fa0b08fde5 100644 --- a/src/nvim/testdir/test_syn_attr.vim +++ b/src/nvim/testdir/test_syn_attr.vim @@ -8,7 +8,7 @@ func Test_missing_attr() call assert_equal('1', synIDattr(hlID("Mine"), "inverse", 'cterm')) hi Mine cterm=standout gui=undercurl call assert_equal('1', synIDattr(hlID("Mine"), "standout", 'cterm')) - call assert_equal('1', synIDattr(hlID("Mine"), "undercurl", 'gui')) + call assert_equal('1', synIDattr("Mine"->hlID(), "undercurl", 'gui')) hi Mine gui=strikethrough call assert_equal('1', synIDattr(hlID("Mine"), "strikethrough", 'gui')) hi Mine cterm=NONE gui=NONE diff --git a/src/nvim/testdir/test_true_false.vim b/src/nvim/testdir/test_true_false.vim index 315ba188cb..f3c7fff4a6 100644 --- a/src/nvim/testdir/test_true_false.vim +++ b/src/nvim/testdir/test_true_false.vim @@ -104,7 +104,7 @@ func Test_true_false_arg() call Try_arg_true_false('maparg("asdf", "i", %v%)', "", "asdff") call Try_arg_true_false('FilterMapArg(maparg("asdf", "i", 1, %v%))', "asdff", {'rhs': 'asdff'}) - call Try_arg_true_false('hasmapto("asdf", "i", %v%)', 0, 1) + call Try_arg_true_false('"asdf"->hasmapto("i", %v%)', 0, 1) new colored call setline(1, '<here>') diff --git a/test/functional/legacy/delete_spec.lua b/test/functional/legacy/delete_spec.lua index b4ed8ff136..141d9583e6 100644 --- a/test/functional/legacy/delete_spec.lua +++ b/test/functional/legacy/delete_spec.lua @@ -39,7 +39,7 @@ describe('Test for delete()', function() eq(eval("['a', 'b']"), eval("readfile('Xdir1/Xfile')")) eq(1, eval("isdirectory('Xdir1/subdir')")) eq(eval("['a', 'b']"), eval("readfile('Xdir1/subdir/Xfile')")) - eq(1, eval("isdirectory('Xdir1/empty')")) + eq(1, eval("'Xdir1/empty'->isdirectory()")) eq(0, eval("delete('Xdir1', 'rf')")) eq(0, eval("isdirectory('Xdir1')")) eq(-1, eval("delete('Xdir1', 'd')")) |