diff options
263 files changed, 7687 insertions, 7555 deletions
diff --git a/contrib/flake.nix b/contrib/flake.nix index 57e56d0fdb..51c2014d6c 100644 --- a/contrib/flake.nix +++ b/contrib/flake.nix @@ -134,7 +134,6 @@ buildInputs = with pkgs; oa.buildInputs ++ [ - cmake lua.pkgs.luacheck sumneko-lua-language-server pythonEnv @@ -142,6 +141,10 @@ jq # jq for scripts/vim-patch.sh -r shellcheck # for `make shlint` doxygen # for script/gen_vimdoc.py + ]; + + nativeBuildInputs = with pkgs; + oa.nativeBuildInputs ++ [ clang-tools # for clangd to find the correct headers ]; diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim index fb551ac675..811a9501fe 100644 --- a/runtime/autoload/netrw.vim +++ b/runtime/autoload/netrw.vim @@ -11477,7 +11477,7 @@ endfun " netrw#RFC2396: converts %xx into characters {{{2 fun! netrw#RFC2396(fname) " call Dfunc("netrw#RFC2396(fname<".a:fname.">)") - let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t") + let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t") " call Dret("netrw#RFC2396 ".fname) return fname endfun diff --git a/runtime/colors/blue.vim b/runtime/colors/blue.vim index 2d0e48f448..d6931e4c71 100644 --- a/runtime/colors/blue.vim +++ b/runtime/colors/blue.vim @@ -4,7 +4,7 @@ " Maintainer: Original maintainer Steven Vertigan <steven@vertigan.wattle.id.au> " Website: https://github.com/vim/colorschemes " License: Same as Vim -" Last Updated: Fri 15 Dec 2023 20:05:33 +" Last Updated: Mon 08 Jan 2024 09:42:49 AM AEDT " Generated by Colortemplate v2.2.3 @@ -81,8 +81,8 @@ hi Underlined guifg=NONE guibg=NONE gui=underline ctermfg=NONE ctermbg=NONE cter hi Label guifg=#ffd700 guibg=NONE gui=NONE cterm=NONE hi! link Terminal Normal hi! link Debug Special -hi! link diffAdded String -hi! link diffRemoved WarningMsg +hi! link Added String +hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg @@ -191,8 +191,8 @@ if s:t_Co >= 256 hi Label ctermfg=220 ctermbg=NONE cterm=NONE hi! link Terminal Normal hi! link Debug Special - hi! link diffAdded String - hi! link diffRemoved WarningMsg + hi! link Added String + hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg @@ -304,8 +304,8 @@ if s:t_Co >= 16 hi Label ctermfg=yellow ctermbg=NONE cterm=NONE hi! link Terminal Normal hi! link Debug Special - hi! link diffAdded String - hi! link diffRemoved WarningMsg + hi! link Added String + hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg @@ -416,8 +416,8 @@ if s:t_Co >= 8 hi Label ctermfg=yellow ctermbg=NONE cterm=NONE hi! link Terminal Normal hi! link Debug Special - hi! link diffAdded String - hi! link diffRemoved WarningMsg + hi! link Added String + hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg diff --git a/runtime/colors/darkblue.vim b/runtime/colors/darkblue.vim index 05b3fa4199..471b8561fb 100644 --- a/runtime/colors/darkblue.vim +++ b/runtime/colors/darkblue.vim @@ -4,7 +4,7 @@ " Maintainer: Original author Bohdan Vlasyuk <bohdan@vstu.edu.ua> " Website: https://github.com/vim/colorschemes " License: Same as Vim -" Last Updated: Fri 15 Dec 2023 20:05:37 +" Last Updated: Mon 08 Jan 2024 09:43:03 AM AEDT " Generated by Colortemplate v2.2.3 @@ -59,8 +59,8 @@ hi! link Structure Type hi! link Tag Special hi! link Typedef Type hi! link Debug Special -hi! link diffAdded String -hi! link diffRemoved WarningMsg +hi! link Added String +hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg @@ -167,8 +167,8 @@ if s:t_Co >= 256 hi! link Tag Special hi! link Typedef Type hi! link Debug Special - hi! link diffAdded String - hi! link diffRemoved WarningMsg + hi! link Added String + hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg diff --git a/runtime/colors/evening.vim b/runtime/colors/evening.vim index 01fc0d8354..1abdd8006f 100644 --- a/runtime/colors/evening.vim +++ b/runtime/colors/evening.vim @@ -4,7 +4,7 @@ " Maintainer: Original maintainer Steven Vertigan <steven@vertigan.wattle.id.au> " Website: https://github.com/vim/colorschemes " License: Same as Vim -" Last Updated: Fri 15 Dec 2023 20:05:35 +" Last Updated: Mon 08 Jan 2024 09:43:27 AM AEDT " Generated by Colortemplate v2.2.3 @@ -33,8 +33,8 @@ hi! link CursorIM Cursor hi! link LineNrAbove LineNr hi! link LineNrBelow LineNr hi! link Debug Special -hi! link diffAdded String -hi! link diffRemoved WarningMsg +hi! link Added String +hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg @@ -141,8 +141,8 @@ if s:t_Co >= 256 hi! link LineNrAbove LineNr hi! link LineNrBelow LineNr hi! link Debug Special - hi! link diffAdded String - hi! link diffRemoved WarningMsg + hi! link Added String + hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg @@ -252,8 +252,8 @@ if s:t_Co >= 16 hi! link LineNrAbove LineNr hi! link LineNrBelow LineNr hi! link Debug Special - hi! link diffAdded String - hi! link diffRemoved WarningMsg + hi! link Added String + hi! link Removed WarningMsg hi! link diffOnly WarningMsg hi! link diffNoEOL WarningMsg hi! link diffIsA WarningMsg diff --git a/runtime/colors/habamax.vim b/runtime/colors/habamax.vim index 1073ba3d93..66f40ab56a 100644 --- a/runtime/colors/habamax.vim +++ b/runtime/colors/habamax.vim @@ -4,7 +4,7 @@ " Maintainer: Maxim Kim <habamax@gmail.com> " Website: https://github.com/vim/colorschemes " License: Same as Vim -" Last Updated: Fri 15 Dec 2023 20:05:35 +" Last Updated: Mon 08 Jan 2024 09:39:53 AM AEDT " Generated by Colortemplate v2.2.3 @@ -111,8 +111,9 @@ hi Ignore guifg=NONE guibg=NONE gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE hi Debug guifg=#5f8787 guibg=NONE gui=NONE cterm=NONE hi DiffAdd guifg=#dadada guibg=#5f875f gui=NONE cterm=NONE hi DiffDelete guifg=#af875f guibg=NONE gui=NONE cterm=NONE -hi diffAdded guifg=#87af87 guibg=NONE gui=NONE cterm=NONE -hi diffRemoved guifg=#d75f5f guibg=NONE gui=NONE cterm=NONE +hi Added guifg=#87af87 guibg=NONE gui=NONE cterm=NONE +hi Changed guifg=#5f8787 guibg=NONE gui=NONE cterm=NONE +hi Removed guifg=#d75f5f guibg=NONE gui=NONE cterm=NONE hi diffSubname guifg=#af87af guibg=NONE gui=NONE cterm=NONE hi DiffText guifg=#dadada guibg=#878787 gui=NONE cterm=NONE hi DiffChange guifg=#bcbcbc guibg=#5f5f5f gui=NONE cterm=NONE @@ -204,8 +205,9 @@ if s:t_Co >= 256 hi Debug ctermfg=66 ctermbg=NONE cterm=NONE hi DiffAdd ctermfg=253 ctermbg=65 cterm=NONE hi DiffDelete ctermfg=137 ctermbg=NONE cterm=NONE - hi diffAdded ctermfg=108 ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=167 ctermbg=NONE cterm=NONE + hi Added ctermfg=108 ctermbg=NONE cterm=NONE + hi Changed ctermfg=66 ctermbg=NONE cterm=NONE + hi Removed ctermfg=167 ctermbg=NONE cterm=NONE hi diffSubname ctermfg=139 ctermbg=NONE cterm=NONE hi DiffText ctermfg=253 ctermbg=102 cterm=NONE hi DiffChange ctermfg=250 ctermbg=59 cterm=NONE @@ -282,8 +284,9 @@ if s:t_Co >= 16 hi Debug ctermfg=darkcyan ctermbg=NONE cterm=NONE hi DiffAdd ctermfg=white ctermbg=darkgreen cterm=NONE hi DiffDelete ctermfg=darkyellow ctermbg=NONE cterm=NONE - hi diffAdded ctermfg=darkgreen ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=darkred ctermbg=NONE cterm=NONE + hi Added ctermfg=darkgreen ctermbg=NONE cterm=NONE + hi Changed ctermfg=darkcyan ctermbg=NONE cterm=NONE + hi Removed ctermfg=darkred ctermbg=NONE cterm=NONE hi diffSubname ctermfg=darkmagenta ctermbg=NONE cterm=NONE hi DiffText ctermfg=white ctermbg=lightgrey cterm=NONE hi DiffChange ctermfg=white ctermbg=darkgray cterm=NONE @@ -360,8 +363,9 @@ if s:t_Co >= 8 hi Debug ctermfg=darkcyan ctermbg=NONE cterm=NONE hi DiffAdd ctermfg=white ctermbg=darkgreen cterm=NONE hi DiffDelete ctermfg=darkyellow ctermbg=NONE cterm=NONE - hi diffAdded ctermfg=darkgreen ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=darkred ctermbg=NONE cterm=NONE + hi Added ctermfg=darkgreen ctermbg=NONE cterm=NONE + hi Changed ctermfg=darkcyan ctermbg=NONE cterm=NONE + hi Removed ctermfg=darkred ctermbg=NONE cterm=NONE hi diffSubname ctermfg=darkmagenta ctermbg=NONE cterm=NONE hi DiffText ctermfg=white ctermbg=black cterm=bold,reverse hi DiffChange ctermfg=black ctermbg=white cterm=NONE diff --git a/runtime/colors/lunaperche.vim b/runtime/colors/lunaperche.vim index 3c8682737e..62538468dc 100644 --- a/runtime/colors/lunaperche.vim +++ b/runtime/colors/lunaperche.vim @@ -4,7 +4,7 @@ " Maintainer: Maxim Kim <habamax@gmail.com> " Website: https://www.github.com/vim/colorschemes " License: Vim License (see `:help license`) -" Last Updated: Fri 15 Dec 2023 20:05:37 +" Last Updated: Mon 08 Jan 2024 09:41:03 AM AEDT " Generated by Colortemplate v2.2.3 @@ -169,8 +169,9 @@ if &background ==# 'dark' hi DiffChange guifg=#c6c6c6 guibg=#5f5f5f gui=NONE cterm=NONE hi DiffText guifg=#afffff guibg=#5f8787 gui=NONE cterm=NONE hi DiffDelete guifg=#d78787 guibg=NONE gui=NONE cterm=NONE - hi diffAdded guifg=#5fd75f guibg=NONE gui=NONE cterm=NONE - hi diffRemoved guifg=#d78787 guibg=NONE gui=NONE cterm=NONE + hi Added guifg=#5fd75f guibg=NONE gui=NONE cterm=NONE + hi Changed guifg=#5fafff guibg=NONE gui=NONE cterm=NONE + hi Removed guifg=#d78787 guibg=NONE gui=NONE cterm=NONE hi diffSubname guifg=#ff87ff guibg=NONE gui=NONE cterm=NONE hi dirType guifg=#d787d7 guibg=NONE gui=NONE cterm=NONE hi dirPermissionUser guifg=#5faf5f guibg=NONE gui=NONE cterm=NONE @@ -263,8 +264,9 @@ else hi DiffChange guifg=#000000 guibg=#d0d0d0 gui=NONE cterm=NONE hi DiffText guifg=#000000 guibg=#5fd7d7 gui=NONE cterm=NONE hi DiffDelete guifg=#870000 guibg=NONE gui=NONE cterm=NONE - hi diffAdded guifg=#008700 guibg=NONE gui=NONE cterm=NONE - hi diffRemoved guifg=#d70000 guibg=NONE gui=NONE cterm=NONE + hi Added guifg=#008700 guibg=NONE gui=NONE cterm=NONE + hi Changed guifg=#005fd7 guibg=NONE gui=NONE cterm=NONE + hi Removed guifg=#d70000 guibg=NONE gui=NONE cterm=NONE hi diffSubname guifg=#af00af guibg=NONE gui=NONE cterm=NONE hi dirType guifg=#005f5f guibg=NONE gui=NONE cterm=NONE hi dirPermissionUser guifg=#af5f00 guibg=NONE gui=NONE cterm=NONE @@ -430,8 +432,9 @@ if s:t_Co >= 256 hi DiffChange ctermfg=251 ctermbg=59 cterm=NONE hi DiffText ctermfg=159 ctermbg=66 cterm=NONE hi DiffDelete ctermfg=174 ctermbg=NONE cterm=NONE - hi diffAdded ctermfg=77 ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=174 ctermbg=NONE cterm=NONE + hi Added ctermfg=77 ctermbg=NONE cterm=NONE + hi Changed ctermfg=75 ctermbg=NONE cterm=NONE + hi Removed ctermfg=174 ctermbg=NONE cterm=NONE hi diffSubname ctermfg=213 ctermbg=NONE cterm=NONE hi dirType ctermfg=176 ctermbg=NONE cterm=NONE hi dirPermissionUser ctermfg=71 ctermbg=NONE cterm=NONE @@ -515,8 +518,9 @@ if s:t_Co >= 256 hi DiffChange ctermfg=16 ctermbg=252 cterm=NONE hi DiffText ctermfg=16 ctermbg=80 cterm=NONE hi DiffDelete ctermfg=88 ctermbg=NONE cterm=NONE - hi diffAdded ctermfg=28 ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=160 ctermbg=NONE cterm=NONE + hi Added ctermfg=28 ctermbg=NONE cterm=NONE + hi Changed ctermfg=26 ctermbg=NONE cterm=NONE + hi Removed ctermfg=160 ctermbg=NONE cterm=NONE hi diffSubname ctermfg=127 ctermbg=NONE cterm=NONE hi dirType ctermfg=23 ctermbg=NONE cterm=NONE hi dirPermissionUser ctermfg=130 ctermbg=NONE cterm=NONE @@ -605,8 +609,9 @@ if s:t_Co >= 16 hi DiffChange ctermfg=white ctermbg=darkgreen cterm=NONE hi DiffText ctermfg=black ctermbg=cyan cterm=NONE hi DiffDelete ctermfg=darkred ctermbg=NONE cterm=NONE - hi diffAdded ctermfg=green ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=darkred ctermbg=NONE cterm=NONE + hi Added ctermfg=green ctermbg=NONE cterm=NONE + hi Changed ctermfg=blue ctermbg=NONE cterm=NONE + hi Removed ctermfg=darkred ctermbg=NONE cterm=NONE hi diffSubname ctermfg=magenta ctermbg=NONE cterm=NONE hi dirType ctermfg=darkmagenta ctermbg=NONE cterm=NONE hi dirPermissionUser ctermfg=darkgreen ctermbg=NONE cterm=NONE @@ -690,8 +695,9 @@ if s:t_Co >= 16 hi DiffChange ctermfg=black ctermbg=lightgray cterm=NONE hi DiffText ctermfg=black ctermbg=cyan cterm=NONE hi DiffDelete ctermfg=darkred ctermbg=NONE cterm=NONE - hi diffAdded ctermfg=darkgreen ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=red ctermbg=NONE cterm=NONE + hi Added ctermfg=darkgreen ctermbg=NONE cterm=NONE + hi Changed ctermfg=darkblue ctermbg=NONE cterm=NONE + hi Removed ctermfg=red ctermbg=NONE cterm=NONE hi diffSubname ctermfg=darkmagenta ctermbg=NONE cterm=NONE hi dirType ctermfg=darkcyan ctermbg=NONE cterm=NONE hi dirPermissionUser ctermfg=darkyellow ctermbg=NONE cterm=NONE diff --git a/runtime/colors/murphy.vim b/runtime/colors/murphy.vim index 66b994a6c7..c1612fbc0e 100644 --- a/runtime/colors/murphy.vim +++ b/runtime/colors/murphy.vim @@ -4,7 +4,7 @@ " Maintainer: Original maintainer Ron Aaron <ron@ronware.org>. " Website: https://github.com/vim/colorschemes " License: Same as Vim -" Last Updated: Fri 15 Dec 2023 20:05:38 +" Last Updated: Mon 08 Jan 2024 09:50:15 AM AEDT " Generated by Colortemplate v2.2.3 @@ -33,6 +33,7 @@ hi! link StatusLineTerm StatusLine hi! link StatusLineTermNC StatusLineNC hi! link MessageWindow Pmenu hi! link PopupNotification Todo +hi! link Added Constant hi Normal guifg=#87ff87 guibg=#000000 gui=NONE cterm=NONE hi EndOfBuffer guifg=#0000ff guibg=#000000 gui=NONE cterm=NONE hi StatusLine guifg=#ffffff guibg=#00008b gui=NONE cterm=NONE @@ -105,6 +106,7 @@ if s:t_Co >= 256 hi! link StatusLineTermNC StatusLineNC hi! link MessageWindow Pmenu hi! link PopupNotification Todo + hi! link Added Constant hi Normal ctermfg=120 ctermbg=16 cterm=NONE hi EndOfBuffer ctermfg=21 ctermbg=16 cterm=NONE hi StatusLine ctermfg=231 ctermbg=18 cterm=NONE diff --git a/runtime/colors/wildcharm.vim b/runtime/colors/wildcharm.vim index ae0489e259..c47a66d148 100644 --- a/runtime/colors/wildcharm.vim +++ b/runtime/colors/wildcharm.vim @@ -4,7 +4,7 @@ " Maintainer: Maxim Kim <habamax@gmail.com> " Website: https://github.com/vim/colorschemes " License: Same as Vim -" Last Updated: Fri 15 Dec 2023 20:05:43 +" Last Updated: Mon 08 Jan 2024 09:40:36 AM AEDT " Generated by Colortemplate v2.2.3 @@ -98,8 +98,9 @@ if &background ==# 'dark' hi DiffChange guifg=#d0d0d0 guibg=#5f5f5f gui=NONE cterm=NONE hi DiffText guifg=#afffff guibg=#5f8787 gui=NONE cterm=NONE hi DiffDelete guifg=#ffafaf guibg=#875f5f gui=NONE cterm=NONE - hi diffAdded guifg=#00af5f guibg=NONE gui=NONE cterm=NONE - hi diffRemoved guifg=#d7005f guibg=NONE gui=NONE cterm=NONE + hi Added guifg=#00af5f guibg=NONE gui=NONE cterm=NONE + hi Changed guifg=#0087d7 guibg=NONE gui=NONE cterm=NONE + hi Removed guifg=#d7005f guibg=NONE gui=NONE cterm=NONE else " Light background if (has('termguicolors') && &termguicolors) || has('gui_running') @@ -176,8 +177,9 @@ else hi DiffChange guifg=#262626 guibg=#dadada gui=NONE cterm=NONE hi DiffText guifg=#005f5f guibg=#afd7d7 gui=NONE cterm=NONE hi DiffDelete guifg=#875f5f guibg=#ffd7d7 gui=NONE cterm=NONE - hi diffAdded guifg=#008700 guibg=NONE gui=NONE cterm=NONE - hi diffRemoved guifg=#d70000 guibg=NONE gui=NONE cterm=NONE + hi Added guifg=#5faf5f guibg=NONE gui=NONE cterm=NONE + hi Changed guifg=#0087d7 guibg=NONE gui=NONE cterm=NONE + hi Removed guifg=#d70000 guibg=NONE gui=NONE cterm=NONE endif if s:t_Co >= 256 @@ -256,8 +258,9 @@ if s:t_Co >= 256 hi DiffChange ctermfg=252 ctermbg=59 cterm=NONE hi DiffText ctermfg=159 ctermbg=66 cterm=NONE hi DiffDelete ctermfg=217 ctermbg=95 cterm=NONE - hi diffAdded ctermfg=35 ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=161 ctermbg=NONE cterm=NONE + hi Added ctermfg=35 ctermbg=NONE cterm=NONE + hi Changed ctermfg=32 ctermbg=NONE cterm=NONE + hi Removed ctermfg=161 ctermbg=NONE cterm=NONE else " Light background hi Normal ctermfg=16 ctermbg=231 cterm=NONE @@ -325,8 +328,9 @@ if s:t_Co >= 256 hi DiffChange ctermfg=235 ctermbg=253 cterm=NONE hi DiffText ctermfg=23 ctermbg=152 cterm=NONE hi DiffDelete ctermfg=95 ctermbg=224 cterm=NONE - hi diffAdded ctermfg=28 ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=160 ctermbg=NONE cterm=NONE + hi Added ctermfg=71 ctermbg=NONE cterm=NONE + hi Changed ctermfg=32 ctermbg=NONE cterm=NONE + hi Removed ctermfg=160 ctermbg=NONE cterm=NONE endif unlet s:t_Co finish @@ -395,12 +399,13 @@ if s:t_Co >= 16 hi Directory ctermfg=blue ctermbg=NONE cterm=bold hi Conceal ctermfg=NONE ctermbg=NONE cterm=NONE hi Ignore ctermfg=NONE ctermbg=NONE cterm=NONE - hi DiffAdd ctermfg=black ctermbg=darkmagenta cterm=NONE + hi DiffAdd ctermfg=black ctermbg=darkgreen cterm=NONE hi DiffChange ctermfg=black ctermbg=lightgray cterm=NONE hi DiffText ctermfg=black ctermbg=cyan cterm=NONE hi DiffDelete ctermfg=black ctermbg=darkred cterm=NONE - hi diffAdded ctermfg=darkgreen ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=darkred ctermbg=NONE cterm=NONE + hi Added ctermfg=darkgreen ctermbg=NONE cterm=NONE + hi Changed ctermfg=darkblue ctermbg=NONE cterm=NONE + hi Removed ctermfg=darkred ctermbg=NONE cterm=NONE else " Light background hi Normal ctermfg=black ctermbg=white cterm=NONE @@ -464,12 +469,13 @@ if s:t_Co >= 16 hi Directory ctermfg=darkblue ctermbg=NONE cterm=bold hi Conceal ctermfg=NONE ctermbg=NONE cterm=NONE hi Ignore ctermfg=NONE ctermbg=NONE cterm=NONE - hi DiffAdd ctermfg=black ctermbg=darkmagenta cterm=NONE + hi DiffAdd ctermfg=black ctermbg=darkgreen cterm=NONE hi DiffChange ctermfg=black ctermbg=lightgray cterm=NONE hi DiffText ctermfg=black ctermbg=cyan cterm=NONE hi DiffDelete ctermfg=black ctermbg=darkred cterm=NONE - hi diffAdded ctermfg=darkgreen ctermbg=NONE cterm=NONE - hi diffRemoved ctermfg=red ctermbg=NONE cterm=NONE + hi Added ctermfg=green ctermbg=NONE cterm=NONE + hi Changed ctermfg=blue ctermbg=NONE cterm=NONE + hi Removed ctermfg=red ctermbg=NONE cterm=NONE endif unlet s:t_Co finish @@ -519,7 +525,7 @@ if s:t_Co >= 8 hi VisualNOS ctermfg=black ctermbg=darkblue cterm=NONE hi CursorLine ctermfg=NONE ctermbg=NONE cterm=underline hi CursorColumn ctermfg=black ctermbg=darkyellow cterm=NONE - hi Folded ctermfg=black ctermbg=NONE cterm=bold + hi Folded ctermfg=grey ctermbg=NONE cterm=bold hi ColorColumn ctermfg=black ctermbg=darkyellow cterm=NONE hi SpellBad ctermfg=darkred ctermbg=NONE cterm=reverse hi SpellCap ctermfg=darkcyan ctermbg=NONE cterm=reverse @@ -528,20 +534,20 @@ if s:t_Co >= 8 hi Comment ctermfg=NONE ctermbg=NONE cterm=bold hi Constant ctermfg=darkred ctermbg=NONE cterm=NONE hi String ctermfg=darkgreen ctermbg=NONE cterm=NONE - hi Identifier ctermfg=NONE ctermbg=NONE cterm=NONE - hi Statement ctermfg=darkblue ctermbg=NONE cterm=bold + hi Identifier ctermfg=darkmagenta ctermbg=NONE cterm=NONE + hi Statement ctermfg=darkblue ctermbg=NONE cterm=NONE hi Type ctermfg=darkyellow ctermbg=NONE cterm=NONE hi PreProc ctermfg=darkcyan ctermbg=NONE cterm=NONE - hi Special ctermfg=darkcyan ctermbg=NONE cterm=NONE + hi Special ctermfg=darkmagenta ctermbg=NONE cterm=NONE hi Underlined ctermfg=NONE ctermbg=NONE cterm=underline hi Title ctermfg=NONE ctermbg=NONE cterm=bold hi Directory ctermfg=darkblue ctermbg=NONE cterm=bold hi Conceal ctermfg=NONE ctermbg=NONE cterm=NONE hi Ignore ctermfg=NONE ctermbg=NONE cterm=NONE - hi DiffAdd ctermfg=black ctermbg=darkmagenta cterm=NONE - hi DiffChange ctermfg=black ctermbg=darkcyan cterm=NONE - hi DiffText ctermfg=black ctermbg=grey cterm=NONE - hi DiffDelete ctermfg=darkred ctermbg=NONE cterm=NONE + hi DiffAdd ctermfg=black ctermbg=darkgreen cterm=NONE + hi DiffChange ctermfg=black ctermbg=darkblue cterm=NONE + hi DiffText ctermfg=black ctermbg=darkmagenta cterm=NONE + hi DiffDelete ctermfg=black ctermbg=darkred cterm=NONE else " Light background hi Normal ctermfg=black ctermbg=grey cterm=NONE @@ -595,20 +601,20 @@ if s:t_Co >= 8 hi Comment ctermfg=NONE ctermbg=NONE cterm=bold hi Constant ctermfg=darkred ctermbg=NONE cterm=NONE hi String ctermfg=darkgreen ctermbg=NONE cterm=NONE - hi Identifier ctermfg=NONE ctermbg=NONE cterm=NONE - hi Statement ctermfg=darkblue ctermbg=NONE cterm=bold + hi Identifier ctermfg=darkmagenta ctermbg=NONE cterm=NONE + hi Statement ctermfg=darkblue ctermbg=NONE cterm=NONE hi Type ctermfg=darkyellow ctermbg=NONE cterm=NONE hi PreProc ctermfg=darkcyan ctermbg=NONE cterm=NONE - hi Special ctermfg=darkcyan ctermbg=NONE cterm=NONE + hi Special ctermfg=darkmagenta ctermbg=NONE cterm=NONE hi Underlined ctermfg=NONE ctermbg=NONE cterm=underline hi Title ctermfg=NONE ctermbg=NONE cterm=bold hi Directory ctermfg=darkblue ctermbg=NONE cterm=bold hi Conceal ctermfg=NONE ctermbg=NONE cterm=NONE hi Ignore ctermfg=NONE ctermbg=NONE cterm=NONE - hi DiffAdd ctermfg=black ctermbg=darkmagenta cterm=NONE - hi DiffChange ctermfg=black ctermbg=darkcyan cterm=NONE - hi DiffText ctermfg=grey ctermbg=black cterm=NONE - hi DiffDelete ctermfg=darkred ctermbg=NONE cterm=NONE + hi DiffAdd ctermfg=black ctermbg=darkgreen cterm=NONE + hi DiffChange ctermfg=black ctermbg=darkblue cterm=NONE + hi DiffText ctermfg=black ctermbg=darkmagenta cterm=NONE + hi DiffDelete ctermfg=black ctermbg=darkred cterm=NONE endif unlet s:t_Co finish @@ -709,7 +715,7 @@ endif " Color: colorlC #ff5fff 207 magenta " Color: colorDim #878787 102 grey " Color: colorMP #ff00af 199 magenta -" Color: diffAdd #5f875f 65 darkmagenta +" Color: diffAdd #5f875f 65 darkgreen " Color: diffAddFg #afffaf 157 black " Color: diffDelete #875f5f 95 darkred " Color: diffDeleteFg #ffafaf 217 black @@ -748,7 +754,7 @@ endif " Color: colorDim #626262 241 darkgrey " Color: colorSt #5f5f5f 59 darkgrey " Color: colorMP #ff00af 199 magenta -" Color: diffAdd #afd7af 151 darkmagenta +" Color: diffAdd #afd7af 151 darkgreen " Color: diffAddFg #005f00 22 black " Color: diffDelete #ffd7d7 224 darkred " Color: diffDeleteFg #875f5f 95 black diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt index ce2ec36ca3..34affb22e9 100644 --- a/runtime/doc/insert.txt +++ b/runtime/doc/insert.txt @@ -160,22 +160,22 @@ CTRL-R CTRL-O {register} *i_CTRL-R_CTRL-O* auto-indent. Does the same as pasting with the mouse |<MiddleMouse>|. When the register is linewise this will insert the text above the current line, like with `P`. - Does not replace characters! The '.' register (last inserted text) is still inserted as typed. After this command, the '.' register contains the command typed and not the text. I.e., the literals "^R^O" and not the text from the register. + Does not replace characters in |Replace-mode|! CTRL-R CTRL-P {register} *i_CTRL-R_CTRL-P* Insert the contents of a register literally and fix the indent, like |[<MiddleMouse>|. - Does not replace characters! The '.' register (last inserted text) is still inserted as typed. After this command, the '.' register contains the command typed and not the text. I.e., the literals "^R^P" and not the text from the register. + Does not replace characters in |Replace-mode|! *i_CTRL-T* CTRL-T Insert one shiftwidth of indent at the start of the current diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 84121be4d6..8cbb958e35 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -243,6 +243,10 @@ Error any erroneous construct Todo anything that needs extra attention; mostly the keywords TODO FIXME and XXX +Added added line in a diff +Changed changed line in a diff +Removed removed line in a diff + The names marked with * are the preferred groups; the others are minor groups. For the preferred groups, the "syntax.vim" file contains default highlighting. The minor groups are linked to the preferred groups, so they get the same @@ -1224,7 +1228,7 @@ To highlight KDE-reserved features, set > g:desktop_enable_kde follows g:desktop_enable_nonstd if not supplied -DIFF *diff.vim* *ft-diff-syntax* +DIFF *diff.vim* The diff highlighting normally finds translated headers. This can be slow if there are very long lines in the file. To disable translations: > @@ -1233,15 +1237,6 @@ there are very long lines in the file. To disable translations: > Also see |diff-slow|. -Since the Vim 9.1 release the diff filetype links the diffAdded, -diffRemoved and diffChanged highlighting groups to |hl-DiffAdd|, -|hl-DiffDelete| and |hl-DiffChange| by default. If you do not want this, you -can change it to the previous groups like this in your |vimrc| > - - hi link diffRemoved Special - hi link diffChanged PreProc - hi link diffAdded Identifier -< DIRCOLORS *dircolors.vim* *ft-dircolors-syntax* The dircolors utility highlighting definition has one option. It exists to diff --git a/runtime/pack/dist/opt/justify/plugin/justify.vim b/runtime/pack/dist/opt/justify/plugin/justify.vim index 4ef3bf95fa..57be790423 100644 --- a/runtime/pack/dist/opt/justify/plugin/justify.vim +++ b/runtime/pack/dist/opt/justify/plugin/justify.vim @@ -80,7 +80,7 @@ " conformant with :left, :right and :center. " " If joinspaces is set, an extra space is added after '.', '?' and '!'. -" If 'cpooptions' include 'j', extra space is only added after '.'. +" If 'cpoptions' include 'j', extra space is only added after '.'. " (This may on occasion conflict with maxspaces.) diff --git a/runtime/syntax/diff.vim b/runtime/syntax/diff.vim index b5c3f5ecbb..b0a8594def 100644 --- a/runtime/syntax/diff.vim +++ b/runtime/syntax/diff.vim @@ -378,9 +378,9 @@ hi def link diffBDiffer Constant hi def link diffIsA Constant hi def link diffNoEOL Constant hi def link diffCommon Constant -hi def link diffRemoved DiffDelete -hi def link diffChanged DiffChange -hi def link diffAdded DiffAdd +hi def link diffRemoved Removed +hi def link diffChanged Changed +hi def link diffAdded Added hi def link diffLine Statement hi def link diffSubname PreProc hi def link diffComment Comment diff --git a/runtime/syntax/help.vim b/runtime/syntax/help.vim index f1e650b2fb..fced5e7dd1 100644 --- a/runtime/syntax/help.vim +++ b/runtime/syntax/help.vim @@ -136,6 +136,10 @@ syn match helpTodo "\t[* ]Todo\t\+[a-z].*" syn match helpURL `\v<(((https?|ftp|gopher)://|(mailto|file|news):)[^' <>"]+|(www|web|w3)[a-z0-9_-]*\.[a-z0-9._-]+\.[^' <>"]+)[a-zA-Z0-9/]` +syn match helpDiffAdded "\t[* ]Added\t\+[a-z].*" +syn match helpDiffChanged "\t[* ]Changed\t\+[a-z].*" +syn match helpDiffRemoved "\t[* ]Removed\t\+[a-z].*" + " Additionally load a language-specific syntax file "help_ab.vim". let s:i = match(expand("%"), '\.\a\ax$') if s:i > 0 @@ -209,6 +213,9 @@ hi def link helpUnderlined Underlined hi def link helpError Error hi def link helpTodo Todo hi def link helpURL String +hi def link helpDiffAdded Added +hi def link helpDiffChanged Changed +hi def link helpDiffRemoved Removed let b:current_syntax = "help" diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 4b472a2fbd..3006f423dc 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3170,7 +3170,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) } else { // TODO(@brammool): multi-byte if (keytyped == (int)(uint8_t)p[-1] - || (icase && keytyped < 256 + || (icase && keytyped < 256 && keytyped >= 0 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((uint8_t)p[-1]))) { char *line = get_cursor_pos_ptr(); assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX); diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 16210fb06f..07ba1088f9 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -313,6 +313,8 @@ static const char *highlight_init_light[] = { "Normal guifg=NvimDarkGrey2 guibg=NvimLightGrey2 ctermfg=NONE ctermbg=NONE", // UI + "Added guifg=NvimDarGreen ctermfg=2", + "Changed guifg=NvimDarkCyan ctermfg=6", "ColorColumn guibg=NvimLightGrey4 cterm=reverse", "Conceal guifg=NvimLightGrey4", "CurSearch guifg=NvimLightGrey1 guibg=NvimDarkYellow ctermfg=15 ctermbg=3", @@ -341,6 +343,7 @@ static const char *highlight_init_light[] = { "RedrawDebugClear guibg=NvimLightYellow ctermfg=15 ctermbg=3", "RedrawDebugComposed guibg=NvimLightGreen ctermfg=15 ctermbg=2", "RedrawDebugRecompose guibg=NvimLightRed ctermfg=15 ctermbg=1", + "Removed guifg=NvimDarkRed ctermfg=1", "Search guifg=NvimDarkGrey1 guibg=NvimLightYellow ctermfg=15 ctermbg=3", "SignColumn guifg=NvimLightGrey4", "SpecialKey guifg=NvimLightGrey4", @@ -382,6 +385,8 @@ static const char *highlight_init_dark[] = { "Normal guifg=NvimLightGrey2 guibg=NvimDarkGrey2 ctermfg=NONE ctermbg=NONE", // UI + "Added guifg=NvimLightGreen ctermfg=10", + "Changed guifg=NvimLightCyan ctermfg=14", "ColorColumn guibg=NvimDarkGrey4 cterm=reverse", "Conceal guifg=NvimDarkGrey4", "CurSearch guifg=NvimDarkGrey1 guibg=NvimLightYellow ctermfg=0 ctermbg=11", @@ -410,6 +415,7 @@ static const char *highlight_init_dark[] = { "RedrawDebugClear guibg=NvimDarkYellow ctermfg=0 ctermbg=11", "RedrawDebugComposed guibg=NvimDarkGreen ctermfg=0 ctermbg=10", "RedrawDebugRecompose guibg=NvimDarkRed ctermfg=0 ctermbg=9", + "Removed guifg=NvimLightRed ctermfg=9", "Search guifg=NvimLightGrey1 guibg=NvimDarkYellow ctermfg=0 ctermbg=11", "SignColumn guifg=NvimDarkGrey4", "SpecialKey guifg=NvimDarkGrey4", diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 78926807e2..7c6e63a2bf 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1283,9 +1283,25 @@ int insert_reg(int regname, bool literally_arg) } else { for (size_t i = 0; i < reg->y_size; i++) { if (regname == '-') { + Direction dir = BACKWARD; + if ((State & REPLACE_FLAG) != 0) { + pos_T curpos; + u_save_cursor(); + if (u_save_cursor() == FAIL) { + return FAIL; + } + del_chars(mb_charlen(reg->y_array[0]), true); + curpos = curwin->w_cursor; + if (oneright() == FAIL) { + // hit end of line, need to put forward (after the current position) + dir = FORWARD; + } + curwin->w_cursor = curpos; + } + AppendCharToRedobuff(Ctrl_R); AppendCharToRedobuff(regname); - do_put(regname, NULL, BACKWARD, 1, PUT_CURSEND); + do_put(regname, NULL, dir, 1, PUT_CURSEND); } else { stuffescaped(reg->y_array[i], literally); } diff --git a/test/client/msgpack_rpc_stream.lua b/test/client/msgpack_rpc_stream.lua index ff054ae62b..c91c4fdc2e 100644 --- a/test/client/msgpack_rpc_stream.lua +++ b/test/client/msgpack_rpc_stream.lua @@ -1,4 +1,4 @@ -local mpack = require('mpack') +local mpack = vim.mpack -- temporary hack to be able to manipulate buffer/window/tabpage local Buffer = {} diff --git a/test/client/session.lua b/test/client/session.lua index 78909d1061..86b4ee7103 100644 --- a/test/client/session.lua +++ b/test/client/session.lua @@ -1,4 +1,4 @@ -local uv = require('luv') +local uv = vim.uv local MsgpackRpcStream = require('test.client.msgpack_rpc_stream') local Session = {} diff --git a/test/client/uv_stream.lua b/test/client/uv_stream.lua index f37a0ec3ce..9e9a69e0a1 100644 --- a/test/client/uv_stream.lua +++ b/test/client/uv_stream.lua @@ -1,4 +1,4 @@ -local uv = require('luv') +local uv = vim.uv local StdioStream = {} StdioStream.__index = StdioStream diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 1590ca2eda..e89abf6c64 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -6,7 +6,7 @@ local eq = helpers.eq local neq = helpers.neq local exec_lua = helpers.exec_lua local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local source = helpers.source local pcall_err = helpers.pcall_err @@ -17,7 +17,7 @@ describe('autocmd api', function() it('validation', function() eq( "Cannot use both 'callback' and 'command'", - pcall_err(meths.create_autocmd, 'BufReadPost', { + pcall_err(api.nvim_create_autocmd, 'BufReadPost', { pattern = '*.py,*.pyi', command = "echo 'Should Have Errored", callback = 'NotAllowed', @@ -25,7 +25,7 @@ describe('autocmd api', function() ) eq( "Cannot use both 'pattern' and 'buffer' for the same autocmd", - pcall_err(meths.create_autocmd, 'FileType', { + pcall_err(api.nvim_create_autocmd, 'FileType', { command = 'let g:called = g:called + 1', buffer = 0, pattern = '*.py', @@ -33,48 +33,48 @@ describe('autocmd api', function() ) eq( "Required: 'event'", - pcall_err(meths.create_autocmd, {}, { + pcall_err(api.nvim_create_autocmd, {}, { command = 'ls', }) ) - eq("Required: 'command' or 'callback'", pcall_err(meths.create_autocmd, 'FileType', {})) + eq("Required: 'command' or 'callback'", pcall_err(api.nvim_create_autocmd, 'FileType', {})) eq( "Invalid 'desc': expected String, got Integer", - pcall_err(meths.create_autocmd, 'FileType', { + pcall_err(api.nvim_create_autocmd, 'FileType', { command = 'ls', desc = 42, }) ) eq( "Invalid 'callback': expected Lua function or Vim function name, got Integer", - pcall_err(meths.create_autocmd, 'FileType', { + pcall_err(api.nvim_create_autocmd, 'FileType', { callback = 0, }) ) eq( "Invalid 'event' item: expected String, got Array", - pcall_err(meths.create_autocmd, { 'FileType', {} }, {}) + pcall_err(api.nvim_create_autocmd, { 'FileType', {} }, {}) ) eq( "Invalid 'group': 0", - pcall_err(meths.create_autocmd, 'FileType', { + pcall_err(api.nvim_create_autocmd, 'FileType', { group = 0, command = 'ls', }) ) - eq("Invalid 'event': 'foo'", pcall_err(meths.create_autocmd, 'foo', { command = '' })) + eq("Invalid 'event': 'foo'", pcall_err(api.nvim_create_autocmd, 'foo', { command = '' })) eq( "Invalid 'event': 'VimEnter '", - pcall_err(meths.create_autocmd, 'VimEnter ', { command = '' }) + pcall_err(api.nvim_create_autocmd, 'VimEnter ', { command = '' }) ) eq( "Invalid 'event': 'VimEnter foo'", - pcall_err(meths.create_autocmd, 'VimEnter foo', { command = '' }) + pcall_err(api.nvim_create_autocmd, 'VimEnter foo', { command = '' }) ) eq( "Invalid 'event': 'BufAdd,BufDelete'", - pcall_err(meths.create_autocmd, 'BufAdd,BufDelete', { command = '' }) + pcall_err(api.nvim_create_autocmd, 'BufAdd,BufDelete', { command = '' }) ) end) @@ -102,25 +102,25 @@ describe('autocmd api', function() end) it('allows passing buffer by key', function() - meths.set_var('called', 0) + api.nvim_set_var('called', 0) - meths.create_autocmd('FileType', { + api.nvim_create_autocmd('FileType', { command = 'let g:called = g:called + 1', buffer = 0, }) - meths.command 'set filetype=txt' - eq(1, meths.get_var('called')) + command 'set filetype=txt' + eq(1, api.nvim_get_var('called')) -- switch to a new buffer - meths.command 'new' - meths.command 'set filetype=python' + command 'new' + command 'set filetype=python' - eq(1, meths.get_var('called')) + eq(1, api.nvim_get_var('called')) end) it('does not allow passing invalid buffers', function() - local ok, msg = pcall(meths.create_autocmd, 'FileType', { + local ok, msg = pcall(api.nvim_create_autocmd, 'FileType', { command = 'let g:called = g:called + 1', buffer = -1, }) @@ -145,7 +145,7 @@ describe('autocmd api', function() end) it('allow passing pattern and <buffer> in same pattern', function() - local ok = pcall(meths.create_autocmd, 'BufReadPost', { + local ok = pcall(api.nvim_create_autocmd, 'BufReadPost', { pattern = '*.py,<buffer>', command = "echo 'Should Not Error'", }) @@ -154,42 +154,42 @@ describe('autocmd api', function() end) it('should handle multiple values as comma separated list', function() - meths.create_autocmd('BufReadPost', { + api.nvim_create_autocmd('BufReadPost', { pattern = '*.py,*.pyi', command = "echo 'Should Not Have Errored'", }) -- We should have one autocmd for *.py and one for *.pyi - eq(2, #meths.get_autocmds { event = 'BufReadPost' }) + eq(2, #api.nvim_get_autocmds { event = 'BufReadPost' }) end) it('should handle multiple values as array', function() - meths.create_autocmd('BufReadPost', { + api.nvim_create_autocmd('BufReadPost', { pattern = { '*.py', '*.pyi' }, command = "echo 'Should Not Have Errored'", }) -- We should have one autocmd for *.py and one for *.pyi - eq(2, #meths.get_autocmds { event = 'BufReadPost' }) + eq(2, #api.nvim_get_autocmds { event = 'BufReadPost' }) end) describe('desc', function() it('can add description to one autocmd', function() local cmd = "echo 'Should Not Have Errored'" local desc = 'Can show description' - meths.create_autocmd('BufReadPost', { + api.nvim_create_autocmd('BufReadPost', { pattern = '*.py', command = cmd, desc = desc, }) - eq(desc, meths.get_autocmds { event = 'BufReadPost' }[1].desc) - eq(cmd, meths.get_autocmds { event = 'BufReadPost' }[1].command) + eq(desc, api.nvim_get_autocmds { event = 'BufReadPost' }[1].desc) + eq(cmd, api.nvim_get_autocmds { event = 'BufReadPost' }[1].command) end) it('can add description to one autocmd that uses a callback', function() local desc = 'Can show description' - meths.set_var('desc', desc) + api.nvim_set_var('desc', desc) local result = exec_lua([[ local callback = function() print 'Should Not Have Errored' end @@ -218,17 +218,17 @@ describe('autocmd api', function() }) ]]) - eq(nil, meths.get_autocmds({ event = 'BufReadPost' })[1].desc) + eq(nil, api.nvim_get_autocmds({ event = 'BufReadPost' })[1].desc) end) it('can add description to multiple autocmd', function() - meths.create_autocmd('BufReadPost', { + api.nvim_create_autocmd('BufReadPost', { pattern = { '*.py', '*.pyi' }, command = "echo 'Should Not Have Errored'", desc = 'Can show description', }) - local aus = meths.get_autocmds { event = 'BufReadPost' } + local aus = api.nvim_get_autocmds { event = 'BufReadPost' } eq(2, #aus) eq('Can show description', aus[1].desc) eq('Can show description', aus[2].desc) @@ -237,19 +237,19 @@ describe('autocmd api', function() pending('script and verbose settings', function() it('marks API client', function() - meths.create_autocmd('BufReadPost', { + api.nvim_create_autocmd('BufReadPost', { pattern = '*.py', command = "echo 'Should Not Have Errored'", desc = 'Can show description', }) - local aus = meths.get_autocmds { event = 'BufReadPost' } + local aus = api.nvim_get_autocmds { event = 'BufReadPost' } eq(1, #aus, aus) end) end) it('removes an autocommand if the callback returns true', function() - meths.set_var('some_condition', false) + api.nvim_set_var('some_condition', false) exec_lua [[ vim.api.nvim_create_autocmd("User", { @@ -261,21 +261,21 @@ describe('autocmd api', function() }) ]] - meths.exec_autocmds('User', { pattern = 'Test' }) + api.nvim_exec_autocmds('User', { pattern = 'Test' }) - local aus = meths.get_autocmds({ event = 'User', pattern = 'Test' }) + local aus = api.nvim_get_autocmds({ event = 'User', pattern = 'Test' }) local first = aus[1] eq(true, first.id > 0) - meths.set_var('some_condition', true) - meths.exec_autocmds('User', { pattern = 'Test' }) - eq({}, meths.get_autocmds({ event = 'User', pattern = 'Test' })) + api.nvim_set_var('some_condition', true) + api.nvim_exec_autocmds('User', { pattern = 'Test' }) + eq({}, api.nvim_get_autocmds({ event = 'User', pattern = 'Test' })) end) it('receives an args table', function() - local group_id = meths.create_augroup('TestGroup', {}) + local group_id = api.nvim_create_augroup('TestGroup', {}) -- Having an existing autocmd calling expand("<afile>") shouldn't change args #18964 - meths.create_autocmd('User', { + api.nvim_create_autocmd('User', { group = 'TestGroup', pattern = 'Te*', command = 'call expand("<afile>")', @@ -291,7 +291,7 @@ describe('autocmd api', function() }) ]] - meths.exec_autocmds('User', { pattern = 'Test pattern' }) + api.nvim_exec_autocmds('User', { pattern = 'Test pattern' }) eq({ id = autocmd_id, group = group_id, @@ -299,7 +299,7 @@ describe('autocmd api', function() match = 'Test pattern', file = 'Test pattern', buf = 1, - }, meths.get_var('autocmd_args')) + }, api.nvim_get_var('autocmd_args')) -- Test without a group autocmd_id = exec_lua [[ @@ -311,7 +311,7 @@ describe('autocmd api', function() }) ]] - meths.exec_autocmds('User', { pattern = 'some_pat' }) + api.nvim_exec_autocmds('User', { pattern = 'some_pat' }) eq({ id = autocmd_id, group = nil, @@ -319,7 +319,7 @@ describe('autocmd api', function() match = 'some_pat', file = 'some_pat', buf = 1, - }, meths.get_var('autocmd_args')) + }, api.nvim_get_var('autocmd_args')) end) it('can receive arbitrary data', function() @@ -361,43 +361,43 @@ describe('autocmd api', function() it('validation', function() eq( "Invalid 'group': 9997999", - pcall_err(meths.get_autocmds, { + pcall_err(api.nvim_get_autocmds, { group = 9997999, }) ) eq( "Invalid 'group': 'bogus'", - pcall_err(meths.get_autocmds, { + pcall_err(api.nvim_get_autocmds, { group = 'bogus', }) ) eq( "Invalid 'group': 0", - pcall_err(meths.get_autocmds, { + pcall_err(api.nvim_get_autocmds, { group = 0, }) ) eq( "Invalid 'group': expected String or Integer, got Array", - pcall_err(meths.get_autocmds, { + pcall_err(api.nvim_get_autocmds, { group = {}, }) ) eq( "Invalid 'buffer': expected Integer or Array, got Boolean", - pcall_err(meths.get_autocmds, { + pcall_err(api.nvim_get_autocmds, { buffer = true, }) ) eq( "Invalid 'event': expected String or Array", - pcall_err(meths.get_autocmds, { + pcall_err(api.nvim_get_autocmds, { event = true, }) ) eq( "Invalid 'pattern': expected String or Array, got Boolean", - pcall_err(meths.get_autocmds, { + pcall_err(api.nvim_get_autocmds, { pattern = true, }) ) @@ -408,7 +408,7 @@ describe('autocmd api', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] - local aus = meths.get_autocmds { event = 'InsertEnter' } + local aus = api.nvim_get_autocmds { event = 'InsertEnter' } eq(1, #aus) end) @@ -417,7 +417,7 @@ describe('autocmd api', function() command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] - local aus = meths.get_autocmds { event = 'InsertEnter' } + local aus = api.nvim_get_autocmds { event = 'InsertEnter' } eq(2, #aus) end) @@ -426,8 +426,8 @@ describe('autocmd api', function() command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] - local string_aus = meths.get_autocmds { event = 'InsertEnter' } - local array_aus = meths.get_autocmds { event = { 'InsertEnter' } } + local string_aus = api.nvim_get_autocmds { event = 'InsertEnter' } + local array_aus = api.nvim_get_autocmds { event = { 'InsertEnter' } } eq(string_aus, array_aus) end) @@ -437,7 +437,7 @@ describe('autocmd api', function() command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] - local aus = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } + local aus = api.nvim_get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } eq(2, #aus) end) @@ -451,7 +451,7 @@ describe('autocmd api', function() \ }) ]] - local aus = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } + local aus = api.nvim_get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } local first = aus[1] eq(first.id, nil) @@ -459,8 +459,8 @@ describe('autocmd api', function() local second = aus[2] neq(second.id, nil) - meths.del_autocmd(second.id) - local new_aus = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } + api.nvim_del_autocmd(second.id) + local new_aus = api.nvim_get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } eq(1, #new_aus) eq(first, new_aus[1]) end) @@ -469,7 +469,7 @@ describe('autocmd api', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] - local aus = meths.get_autocmds { event = 'InsertEnter' } + local aus = api.nvim_get_autocmds { event = 'InsertEnter' } eq({ { buflocal = false, @@ -487,7 +487,7 @@ describe('autocmd api', function() command [[au InsertEnter <buffer=1> :echo "1"]] command [[au InsertEnter <buffer=2> :echo "2"]] - local aus = meths.get_autocmds { event = 'InsertEnter', buffer = 0 } + local aus = api.nvim_get_autocmds { event = 'InsertEnter', buffer = 0 } eq({ { buffer = 2, @@ -499,7 +499,7 @@ describe('autocmd api', function() }, }, aus) - aus = meths.get_autocmds { event = 'InsertEnter', buffer = 1 } + aus = api.nvim_get_autocmds { event = 'InsertEnter', buffer = 1 } eq({ { buffer = 1, @@ -511,7 +511,7 @@ describe('autocmd api', function() }, }, aus) - aus = meths.get_autocmds { event = 'InsertEnter', buffer = { 1, 2 } } + aus = api.nvim_get_autocmds { event = 'InsertEnter', buffer = { 1, 2 } } eq({ { buffer = 1, @@ -533,50 +533,50 @@ describe('autocmd api', function() eq( "Invalid 'buffer': expected Integer or Array, got String", - pcall_err(meths.get_autocmds, { event = 'InsertEnter', buffer = 'foo' }) + pcall_err(api.nvim_get_autocmds, { event = 'InsertEnter', buffer = 'foo' }) ) eq( "Invalid 'buffer': expected Integer, got String", - pcall_err(meths.get_autocmds, { event = 'InsertEnter', buffer = { 'foo', 42 } }) + pcall_err(api.nvim_get_autocmds, { event = 'InsertEnter', buffer = { 'foo', 42 } }) ) eq( 'Invalid buffer id: 42', - pcall_err(meths.get_autocmds, { event = 'InsertEnter', buffer = { 42 } }) + pcall_err(api.nvim_get_autocmds, { event = 'InsertEnter', buffer = { 42 } }) ) local bufs = {} for _ = 1, 257 do - table.insert(bufs, meths.create_buf(true, false)) + table.insert(bufs, api.nvim_create_buf(true, false)) end eq( 'Too many buffers (maximum of 256)', - pcall_err(meths.get_autocmds, { event = 'InsertEnter', buffer = bufs }) + pcall_err(api.nvim_get_autocmds, { event = 'InsertEnter', buffer = bufs }) ) end) it('returns autocmds when group is specified by id', function() - local auid = meths.create_augroup('nvim_test_augroup', { clear = true }) - meths.create_autocmd('FileType', { group = auid, command = 'echo "1"' }) - meths.create_autocmd('FileType', { group = auid, command = 'echo "2"' }) + local auid = api.nvim_create_augroup('nvim_test_augroup', { clear = true }) + api.nvim_create_autocmd('FileType', { group = auid, command = 'echo "1"' }) + api.nvim_create_autocmd('FileType', { group = auid, command = 'echo "2"' }) - local aus = meths.get_autocmds { group = auid } + local aus = api.nvim_get_autocmds { group = auid } eq(2, #aus) - local aus2 = meths.get_autocmds { group = auid, event = 'InsertEnter' } + local aus2 = api.nvim_get_autocmds { group = auid, event = 'InsertEnter' } eq(0, #aus2) end) it('returns autocmds when group is specified by name', function() local auname = 'nvim_test_augroup' - meths.create_augroup(auname, { clear = true }) - meths.create_autocmd('FileType', { group = auname, command = 'echo "1"' }) - meths.create_autocmd('FileType', { group = auname, command = 'echo "2"' }) + api.nvim_create_augroup(auname, { clear = true }) + api.nvim_create_autocmd('FileType', { group = auname, command = 'echo "1"' }) + api.nvim_create_autocmd('FileType', { group = auname, command = 'echo "2"' }) - local aus = meths.get_autocmds { group = auname } + local aus = api.nvim_get_autocmds { group = auname } eq(2, #aus) - local aus2 = meths.get_autocmds { group = auname, event = 'InsertEnter' } + local aus2 = api.nvim_get_autocmds { group = auname, event = 'InsertEnter' } eq(0, #aus2) end) @@ -609,7 +609,7 @@ describe('autocmd api', function() it('can retrieve a callback from an autocmd', function() local content = 'I Am A Callback' - meths.set_var('content', content) + api.nvim_set_var('content', content) local result = exec_lua([[ local cb = function() return vim.g.content end @@ -671,7 +671,7 @@ describe('autocmd api', function() end) it('returns all groups if no group is specified', function() - local aus = meths.get_autocmds { event = 'InsertEnter' } + local aus = api.nvim_get_autocmds { event = 'InsertEnter' } if #aus ~= 4 then eq({}, aus) end @@ -680,7 +680,7 @@ describe('autocmd api', function() end) it('returns only the group specified', function() - local aus = meths.get_autocmds { + local aus = api.nvim_get_autocmds { event = 'InsertEnter', group = 'GroupOne', } @@ -691,7 +691,7 @@ describe('autocmd api', function() end) it('returns only the group specified, multiple values', function() - local aus = meths.get_autocmds { + local aus = api.nvim_get_autocmds { event = 'InsertEnter', group = 'GroupTwo', } @@ -706,7 +706,7 @@ describe('autocmd api', function() describe('groups: 2', function() it('raises error for undefined augroup name', function() - local success, code = unpack(meths.exec_lua( + local success, code = unpack(api.nvim_exec_lua( [[ return {pcall(function() vim.api.nvim_create_autocmd("FileType", { @@ -724,7 +724,7 @@ describe('autocmd api', function() end) it('raises error for undefined augroup id', function() - local success, code = unpack(meths.exec_lua( + local success, code = unpack(api.nvim_exec_lua( [[ return {pcall(function() -- Make sure the augroup is deleted @@ -745,7 +745,7 @@ describe('autocmd api', function() end) it('raises error for invalid group type', function() - local success, code = unpack(meths.exec_lua( + local success, code = unpack(api.nvim_exec_lua( [[ return {pcall(function() vim.api.nvim_create_autocmd("FileType", { @@ -763,7 +763,7 @@ describe('autocmd api', function() end) it('raises error for invalid pattern array', function() - local success, code = unpack(meths.exec_lua( + local success, code = unpack(api.nvim_exec_lua( [[ return {pcall(function() vim.api.nvim_create_autocmd("FileType", { @@ -792,7 +792,7 @@ describe('autocmd api', function() end) it('returns for literal match', function() - local aus = meths.get_autocmds { + local aus = api.nvim_get_autocmds { event = 'InsertEnter', pattern = '*', } @@ -803,7 +803,7 @@ describe('autocmd api', function() it('returns for multiple matches', function() -- vim.api.nvim_get_autocmds - local aus = meths.get_autocmds { + local aus = api.nvim_get_autocmds { event = 'InsertEnter', pattern = { '*.one', '*.two' }, } @@ -815,17 +815,17 @@ describe('autocmd api', function() end) it('should work for buffer autocmds', function() - local normalized_aus = meths.get_autocmds { + local normalized_aus = api.nvim_get_autocmds { event = 'InsertEnter', pattern = '<buffer=1>', } - local raw_aus = meths.get_autocmds { + local raw_aus = api.nvim_get_autocmds { event = 'InsertEnter', pattern = '<buffer>', } - local zero_aus = meths.get_autocmds { + local zero_aus = api.nvim_get_autocmds { event = 'InsertEnter', pattern = '<buffer=0>', } @@ -841,110 +841,110 @@ describe('autocmd api', function() it('validation', function() eq( "Invalid 'group': 9997999", - pcall_err(meths.exec_autocmds, 'FileType', { + pcall_err(api.nvim_exec_autocmds, 'FileType', { group = 9997999, }) ) eq( "Invalid 'group': 'bogus'", - pcall_err(meths.exec_autocmds, 'FileType', { + pcall_err(api.nvim_exec_autocmds, 'FileType', { group = 'bogus', }) ) eq( "Invalid 'group': expected String or Integer, got Array", - pcall_err(meths.exec_autocmds, 'FileType', { + pcall_err(api.nvim_exec_autocmds, 'FileType', { group = {}, }) ) eq( "Invalid 'group': 0", - pcall_err(meths.exec_autocmds, 'FileType', { + pcall_err(api.nvim_exec_autocmds, 'FileType', { group = 0, }) ) eq( "Invalid 'buffer': expected Buffer, got Array", - pcall_err(meths.exec_autocmds, 'FileType', { + pcall_err(api.nvim_exec_autocmds, 'FileType', { buffer = {}, }) ) eq( "Invalid 'event' item: expected String, got Array", - pcall_err(meths.exec_autocmds, { 'FileType', {} }, {}) + pcall_err(api.nvim_exec_autocmds, { 'FileType', {} }, {}) ) end) it('can trigger builtin autocmds', function() - meths.set_var('autocmd_executed', false) + api.nvim_set_var('autocmd_executed', false) - meths.create_autocmd('BufReadPost', { + api.nvim_create_autocmd('BufReadPost', { pattern = '*', command = 'let g:autocmd_executed = v:true', }) - eq(false, meths.get_var('autocmd_executed')) - meths.exec_autocmds('BufReadPost', {}) - eq(true, meths.get_var('autocmd_executed')) + eq(false, api.nvim_get_var('autocmd_executed')) + api.nvim_exec_autocmds('BufReadPost', {}) + eq(true, api.nvim_get_var('autocmd_executed')) end) it('can trigger multiple patterns', function() - meths.set_var('autocmd_executed', 0) + api.nvim_set_var('autocmd_executed', 0) - meths.create_autocmd('BufReadPost', { + api.nvim_create_autocmd('BufReadPost', { pattern = '*', command = 'let g:autocmd_executed += 1', }) - meths.exec_autocmds('BufReadPost', { pattern = { '*.lua', '*.vim' } }) - eq(2, meths.get_var('autocmd_executed')) + api.nvim_exec_autocmds('BufReadPost', { pattern = { '*.lua', '*.vim' } }) + eq(2, api.nvim_get_var('autocmd_executed')) - meths.create_autocmd('BufReadPre', { + api.nvim_create_autocmd('BufReadPre', { pattern = { 'bar', 'foo' }, command = 'let g:autocmd_executed += 10', }) - meths.exec_autocmds('BufReadPre', { pattern = { 'foo', 'bar', 'baz', 'frederick' } }) - eq(22, meths.get_var('autocmd_executed')) + api.nvim_exec_autocmds('BufReadPre', { pattern = { 'foo', 'bar', 'baz', 'frederick' } }) + eq(22, api.nvim_get_var('autocmd_executed')) end) it('can pass the buffer', function() - meths.set_var('buffer_executed', -1) - eq(-1, meths.get_var('buffer_executed')) + api.nvim_set_var('buffer_executed', -1) + eq(-1, api.nvim_get_var('buffer_executed')) - meths.create_autocmd('BufLeave', { + api.nvim_create_autocmd('BufLeave', { pattern = '*', command = 'let g:buffer_executed = +expand("<abuf>")', }) -- Doesn't execute for other non-matching events - meths.exec_autocmds('CursorHold', { buffer = 1 }) - eq(-1, meths.get_var('buffer_executed')) + api.nvim_exec_autocmds('CursorHold', { buffer = 1 }) + eq(-1, api.nvim_get_var('buffer_executed')) - meths.exec_autocmds('BufLeave', { buffer = 1 }) - eq(1, meths.get_var('buffer_executed')) + api.nvim_exec_autocmds('BufLeave', { buffer = 1 }) + eq(1, api.nvim_get_var('buffer_executed')) end) it('can pass the filename, pattern match', function() - meths.set_var('filename_executed', 'none') - eq('none', meths.get_var('filename_executed')) + api.nvim_set_var('filename_executed', 'none') + eq('none', api.nvim_get_var('filename_executed')) - meths.create_autocmd('BufEnter', { + api.nvim_create_autocmd('BufEnter', { pattern = '*.py', command = 'let g:filename_executed = expand("<afile>")', }) -- Doesn't execute for other non-matching events - meths.exec_autocmds('CursorHold', { buffer = 1 }) - eq('none', meths.get_var('filename_executed')) + api.nvim_exec_autocmds('CursorHold', { buffer = 1 }) + eq('none', api.nvim_get_var('filename_executed')) - meths.command('edit __init__.py') - eq('__init__.py', meths.get_var('filename_executed')) + command('edit __init__.py') + eq('__init__.py', api.nvim_get_var('filename_executed')) end) it('cannot pass buf and fname', function() local ok = pcall( - meths.exec_autocmds, + api.nvim_exec_autocmds, 'BufReadPre', { pattern = 'literally_cannot_error.rs', buffer = 1 } ) @@ -952,73 +952,73 @@ describe('autocmd api', function() end) it('can pass the filename, exact match', function() - meths.set_var('filename_executed', 'none') - eq('none', meths.get_var('filename_executed')) + api.nvim_set_var('filename_executed', 'none') + eq('none', api.nvim_get_var('filename_executed')) - meths.command('edit other_file.txt') - meths.command('edit __init__.py') - eq('none', meths.get_var('filename_executed')) + command('edit other_file.txt') + command('edit __init__.py') + eq('none', api.nvim_get_var('filename_executed')) - meths.create_autocmd('CursorHoldI', { + api.nvim_create_autocmd('CursorHoldI', { pattern = '__init__.py', command = 'let g:filename_executed = expand("<afile>")', }) -- Doesn't execute for other non-matching events - meths.exec_autocmds('CursorHoldI', { buffer = 1 }) - eq('none', meths.get_var('filename_executed')) + api.nvim_exec_autocmds('CursorHoldI', { buffer = 1 }) + eq('none', api.nvim_get_var('filename_executed')) - meths.exec_autocmds('CursorHoldI', { buffer = meths.get_current_buf() }) - eq('__init__.py', meths.get_var('filename_executed')) + api.nvim_exec_autocmds('CursorHoldI', { buffer = api.nvim_get_current_buf() }) + eq('__init__.py', api.nvim_get_var('filename_executed')) -- Reset filename - meths.set_var('filename_executed', 'none') + api.nvim_set_var('filename_executed', 'none') - meths.exec_autocmds('CursorHoldI', { pattern = '__init__.py' }) - eq('__init__.py', meths.get_var('filename_executed')) + api.nvim_exec_autocmds('CursorHoldI', { pattern = '__init__.py' }) + eq('__init__.py', api.nvim_get_var('filename_executed')) end) it('works with user autocmds', function() - meths.set_var('matched', 'none') + api.nvim_set_var('matched', 'none') - meths.create_autocmd('User', { + api.nvim_create_autocmd('User', { pattern = 'TestCommand', command = 'let g:matched = "matched"', }) - meths.exec_autocmds('User', { pattern = 'OtherCommand' }) - eq('none', meths.get_var('matched')) - meths.exec_autocmds('User', { pattern = 'TestCommand' }) - eq('matched', meths.get_var('matched')) + api.nvim_exec_autocmds('User', { pattern = 'OtherCommand' }) + eq('none', api.nvim_get_var('matched')) + api.nvim_exec_autocmds('User', { pattern = 'TestCommand' }) + eq('matched', api.nvim_get_var('matched')) end) it('can pass group by id', function() - meths.set_var('group_executed', false) + api.nvim_set_var('group_executed', false) - local auid = meths.create_augroup('nvim_test_augroup', { clear = true }) - meths.create_autocmd('FileType', { + local auid = api.nvim_create_augroup('nvim_test_augroup', { clear = true }) + api.nvim_create_autocmd('FileType', { group = auid, command = 'let g:group_executed = v:true', }) - eq(false, meths.get_var('group_executed')) - meths.exec_autocmds('FileType', { group = auid }) - eq(true, meths.get_var('group_executed')) + eq(false, api.nvim_get_var('group_executed')) + api.nvim_exec_autocmds('FileType', { group = auid }) + eq(true, api.nvim_get_var('group_executed')) end) it('can pass group by name', function() - meths.set_var('group_executed', false) + api.nvim_set_var('group_executed', false) local auname = 'nvim_test_augroup' - meths.create_augroup(auname, { clear = true }) - meths.create_autocmd('FileType', { + api.nvim_create_augroup(auname, { clear = true }) + api.nvim_create_autocmd('FileType', { group = auname, command = 'let g:group_executed = v:true', }) - eq(false, meths.get_var('group_executed')) - meths.exec_autocmds('FileType', { group = auname }) - eq(true, meths.get_var('group_executed')) + eq(false, api.nvim_get_var('group_executed')) + api.nvim_exec_autocmds('FileType', { group = auname }) + eq(true, api.nvim_get_var('group_executed')) end) end) @@ -1026,7 +1026,7 @@ describe('autocmd api', function() before_each(function() clear() - meths.set_var('executed', 0) + api.nvim_set_var('executed', 0) end) local make_counting_autocmd = function(opts) @@ -1040,7 +1040,7 @@ describe('autocmd api', function() resulting.group = opts.group resulting.once = opts.once - meths.create_autocmd('FileType', resulting) + api.nvim_create_autocmd('FileType', resulting) end local set_ft = function(ft) @@ -1049,12 +1049,12 @@ describe('autocmd api', function() end local get_executed_count = function() - return meths.get_var('executed') + return api.nvim_get_var('executed') end it('can be added in a group', function() local augroup = 'TestGroup' - meths.create_augroup(augroup, { clear = true }) + api.nvim_create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup } set_ft('txt') @@ -1083,7 +1083,7 @@ describe('autocmd api', function() end) it('errors on unexpected keys', function() - local success, code = pcall(meths.create_autocmd, 'FileType', { + local success, code = pcall(api.nvim_create_autocmd, 'FileType', { pattern = '*', not_a_valid_key = 'NotDefined', }) @@ -1190,8 +1190,8 @@ describe('autocmd api', function() it('groups can be cleared', function() local augroup = 'TestGroup' - meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd('FileType', { + api.nvim_create_augroup(augroup, { clear = true }) + api.nvim_create_autocmd('FileType', { group = augroup, command = 'let g:executed = g:executed + 1', }) @@ -1200,8 +1200,8 @@ describe('autocmd api', function() set_ft('txt') eq(2, get_executed_count(), 'should only count twice') - meths.create_augroup(augroup, { clear = true }) - eq({}, meths.get_autocmds { group = augroup }) + api.nvim_create_augroup(augroup, { clear = true }) + eq({}, api.nvim_get_autocmds { group = augroup }) set_ft('txt') set_ft('txt') @@ -1210,22 +1210,22 @@ describe('autocmd api', function() it('can delete non-existent groups with pcall', function() eq(false, exec_lua [[return pcall(vim.api.nvim_del_augroup_by_name, 'noexist')]]) - eq('Vim:E367: No such group: "noexist"', pcall_err(meths.del_augroup_by_name, 'noexist')) + eq('Vim:E367: No such group: "noexist"', pcall_err(api.nvim_del_augroup_by_name, 'noexist')) eq(false, exec_lua [[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]]) - eq('Vim:E367: No such group: "--Deleted--"', pcall_err(meths.del_augroup_by_id, -12312)) + eq('Vim:E367: No such group: "--Deleted--"', pcall_err(api.nvim_del_augroup_by_id, -12312)) eq(false, exec_lua [[return pcall(vim.api.nvim_del_augroup_by_id, 0)]]) - eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 0)) + eq('Vim:E367: No such group: "[NULL]"', pcall_err(api.nvim_del_augroup_by_id, 0)) eq(false, exec_lua [[return pcall(vim.api.nvim_del_augroup_by_id, 12342)]]) - eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 12312)) + eq('Vim:E367: No such group: "[NULL]"', pcall_err(api.nvim_del_augroup_by_id, 12312)) end) it('groups work with once', function() local augroup = 'TestGroup' - meths.create_augroup(augroup, { clear = true }) + api.nvim_create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup, once = true } set_ft('txt') @@ -1237,7 +1237,7 @@ describe('autocmd api', function() it('autocmds can be registered multiple times.', function() local augroup = 'TestGroup' - meths.create_augroup(augroup, { clear = true }) + api.nvim_create_augroup(augroup, { clear = true }) make_counting_autocmd { group = augroup, once = false } make_counting_autocmd { group = augroup, once = false } make_counting_autocmd { group = augroup, once = false } @@ -1251,16 +1251,16 @@ describe('autocmd api', function() it('can be deleted', function() local augroup = 'WillBeDeleted' - meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd({ 'FileType' }, { + api.nvim_create_augroup(augroup, { clear = true }) + api.nvim_create_autocmd({ 'FileType' }, { pattern = '*', command = "echo 'does not matter'", }) -- Clears the augroup from before, which erases the autocmd - meths.create_augroup(augroup, { clear = true }) + api.nvim_create_augroup(augroup, { clear = true }) - local result = #meths.get_autocmds { group = augroup } + local result = #api.nvim_get_autocmds { group = augroup } eq(0, result) end) @@ -1268,10 +1268,10 @@ describe('autocmd api', function() it('can be used for buffer local autocmds', function() local augroup = 'WillBeDeleted' - meths.set_var('value_set', false) + api.nvim_set_var('value_set', false) - meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd('FileType', { + api.nvim_create_augroup(augroup, { clear = true }) + api.nvim_create_autocmd('FileType', { pattern = '<buffer>', command = 'let g:value_set = v:true', }) @@ -1279,7 +1279,7 @@ describe('autocmd api', function() command 'new' command 'set filetype=python' - eq(false, meths.get_var('value_set')) + eq(false, api.nvim_get_var('value_set')) end) it('can accept vimscript functions', function() @@ -1302,7 +1302,7 @@ describe('autocmd api', function() set filetype=txt ]] - eq(2, meths.get_var('vimscript_executed')) + eq(2, api.nvim_get_var('vimscript_executed')) end) end) @@ -1314,11 +1314,11 @@ describe('autocmd api', function() command('augroup! TEMP_A') - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_A' })) + eq(false, pcall(api.nvim_get_autocmds, { group = 'TEMP_A' })) -- For some reason, augroup! doesn't clear the autocmds themselves, which is just wild -- but we managed to keep this behavior. - eq(1, #meths.get_autocmds { event = 'BufReadPost' }) + eq(1, #api.nvim_get_autocmds { event = 'BufReadPost' }) end) it('legacy: remove augroups that have no autocmds', function() @@ -1327,8 +1327,8 @@ describe('autocmd api', function() command('augroup! TEMP_AB') - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_AB' })) - eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + eq(false, pcall(api.nvim_get_autocmds, { group = 'TEMP_AB' })) + eq(0, #api.nvim_get_autocmds { event = 'BufReadPost' }) end) it('legacy: multiple remove and add augroup', function() @@ -1340,7 +1340,7 @@ describe('autocmd api', function() command('augroup! TEMP_ABC') -- Should still have one autocmd :'( - local aus = meths.get_autocmds { event = 'BufReadPost' } + local aus = api.nvim_get_autocmds { event = 'BufReadPost' } eq(1, #aus, aus) command('augroup TEMP_ABC') @@ -1349,13 +1349,13 @@ describe('autocmd api', function() command('augroup END') -- Should now have two autocmds :'( - aus = meths.get_autocmds { event = 'BufReadPost' } + aus = api.nvim_get_autocmds { event = 'BufReadPost' } eq(2, #aus, aus) command('augroup! TEMP_ABC') - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABC' })) - eq(2, #meths.get_autocmds { event = 'BufReadPost' }) + eq(false, pcall(api.nvim_get_autocmds, { group = 'TEMP_ABC' })) + eq(2, #api.nvim_get_autocmds { event = 'BufReadPost' }) end) it('api: should clear and not return any autocmds for delete groups by id', function() @@ -1363,13 +1363,13 @@ describe('autocmd api', function() command('autocmd! BufReadPost *.py :echo "Hello"') command('augroup END') - local augroup_id = meths.create_augroup('TEMP_ABCD', { clear = false }) - meths.del_augroup_by_id(augroup_id) + local augroup_id = api.nvim_create_augroup('TEMP_ABCD', { clear = false }) + api.nvim_del_augroup_by_id(augroup_id) -- For good reason, we kill all the autocmds from del_augroup, -- so now this works as expected - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABCD' })) - eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + eq(false, pcall(api.nvim_get_autocmds, { group = 'TEMP_ABCD' })) + eq(0, #api.nvim_get_autocmds { event = 'BufReadPost' }) end) it('api: should clear and not return any autocmds for delete groups by name', function() @@ -1377,12 +1377,12 @@ describe('autocmd api', function() command('autocmd! BufReadPost *.py :echo "Hello"') command('augroup END') - meths.del_augroup_by_name('TEMP_ABCDE') + api.nvim_del_augroup_by_name('TEMP_ABCDE') -- For good reason, we kill all the autocmds from del_augroup, -- so now this works as expected - eq(false, pcall(meths.get_autocmds, { group = 'TEMP_ABCDE' })) - eq(0, #meths.get_autocmds { event = 'BufReadPost' }) + eq(false, pcall(api.nvim_get_autocmds, { group = 'TEMP_ABCDE' })) + eq(0, #api.nvim_get_autocmds { event = 'BufReadPost' }) end) end) @@ -1390,18 +1390,18 @@ describe('autocmd api', function() it('validation', function() eq( "Cannot use both 'pattern' and 'buffer'", - pcall_err(meths.clear_autocmds, { + pcall_err(api.nvim_clear_autocmds, { pattern = '*', buffer = 42, }) ) eq( "Invalid 'event' item: expected String, got Array", - pcall_err(meths.clear_autocmds, { + pcall_err(api.nvim_clear_autocmds, { event = { 'FileType', {} }, }) ) - eq("Invalid 'group': 0", pcall_err(meths.clear_autocmds, { group = 0 })) + eq("Invalid 'group': 0", pcall_err(api.nvim_clear_autocmds, { group = 0 })) end) it('should clear based on event + pattern', function() @@ -1409,17 +1409,17 @@ describe('autocmd api', function() command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') local search = { event = 'InsertEnter', pattern = '*.txt' } - local before_delete = meths.get_autocmds(search) + local before_delete = api.nvim_get_autocmds(search) eq(1, #before_delete) - local before_delete_all = meths.get_autocmds { event = search.event } + local before_delete_all = api.nvim_get_autocmds { event = search.event } eq(2, #before_delete_all) - meths.clear_autocmds(search) - local after_delete = meths.get_autocmds(search) + api.nvim_clear_autocmds(search) + local after_delete = api.nvim_get_autocmds(search) eq(0, #after_delete) - local after_delete_all = meths.get_autocmds { event = search.event } + local after_delete_all = api.nvim_get_autocmds { event = search.event } eq(1, #after_delete_all) end) @@ -1428,11 +1428,11 @@ describe('autocmd api', function() command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') local search = { event = 'InsertEnter' } - local before_delete = meths.get_autocmds(search) + local before_delete = api.nvim_get_autocmds(search) eq(2, #before_delete) - meths.clear_autocmds(search) - local after_delete = meths.get_autocmds(search) + api.nvim_clear_autocmds(search) + local after_delete = api.nvim_get_autocmds(search) eq(0, #after_delete) end) @@ -1443,16 +1443,17 @@ describe('autocmd api', function() command('autocmd InsertLeave *.TestPat2 :echo "Leave 2"') local search = { pattern = '*.TestPat1' } - local before_delete = meths.get_autocmds(search) + local before_delete = api.nvim_get_autocmds(search) eq(2, #before_delete) - local before_delete_events = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } + local before_delete_events = + api.nvim_get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } eq(4, #before_delete_events) - meths.clear_autocmds(search) - local after_delete = meths.get_autocmds(search) + api.nvim_clear_autocmds(search) + local after_delete = api.nvim_get_autocmds(search) eq(0, #after_delete) - local after_delete_events = meths.get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } + local after_delete_events = api.nvim_get_autocmds { event = { 'InsertEnter', 'InsertLeave' } } eq(2, #after_delete_events) end) @@ -1462,11 +1463,11 @@ describe('autocmd api', function() command('autocmd InsertEnter *.TestPat1 :echo "Enter Pattern"') local search = { event = 'InsertEnter' } - local before_delete = meths.get_autocmds(search) + local before_delete = api.nvim_get_autocmds(search) eq(2, #before_delete) - meths.clear_autocmds { buffer = 0 } - local after_delete = meths.get_autocmds(search) + api.nvim_clear_autocmds { buffer = 0 } + local after_delete = api.nvim_get_autocmds(search) eq(1, #after_delete) eq('*.TestPat1', after_delete[1].pattern) end) @@ -1479,17 +1480,17 @@ describe('autocmd api', function() command('augroup END') local search = { event = 'InsertEnter', group = 'TestNvimClearAutocmds' } - local before_delete = meths.get_autocmds(search) + local before_delete = api.nvim_get_autocmds(search) eq(2, #before_delete) -- Doesn't clear without passing group. - meths.clear_autocmds { buffer = 0 } - local without_group = meths.get_autocmds(search) + api.nvim_clear_autocmds { buffer = 0 } + local without_group = api.nvim_get_autocmds(search) eq(2, #without_group) -- Doesn't clear with passing group. - meths.clear_autocmds { buffer = 0, group = search.group } - local with_group = meths.get_autocmds(search) + api.nvim_clear_autocmds { buffer = 0, group = search.group } + local with_group = api.nvim_get_autocmds(search) eq(1, #with_group) end) end) diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index e8fff7443d..10be4c56a7 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -1,19 +1,18 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer -local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq -local curbufmeths, ok = helpers.curbufmeths, helpers.ok +local clear = helpers.clear +local eq = helpers.eq +local ok = helpers.ok local describe_lua_and_rpc = helpers.describe_lua_and_rpc(describe) -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local request = helpers.request local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua local feed_command = helpers.feed_command local insert = helpers.insert -local NIL = helpers.NIL +local NIL = vim.NIL local command = helpers.command -local bufmeths = helpers.bufmeths local feed = helpers.feed local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -42,108 +41,114 @@ describe('api/buf', function() end) it("doesn't crash just after set undolevels=1 #24894", function() - local buf = meths.create_buf(false, true) - meths.buf_set_option(buf, 'undolevels', -1) - meths.buf_set_lines(buf, 0, 1, false, {}) + local buf = api.nvim_create_buf(false, true) + api.nvim_buf_set_option(buf, 'undolevels', -1) + api.nvim_buf_set_lines(buf, 0, 1, false, {}) assert_alive() end) it('cursor position is maintained after lines are inserted #9961', function() -- replace the buffer contents with these three lines. - request('nvim_buf_set_lines', 0, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) -- Set the current cursor to {3, 2}. - curwin('set_cursor', { 3, 2 }) + api.nvim_win_set_cursor(0, { 3, 2 }) -- add 2 lines and delete 1 line above the current cursor position. - request('nvim_buf_set_lines', 0, 1, 2, 1, { 'line5', 'line6' }) + api.nvim_buf_set_lines(0, 1, 2, true, { 'line5', 'line6' }) -- check the current set of lines in the buffer. - eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, buffer('get_lines', 0, 0, -1, 1)) + eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, api.nvim_buf_get_lines(0, 0, -1, true)) -- cursor should be moved below by 1 line. - eq({ 4, 2 }, curwin('get_cursor')) + eq({ 4, 2 }, api.nvim_win_get_cursor(0)) -- add a line after the current cursor position. - request('nvim_buf_set_lines', 0, 5, 5, 1, { 'line7' }) + api.nvim_buf_set_lines(0, 5, 5, true, { 'line7' }) -- check the current set of lines in the buffer. - eq({ 'line1', 'line5', 'line6', 'line3', 'line4', 'line7' }, buffer('get_lines', 0, 0, -1, 1)) + eq( + { 'line1', 'line5', 'line6', 'line3', 'line4', 'line7' }, + api.nvim_buf_get_lines(0, 0, -1, true) + ) -- cursor position is unchanged. - eq({ 4, 2 }, curwin('get_cursor')) + eq({ 4, 2 }, api.nvim_win_get_cursor(0)) -- overwrite current cursor line. - request('nvim_buf_set_lines', 0, 3, 5, 1, { 'line8', 'line9' }) + api.nvim_buf_set_lines(0, 3, 5, true, { 'line8', 'line9' }) -- check the current set of lines in the buffer. - eq({ 'line1', 'line5', 'line6', 'line8', 'line9', 'line7' }, buffer('get_lines', 0, 0, -1, 1)) + eq( + { 'line1', 'line5', 'line6', 'line8', 'line9', 'line7' }, + api.nvim_buf_get_lines(0, 0, -1, true) + ) -- cursor position is unchanged. - eq({ 4, 2 }, curwin('get_cursor')) + eq({ 4, 2 }, api.nvim_win_get_cursor(0)) -- delete current cursor line. - request('nvim_buf_set_lines', 0, 3, 5, 1, {}) + api.nvim_buf_set_lines(0, 3, 5, true, {}) -- check the current set of lines in the buffer. - eq({ 'line1', 'line5', 'line6', 'line7' }, buffer('get_lines', 0, 0, -1, 1)) + eq({ 'line1', 'line5', 'line6', 'line7' }, api.nvim_buf_get_lines(0, 0, -1, true)) -- cursor position is unchanged. - eq({ 4, 2 }, curwin('get_cursor')) + eq({ 4, 2 }, api.nvim_win_get_cursor(0)) end) it('cursor position is maintained in non-current window', function() - meths.buf_set_lines(0, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) - meths.win_set_cursor(0, { 3, 2 }) - local win = meths.get_current_win() - local buf = meths.get_current_buf() + api.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) + api.nvim_win_set_cursor(0, { 3, 2 }) + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('new') - meths.buf_set_lines(buf, 1, 2, 1, { 'line5', 'line6' }) - eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.buf_get_lines(buf, 0, -1, true)) - eq({ 4, 2 }, meths.win_get_cursor(win)) + api.nvim_buf_set_lines(buf, 1, 2, true, { 'line5', 'line6' }) + eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, api.nvim_buf_get_lines(buf, 0, -1, true)) + eq({ 4, 2 }, api.nvim_win_get_cursor(win)) end) it('cursor position is maintained in TWO non-current windows', function() - meths.buf_set_lines(0, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) - meths.win_set_cursor(0, { 3, 2 }) - local win = meths.get_current_win() - local buf = meths.get_current_buf() + api.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) + api.nvim_win_set_cursor(0, { 3, 2 }) + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('split') - meths.win_set_cursor(0, { 4, 2 }) - local win2 = meths.get_current_win() + api.nvim_win_set_cursor(0, { 4, 2 }) + local win2 = api.nvim_get_current_win() -- set current window to third one with another buffer command('new') - meths.buf_set_lines(buf, 1, 2, 1, { 'line5', 'line6' }) - eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, meths.buf_get_lines(buf, 0, -1, true)) - eq({ 4, 2 }, meths.win_get_cursor(win)) - eq({ 5, 2 }, meths.win_get_cursor(win2)) + api.nvim_buf_set_lines(buf, 1, 2, true, { 'line5', 'line6' }) + eq({ 'line1', 'line5', 'line6', 'line3', 'line4' }, api.nvim_buf_get_lines(buf, 0, -1, true)) + eq({ 4, 2 }, api.nvim_win_get_cursor(win)) + eq({ 5, 2 }, api.nvim_win_get_cursor(win2)) end) it('line_count has defined behaviour for unloaded buffers', function() -- we'll need to know our bufnr for when it gets unloaded - local bufnr = curbuf('get_number') + local bufnr = api.nvim_buf_get_number(0) -- replace the buffer contents with these three lines - request('nvim_buf_set_lines', bufnr, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) + api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) -- check the line count is correct - eq(4, request('nvim_buf_line_count', bufnr)) + eq(4, api.nvim_buf_line_count(bufnr)) -- force unload the buffer (this will discard changes) command('new') command('bunload! ' .. bufnr) -- line count for an unloaded buffer should always be 0 - eq(0, request('nvim_buf_line_count', bufnr)) + eq(0, api.nvim_buf_line_count(bufnr)) end) it('get_lines has defined behaviour for unloaded buffers', function() -- we'll need to know our bufnr for when it gets unloaded - local bufnr = curbuf('get_number') + local bufnr = api.nvim_buf_get_number(0) -- replace the buffer contents with these three lines - buffer('set_lines', bufnr, 0, -1, 1, { 'line1', 'line2', 'line3', 'line4' }) + api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'line1', 'line2', 'line3', 'line4' }) -- confirm that getting lines works - eq({ 'line2', 'line3' }, buffer('get_lines', bufnr, 1, 3, 1)) + eq({ 'line2', 'line3' }, api.nvim_buf_get_lines(bufnr, 1, 3, true)) -- force unload the buffer (this will discard changes) command('new') command('bunload! ' .. bufnr) -- attempting to get lines now always gives empty list - eq({}, buffer('get_lines', bufnr, 1, 3, 1)) + eq({}, api.nvim_buf_get_lines(bufnr, 1, 3, true)) -- it's impossible to get out-of-bounds errors for an unloaded buffer - eq({}, buffer('get_lines', bufnr, 8888, 9999, 1)) + eq({}, api.nvim_buf_get_lines(bufnr, 8888, 9999, true)) end) describe('handles topline', function() @@ -156,16 +161,22 @@ describe('api/buf', function() [3] = { reverse = true }, } screen:attach() - meths.buf_set_lines(0, 0, -1, 1, { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' }) - meths.set_option_value('modified', false, {}) + api.nvim_buf_set_lines( + 0, + 0, + -1, + true, + { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' } + ) + api.nvim_set_option_value('modified', false, {}) end) it('of current window', function() - local win = meths.get_current_win() - local buf = meths.get_current_buf() + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('new | wincmd w') - meths.win_set_cursor(win, { 8, 0 }) + api.nvim_win_set_cursor(win, { 8, 0 }) screen:expect { grid = [[ @@ -181,7 +192,7 @@ describe('api/buf', function() ]], } - meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' }) + api.nvim_buf_set_lines(buf, 0, 2, true, { 'aaabbb' }) screen:expect { grid = [[ | @@ -197,7 +208,7 @@ describe('api/buf', function() } -- replacing topline keeps it the topline - meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' }) + api.nvim_buf_set_lines(buf, 3, 4, true, { 'wwweeee' }) screen:expect { grid = [[ | @@ -213,7 +224,7 @@ describe('api/buf', function() } -- inserting just before topline does not scroll up if cursor would be moved - meths.buf_set_lines(buf, 3, 3, true, { 'mmm' }) + api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' }) screen:expect { grid = [[ | @@ -229,7 +240,7 @@ describe('api/buf', function() unchanged = true, } - meths.win_set_cursor(0, { 7, 0 }) + api.nvim_win_set_cursor(0, { 7, 0 }) screen:expect { grid = [[ | @@ -244,7 +255,7 @@ describe('api/buf', function() ]], } - meths.buf_set_lines(buf, 4, 4, true, { 'mmmeeeee' }) + api.nvim_buf_set_lines(buf, 4, 4, true, { 'mmmeeeee' }) screen:expect { grid = [[ | @@ -261,11 +272,11 @@ describe('api/buf', function() end) it('of non-current window', function() - local win = meths.get_current_win() - local buf = meths.get_current_buf() + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('new') - meths.win_set_cursor(win, { 8, 0 }) + api.nvim_win_set_cursor(win, { 8, 0 }) screen:expect { grid = [[ @@ -281,7 +292,7 @@ describe('api/buf', function() ]], } - meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' }) + api.nvim_buf_set_lines(buf, 0, 2, true, { 'aaabbb' }) screen:expect { grid = [[ ^ | @@ -297,7 +308,7 @@ describe('api/buf', function() } -- replacing topline keeps it the topline - meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' }) + api.nvim_buf_set_lines(buf, 3, 4, true, { 'wwweeee' }) screen:expect { grid = [[ ^ | @@ -313,7 +324,7 @@ describe('api/buf', function() } -- inserting just before topline scrolls up - meths.buf_set_lines(buf, 3, 3, true, { 'mmm' }) + api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' }) screen:expect { grid = [[ ^ | @@ -330,12 +341,12 @@ describe('api/buf', function() end) it('of split windows with same buffer', function() - local win = meths.get_current_win() - local buf = meths.get_current_buf() + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('split') - meths.win_set_cursor(win, { 8, 0 }) - meths.win_set_cursor(0, { 1, 0 }) + api.nvim_win_set_cursor(win, { 8, 0 }) + api.nvim_win_set_cursor(0, { 1, 0 }) screen:expect { grid = [[ @@ -353,7 +364,7 @@ describe('api/buf', function() | ]], } - meths.buf_set_lines(buf, 0, 2, true, { 'aaabbb' }) + api.nvim_buf_set_lines(buf, 0, 2, true, { 'aaabbb' }) screen:expect { grid = [[ @@ -373,7 +384,7 @@ describe('api/buf', function() } -- replacing topline keeps it the topline - meths.buf_set_lines(buf, 3, 4, true, { 'wwweeee' }) + api.nvim_buf_set_lines(buf, 3, 4, true, { 'wwweeee' }) screen:expect { grid = [[ ^aaabbb | @@ -392,7 +403,7 @@ describe('api/buf', function() } -- inserting just before topline scrolls up - meths.buf_set_lines(buf, 3, 3, true, { 'mmm' }) + api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' }) screen:expect { grid = [[ ^aaabbb | @@ -413,15 +424,15 @@ describe('api/buf', function() end) it('handles clearing out non-current buffer #24911', function() - local buf = meths.get_current_buf() - meths.buf_set_lines(buf, 0, -1, true, { 'aaa', 'bbb', 'ccc' }) + local buf = api.nvim_get_current_buf() + api.nvim_buf_set_lines(buf, 0, -1, true, { 'aaa', 'bbb', 'ccc' }) command('new') - meths.buf_set_lines(0, 0, -1, true, { 'xxx', 'yyy', 'zzz' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'xxx', 'yyy', 'zzz' }) - meths.buf_set_lines(buf, 0, -1, true, {}) - eq({ 'xxx', 'yyy', 'zzz' }, meths.buf_get_lines(0, 0, -1, true)) - eq({ '' }, meths.buf_get_lines(buf, 0, -1, true)) + api.nvim_buf_set_lines(buf, 0, -1, true, {}) + eq({ 'xxx', 'yyy', 'zzz' }, api.nvim_buf_get_lines(0, 0, -1, true)) + eq({ '' }, api.nvim_buf_get_lines(buf, 0, -1, true)) end) end) @@ -503,16 +514,24 @@ describe('api/buf', function() end) end) - describe_lua_and_rpc('nvim_buf_get_lines, nvim_buf_set_lines', function(api) - local get_lines = api.curbufmeths.get_lines - local set_lines = api.curbufmeths.set_lines - local line_count = api.curbufmeths.line_count + describe_lua_and_rpc('nvim_buf_get_lines, nvim_buf_set_lines', function(lua_or_rpc) + local function get_lines(...) + return lua_or_rpc.nvim_buf_get_lines(0, ...) + end + + local function set_lines(...) + return lua_or_rpc.nvim_buf_set_lines(0, ...) + end + + local function line_count() + return lua_or_rpc.nvim_buf_line_count(0) + end it('fails correctly when input is not valid', function() - eq(1, api.curbufmeths.get_number()) + eq(1, lua_or_rpc.nvim_buf_get_number(0)) eq( [['replacement string' item contains newlines]], - pcall_err(bufmeths.set_lines, 1, 1, 2, false, { 'b\na' }) + pcall_err(lua_or_rpc.nvim_buf_set_lines, 1, 1, 2, false, { 'b\na' }) ) end) @@ -520,7 +539,7 @@ describe('api/buf', function() command('set nomodifiable') eq( [[Buffer is not 'modifiable']], - pcall_err(api.bufmeths.set_lines, 1, 1, 2, false, { 'a', 'b' }) + pcall_err(lua_or_rpc.nvim_buf_set_lines, 1, 1, 2, false, { 'a', 'b' }) ) end) @@ -676,7 +695,7 @@ describe('api/buf', function() Who would win? A real window with proper text]]) - local buf = api.meths.create_buf(false, true) + local buf = lua_or_rpc.nvim_create_buf(false, true) screen:expect([[ Who would win? | A real window | @@ -685,7 +704,7 @@ describe('api/buf', function() | ]]) - api.meths.buf_set_lines(buf, 0, -1, true, { 'or some', 'scratchy text' }) + lua_or_rpc.nvim_buf_set_lines(buf, 0, -1, true, { 'or some', 'scratchy text' }) feed('i') -- provoke redraw screen:expect([[ Who would win? | @@ -701,36 +720,42 @@ describe('api/buf', function() visible buffer line 1 line 2 ]]) - local hiddenbuf = api.meths.create_buf(false, true) + local hiddenbuf = lua_or_rpc.nvim_create_buf(false, true) command('vsplit') command('vsplit') feed('<c-w>l<c-w>l<c-w>l') - eq(3, funcs.winnr()) + eq(3, fn.winnr()) feed('<c-w>h') - eq(2, funcs.winnr()) - api.meths.buf_set_lines(hiddenbuf, 0, -1, true, { 'hidden buffer line 1', 'line 2' }) + eq(2, fn.winnr()) + lua_or_rpc.nvim_buf_set_lines(hiddenbuf, 0, -1, true, { 'hidden buffer line 1', 'line 2' }) feed('<c-w>p') - eq(3, funcs.winnr()) + eq(3, fn.winnr()) end) it('set_lines on unloaded buffer #8659 #22670', function() - local bufnr = curbuf('get_number') - meths.buf_set_lines(bufnr, 0, -1, false, { 'a', 'b', 'c' }) - meths.buf_set_name(bufnr, 'set_lines') + local bufnr = api.nvim_get_current_buf().id + lua_or_rpc.nvim_buf_set_lines(bufnr, 0, -1, false, { 'a', 'b', 'c' }) + lua_or_rpc.nvim_buf_set_name(bufnr, 'set_lines') finally(function() os.remove('set_lines') end) command('write!') command('new') command('bunload! ' .. bufnr) - local new_bufnr = funcs.bufnr('set_lines', true) - meths.buf_set_lines(new_bufnr, 0, -1, false, {}) - eq({ '' }, meths.buf_get_lines(new_bufnr, 0, -1, false)) + local new_bufnr = fn.bufnr('set_lines', true) + lua_or_rpc.nvim_buf_set_lines(new_bufnr, 0, -1, false, {}) + eq({ '' }, lua_or_rpc.nvim_buf_get_lines(new_bufnr, 0, -1, false)) end) end) describe('nvim_buf_set_text', function() - local get_lines, set_text = curbufmeths.get_lines, curbufmeths.set_text + local function get_lines(...) + return api.nvim_buf_get_lines(0, ...) + end + + local function set_text(...) + return api.nvim_buf_set_text(0, ...) + end it('works', function() insert([[ @@ -809,12 +834,12 @@ describe('api/buf', function() ]]) -- position the cursor on `!` - curwin('set_cursor', { 1, 11 }) + api.nvim_win_set_cursor(0, { 1, 11 }) -- replace 'world' with 'foo' set_text(0, 6, 0, 11, { 'foo' }) eq('hello foo!', curbuf_depr('get_line', 0)) -- cursor should be moved left by two columns (replacement is shorter by 2 chars) - eq({ 1, 9 }, curwin('get_cursor')) + eq({ 1, 9 }, api.nvim_win_get_cursor(0)) end) it('updates the cursor position in non-current window', function() @@ -822,18 +847,18 @@ describe('api/buf', function() hello world!]]) -- position the cursor on `!` - meths.win_set_cursor(0, { 1, 11 }) + api.nvim_win_set_cursor(0, { 1, 11 }) - local win = meths.get_current_win() - local buf = meths.get_current_buf() + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('new') -- replace 'world' with 'foo' - meths.buf_set_text(buf, 0, 6, 0, 11, { 'foo' }) - eq({ 'hello foo!' }, meths.buf_get_lines(buf, 0, -1, true)) + api.nvim_buf_set_text(buf, 0, 6, 0, 11, { 'foo' }) + eq({ 'hello foo!' }, api.nvim_buf_get_lines(buf, 0, -1, true)) -- cursor should be moved left by two columns (replacement is shorter by 2 chars) - eq({ 1, 9 }, meths.win_get_cursor(win)) + eq({ 1, 9 }, api.nvim_win_get_cursor(win)) end) it('updates the cursor position in TWO non-current windows', function() @@ -841,24 +866,24 @@ describe('api/buf', function() hello world!]]) -- position the cursor on `!` - meths.win_set_cursor(0, { 1, 11 }) - local win = meths.get_current_win() - local buf = meths.get_current_buf() + api.nvim_win_set_cursor(0, { 1, 11 }) + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('split') - local win2 = meths.get_current_win() + local win2 = api.nvim_get_current_win() -- position the cursor on `w` - meths.win_set_cursor(0, { 1, 6 }) + api.nvim_win_set_cursor(0, { 1, 6 }) command('new') -- replace 'hello' with 'foo' - meths.buf_set_text(buf, 0, 0, 0, 5, { 'foo' }) - eq({ 'foo world!' }, meths.buf_get_lines(buf, 0, -1, true)) + api.nvim_buf_set_text(buf, 0, 0, 0, 5, { 'foo' }) + eq({ 'foo world!' }, api.nvim_buf_get_lines(buf, 0, -1, true)) -- both cursors should be moved left by two columns (replacement is shorter by 2 chars) - eq({ 1, 9 }, meths.win_get_cursor(win)) - eq({ 1, 4 }, meths.win_get_cursor(win2)) + eq({ 1, 9 }, api.nvim_win_get_cursor(win)) + eq({ 1, 4 }, api.nvim_win_get_cursor(win2)) end) describe('when text is being added right at cursor position #22526', function() @@ -867,12 +892,12 @@ describe('api/buf', function() abcd]]) -- position the cursor on 'c' - curwin('set_cursor', { 1, 2 }) + api.nvim_win_set_cursor(0, { 1, 2 }) -- add 'xxx' before 'c' set_text(0, 2, 0, 2, { 'xxx' }) eq({ 'abxxxcd' }, get_lines(0, -1, true)) -- cursor should be on 'c' - eq({ 1, 5 }, curwin('get_cursor')) + eq({ 1, 5 }, api.nvim_win_get_cursor(0)) end) it('updates the cursor position only in non-current window when in INSERT mode', function() @@ -880,7 +905,7 @@ describe('api/buf', function() abcd]]) -- position the cursor on 'c' - curwin('set_cursor', { 1, 2 }) + api.nvim_win_set_cursor(0, { 1, 2 }) -- open vertical split feed('<c-w>v') -- get into INSERT mode to treat cursor @@ -890,13 +915,13 @@ describe('api/buf', function() set_text(0, 2, 0, 2, { 'xxx' }) eq({ 'abxxxcd' }, get_lines(0, -1, true)) -- in the current window cursor should stay after 'b' - eq({ 1, 2 }, curwin('get_cursor')) + eq({ 1, 2 }, api.nvim_win_get_cursor(0)) -- quit INSERT mode feed('<esc>') -- close current window feed('<c-w>c') -- in another window cursor should be on 'c' - eq({ 1, 5 }, curwin('get_cursor')) + eq({ 1, 5 }, api.nvim_win_get_cursor(0)) end) end) @@ -906,12 +931,12 @@ describe('api/buf', function() abcd]]) -- position the cursor on 'b' - curwin('set_cursor', { 1, 1 }) + api.nvim_win_set_cursor(0, { 1, 1 }) -- delete 'b' set_text(0, 1, 0, 2, {}) eq({ 'acd' }, get_lines(0, -1, true)) -- cursor is now on 'c' - eq({ 1, 1 }, curwin('get_cursor')) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) end) it('maintains INSERT-mode cursor position current/non-current window', function() @@ -919,7 +944,7 @@ describe('api/buf', function() abcd]]) -- position the cursor on 'b' - curwin('set_cursor', { 1, 1 }) + api.nvim_win_set_cursor(0, { 1, 1 }) -- open vertical split feed('<c-w>v') -- get into INSERT mode to treat cursor @@ -929,13 +954,13 @@ describe('api/buf', function() set_text(0, 1, 0, 2, {}) eq({ 'acd' }, get_lines(0, -1, true)) -- cursor in the current window should stay after 'a' - eq({ 1, 1 }, curwin('get_cursor')) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) -- quit INSERT mode feed('<esc>') -- close current window feed('<c-w>c') -- cursor in non-current window should stay on 'c' - eq({ 1, 1 }, curwin('get_cursor')) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) end) end) @@ -947,7 +972,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on ' ' before 'first' - curwin('set_cursor', { 1, 14 }) + api.nvim_win_set_cursor(0, { 1, 14 }) set_text(0, 15, 2, 11, { 'the line we do not want', @@ -959,7 +984,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should stay at the same position - eq({ 1, 14 }, curwin('get_cursor')) + eq({ 1, 14 }, api.nvim_win_get_cursor(0)) end) it('maintains cursor position if at start_row and column is still valid', function() @@ -969,7 +994,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'f' in 'first' - curwin('set_cursor', { 1, 15 }) + api.nvim_win_set_cursor(0, { 1, 15 }) set_text(0, 15, 2, 11, { 'the line we do not want', @@ -981,7 +1006,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should stay at the same position - eq({ 1, 15 }, curwin('get_cursor')) + eq({ 1, 15 }, api.nvim_win_get_cursor(0)) end) it('adjusts cursor column to keep it valid if start_row got smaller', function() @@ -991,7 +1016,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 't' in 'first' - curwin('set_cursor', { 1, 19 }) + api.nvim_win_set_cursor(0, { 1, 19 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 15, 2, 24, {'last'}) @@ -1000,7 +1025,7 @@ describe('api/buf', function() eq({ 'This should be last' }, get_lines(0, -1, true)) -- cursor should end up on 't' in 'last' - eq({ 1, 18 }, curwin('get_cursor')) + eq({ 1, 18 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 18 }, cursor) end) @@ -1012,7 +1037,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 't' in 'first' - curwin('set_cursor', { 1, 19 }) + api.nvim_win_set_cursor(0, { 1, 19 }) -- enter INSERT mode to treat cursor as being after 't' feed('a') @@ -1023,7 +1048,7 @@ describe('api/buf', function() eq({ 'This should be last' }, get_lines(0, -1, true)) -- cursor should end up after 't' in 'last' - eq({ 1, 19 }, curwin('get_cursor')) + eq({ 1, 19 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 19 }, cursor) end) @@ -1035,7 +1060,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'w' in 'want' - curwin('set_cursor', { 2, 31 }) + api.nvim_win_set_cursor(0, { 2, 31 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { @@ -1052,7 +1077,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor column should end up at the end of a row - eq({ 2, 5 }, curwin('get_cursor')) + eq({ 2, 5 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 5 }, cursor) end) @@ -1066,7 +1091,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'w' in 'want' - curwin('set_cursor', { 2, 31 }) + api.nvim_win_set_cursor(0, { 2, 31 }) -- enter INSERT mode feed('a') @@ -1085,7 +1110,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor column should end up at the end of a row - eq({ 2, 6 }, curwin('get_cursor')) + eq({ 2, 6 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 6 }, cursor) end @@ -1098,7 +1123,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'n' in 'finally' - curwin('set_cursor', { 3, 6 }) + api.nvim_win_set_cursor(0, { 3, 6 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, { @@ -1114,7 +1139,7 @@ describe('api/buf', function() }, get_lines(0, -1, true)) -- cursor should end up on 'y' in 'hopefully' -- to stay in the range, because it got smaller - eq({ 2, 12 }, curwin('get_cursor')) + eq({ 2, 12 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 12 }, cursor) end) @@ -1126,7 +1151,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'r' in 'there' - curwin('set_cursor', { 2, 8 }) + api.nvim_win_set_cursor(0, { 2, 8 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 15, 2, 12, {}) @@ -1135,7 +1160,7 @@ describe('api/buf', function() eq({ 'This should be the last one' }, get_lines(0, -1, true)) -- cursor should end up on the next column after deleted range - eq({ 1, 15 }, curwin('get_cursor')) + eq({ 1, 15 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 15 }, cursor) end) @@ -1147,7 +1172,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'r' in 'there' - curwin('set_cursor', { 2, 8 }) + api.nvim_win_set_cursor(0, { 2, 8 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 0, 2, 4, {}) @@ -1156,7 +1181,7 @@ describe('api/buf', function() eq({ 'finally the last one' }, get_lines(0, -1, true)) -- cursor should end up in column 0 - eq({ 1, 0 }, curwin('get_cursor')) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 0 }, cursor) end) @@ -1168,7 +1193,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'y' in 'finally' - curwin('set_cursor', { 3, 10 }) + api.nvim_win_set_cursor(0, { 3, 10 }) set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' }) eq({ @@ -1177,7 +1202,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor should end up on 'n' in 'then' - eq({ 3, 7 }, curwin('get_cursor')) + eq({ 3, 7 }, api.nvim_win_get_cursor(0)) end) it( @@ -1189,7 +1214,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'y' at 'finally' - curwin('set_cursor', { 3, 10 }) + api.nvim_win_set_cursor(0, { 3, 10 }) -- enter INSERT mode to treat cursor as being between 'l' and 'y' feed('i') set_text(0, 15, 2, 11, { '1', 'this 2', 'and then' }) @@ -1200,7 +1225,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor should end up after 'n' in 'then' - eq({ 3, 8 }, curwin('get_cursor')) + eq({ 3, 8 }, api.nvim_win_get_cursor(0)) end ) @@ -1211,7 +1236,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'y' in 'finally' - curwin('set_cursor', { 3, 10 }) + api.nvim_win_set_cursor(0, { 3, 10 }) set_text(2, 4, 2, 11, { 'then' }) eq({ @@ -1220,7 +1245,7 @@ describe('api/buf', function() 'and then the last one', }, get_lines(0, -1, true)) -- cursor should end up on 'n' in 'then' - eq({ 3, 7 }, curwin('get_cursor')) + eq({ 3, 7 }, api.nvim_win_get_cursor(0)) end) it('does not move cursor column after end of a line', function() @@ -1229,7 +1254,7 @@ describe('api/buf', function() !!!]]) -- position cursor on the last '1' - curwin('set_cursor', { 2, 2 }) + api.nvim_win_set_cursor(0, { 2, 2 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 33, 1, 3, {}) @@ -1238,7 +1263,7 @@ describe('api/buf', function() eq({ 'This should be the only line here' }, get_lines(0, -1, true)) -- cursor should end up on '!' - eq({ 1, 32 }, curwin('get_cursor')) + eq({ 1, 32 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 32 }, cursor) end) @@ -1247,7 +1272,7 @@ describe('api/buf', function() insert('\n!!!') -- position cursor on the last '1' - curwin('set_cursor', { 2, 2 }) + api.nvim_win_set_cursor(0, { 2, 2 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 0, 1, 3, {}) @@ -1256,7 +1281,7 @@ describe('api/buf', function() eq({ '' }, get_lines(0, -1, true)) -- cursor should end up on '!' - eq({ 1, 0 }, curwin('get_cursor')) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 0 }, cursor) end) @@ -1269,7 +1294,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 't' in 'want' - curwin('set_cursor', { 2, 34 }) + api.nvim_win_set_cursor(0, { 2, 34 }) -- turn on virtualedit command('set virtualedit=all') @@ -1287,7 +1312,7 @@ describe('api/buf', function() }, get_lines(0, -1, true)) -- cursor should end up on 'y' in 'hopefully' -- to stay in the range - eq({ 2, 12 }, curwin('get_cursor')) + eq({ 2, 12 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 12 }, cursor) -- coladd should be 0 @@ -1306,7 +1331,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 't' in 'want' - curwin('set_cursor', { 2, 34 }) + api.nvim_win_set_cursor(0, { 2, 34 }) -- turn on virtualedit command('set virtualedit=all') -- move cursor after eol @@ -1327,7 +1352,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should end up at eol of a new row - eq({ 2, 26 }, curwin('get_cursor')) + eq({ 2, 26 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 26 }, cursor) -- coladd should be increased so that cursor stays in the same screen column @@ -1348,7 +1373,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 't' in 'first' - curwin('set_cursor', { 1, 19 }) + api.nvim_win_set_cursor(0, { 1, 19 }) -- turn on virtualedit command('set virtualedit=all') -- move cursor after eol @@ -1369,7 +1394,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should end up at eol of a new row - eq({ 1, 38 }, curwin('get_cursor')) + eq({ 1, 38 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 38 }, cursor) -- coladd should be increased so that cursor stays in the same screen column @@ -1391,7 +1416,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 't' in 'first' - curwin('set_cursor', { 1, 19 }) + api.nvim_win_set_cursor(0, { 1, 19 }) -- turn on virtualedit command('set virtualedit=all') -- move cursor after eol just a bit @@ -1412,7 +1437,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should stay at the same screen column - eq({ 1, 22 }, curwin('get_cursor')) + eq({ 1, 22 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 22 }, cursor) -- coladd should become 0 @@ -1435,7 +1460,7 @@ describe('api/buf', function() and finally the last one]]) -- position cursor on 'e' in 'more' - curwin('set_cursor', { 3, 11 }) + api.nvim_win_set_cursor(0, { 3, 11 }) -- turn on virtualedit command('set virtualedit=all') -- move cursor after eol @@ -1456,7 +1481,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should end up at eol of a new row - eq({ 2, 26 }, curwin('get_cursor')) + eq({ 2, 26 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 2, 26 }, cursor) -- coladd should be increased so that cursor stays in the same screen column @@ -1479,17 +1504,17 @@ describe('api/buf', function() line]]) -- position the cursor on 'i' - curwin('set_cursor', { 3, 2 }) + api.nvim_win_set_cursor(0, { 3, 2 }) set_text(1, 6, 2, 0, {}) eq({ 'first line', 'second line' }, get_lines(0, -1, true)) -- cursor should stay on 'i' - eq({ 2, 8 }, curwin('get_cursor')) + eq({ 2, 8 }, api.nvim_win_get_cursor(0)) -- add a newline back set_text(1, 6, 1, 6, { '', '' }) eq({ 'first line', 'second', ' line' }, get_lines(0, -1, true)) -- cursor should return back to the original position - eq({ 3, 2 }, curwin('get_cursor')) + eq({ 3, 2 }, api.nvim_win_get_cursor(0)) end) it( @@ -1501,11 +1526,11 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 'h' in 'the' - curwin('set_cursor', { 3, 13 }) + api.nvim_win_set_cursor(0, { 3, 13 }) set_text(0, 14, 2, 11, {}) eq({ 'This should be the last one' }, get_lines(0, -1, true)) -- cursor should stay on 'h' - eq({ 1, 16 }, curwin('get_cursor')) + eq({ 1, 16 }, api.nvim_win_get_cursor(0)) -- add deleted lines back set_text(0, 14, 0, 14, { ' first', @@ -1518,7 +1543,7 @@ describe('api/buf', function() 'and finally the last one', }, get_lines(0, -1, true)) -- cursor should return back to the original position - eq({ 3, 13 }, curwin('get_cursor')) + eq({ 3, 13 }, api.nvim_win_get_cursor(0)) end ) @@ -1531,7 +1556,7 @@ describe('api/buf', function() and finally the last one]]) -- position the cursor on 's' in 'last' - curwin('set_cursor', { 3, 18 }) + api.nvim_win_set_cursor(0, { 3, 18 }) set_text(0, 15, 2, 11, { 'the line we do not want', 'but hopefully', @@ -1542,7 +1567,7 @@ describe('api/buf', function() 'but hopefully the last one', }, get_lines(0, -1, true)) -- cursor should stay on 's' - eq({ 2, 20 }, curwin('get_cursor')) + eq({ 2, 20 }, api.nvim_win_get_cursor(0)) set_text(0, 15, 1, 13, { 'first', @@ -1556,7 +1581,7 @@ describe('api/buf', function() 'and finally the last one', }, get_lines(0, -1, true)) -- cursor should return back to the original position - eq({ 3, 18 }, curwin('get_cursor')) + eq({ 3, 18 }, api.nvim_win_get_cursor(0)) end ) @@ -1566,7 +1591,7 @@ describe('api/buf', function() ]]) -- position cursor at the empty line - curwin('set_cursor', { 2, 0 }) + api.nvim_win_set_cursor(0, { 2, 0 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 33, 1, 0, {'!'}) @@ -1575,7 +1600,7 @@ describe('api/buf', function() eq({ 'This should be the only line here!' }, get_lines(0, -1, true)) -- cursor should end up on '!' - eq({ 1, 33 }, curwin('get_cursor')) + eq({ 1, 33 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 33 }, cursor) end) @@ -1586,7 +1611,7 @@ describe('api/buf', function() eq({ '', '' }, get_lines(0, -1, true)) -- position cursor on the last '1' - curwin('set_cursor', { 2, 2 }) + api.nvim_win_set_cursor(0, { 2, 2 }) local cursor = exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 0, 1, 0, {''}) @@ -1595,7 +1620,7 @@ describe('api/buf', function() eq({ '' }, get_lines(0, -1, true)) -- cursor should end up on '!' - eq({ 1, 0 }, curwin('get_cursor')) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) -- immediate call to nvim_win_get_cursor should have returned the same position eq({ 1, 0 }, cursor) end) @@ -1607,46 +1632,46 @@ describe('api/buf', function() end) it('adjusts extmarks', function() - local ns = request('nvim_create_namespace', 'my-fancy-plugin') + local ns = api.nvim_create_namespace('my-fancy-plugin') insert([[ foo bar baz ]]) - local id1 = curbufmeths.set_extmark(ns, 0, 1, {}) - local id2 = curbufmeths.set_extmark(ns, 0, 7, {}) - local id3 = curbufmeths.set_extmark(ns, 1, 1, {}) + local id1 = api.nvim_buf_set_extmark(0, ns, 0, 1, {}) + local id2 = api.nvim_buf_set_extmark(0, ns, 0, 7, {}) + local id3 = api.nvim_buf_set_extmark(0, ns, 1, 1, {}) set_text(0, 4, 0, 7, { 'q' }) eq({ 'foo q', 'baz' }, get_lines(0, 2, true)) -- mark before replacement point is unaffected - eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {})) + eq({ 0, 1 }, api.nvim_buf_get_extmark_by_id(0, ns, id1, {})) -- mark gets shifted back because the replacement was shorter - eq({ 0, 5 }, curbufmeths.get_extmark_by_id(ns, id2, {})) + eq({ 0, 5 }, api.nvim_buf_get_extmark_by_id(0, ns, id2, {})) -- mark on the next line is unaffected - eq({ 1, 1 }, curbufmeths.get_extmark_by_id(ns, id3, {})) + eq({ 1, 1 }, api.nvim_buf_get_extmark_by_id(0, ns, id3, {})) -- replacing the text spanning two lines will adjust the mark on the next line set_text(0, 3, 1, 3, { 'qux' }) eq({ 'fooqux', '' }, get_lines(0, 2, true)) - eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id3, {})) + eq({ 0, 6 }, api.nvim_buf_get_extmark_by_id(0, ns, id3, {})) -- but mark before replacement point is still unaffected - eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {})) + eq({ 0, 1 }, api.nvim_buf_get_extmark_by_id(0, ns, id1, {})) -- and the mark in the middle was shifted to the end of the insertion - eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id2, {})) + eq({ 0, 6 }, api.nvim_buf_get_extmark_by_id(0, ns, id2, {})) -- marks should be put back into the same place after undoing set_text(0, 0, 0, 2, { '' }) feed('u') - eq({ 0, 1 }, curbufmeths.get_extmark_by_id(ns, id1, {})) - eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id2, {})) - eq({ 0, 6 }, curbufmeths.get_extmark_by_id(ns, id3, {})) + eq({ 0, 1 }, api.nvim_buf_get_extmark_by_id(0, ns, id1, {})) + eq({ 0, 6 }, api.nvim_buf_get_extmark_by_id(0, ns, id2, {})) + eq({ 0, 6 }, api.nvim_buf_get_extmark_by_id(0, ns, id3, {})) -- marks should be shifted over by the correct number of bytes for multibyte -- chars set_text(0, 0, 0, 0, { 'Ø' }) - eq({ 0, 3 }, curbufmeths.get_extmark_by_id(ns, id1, {})) - eq({ 0, 8 }, curbufmeths.get_extmark_by_id(ns, id2, {})) - eq({ 0, 8 }, curbufmeths.get_extmark_by_id(ns, id3, {})) + eq({ 0, 3 }, api.nvim_buf_get_extmark_by_id(0, ns, id1, {})) + eq({ 0, 8 }, api.nvim_buf_get_extmark_by_id(0, ns, id2, {})) + eq({ 0, 8 }, api.nvim_buf_get_extmark_by_id(0, ns, id3, {})) end) it('correctly marks changed region for redraw #13890', function() @@ -1658,7 +1683,7 @@ describe('api/buf', function() BBB ]]) - curbufmeths.set_text(0, 0, 1, 3, { 'XXX', 'YYY' }) + api.nvim_buf_set_text(0, 0, 0, 1, 3, { 'XXX', 'YYY' }) screen:expect([[ XXX | @@ -1693,7 +1718,7 @@ describe('api/buf', function() it('no heap-use-after-free when called consecutively #19643', function() set_text(0, 0, 0, 0, { 'one', '', '', 'two' }) eq({ 'one', '', '', 'two' }, get_lines(0, 4, true)) - meths.win_set_cursor(0, { 1, 0 }) + api.nvim_win_set_cursor(0, { 1, 0 }) exec_lua([[ vim.api.nvim_buf_set_text(0, 0, 3, 1, 0, {''}) vim.api.nvim_buf_set_text(0, 0, 3, 1, 0, {''}) @@ -1711,16 +1736,22 @@ describe('api/buf', function() [3] = { reverse = true }, } screen:attach() - meths.buf_set_lines(0, 0, -1, 1, { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' }) - meths.set_option_value('modified', false, {}) + api.nvim_buf_set_lines( + 0, + 0, + -1, + true, + { 'aaa', 'bbb', 'ccc', 'ddd', 'www', 'xxx', 'yyy', 'zzz' } + ) + api.nvim_set_option_value('modified', false, {}) end) it('of current window', function() - local win = meths.get_current_win() - local buf = meths.get_current_buf() + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('new | wincmd w') - meths.win_set_cursor(win, { 8, 0 }) + api.nvim_win_set_cursor(win, { 8, 0 }) screen:expect { grid = [[ @@ -1735,7 +1766,7 @@ describe('api/buf', function() | ]], } - meths.buf_set_text(buf, 0, 3, 1, 0, { 'X' }) + api.nvim_buf_set_text(buf, 0, 3, 1, 0, { 'X' }) screen:expect { grid = [[ @@ -1753,11 +1784,11 @@ describe('api/buf', function() end) it('of non-current window', function() - local win = meths.get_current_win() - local buf = meths.get_current_buf() + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('new') - meths.win_set_cursor(win, { 8, 0 }) + api.nvim_win_set_cursor(win, { 8, 0 }) screen:expect { grid = [[ @@ -1773,7 +1804,7 @@ describe('api/buf', function() ]], } - meths.buf_set_text(buf, 0, 3, 1, 0, { 'X' }) + api.nvim_buf_set_text(buf, 0, 3, 1, 0, { 'X' }) screen:expect { grid = [[ ^ | @@ -1790,12 +1821,12 @@ describe('api/buf', function() end) it('of split windows with same buffer', function() - local win = meths.get_current_win() - local buf = meths.get_current_buf() + local win = api.nvim_get_current_win() + local buf = api.nvim_get_current_buf() command('split') - meths.win_set_cursor(win, { 8, 0 }) - meths.win_set_cursor(0, { 1, 1 }) + api.nvim_win_set_cursor(win, { 8, 0 }) + api.nvim_win_set_cursor(0, { 1, 1 }) screen:expect { grid = [[ @@ -1813,7 +1844,7 @@ describe('api/buf', function() | ]], } - meths.buf_set_text(buf, 0, 3, 1, 0, { 'X' }) + api.nvim_buf_set_text(buf, 0, 3, 1, 0, { 'X' }) screen:expect { grid = [[ @@ -1835,8 +1866,8 @@ describe('api/buf', function() end) end) - describe_lua_and_rpc('nvim_buf_get_text', function(api) - local get_text = api.curbufmeths.get_text + describe_lua_and_rpc('nvim_buf_get_text', function(lua_or_rpc) + local get_text = lua_or_rpc.nvim_buf_get_text before_each(function() insert([[ hello foo! @@ -1845,105 +1876,105 @@ describe('api/buf', function() end) it('works', function() - eq({ 'hello' }, get_text(0, 0, 0, 5, {})) - eq({ 'hello foo!' }, get_text(0, 0, 0, 42, {})) - eq({ 'foo!' }, get_text(0, 6, 0, 10, {})) - eq({ 'foo!', 'tex' }, get_text(0, 6, 1, 3, {})) - eq({ 'foo!', 'tex' }, get_text(-3, 6, -2, 3, {})) - eq({ '' }, get_text(0, 18, 0, 20, {})) - eq({ 'ext' }, get_text(-2, 1, -2, 4, {})) - eq({ 'hello foo!', 'text', 'm' }, get_text(0, 0, 2, 1, {})) + eq({ 'hello' }, get_text(0, 0, 0, 0, 5, {})) + eq({ 'hello foo!' }, get_text(0, 0, 0, 0, 42, {})) + eq({ 'foo!' }, get_text(0, 0, 6, 0, 10, {})) + eq({ 'foo!', 'tex' }, get_text(0, 0, 6, 1, 3, {})) + eq({ 'foo!', 'tex' }, get_text(0, -3, 6, -2, 3, {})) + eq({ '' }, get_text(0, 0, 18, 0, 20, {})) + eq({ 'ext' }, get_text(0, -2, 1, -2, 4, {})) + eq({ 'hello foo!', 'text', 'm' }, get_text(0, 0, 0, 2, 1, {})) end) it('errors on out-of-range', function() - eq('Index out of bounds', pcall_err(get_text, 2, 0, 4, 0, {})) - eq('Index out of bounds', pcall_err(get_text, -4, 0, 0, 0, {})) - eq('Index out of bounds', pcall_err(get_text, 0, 0, 3, 0, {})) - eq('Index out of bounds', pcall_err(get_text, 0, 0, -4, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 2, 0, 4, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, -4, 0, 0, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, 0, 3, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, 0, -4, 0, {})) -- no ml_get errors should happen #19017 - eq('', meths.get_vvar('errmsg')) + eq('', api.nvim_get_vvar('errmsg')) end) it('errors when start is greater than end', function() - eq("'start' is higher than 'end'", pcall_err(get_text, 1, 0, 0, 0, {})) - eq('start_col must be less than end_col', pcall_err(get_text, 0, 1, 0, 0, {})) + eq("'start' is higher than 'end'", pcall_err(get_text, 0, 1, 0, 0, 0, {})) + eq('start_col must be less than end_col', pcall_err(get_text, 0, 0, 1, 0, 0, {})) end) end) describe('nvim_buf_get_offset', function() - local get_offset = curbufmeths.get_offset + local get_offset = api.nvim_buf_get_offset it('works', function() - curbufmeths.set_lines(0, -1, true, { 'Some\r', 'exa\000mple', '', 'buf\rfer', 'text' }) - eq(5, curbufmeths.line_count()) - eq(0, get_offset(0)) - eq(6, get_offset(1)) - eq(15, get_offset(2)) - eq(16, get_offset(3)) - eq(24, get_offset(4)) - eq(29, get_offset(5)) - eq('Index out of bounds', pcall_err(get_offset, 6)) - eq('Index out of bounds', pcall_err(get_offset, -1)) - - meths.set_option_value('eol', false, {}) - meths.set_option_value('fixeol', false, {}) - eq(28, get_offset(5)) + api.nvim_buf_set_lines(0, 0, -1, true, { 'Some\r', 'exa\000mple', '', 'buf\rfer', 'text' }) + eq(5, api.nvim_buf_line_count(0)) + eq(0, get_offset(0, 0)) + eq(6, get_offset(0, 1)) + eq(15, get_offset(0, 2)) + eq(16, get_offset(0, 3)) + eq(24, get_offset(0, 4)) + eq(29, get_offset(0, 5)) + eq('Index out of bounds', pcall_err(get_offset, 0, 6)) + eq('Index out of bounds', pcall_err(get_offset, 0, -1)) + + api.nvim_set_option_value('eol', false, {}) + api.nvim_set_option_value('fixeol', false, {}) + eq(28, get_offset(0, 5)) -- fileformat is ignored - meths.set_option_value('fileformat', 'dos', {}) - eq(0, get_offset(0)) - eq(6, get_offset(1)) - eq(15, get_offset(2)) - eq(16, get_offset(3)) - eq(24, get_offset(4)) - eq(28, get_offset(5)) - meths.set_option_value('eol', true, {}) - eq(29, get_offset(5)) + api.nvim_set_option_value('fileformat', 'dos', {}) + eq(0, get_offset(0, 0)) + eq(6, get_offset(0, 1)) + eq(15, get_offset(0, 2)) + eq(16, get_offset(0, 3)) + eq(24, get_offset(0, 4)) + eq(28, get_offset(0, 5)) + api.nvim_set_option_value('eol', true, {}) + eq(29, get_offset(0, 5)) command('set hidden') command('enew') - eq(6, bufmeths.get_offset(1, 1)) + eq(6, api.nvim_buf_get_offset(1, 1)) command('bunload! 1') - eq(-1, bufmeths.get_offset(1, 1)) - eq(-1, bufmeths.get_offset(1, 0)) + eq(-1, api.nvim_buf_get_offset(1, 1)) + eq(-1, api.nvim_buf_get_offset(1, 0)) end) it('works in empty buffer', function() - eq(0, get_offset(0)) - eq(1, get_offset(1)) - eq(-1, funcs.line2byte('$')) + eq(0, get_offset(0, 0)) + eq(1, get_offset(0, 1)) + eq(-1, fn.line2byte('$')) end) it('works in buffer with one line inserted', function() feed('itext') - eq(0, get_offset(0)) - eq(5, get_offset(1)) + eq(0, get_offset(0, 0)) + eq(5, get_offset(0, 1)) end) end) describe('nvim_buf_get_var, nvim_buf_set_var, nvim_buf_del_var', function() it('works', function() - curbuf('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) - eq({ 1, 2, { ['3'] = 1 } }, curbuf('get_var', 'lua')) - eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'b:lua')) - eq(1, funcs.exists('b:lua')) - curbufmeths.del_var('lua') - eq(0, funcs.exists('b:lua')) - eq('Key not found: lua', pcall_err(curbufmeths.del_var, 'lua')) - curbufmeths.set_var('lua', 1) + api.nvim_buf_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_buf_get_var(0, 'lua')) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_eval('b:lua')) + eq(1, fn.exists('b:lua')) + api.nvim_buf_del_var(0, 'lua') + eq(0, fn.exists('b:lua')) + eq('Key not found: lua', pcall_err(api.nvim_buf_del_var, 0, 'lua')) + api.nvim_buf_set_var(0, 'lua', 1) command('lockvar b:lua') - eq('Key is locked: lua', pcall_err(curbufmeths.del_var, 'lua')) - eq('Key is locked: lua', pcall_err(curbufmeths.set_var, 'lua', 1)) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, 'changedtick')) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.set_var, 'changedtick', 1)) + eq('Key is locked: lua', pcall_err(api.nvim_buf_del_var, 0, 'lua')) + eq('Key is locked: lua', pcall_err(api.nvim_buf_set_var, 0, 'lua', 1)) + eq('Key is read-only: changedtick', pcall_err(api.nvim_buf_del_var, 0, 'changedtick')) + eq('Key is read-only: changedtick', pcall_err(api.nvim_buf_set_var, 0, 'changedtick', 1)) end) end) describe('nvim_buf_get_changedtick', function() it('works', function() - eq(2, curbufmeths.get_changedtick()) - curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' }) - eq(3, curbufmeths.get_changedtick()) - eq(3, curbufmeths.get_var('changedtick')) + eq(2, api.nvim_buf_get_changedtick(0)) + api.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' }) + eq(3, api.nvim_buf_get_changedtick(0)) + eq(3, api.nvim_buf_get_var(0, 'changedtick')) end) it('buffer_set_var returns the old value', function() @@ -1964,33 +1995,33 @@ describe('api/buf', function() describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - eq(8, nvim('get_option_value', 'shiftwidth', {})) - nvim('set_option_value', 'shiftwidth', 4, {}) - eq(4, nvim('get_option_value', 'shiftwidth', {})) + eq(8, api.nvim_get_option_value('shiftwidth', {})) + api.nvim_set_option_value('shiftwidth', 4, {}) + eq(4, api.nvim_get_option_value('shiftwidth', {})) -- global-local option - nvim('set_option_value', 'define', 'test', { buf = 0 }) - eq('test', nvim('get_option_value', 'define', { buf = 0 })) + api.nvim_set_option_value('define', 'test', { buf = 0 }) + eq('test', api.nvim_get_option_value('define', { buf = 0 })) -- Doesn't change the global value - eq('', nvim('get_option_value', 'define', { scope = 'global' })) + eq('', api.nvim_get_option_value('define', { scope = 'global' })) end) it('returns values for unset local options', function() -- 'undolevels' is only set to its "unset" value when a new buffer is -- created command('enew') - eq(-123456, nvim('get_option_value', 'undolevels', { buf = 0 })) + eq(-123456, api.nvim_get_option_value('undolevels', { buf = 0 })) end) end) describe('nvim_buf_get_name, nvim_buf_set_name', function() it('works', function() - nvim('command', 'new') - eq('', curbuf('get_name')) - local new_name = nvim('eval', 'resolve(tempname())') - curbuf('set_name', new_name) - eq(new_name, curbuf('get_name')) - nvim('command', 'w!') - eq(1, funcs.filereadable(new_name)) + command('new') + eq('', api.nvim_buf_get_name(0)) + local new_name = api.nvim_eval('resolve(tempname())') + api.nvim_buf_set_name(0, new_name) + eq(new_name, api.nvim_buf_get_name(0)) + command('w!') + eq(1, fn.filereadable(new_name)) os.remove(new_name) end) end) @@ -1998,121 +2029,121 @@ describe('api/buf', function() describe('nvim_buf_is_loaded', function() it('works', function() -- record our buffer number for when we unload it - local bufnr = curbuf('get_number') + local bufnr = api.nvim_buf_get_number(0) -- api should report that the buffer is loaded - ok(buffer('is_loaded', bufnr)) + ok(api.nvim_buf_is_loaded(bufnr)) -- hide the current buffer by switching to a new empty buffer -- Careful! we need to modify the buffer first or vim will just reuse it - buffer('set_lines', bufnr, 0, -1, 1, { 'line1' }) + api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'line1' }) command('hide enew') -- confirm the buffer is hidden, but still loaded - local infolist = nvim('eval', 'getbufinfo(' .. bufnr .. ')') + local infolist = api.nvim_eval('getbufinfo(' .. bufnr .. ')') eq(1, #infolist) eq(1, infolist[1].hidden) eq(1, infolist[1].loaded) -- now force unload the buffer command('bunload! ' .. bufnr) -- confirm the buffer is unloaded - infolist = nvim('eval', 'getbufinfo(' .. bufnr .. ')') + infolist = api.nvim_eval('getbufinfo(' .. bufnr .. ')') eq(0, infolist[1].loaded) -- nvim_buf_is_loaded() should also report the buffer as unloaded - eq(false, buffer('is_loaded', bufnr)) + eq(false, api.nvim_buf_is_loaded(bufnr)) end) end) describe('nvim_buf_is_valid', function() it('works', function() - nvim('command', 'new') - local b = nvim('get_current_buf') - ok(buffer('is_valid', b)) - nvim('command', 'bw!') - ok(not buffer('is_valid', b)) + command('new') + local b = api.nvim_get_current_buf() + ok(api.nvim_buf_is_valid(b)) + command('bw!') + ok(not api.nvim_buf_is_valid(b)) end) end) describe('nvim_buf_delete', function() it('allows for just deleting', function() - nvim('command', 'new') - local b = nvim('get_current_buf') - ok(buffer('is_valid', b)) - nvim('buf_delete', b, {}) - ok(not buffer('is_loaded', b)) - ok(not buffer('is_valid', b)) + command('new') + local b = api.nvim_get_current_buf() + ok(api.nvim_buf_is_valid(b)) + api.nvim_buf_delete(b, {}) + ok(not api.nvim_buf_is_loaded(b)) + ok(not api.nvim_buf_is_valid(b)) end) it('allows for just unloading', function() - nvim('command', 'new') - local b = nvim('get_current_buf') - ok(buffer('is_valid', b)) - nvim('buf_delete', b, { unload = true }) - ok(not buffer('is_loaded', b)) - ok(buffer('is_valid', b)) + command('new') + local b = api.nvim_get_current_buf() + ok(api.nvim_buf_is_valid(b)) + api.nvim_buf_delete(b, { unload = true }) + ok(not api.nvim_buf_is_loaded(b)) + ok(api.nvim_buf_is_valid(b)) end) end) describe('nvim_buf_get_mark', function() it('works', function() - curbuf('set_lines', -1, -1, true, { 'a', 'bit of', 'text' }) - curwin('set_cursor', { 3, 4 }) - nvim('command', 'mark v') - eq({ 3, 0 }, curbuf('get_mark', 'v')) + api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + api.nvim_win_set_cursor(0, { 3, 4 }) + command('mark v') + eq({ 3, 0 }, api.nvim_buf_get_mark(0, 'v')) end) end) describe('nvim_buf_set_mark', function() it('works with buffer local marks', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - eq(true, curbufmeths.set_mark('z', 1, 1, {})) - eq({ 1, 1 }, curbufmeths.get_mark('z')) - eq({ 0, 1, 2, 0 }, funcs.getpos("'z")) + api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + eq(true, api.nvim_buf_set_mark(0, 'z', 1, 1, {})) + eq({ 1, 1 }, api.nvim_buf_get_mark(0, 'z')) + eq({ 0, 1, 2, 0 }, fn.getpos("'z")) end) it('works with file/uppercase marks', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - eq(true, curbufmeths.set_mark('Z', 3, 2, {})) - eq({ 3, 2 }, curbufmeths.get_mark('Z')) - eq({ curbuf().id, 3, 3, 0 }, funcs.getpos("'Z")) + api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + eq(true, api.nvim_buf_set_mark(0, 'Z', 3, 2, {})) + eq({ 3, 2 }, api.nvim_buf_get_mark(0, 'Z')) + eq({ api.nvim_get_current_buf().id, 3, 3, 0 }, fn.getpos("'Z")) end) it('fails when invalid marks names are used', function() - eq(false, pcall(curbufmeths.set_mark, '!', 1, 0, {})) - eq(false, pcall(curbufmeths.set_mark, 'fail', 1, 0, {})) + eq(false, pcall(api.nvim_buf_set_mark, 0, '!', 1, 0, {})) + eq(false, pcall(api.nvim_buf_set_mark, 0, 'fail', 1, 0, {})) end) it('fails when invalid buffer number is used', function() - eq(false, pcall(meths.buf_set_mark, 99, 'a', 1, 1, {})) + eq(false, pcall(api.nvim_buf_set_mark, 99, 'a', 1, 1, {})) end) end) describe('nvim_buf_del_mark', function() it('works with buffer local marks', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - curbufmeths.set_mark('z', 3, 1, {}) - eq(true, curbufmeths.del_mark('z')) - eq({ 0, 0 }, curbufmeths.get_mark('z')) + api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + api.nvim_buf_set_mark(0, 'z', 3, 1, {}) + eq(true, api.nvim_buf_del_mark(0, 'z')) + eq({ 0, 0 }, api.nvim_buf_get_mark(0, 'z')) end) it('works with file/uppercase marks', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - curbufmeths.set_mark('Z', 3, 3, {}) - eq(true, curbufmeths.del_mark('Z')) - eq({ 0, 0 }, curbufmeths.get_mark('Z')) + api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + api.nvim_buf_set_mark(0, 'Z', 3, 3, {}) + eq(true, api.nvim_buf_del_mark(0, 'Z')) + eq({ 0, 0 }, api.nvim_buf_get_mark(0, 'Z')) end) it('returns false in marks not set in this buffer', function() - local abuf = meths.create_buf(false, true) - bufmeths.set_lines(abuf, -1, -1, true, { 'a', 'bit of', 'text' }) - bufmeths.set_mark(abuf, 'A', 2, 2, {}) - eq(false, curbufmeths.del_mark('A')) - eq({ 2, 2 }, bufmeths.get_mark(abuf, 'A')) + local abuf = api.nvim_create_buf(false, true) + api.nvim_buf_set_lines(abuf, -1, -1, true, { 'a', 'bit of', 'text' }) + api.nvim_buf_set_mark(abuf, 'A', 2, 2, {}) + eq(false, api.nvim_buf_del_mark(0, 'A')) + eq({ 2, 2 }, api.nvim_buf_get_mark(abuf, 'A')) end) it('returns false if mark was not deleted', function() - curbufmeths.set_lines(-1, -1, true, { 'a', 'bit of', 'text' }) - curbufmeths.set_mark('z', 3, 1, {}) - eq(true, curbufmeths.del_mark('z')) - eq(false, curbufmeths.del_mark('z')) -- Mark was already deleted + api.nvim_buf_set_lines(0, -1, -1, true, { 'a', 'bit of', 'text' }) + api.nvim_buf_set_mark(0, 'z', 3, 1, {}) + eq(true, api.nvim_buf_del_mark(0, 'z')) + eq(false, api.nvim_buf_del_mark(0, 'z')) -- Mark was already deleted end) it('fails when invalid marks names are used', function() - eq(false, pcall(curbufmeths.del_mark, '!')) - eq(false, pcall(curbufmeths.del_mark, 'fail')) + eq(false, pcall(api.nvim_buf_del_mark, 0, '!')) + eq(false, pcall(api.nvim_buf_del_mark, 0, 'fail')) end) it('fails when invalid buffer number is used', function() - eq(false, pcall(meths.buf_del_mark, 99, 'a')) + eq(false, pcall(api.nvim_buf_del_mark, 99, 'a')) end) end) end) diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 8e43d28322..40fa129772 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -1,12 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq, ok = helpers.eq, helpers.ok -local funcs = helpers.funcs -local buffer, command, eval, nvim, next_msg = - helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg +local fn = helpers.fn +local api = helpers.api +local command, eval, next_msg = helpers.command, helpers.eval, helpers.next_msg local nvim_prog = helpers.nvim_prog local pcall_err = helpers.pcall_err -local sleep = helpers.sleep +local sleep = vim.uv.sleep local write_file = helpers.write_file local origlines = { @@ -24,7 +24,7 @@ local function expectn(name, args) end local function sendkeys(keys) - nvim('input', keys) + api.nvim_input(keys) -- give nvim some time to process msgpack requests before possibly sending -- more key presses - otherwise they all pile up in the queue and get -- processed at once @@ -37,7 +37,7 @@ local function open(activate, lines) local filename = helpers.tmpname() write_file(filename, table.concat(lines, '\n') .. '\n', true) command('edit ' .. filename) - local b = nvim('get_current_buf') + local b = api.nvim_get_current_buf() -- what is the value of b:changedtick? local tick = eval('b:changedtick') @@ -45,7 +45,7 @@ local function open(activate, lines) -- arrive as expected if activate then local firstline = 0 - ok(buffer('attach', b, true, {})) + ok(api.nvim_buf_attach(b, true, {})) expectn('nvim_buf_lines_event', { b, tick, firstline, -1, lines, false }) end @@ -62,12 +62,12 @@ local function editoriginal(activate, lines) end local function reopen(buf, expectedlines) - ok(buffer('detach', buf)) + ok(api.nvim_buf_detach(buf)) expectn('nvim_buf_detach_event', { buf }) -- for some reason the :edit! increments tick by 2 command('edit!') local tick = eval('b:changedtick') - ok(buffer('attach', buf, true, {})) + ok(api.nvim_buf_attach(buf, true, {})) local firstline = 0 expectn('nvim_buf_lines_event', { buf, tick, firstline, -1, expectedlines, false }) command('normal! gg') @@ -197,21 +197,21 @@ describe('API: buffer events:', function() -- add a line at the start of an empty file command('enew') tick = eval('b:changedtick') - local b2 = nvim('get_current_buf') - ok(buffer('attach', b2, true, {})) + local b2 = api.nvim_get_current_buf() + ok(api.nvim_buf_attach(b2, true, {})) expectn('nvim_buf_lines_event', { b2, tick, 0, -1, { '' }, false }) eval('append(0, ["new line 1"])') tick = tick + 1 expectn('nvim_buf_lines_event', { b2, tick, 0, 0, { 'new line 1' }, false }) -- turn off buffer events manually - buffer('detach', b2) + api.nvim_buf_detach(b2) expectn('nvim_buf_detach_event', { b2 }) -- add multiple lines to a blank file command('enew!') - local b3 = nvim('get_current_buf') - ok(buffer('attach', b3, true, {})) + local b3 = api.nvim_get_current_buf() + ok(api.nvim_buf_attach(b3, true, {})) tick = eval('b:changedtick') expectn('nvim_buf_lines_event', { b3, tick, 0, -1, { '' }, false }) eval('append(0, ["new line 1", "new line 2", "new line 3"])') @@ -222,7 +222,7 @@ describe('API: buffer events:', function() ) -- use the API itself to add a line to the start of the buffer - buffer('set_lines', b3, 0, 0, true, { 'New First Line' }) + api.nvim_buf_set_lines(b3, 0, 0, true, { 'New First Line' }) tick = tick + 1 expectn('nvim_buf_lines_event', { b3, tick, 0, 0, { 'New First Line' }, false }) end) @@ -306,8 +306,8 @@ describe('API: buffer events:', function() command('bdelete!') tick = 2 expectn('nvim_buf_detach_event', { b }) - local bnew = nvim('get_current_buf') - ok(buffer('attach', bnew, true, {})) + local bnew = api.nvim_get_current_buf() + ok(api.nvim_buf_attach(bnew, true, {})) expectn('nvim_buf_lines_event', { bnew, tick, 0, -1, { '' }, false }) sendkeys('i') sendkeys('h') @@ -482,25 +482,25 @@ describe('API: buffer events:', function() end) it('does not get confused if enabled/disabled many times', function() - local channel = nvim('get_api_info')[1] + local channel = api.nvim_get_api_info()[1] local b, tick = editoriginal(false) -- Enable buffer events many times. - ok(buffer('attach', b, true, {})) - ok(buffer('attach', b, true, {})) - ok(buffer('attach', b, true, {})) - ok(buffer('attach', b, true, {})) - ok(buffer('attach', b, true, {})) + ok(api.nvim_buf_attach(b, true, {})) + ok(api.nvim_buf_attach(b, true, {})) + ok(api.nvim_buf_attach(b, true, {})) + ok(api.nvim_buf_attach(b, true, {})) + ok(api.nvim_buf_attach(b, true, {})) expectn('nvim_buf_lines_event', { b, tick, 0, -1, origlines, false }) eval('rpcnotify(' .. channel .. ', "Hello There")') expectn('Hello There', {}) -- Disable buffer events many times. - ok(buffer('detach', b)) - ok(buffer('detach', b)) - ok(buffer('detach', b)) - ok(buffer('detach', b)) - ok(buffer('detach', b)) + ok(api.nvim_buf_detach(b)) + ok(api.nvim_buf_detach(b)) + ok(api.nvim_buf_detach(b)) + ok(api.nvim_buf_detach(b)) + ok(api.nvim_buf_detach(b)) expectn('nvim_buf_detach_event', { b }) eval('rpcnotify(' .. channel .. ', "Hello Again")') expectn('Hello Again', {}) @@ -583,7 +583,7 @@ describe('API: buffer events:', function() it('works with :diffput and :diffget', function() local b1, tick1 = editoriginal(true, { 'AAA', 'BBB' }) - local channel = nvim('get_api_info')[1] + local channel = api.nvim_get_api_info()[1] command('diffthis') command('rightbelow vsplit') local b2, tick2 = open(true, { 'BBB', 'CCC' }) @@ -700,7 +700,7 @@ describe('API: buffer events:', function() it('detaches if the buffer is closed', function() local b, tick = editoriginal(true, { 'AAA' }) - local channel = nvim('get_api_info')[1] + local channel = api.nvim_get_api_info()[1] -- Test that buffer events are working. command('normal! x') @@ -739,7 +739,7 @@ describe('API: buffer events:', function() it(':enew! does not detach hidden buffer', function() local b, tick = editoriginal(true, { 'AAA', 'BBB' }) - local channel = nvim('get_api_info')[1] + local channel = api.nvim_get_api_info()[1] command('set undoreload=1 hidden') command('normal! x') @@ -753,7 +753,7 @@ describe('API: buffer events:', function() it('stays attached if the buffer is hidden', function() local b, tick = editoriginal(true, { 'AAA' }) - local channel = nvim('get_api_info')[1] + local channel = api.nvim_get_api_info()[1] -- Test that buffer events are working. command('normal! x') @@ -800,14 +800,14 @@ describe('API: buffer events:', function() it('does not send the buffer content if not requested', function() clear() local b, tick = editoriginal(false) - ok(buffer('attach', b, false, {})) + ok(api.nvim_buf_attach(b, false, {})) expectn('nvim_buf_changedtick_event', { b, tick }) end) it('returns a proper error on nonempty options dict', function() clear() local b = editoriginal(false) - eq("Invalid key: 'builtin'", pcall_err(buffer, 'attach', b, false, { builtin = 'asfd' })) + eq("Invalid key: 'builtin'", pcall_err(api.nvim_buf_attach, b, false, { builtin = 'asfd' })) end) it('nvim_buf_attach returns response after delay #8634', function() @@ -879,12 +879,12 @@ describe('API: buffer events:', function() it('when :terminal lines change', function() local buffer_lines = {} local expected_lines = {} - funcs.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, { + fn.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) - local b = nvim('get_current_buf') - ok(buffer('attach', b, true, {})) + local b = api.nvim_get_current_buf() + ok(api.nvim_buf_attach(b, true, {})) for _ = 1, 22 do table.insert(expected_lines, '~') diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua index e286181bce..f73b9c8b13 100644 --- a/test/functional/api/command_spec.lua +++ b/test/functional/api/command_spec.lua @@ -1,19 +1,17 @@ local helpers = require('test.functional.helpers')(after_each) -local NIL = helpers.NIL +local NIL = vim.NIL local clear = helpers.clear local command = helpers.command -local curbufmeths = helpers.curbufmeths local eq = helpers.eq -local meths = helpers.meths -local bufmeths = helpers.bufmeths +local api = helpers.api local matches = helpers.matches local source = helpers.source local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua local assert_alive = helpers.assert_alive local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn describe('nvim_get_commands', function() local cmd_dict = { @@ -51,39 +49,39 @@ describe('nvim_get_commands', function() before_each(clear) it('gets empty list if no commands were defined', function() - eq({}, meths.get_commands({ builtin = false })) + eq({}, api.nvim_get_commands({ builtin = false })) end) it('validation', function() - eq('builtin=true not implemented', pcall_err(meths.get_commands, { builtin = true })) - eq("Invalid key: 'foo'", pcall_err(meths.get_commands, { foo = 'blah' })) + eq('builtin=true not implemented', pcall_err(api.nvim_get_commands, { builtin = true })) + eq("Invalid key: 'foo'", pcall_err(api.nvim_get_commands, { foo = 'blah' })) end) it('gets global user-defined commands', function() -- Define a command. command('command -nargs=1 Hello echo "Hello World"') - eq({ Hello = cmd_dict }, meths.get_commands({ builtin = false })) + eq({ Hello = cmd_dict }, api.nvim_get_commands({ builtin = false })) -- Define another command. command('command -nargs=? Pwd pwd') - eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.get_commands({ builtin = false })) + eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, api.nvim_get_commands({ builtin = false })) -- Delete a command. command('delcommand Pwd') - eq({ Hello = cmd_dict }, meths.get_commands({ builtin = false })) + eq({ Hello = cmd_dict }, api.nvim_get_commands({ builtin = false })) end) it('gets buffer-local user-defined commands', function() -- Define a buffer-local command. command('command -buffer -nargs=1 Hello echo "Hello World"') - eq({ Hello = cmd_dict }, curbufmeths.get_commands({ builtin = false })) + eq({ Hello = cmd_dict }, api.nvim_buf_get_commands(0, { builtin = false })) -- Define another buffer-local command. command('command -buffer -nargs=? Pwd pwd') - eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, curbufmeths.get_commands({ builtin = false })) + eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, api.nvim_buf_get_commands(0, { builtin = false })) -- Delete a command. command('delcommand Pwd') - eq({ Hello = cmd_dict }, curbufmeths.get_commands({ builtin = false })) + eq({ Hello = cmd_dict }, api.nvim_buf_get_commands(0, { builtin = false })) -- {builtin=true} always returns empty for buffer-local case. - eq({}, curbufmeths.get_commands({ builtin = true })) + eq({}, api.nvim_buf_get_commands(0, { builtin = true })) end) it('gets various command attributes', function() @@ -171,9 +169,9 @@ describe('nvim_get_commands', function() let s:foo = 1 command -complete=custom,ListUsers -nargs=+ Finger !finger <args> ]]) - eq({ Finger = cmd1 }, meths.get_commands({ builtin = false })) + eq({ Finger = cmd1 }, api.nvim_get_commands({ builtin = false })) command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>') - eq({ Finger = cmd1, TestCmd = cmd0 }, meths.get_commands({ builtin = false })) + eq({ Finger = cmd1, TestCmd = cmd0 }, api.nvim_get_commands({ builtin = false })) source([[ function! s:foo() abort @@ -193,7 +191,7 @@ describe('nvim_get_commands', function() -- TODO(justinmk): Order is stable but undefined. Sort before return? eq( { Cmd2 = cmd2, Cmd3 = cmd3, Cmd4 = cmd4, Finger = cmd1, TestCmd = cmd0 }, - meths.get_commands({ builtin = false }) + api.nvim_get_commands({ builtin = false }) ) end) end) @@ -202,9 +200,9 @@ describe('nvim_create_user_command', function() before_each(clear) it('works with strings', function() - meths.create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 }) - meths.command('SomeCommand 42') - eq(42, meths.eval('g:command_fired')) + api.nvim_create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 }) + command('SomeCommand 42') + eq(42, api.nvim_eval('g:command_fired')) end) it('works with Lua functions', function() @@ -646,11 +644,11 @@ describe('nvim_create_user_command', function() end) it('can define buffer-local commands', function() - local bufnr = meths.create_buf(false, false) - bufmeths.create_user_command(bufnr, 'Hello', '', {}) - matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello')) - meths.set_current_buf(bufnr) - meths.command('Hello') + local bufnr = api.nvim_create_buf(false, false) + api.nvim_buf_create_user_command(bufnr, 'Hello', '', {}) + matches('Not an editor command: Hello', pcall_err(command, 'Hello')) + api.nvim_set_current_buf(bufnr) + command('Hello') assert_alive() end) @@ -672,9 +670,9 @@ describe('nvim_create_user_command', function() ]] feed(':Test a<Tab>') - eq('Test aaa', funcs.getcmdline()) + eq('Test aaa', fn.getcmdline()) feed('<C-U>Test b<Tab>') - eq('Test bbb', funcs.getcmdline()) + eq('Test bbb', fn.getcmdline()) end) it('does not allow invalid command names', function() @@ -731,29 +729,29 @@ describe('nvim_create_user_command', function() vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {}) end, {}) ]] - eq('3', meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true })) + eq('3', api.nvim_cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true })) - eq(1, #meths.list_tabpages()) + eq(1, #api.nvim_list_tabpages()) exec_lua [[ vim.api.nvim_create_user_command('MySplit', function(opts) vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {}) end, {}) ]] - meths.cmd({ cmd = 'MySplit' }, {}) - eq(1, #meths.list_tabpages()) - eq(2, #meths.list_wins()) - meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) - eq(2, #meths.list_tabpages()) - eq(2, funcs.tabpagenr()) - meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) - eq(3, #meths.list_tabpages()) - eq(2, funcs.tabpagenr()) - meths.cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {}) - eq(4, #meths.list_tabpages()) - eq(4, funcs.tabpagenr()) - meths.cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {}) - eq(5, #meths.list_tabpages()) - eq(1, funcs.tabpagenr()) + api.nvim_cmd({ cmd = 'MySplit' }, {}) + eq(1, #api.nvim_list_tabpages()) + eq(2, #api.nvim_list_wins()) + api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) + eq(2, #api.nvim_list_tabpages()) + eq(2, fn.tabpagenr()) + api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) + eq(3, #api.nvim_list_tabpages()) + eq(2, fn.tabpagenr()) + api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {}) + eq(4, #api.nvim_list_tabpages()) + eq(4, fn.tabpagenr()) + api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {}) + eq(5, #api.nvim_list_tabpages()) + eq(1, fn.tabpagenr()) end) end) @@ -761,16 +759,16 @@ describe('nvim_del_user_command', function() before_each(clear) it('can delete global commands', function() - meths.create_user_command('Hello', 'echo "Hi"', {}) - meths.command('Hello') - meths.del_user_command('Hello') - matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello')) + api.nvim_create_user_command('Hello', 'echo "Hi"', {}) + command('Hello') + api.nvim_del_user_command('Hello') + matches('Not an editor command: Hello', pcall_err(command, 'Hello')) end) it('can delete buffer-local commands', function() - bufmeths.create_user_command(0, 'Hello', 'echo "Hi"', {}) - meths.command('Hello') - bufmeths.del_user_command(0, 'Hello') - matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello')) + api.nvim_buf_create_user_command(0, 'Hello', 'echo "Hi"', {}) + command('Hello') + api.nvim_buf_del_user_command(0, 'Hello') + matches('Not an editor command: Hello', pcall_err(command, 'Hello')) end) end) diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 0594f36d0e..ed7c52971d 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -4,15 +4,13 @@ local Screen = require('test.functional.ui.screen') local request = helpers.request local eq = helpers.eq local ok = helpers.ok -local curbufmeths = helpers.curbufmeths -local bufmeths = helpers.bufmeths local pcall_err = helpers.pcall_err local insert = helpers.insert local feed = helpers.feed local clear = helpers.clear local command = helpers.command local exec = helpers.exec -local meths = helpers.meths +local api = helpers.api local assert_alive = helpers.assert_alive local function expect(contents) @@ -26,21 +24,21 @@ local function set_extmark(ns_id, id, line, col, opts) if id ~= nil and id ~= 0 then opts.id = id end - return curbufmeths.set_extmark(ns_id, line, col, opts) + return api.nvim_buf_set_extmark(0, ns_id, line, col, opts) end local function get_extmarks(ns_id, start, end_, opts) if opts == nil then opts = {} end - return curbufmeths.get_extmarks(ns_id, start, end_, opts) + return api.nvim_buf_get_extmarks(0, ns_id, start, end_, opts) end local function get_extmark_by_id(ns_id, id, opts) if opts == nil then opts = {} end - return curbufmeths.get_extmark_by_id(ns_id, id, opts) + return api.nvim_buf_get_extmark_by_id(0, ns_id, id, opts) end local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end @@ -198,11 +196,11 @@ describe('API/extmarks', function() eq({ row, col }, rv) -- remove the test marks - eq(true, curbufmeths.del_extmark(ns, marks[1])) - eq(false, curbufmeths.del_extmark(ns, marks[1])) - eq(true, curbufmeths.del_extmark(ns, marks[2])) - eq(false, curbufmeths.del_extmark(ns, marks[3])) - eq(false, curbufmeths.del_extmark(ns, 1000)) + eq(true, api.nvim_buf_del_extmark(0, ns, marks[1])) + eq(false, api.nvim_buf_del_extmark(0, ns, marks[1])) + eq(true, api.nvim_buf_del_extmark(0, ns, marks[2])) + eq(false, api.nvim_buf_del_extmark(0, ns, marks[3])) + eq(false, api.nvim_buf_del_extmark(0, ns, 1000)) end) it('can clear a specific namespace range', function() @@ -210,7 +208,7 @@ describe('API/extmarks', function() set_extmark(ns2, 1, 0, 1) -- force a new undo buffer feed('o<esc>') - curbufmeths.clear_namespace(ns2, 0, -1) + api.nvim_buf_clear_namespace(0, ns2, 0, -1) eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) feed('u') @@ -226,7 +224,7 @@ describe('API/extmarks', function() set_extmark(ns2, 1, 0, 1) -- force a new undo buffer feed('o<esc>') - curbufmeths.clear_namespace(-1, 0, -1) + api.nvim_buf_clear_namespace(0, -1, 0, -1) eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) feed('u') @@ -244,14 +242,14 @@ describe('API/extmarks', function() eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) feed('dd') eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) - curbufmeths.clear_namespace(ns, 0, -1) + api.nvim_buf_clear_namespace(0, ns, 0, -1) eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) set_extmark(ns, 1, 0, 0, { right_gravity = false }) set_extmark(ns, 2, 1, 0, { right_gravity = false }) eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) feed('u') eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) - curbufmeths.clear_namespace(ns, 0, -1) + api.nvim_buf_clear_namespace(0, ns, 0, -1) end) it('querying for information and ranges', function() @@ -933,7 +931,7 @@ describe('API/extmarks', function() -- Test unset feed('o<esc>') - curbufmeths.del_extmark(ns, marks[3]) + api.nvim_buf_del_extmark(0, ns, marks[3]) feed('u') rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) -- undo does NOT restore deleted marks @@ -989,10 +987,10 @@ describe('API/extmarks', function() rv = get_extmarks(ns2, positions[2], positions[1]) eq(2, #rv) - curbufmeths.del_extmark(ns, marks[1]) + api.nvim_buf_del_extmark(0, ns, marks[1]) rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) eq(2, #rv) - curbufmeths.del_extmark(ns2, marks[1]) + api.nvim_buf_del_extmark(0, ns2, marks[1]) rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 }) eq(2, #rv) end) @@ -1429,7 +1427,7 @@ describe('API/extmarks', function() "Invalid 'ns_id': 3", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]) ) - eq("Invalid 'ns_id': 3", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1])) + eq("Invalid 'ns_id': 3", pcall_err(api.nvim_buf_del_extmark, 0, ns_invalid, marks[1])) eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2])) eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1])) end) @@ -1472,7 +1470,7 @@ describe('API/extmarks', function() it('in read-only buffer', function() command('view! runtime/doc/help.txt') - eq(true, meths.get_option_value('ro', {})) + eq(true, api.nvim_get_option_value('ro', {})) local id = set_extmark(ns, 0, 0, 2) eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1)) end) @@ -1480,8 +1478,8 @@ describe('API/extmarks', function() it('can set a mark to other buffer', function() local buf = request('nvim_create_buf', 0, 1) request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' }) - local id = bufmeths.set_extmark(buf, ns, 1, 0, {}) - eq({ { id, 1, 0 } }, bufmeths.get_extmarks(buf, ns, 0, -1, {})) + local id = api.nvim_buf_set_extmark(buf, ns, 1, 0, {}) + eq({ { id, 1, 0 } }, api.nvim_buf_get_extmarks(buf, ns, 0, -1, {})) end) it('does not crash with append/delete/undo sequence', function() @@ -1497,30 +1495,30 @@ describe('API/extmarks', function() it('works with left and right gravity', function() -- right gravity should move with inserted text, while -- left gravity should stay in place. - curbufmeths.set_extmark(ns, 0, 5, { right_gravity = false }) - curbufmeths.set_extmark(ns, 0, 5, { right_gravity = true }) + api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = false }) + api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true }) feed([[Aasdfasdf]]) - eq({ { 1, 0, 5 }, { 2, 0, 13 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) + eq({ { 1, 0, 5 }, { 2, 0, 13 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {})) -- but both move when text is inserted before feed([[<esc>Iasdf<esc>]]) - -- eq({}, curbufmeths.get_lines(0, -1, true)) - eq({ { 1, 0, 9 }, { 2, 0, 17 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) + -- eq({}, api.nvim_buf_get_lines(0, 0, -1, true)) + eq({ { 1, 0, 9 }, { 2, 0, 17 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {})) -- clear text - curbufmeths.set_text(0, 0, 0, 17, {}) + api.nvim_buf_set_text(0, 0, 0, 0, 17, {}) -- handles set_text correctly as well - eq({ { 1, 0, 0 }, { 2, 0, 0 } }, meths.buf_get_extmarks(0, ns, 0, -1, {})) - curbufmeths.set_text(0, 0, 0, 0, { 'asdfasdf' }) - eq({ { 1, 0, 0 }, { 2, 0, 8 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) + eq({ { 1, 0, 0 }, { 2, 0, 0 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {})) + api.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' }) + eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {})) feed('u') -- handles pasting exec([[let @a='asdfasdf']]) feed([["ap]]) - eq({ { 1, 0, 0 }, { 2, 0, 8 } }, meths.buf_get_extmarks(0, ns, 0, -1, {})) + eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {})) end) it('can accept "end_row" or "end_line" #16548', function() @@ -1547,7 +1545,7 @@ describe('API/extmarks', function() it('in prompt buffer', function() feed('dd') local id = set_extmark(ns, marks[1], 0, 0, {}) - meths.set_option_value('buftype', 'prompt', {}) + api.nvim_set_option_value('buftype', 'prompt', {}) feed('i<esc>') eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1)) end) @@ -1641,7 +1639,7 @@ describe('API/extmarks', function() right_gravity = true, }, }, get_extmark_by_id(ns, marks[3], { details = true })) - curbufmeths.clear_namespace(ns, 0, -1) + api.nvim_buf_clear_namespace(0, ns, 0, -1) -- legacy sign mark includes sign name command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine') command('sign place 1 name=sign1 line=1') @@ -1695,7 +1693,7 @@ describe('API/extmarks', function() screen = Screen.new(40, 6) screen:attach() feed('dd6iaaa bbb ccc<CR><ESC>gg') - meths.set_option_value('signcolumn', 'auto:2', {}) + api.nvim_set_option_value('signcolumn', 'auto:2', {}) set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1', end_row = 1 }) set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2', end_row = 2 }) -- mark with invalidate is removed @@ -1770,7 +1768,7 @@ describe('Extmarks buffer api with many marks', function() for i = 1, 30 do lines[#lines + 1] = string.rep('x ', i) end - curbufmeths.set_lines(0, -1, true, lines) + api.nvim_buf_set_lines(0, 0, -1, true, lines) local ns = ns1 local q = 0 for i = 0, 29 do @@ -1804,16 +1802,16 @@ describe('Extmarks buffer api with many marks', function() end) it('can clear all marks in ns', function() - curbufmeths.clear_namespace(ns1, 0, -1) + api.nvim_buf_clear_namespace(0, ns1, 0, -1) eq({}, get_marks(ns1)) eq(ns_marks[ns2], get_marks(ns2)) - curbufmeths.clear_namespace(ns2, 0, -1) + api.nvim_buf_clear_namespace(0, ns2, 0, -1) eq({}, get_marks(ns1)) eq({}, get_marks(ns2)) end) it('can clear line range', function() - curbufmeths.clear_namespace(ns1, 10, 20) + api.nvim_buf_clear_namespace(0, ns1, 10, 20) for id, mark in pairs(ns_marks[ns1]) do if 10 <= mark[1] and mark[1] < 20 then ns_marks[ns1][id] = nil diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index fe9e2a7727..1973d3e1c7 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim = helpers.clear, helpers.nvim +local clear = helpers.clear local Screen = require('test.functional.ui.screen') local eq, eval = helpers.eq, helpers.eval local command = helpers.command local exec_capture = helpers.exec_capture -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local pcall_err = helpers.pcall_err local ok = helpers.ok local assert_alive = helpers.assert_alive @@ -52,125 +52,125 @@ describe('API: highlight', function() it('nvim_get_hl_by_id', function() local hl_id = eval("hlID('NewHighlight')") - eq(expected_cterm, nvim('get_hl_by_id', hl_id, false)) + eq(expected_cterm, api.nvim_get_hl_by_id(hl_id, false)) hl_id = eval("hlID('NewHighlight')") -- Test valid id. - eq(expected_rgb, nvim('get_hl_by_id', hl_id, true)) + eq(expected_rgb, api.nvim_get_hl_by_id(hl_id, true)) -- Test invalid id. - eq('Invalid highlight id: 30000', pcall_err(meths.get_hl_by_id, 30000, false)) + eq('Invalid highlight id: 30000', pcall_err(api.nvim_get_hl_by_id, 30000, false)) -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') - eq(expected_rgb2, nvim('get_hl_by_id', hl_id, true)) + eq(expected_rgb2, api.nvim_get_hl_by_id(hl_id, true)) -- Test undercurl command('hi NewHighlight gui=undercurl') - eq(expected_undercurl, nvim('get_hl_by_id', hl_id, true)) + eq(expected_undercurl, api.nvim_get_hl_by_id(hl_id, true)) -- Test nil argument. eq( 'Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', - pcall_err(meths.get_hl_by_id, { nil }, false) + pcall_err(api.nvim_get_hl_by_id, { nil }, false) ) -- Test 0 argument. - eq('Invalid highlight id: 0', pcall_err(meths.get_hl_by_id, 0, false)) + eq('Invalid highlight id: 0', pcall_err(api.nvim_get_hl_by_id, 0, false)) -- Test -1 argument. - eq('Invalid highlight id: -1', pcall_err(meths.get_hl_by_id, -1, false)) + eq('Invalid highlight id: -1', pcall_err(api.nvim_get_hl_by_id, -1, false)) -- Test highlight group without ctermbg value. command('hi Normal ctermfg=red ctermbg=yellow') command('hi NewConstant ctermfg=green guifg=white guibg=blue') hl_id = eval("hlID('NewConstant')") - eq({ foreground = 10 }, meths.get_hl_by_id(hl_id, false)) + eq({ foreground = 10 }, api.nvim_get_hl_by_id(hl_id, false)) -- Test highlight group without ctermfg value. command('hi clear NewConstant') command('hi NewConstant ctermbg=Magenta guifg=white guibg=blue') - eq({ background = 13 }, meths.get_hl_by_id(hl_id, false)) + eq({ background = 13 }, api.nvim_get_hl_by_id(hl_id, false)) -- Test highlight group with ctermfg and ctermbg values. command('hi clear NewConstant') command('hi NewConstant ctermfg=green ctermbg=Magenta guifg=white guibg=blue') - eq({ foreground = 10, background = 13 }, meths.get_hl_by_id(hl_id, false)) + eq({ foreground = 10, background = 13 }, api.nvim_get_hl_by_id(hl_id, false)) end) it('nvim_get_hl_by_name', function() local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } -- Test `Normal` default values. - eq({}, nvim('get_hl_by_name', 'Normal', true)) + eq({}, api.nvim_get_hl_by_name('Normal', true)) - eq(expected_cterm, nvim('get_hl_by_name', 'NewHighlight', false)) - eq(expected_rgb, nvim('get_hl_by_name', 'NewHighlight', true)) + eq(expected_cterm, api.nvim_get_hl_by_name('NewHighlight', false)) + eq(expected_rgb, api.nvim_get_hl_by_name('NewHighlight', true)) -- Test `Normal` modified values. command('hi Normal guifg=red guibg=yellow') - eq(expected_normal, nvim('get_hl_by_name', 'Normal', true)) + eq(expected_normal, api.nvim_get_hl_by_name('Normal', true)) -- Test invalid name. eq( "Invalid highlight name: 'unknown_highlight'", - pcall_err(meths.get_hl_by_name, 'unknown_highlight', false) + pcall_err(api.nvim_get_hl_by_name, 'unknown_highlight', false) ) -- Test nil argument. eq( 'Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', - pcall_err(meths.get_hl_by_name, { nil }, false) + pcall_err(api.nvim_get_hl_by_name, { nil }, false) ) -- Test empty string argument. - eq('Invalid highlight name', pcall_err(meths.get_hl_by_name, '', false)) + eq('Invalid highlight name', pcall_err(api.nvim_get_hl_by_name, '', false)) -- Test "standout" attribute. #8054 - eq({ underline = true }, meths.get_hl_by_name('cursorline', 0)) + eq({ underline = true }, api.nvim_get_hl_by_name('cursorline', 0)) command('hi CursorLine cterm=standout,underline term=standout,underline gui=standout,underline') command('set cursorline') - eq({ underline = true, standout = true }, meths.get_hl_by_name('cursorline', 0)) + eq({ underline = true, standout = true }, api.nvim_get_hl_by_name('cursorline', 0)) -- Test cterm & Normal values. #18024 (tail) & #18980 -- Ensure Normal, and groups that match Normal return their fg & bg cterm values - meths.set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) - meths.set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) + api.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) + api.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) -- Note colors are "cterm" values, not rgb-as-ints - eq({ foreground = 17, background = 213 }, nvim('get_hl_by_name', 'Normal', false)) + eq({ foreground = 17, background = 213 }, api.nvim_get_hl_by_name('Normal', false)) eq( { foreground = 17, background = 213, nocombine = true }, - nvim('get_hl_by_name', 'NotNormal', false) + api.nvim_get_hl_by_name('NotNormal', false) ) end) it('nvim_get_hl_id_by_name', function() -- precondition: use a hl group that does not yet exist - eq("Invalid highlight name: 'Shrubbery'", pcall_err(meths.get_hl_by_name, 'Shrubbery', true)) - eq(0, funcs.hlID('Shrubbery')) + eq("Invalid highlight name: 'Shrubbery'", pcall_err(api.nvim_get_hl_by_name, 'Shrubbery', true)) + eq(0, fn.hlID('Shrubbery')) - local hl_id = meths.get_hl_id_by_name('Shrubbery') + local hl_id = api.nvim_get_hl_id_by_name('Shrubbery') ok(hl_id > 0) - eq(hl_id, funcs.hlID('Shrubbery')) + eq(hl_id, fn.hlID('Shrubbery')) command('hi Shrubbery guifg=#888888 guibg=#888888') eq( { foreground = tonumber('0x888888'), background = tonumber('0x888888') }, - meths.get_hl_by_id(hl_id, true) + api.nvim_get_hl_by_id(hl_id, true) ) eq( { foreground = tonumber('0x888888'), background = tonumber('0x888888') }, - meths.get_hl_by_name('Shrubbery', true) + api.nvim_get_hl_by_name('Shrubbery', true) ) end) it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() command('vsplit file') - local err, _ = pcall(meths.set_option_value, 'undofile', false, { buf = 1 }) + local err, _ = pcall(api.nvim_set_option_value, 'undofile', false, { buf = 1 }) eq(true, err) - err, _ = pcall(meths.set_option_value, 'undolevels', -1, { buf = 1 }) + err, _ = pcall(api.nvim_set_option_value, 'undolevels', -1, { buf = 1 }) eq(true, err) - err, _ = pcall(meths.buf_add_highlight, 1, -1, 'Question', 0, 0, -1) + err, _ = pcall(api.nvim_buf_add_highlight, 1, -1, 'Question', 0, 0, -1) eq(true, err) assert_alive() end) @@ -241,8 +241,8 @@ describe('API: set highlight', function() } local function get_ns() - local ns = meths.create_namespace('Test_set_hl') - meths.set_hl_ns(ns) + local ns = api.nvim_create_namespace('Test_set_hl') + api.nvim_set_hl_ns(ns) return ns end @@ -251,51 +251,51 @@ describe('API: set highlight', function() it('validation', function() eq( "Invalid 'blend': out of range", - pcall_err(meths.set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = 999 }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = 999 }) ) eq( "Invalid 'blend': expected Integer, got Array", - pcall_err(meths.set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = {} }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = {} }) ) end) it('can set gui highlight', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight1) - eq(highlight1, meths.get_hl_by_name('Test_hl', true)) + api.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, api.nvim_get_hl_by_name('Test_hl', true)) end) it('can set cterm highlight', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight2_config) - eq(highlight2_result, meths.get_hl_by_name('Test_hl', false)) + api.nvim_set_hl(ns, 'Test_hl', highlight2_config) + eq(highlight2_result, api.nvim_get_hl_by_name('Test_hl', false)) end) it('can set empty cterm attr', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', { cterm = {} }) - eq({}, meths.get_hl_by_name('Test_hl', false)) + api.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, api.nvim_get_hl_by_name('Test_hl', false)) end) it('cterm attr defaults to gui attr', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight1) + api.nvim_set_hl(ns, 'Test_hl', highlight1) eq({ bold = true, italic = true, - }, meths.get_hl_by_name('Test_hl', false)) + }, api.nvim_get_hl_by_name('Test_hl', false)) end) it('can overwrite attr for cterm', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight3_config) - eq(highlight3_result_gui, meths.get_hl_by_name('Test_hl', true)) - eq(highlight3_result_cterm, meths.get_hl_by_name('Test_hl', false)) + api.nvim_set_hl(ns, 'Test_hl', highlight3_config) + eq(highlight3_result_gui, api.nvim_get_hl_by_name('Test_hl', true)) + eq(highlight3_result_cterm, api.nvim_get_hl_by_name('Test_hl', false)) end) it('only allows one underline attribute #22371', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', { + api.nvim_set_hl(ns, 'Test_hl', { underdouble = true, underdotted = true, cterm = { @@ -303,21 +303,21 @@ describe('API: set highlight', function() undercurl = true, }, }) - eq({ undercurl = true }, meths.get_hl_by_name('Test_hl', false)) - eq({ underdotted = true }, meths.get_hl_by_name('Test_hl', true)) + eq({ undercurl = true }, api.nvim_get_hl_by_name('Test_hl', false)) + eq({ underdotted = true }, api.nvim_get_hl_by_name('Test_hl', true)) end) it('can set a highlight in the global namespace', function() - meths.set_hl(0, 'Test_hl', highlight2_config) + api.nvim_set_hl(0, 'Test_hl', highlight2_config) eq( 'Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse', exec_capture('highlight Test_hl') ) - meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) + api.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) eq('Test_hl xxx guibg=#0032aa', exec_capture('highlight Test_hl')) - meths.set_hl(0, 'Test_hl2', highlight3_config) + api.nvim_set_hl(0, 'Test_hl2', highlight3_config) eq( 'Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', exec_capture('highlight Test_hl2') @@ -325,58 +325,64 @@ describe('API: set highlight', function() -- Colors are stored with the name they are defined, but -- with canonical casing - meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + api.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) end) it('can modify a highlight in the global namespace', function() - meths.set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue' }) + api.nvim_set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue' }) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { bg = 'red' }) + api.nvim_set_hl(0, 'Test_hl3', { bg = 'red' }) eq('Test_hl3 xxx guibg=Red', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) + api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) + api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 9 }) + api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9 }) eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) - eq("Invalid highlight color: 'redd'", pcall_err(meths.set_hl, 0, 'Test_hl3', { fg = 'redd' })) + eq( + "Invalid highlight color: 'redd'", + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = 'redd' }) + ) eq( "Invalid highlight color: 'bleu'", - pcall_err(meths.set_hl, 0, 'Test_hl3', { ctermfg = 'bleu' }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { ctermfg = 'bleu' }) ) - meths.set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) + api.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3')) eq( "Invalid highlight color: '#FF00FF'", - pcall_err(meths.set_hl, 0, 'Test_hl3', { ctermfg = '#FF00FF' }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { ctermfg = '#FF00FF' }) ) for _, fg_val in ipairs { nil, 'NONE', 'nOnE', '', -1 } do - meths.set_hl(0, 'Test_hl3', { fg = fg_val }) + api.nvim_set_hl(0, 'Test_hl3', { fg = fg_val }) eq('Test_hl3 xxx cleared', exec_capture('highlight Test_hl3')) end - meths.set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) + api.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) eq('Test_hl3 xxx guifg=#ff00ff blend=50', exec_capture('highlight Test_hl3')) end) it("correctly sets 'Normal' internal properties", function() -- Normal has some special handling internally. #18024 - meths.set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) - eq({ foreground = 131, background = 243 }, nvim('get_hl_by_name', 'Normal', true)) + api.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) + eq({ foreground = 131, background = 243 }, api.nvim_get_hl_by_name('Normal', true)) end) it('does not segfault on invalid group name #20009', function() - eq("Invalid highlight name: 'foo bar'", pcall_err(meths.set_hl, 0, 'foo bar', { bold = true })) + eq( + "Invalid highlight name: 'foo bar'", + pcall_err(api.nvim_set_hl, 0, 'foo bar', { bold = true }) + ) assert_alive() end) end) @@ -443,14 +449,14 @@ describe('API: get highlight', function() local function get_ns() -- Test namespace filtering behavior - local ns2 = meths.create_namespace('Another_namespace') - meths.set_hl(ns2, 'Test_hl', { ctermfg = 23 }) - meths.set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' }) - meths.set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' }) - meths.set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' }) + local ns2 = api.nvim_create_namespace('Another_namespace') + api.nvim_set_hl(ns2, 'Test_hl', { ctermfg = 23 }) + api.nvim_set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' }) + api.nvim_set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' }) + api.nvim_set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' }) - local ns = meths.create_namespace('Test_set_hl') - meths.set_hl_ns(ns) + local ns = api.nvim_create_namespace('Test_set_hl') + api.nvim_set_hl_ns(ns) return ns end @@ -458,23 +464,26 @@ describe('API: get highlight', function() before_each(clear) it('validation', function() - eq("Invalid 'name': expected String, got Integer", pcall_err(meths.get_hl, 0, { name = 177 })) - eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' })) + eq( + "Invalid 'name': expected String, got Integer", + pcall_err(api.nvim_get_hl, 0, { name = 177 }) + ) + eq('Highlight id out of bounds', pcall_err(api.nvim_get_hl, 0, { name = 'Test set hl' })) end) it('nvim_get_hl with create flag', function() - eq({}, nvim('get_hl', 0, { name = 'Foo', create = false })) - eq(0, funcs.hlexists('Foo')) - meths.get_hl(0, { name = 'Bar', create = true }) - eq(1, funcs.hlexists('Bar')) - meths.get_hl(0, { name = 'FooBar' }) - eq(1, funcs.hlexists('FooBar')) + eq({}, api.nvim_get_hl(0, { name = 'Foo', create = false })) + eq(0, fn.hlexists('Foo')) + api.nvim_get_hl(0, { name = 'Bar', create = true }) + eq(1, fn.hlexists('Bar')) + api.nvim_get_hl(0, { name = 'FooBar' }) + eq(1, fn.hlexists('FooBar')) end) it('can get all highlights in current namespace', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) - meths.set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) + api.nvim_set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) + api.nvim_set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) eq({ Test_hl = { bg = 11845374, @@ -482,42 +491,42 @@ describe('API: get highlight', function() Test_hl_link = { link = 'Test_hl', }, - }, meths.get_hl(ns, {})) + }, api.nvim_get_hl(ns, {})) end) it('can get gui highlight', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight1) - eq(highlight1, meths.get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('can get cterm highlight', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight2) - eq(highlight2, meths.get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', highlight2) + eq(highlight2, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('can get empty cterm attr', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', { cterm = {} }) - eq({}, meths.get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('cterm attr defaults to gui attr', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight1) - eq(highlight1, meths.get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('can overwrite attr for cterm', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight3_config) - eq(highlight3_result, meths.get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', highlight3_config) + eq(highlight3_result, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('only allows one underline attribute #22371', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', { + api.nvim_set_hl(ns, 'Test_hl', { underdouble = true, underdotted = true, cterm = { @@ -525,32 +534,35 @@ describe('API: get highlight', function() undercurl = true, }, }) - eq({ underdotted = true, cterm = { undercurl = true } }, meths.get_hl(ns, { name = 'Test_hl' })) + eq( + { underdotted = true, cterm = { undercurl = true } }, + api.nvim_get_hl(ns, { name = 'Test_hl' }) + ) end) it('can get a highlight in the global namespace', function() - meths.set_hl(0, 'Test_hl', highlight2) - eq(highlight2, meths.get_hl(0, { name = 'Test_hl' })) + api.nvim_set_hl(0, 'Test_hl', highlight2) + eq(highlight2, api.nvim_get_hl(0, { name = 'Test_hl' })) - meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) + api.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) eq({ bg = 12970, - }, meths.get_hl(0, { name = 'Test_hl' })) + }, api.nvim_get_hl(0, { name = 'Test_hl' })) - meths.set_hl(0, 'Test_hl2', highlight3_config) - eq(highlight3_result, meths.get_hl(0, { name = 'Test_hl2' })) + api.nvim_set_hl(0, 'Test_hl2', highlight3_config) + eq(highlight3_result, api.nvim_get_hl(0, { name = 'Test_hl2' })) -- Colors are stored with the name they are defined, but -- with canonical casing - meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + api.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) eq({ bg = 16711680, fg = 255, - }, meths.get_hl(0, { name = 'Test_hl3' })) + }, api.nvim_get_hl(0, { name = 'Test_hl3' })) end) it('nvim_get_hl by id', function() - local hl_id = meths.get_hl_id_by_name('NewHighlight') + local hl_id = api.nvim_get_hl_id_by_name('NewHighlight') command( 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' @@ -562,14 +574,14 @@ describe('API: get highlight', function() bold = true, ctermbg = 10, cterm = { underline = true }, - }, meths.get_hl(0, { id = hl_id })) + }, api.nvim_get_hl(0, { id = hl_id })) -- Test 0 argument - eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 })) + eq('Highlight id out of bounds', pcall_err(api.nvim_get_hl, 0, { id = 0 })) eq( "Invalid 'id': expected Integer, got String", - pcall_err(meths.get_hl, 0, { id = 'Test_set_hl' }) + pcall_err(api.nvim_get_hl, 0, { id = 'Test_set_hl' }) ) -- Test all highlight properties. @@ -587,7 +599,7 @@ describe('API: get highlight', function() underline = true, ctermbg = 10, cterm = { underline = true }, - }, meths.get_hl(0, { id = hl_id })) + }, api.nvim_get_hl(0, { id = hl_id })) -- Test undercurl command('hi NewHighlight gui=undercurl') @@ -598,16 +610,16 @@ describe('API: get highlight', function() undercurl = true, ctermbg = 10, cterm = { underline = true }, - }, meths.get_hl(0, { id = hl_id })) + }, api.nvim_get_hl(0, { id = hl_id })) end) it('can correctly detect links', function() command('hi String guifg=#a6e3a1 ctermfg=NONE') command('hi link @string string') command('hi link @string.cpp @string') - eq({ fg = 10937249 }, meths.get_hl(0, { name = 'String' })) - eq({ link = 'String' }, meths.get_hl(0, { name = '@string' })) - eq({ fg = 10937249 }, meths.get_hl(0, { name = '@string.cpp', link = false })) + eq({ fg = 10937249 }, api.nvim_get_hl(0, { name = 'String' })) + eq({ link = 'String' }, api.nvim_get_hl(0, { name = '@string' })) + eq({ fg = 10937249 }, api.nvim_get_hl(0, { name = '@string.cpp', link = false })) end) it('can get all attributes for a linked group', function() @@ -616,55 +628,55 @@ describe('API: get highlight', function() command('hi! link Foo Bar') eq( { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true }, - meths.get_hl(0, { name = 'Foo', link = true }) + api.nvim_get_hl(0, { name = 'Foo', link = true }) ) end) it('can set link as well as other attributes', function() command('hi Bar guifg=red') local hl = { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, cterm = { bold = true } } - meths.set_hl(0, 'Foo', hl) - eq(hl, meths.get_hl(0, { name = 'Foo', link = true })) + api.nvim_set_hl(0, 'Foo', hl) + eq(hl, api.nvim_get_hl(0, { name = 'Foo', link = true })) end) it("doesn't contain unset groups", function() - local id = meths.get_hl_id_by_name '@foobar.hubbabubba' + local id = api.nvim_get_hl_id_by_name '@foobar.hubbabubba' ok(id > 0) - local data = meths.get_hl(0, {}) + local data = api.nvim_get_hl(0, {}) eq(nil, data['@foobar.hubbabubba']) eq(nil, data['@foobar']) command 'hi @foobar.hubbabubba gui=bold' - data = meths.get_hl(0, {}) + data = api.nvim_get_hl(0, {}) eq({ bold = true }, data['@foobar.hubbabubba']) eq(nil, data['@foobar']) -- @foobar.hubbabubba was explicitly cleared and thus shows up -- but @foobar was never touched, and thus doesn't command 'hi clear @foobar.hubbabubba' - data = meths.get_hl(0, {}) + data = api.nvim_get_hl(0, {}) eq({}, data['@foobar.hubbabubba']) eq(nil, data['@foobar']) end) it('should return default flag', function() - meths.set_hl(0, 'Tried', { fg = '#00ff00', default = true }) - eq({ fg = tonumber('00ff00', 16), default = true }, meths.get_hl(0, { name = 'Tried' })) + api.nvim_set_hl(0, 'Tried', { fg = '#00ff00', default = true }) + eq({ fg = tonumber('00ff00', 16), default = true }, api.nvim_get_hl(0, { name = 'Tried' })) end) it('should not output empty gui and cterm #23474', function() - meths.set_hl(0, 'Foo', { default = true }) - meths.set_hl(0, 'Bar', { default = true, fg = '#ffffff' }) - meths.set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } }) - meths.set_hl( + api.nvim_set_hl(0, 'Foo', { default = true }) + api.nvim_set_hl(0, 'Bar', { default = true, fg = '#ffffff' }) + api.nvim_set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } }) + api.nvim_set_hl( 0, 'FooBarA', { default = true, fg = '#ffffff', cterm = { bold = true, italic = true } } ) eq('Foo xxx cleared', exec_capture('highlight Foo')) - eq({ default = true }, meths.get_hl(0, { name = 'Foo' })) + eq({ default = true }, api.nvim_get_hl(0, { name = 'Foo' })) eq('Bar xxx guifg=#ffffff', exec_capture('highlight Bar')) eq('FooBar xxx cterm=bold guifg=#ffffff', exec_capture('highlight FooBar')) eq('FooBarA xxx cterm=bold,italic guifg=#ffffff', exec_capture('highlight FooBarA')) @@ -673,27 +685,27 @@ describe('API: get highlight', function() it('can override exist highlight group by force #20323', function() local white = tonumber('ffffff', 16) local green = tonumber('00ff00', 16) - meths.set_hl(0, 'Foo', { fg = white }) - meths.set_hl(0, 'Foo', { fg = green, force = true }) - eq({ fg = green }, meths.get_hl(0, { name = 'Foo' })) - meths.set_hl(0, 'Bar', { link = 'Comment', default = true }) - meths.set_hl(0, 'Bar', { link = 'Foo', default = true, force = true }) - eq({ link = 'Foo', default = true }, meths.get_hl(0, { name = 'Bar' })) + api.nvim_set_hl(0, 'Foo', { fg = white }) + api.nvim_set_hl(0, 'Foo', { fg = green, force = true }) + eq({ fg = green }, api.nvim_get_hl(0, { name = 'Foo' })) + api.nvim_set_hl(0, 'Bar', { link = 'Comment', default = true }) + api.nvim_set_hl(0, 'Bar', { link = 'Foo', default = true, force = true }) + eq({ link = 'Foo', default = true }, api.nvim_get_hl(0, { name = 'Bar' })) end) end) describe('API: set/get highlight namespace', function() it('set/get highlight namespace', function() - eq(0, meths.get_hl_ns({})) - local ns = meths.create_namespace('') - meths.set_hl_ns(ns) - eq(ns, meths.get_hl_ns({})) + eq(0, api.nvim_get_hl_ns({})) + local ns = api.nvim_create_namespace('') + api.nvim_set_hl_ns(ns) + eq(ns, api.nvim_get_hl_ns({})) end) it('set/get window highlight namespace', function() - eq(-1, meths.get_hl_ns({ winid = 0 })) - local ns = meths.create_namespace('') - meths.win_set_hl_ns(0, ns) - eq(ns, meths.get_hl_ns({ winid = 0 })) + eq(-1, api.nvim_get_hl_ns({ winid = 0 })) + local ns = api.nvim_create_namespace('') + api.nvim_win_set_hl_ns(0, ns) + eq(ns, api.nvim_get_hl_ns({ winid = 0 })) end) end) diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 50c353d764..4f57f6d0bd 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -1,20 +1,18 @@ local helpers = require('test.functional.helpers')(after_each) -local bufmeths = helpers.bufmeths local clear = helpers.clear local command = helpers.command -local curbufmeths = helpers.curbufmeths local eq, neq = helpers.eq, helpers.neq local exec_lua = helpers.exec_lua local exec = helpers.exec local feed = helpers.feed -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local source = helpers.source local pcall_err = helpers.pcall_err local shallowcopy = helpers.shallowcopy -local sleep = helpers.sleep +local sleep = vim.uv.sleep local sid_api_client = -9 local sid_lua = -8 @@ -57,7 +55,7 @@ describe('nvim_get_keymap', function() } it('returns empty list when no map', function() - eq({}, meths.get_keymap('n')) + eq({}, api.nvim_get_keymap('n')) end) it('returns list of all applicable mappings', function() @@ -66,8 +64,8 @@ describe('nvim_get_keymap', function() -- Should be the same as the dictionary we supplied earlier -- and the dictionary you would get from maparg -- since this is a global map, and not script local - eq({ foo_bar_map_table }, meths.get_keymap('n')) - eq({ funcs.maparg('foo', 'n', false, true) }, meths.get_keymap('n')) + eq({ foo_bar_map_table }, api.nvim_get_keymap('n')) + eq({ fn.maparg('foo', 'n', false, true) }, api.nvim_get_keymap('n')) -- Add another mapping command('nnoremap foo_longer bar_longer') @@ -76,11 +74,11 @@ describe('nvim_get_keymap', function() foolong_bar_map_table['lhsraw'] = 'foo_longer' foolong_bar_map_table['rhs'] = 'bar_longer' - eq({ foolong_bar_map_table, foo_bar_map_table }, meths.get_keymap('n')) + eq({ foolong_bar_map_table, foo_bar_map_table }, api.nvim_get_keymap('n')) -- Remove a mapping command('unmap foo_longer') - eq({ foo_bar_map_table }, meths.get_keymap('n')) + eq({ foo_bar_map_table }, api.nvim_get_keymap('n')) end) it('works for other modes', function() @@ -94,7 +92,7 @@ describe('nvim_get_keymap', function() insert_table['mode'] = 'i' insert_table['mode_bits'] = 0x10 - eq({ insert_table }, meths.get_keymap('i')) + eq({ insert_table }, api.nvim_get_keymap('i')) end) it('considers scope', function() @@ -111,8 +109,8 @@ describe('nvim_get_keymap', function() command('nnoremap <buffer> foo bar') -- The buffer mapping should not show up - eq({ foolong_bar_map_table }, meths.get_keymap('n')) - eq({ buffer_table }, curbufmeths.get_keymap('n')) + eq({ foolong_bar_map_table }, api.nvim_get_keymap('n')) + eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n')) end) it('considers scope for overlapping maps', function() @@ -123,12 +121,12 @@ describe('nvim_get_keymap', function() command('nnoremap <buffer> foo bar') - eq({ foo_bar_map_table }, meths.get_keymap('n')) - eq({ buffer_table }, curbufmeths.get_keymap('n')) + eq({ foo_bar_map_table }, api.nvim_get_keymap('n')) + eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n')) end) it('can retrieve mapping for different buffers', function() - local original_buffer = curbufmeths.get_number() + local original_buffer = api.nvim_buf_get_number(0) -- Place something in each of the buffers to make sure they stick around -- and set hidden so we can leave them command('set hidden') @@ -137,21 +135,21 @@ describe('nvim_get_keymap', function() command('new') command('normal! ihello 3') - local final_buffer = curbufmeths.get_number() + local final_buffer = api.nvim_buf_get_number(0) command('nnoremap <buffer> foo bar') -- Final buffer will have buffer mappings local buffer_table = shallowcopy(foo_bar_map_table) buffer_table['buffer'] = final_buffer - eq({ buffer_table }, meths.buf_get_keymap(final_buffer, 'n')) - eq({ buffer_table }, meths.buf_get_keymap(0, 'n')) + eq({ buffer_table }, api.nvim_buf_get_keymap(final_buffer, 'n')) + eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n')) command('buffer ' .. original_buffer) - eq(original_buffer, curbufmeths.get_number()) + eq(original_buffer, api.nvim_buf_get_number(0)) -- Original buffer won't have any mappings - eq({}, meths.get_keymap('n')) - eq({}, curbufmeths.get_keymap('n')) - eq({ buffer_table }, meths.buf_get_keymap(final_buffer, 'n')) + eq({}, api.nvim_get_keymap('n')) + eq({}, api.nvim_buf_get_keymap(0, 'n')) + eq({ buffer_table }, api.nvim_buf_get_keymap(final_buffer, 'n')) end) -- Test toggle switches for basic options @@ -191,7 +189,7 @@ describe('nvim_get_keymap', function() function() make_new_windows(new_windows) command(map .. ' ' .. option_token .. ' foo bar') - local result = meths.get_keymap(mode)[1][option] + local result = api.nvim_get_keymap(mode)[1][option] eq(global_on_result, result) end ) @@ -209,7 +207,7 @@ describe('nvim_get_keymap', function() function() make_new_windows(new_windows) command(map .. ' <buffer> ' .. option_token .. ' foo bar') - local result = curbufmeths.get_keymap(mode)[1][option] + local result = api.nvim_buf_get_keymap(0, mode)[1][option] eq(buffer_on_result, result) end ) @@ -228,7 +226,7 @@ describe('nvim_get_keymap', function() function() make_new_windows(new_windows) command(map .. ' baz bat') - local result = meths.get_keymap(mode)[1][option] + local result = api.nvim_get_keymap(mode)[1][option] eq(global_off_result, result) end ) @@ -246,7 +244,7 @@ describe('nvim_get_keymap', function() make_new_windows(new_windows) command(map .. ' <buffer> foo bar') - local result = curbufmeths.get_keymap(mode)[1][option] + local result = api.nvim_buf_get_keymap(0, mode)[1][option] eq(buffer_off_result, result) end ) @@ -277,9 +275,9 @@ describe('nvim_get_keymap', function() nnoremap fizz :call <SID>maparg_test_function()<CR> ]]) - local sid_result = meths.get_keymap('n')[1]['sid'] + local sid_result = api.nvim_get_keymap('n')[1]['sid'] eq(1, sid_result) - eq('testing', meths.call_function('<SNR>' .. sid_result .. '_maparg_test_function', {})) + eq('testing', api.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {})) end) it('returns script numbers for buffer maps', function() @@ -290,15 +288,15 @@ describe('nvim_get_keymap', function() nnoremap <buffer> fizz :call <SID>maparg_test_function()<CR> ]]) - local sid_result = curbufmeths.get_keymap('n')[1]['sid'] + local sid_result = api.nvim_buf_get_keymap(0, 'n')[1]['sid'] eq(1, sid_result) - eq('testing', meths.call_function('<SNR>' .. sid_result .. '_maparg_test_function', {})) + eq('testing', api.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {})) end) it('works with <F12> and others', function() command('nnoremap <F12> :let g:maparg_test_var = 1<CR>') - eq('<F12>', meths.get_keymap('n')[1]['lhs']) - eq(':let g:maparg_test_var = 1<CR>', meths.get_keymap('n')[1]['rhs']) + eq('<F12>', api.nvim_get_keymap('n')[1]['lhs']) + eq(':let g:maparg_test_var = 1<CR>', api.nvim_get_keymap('n')[1]['rhs']) end) it('works correctly despite various &cpo settings', function() @@ -341,7 +339,7 @@ describe('nvim_get_keymap', function() -- wrapper around get_keymap() that drops "lhsraw" and "lhsrawalt" which are hard to check local function get_keymap_noraw(...) - local ret = meths.get_keymap(...) + local ret = api.nvim_get_keymap(...) for _, item in ipairs(ret) do item.lhsraw = nil item.lhsrawalt = nil @@ -392,7 +390,7 @@ describe('nvim_get_keymap', function() lnum = 0, } command('nnoremap \\|<Char-0x20><Char-32><Space><Bar> \\|<Char-0x20><Char-32><Space> <Bar>') - eq({ space_table }, meths.get_keymap('n')) + eq({ space_table }, api.nvim_get_keymap('n')) end) it('can handle lua mappings', function() @@ -421,7 +419,7 @@ describe('nvim_get_keymap', function() ]]) eq(3, exec_lua([[return GlobalCount]])) - local mapargs = meths.get_keymap('n') + local mapargs = api.nvim_get_keymap('n') mapargs[1].callback = nil eq({ lhs = 'asdf', @@ -442,7 +440,7 @@ describe('nvim_get_keymap', function() end) it('can handle map descriptions', function() - meths.set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) + api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) eq({ lhs = 'lhs', lhsraw = 'lhs', @@ -460,7 +458,7 @@ describe('nvim_get_keymap', function() noremap = 0, lnum = 0, desc = 'map description', - }, meths.get_keymap('n')[1]) + }, api.nvim_get_keymap('n')[1]) end) end) @@ -513,7 +511,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- Gets a maparg() dict from Nvim, if one exists. local function get_mapargs(mode, lhs) - local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), mode:sub(-1) == 'a', true) + local mapargs = fn.maparg(lhs, normalize_mapmode(mode), mode:sub(-1) == 'a', true) -- drop "lhsraw" and "lhsrawalt" which are hard to check mapargs.lhsraw = nil mapargs.lhsrawalt = nil @@ -522,9 +520,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('error on empty LHS', function() -- escape parentheses in lua string, else comparison fails erroneously - eq('Invalid (empty) LHS', pcall_err(meths.set_keymap, '', '', 'rhs', {})) - eq('Invalid (empty) LHS', pcall_err(meths.set_keymap, '', '', '', {})) - eq('Invalid (empty) LHS', pcall_err(meths.del_keymap, '', '')) + eq('Invalid (empty) LHS', pcall_err(api.nvim_set_keymap, '', '', 'rhs', {})) + eq('Invalid (empty) LHS', pcall_err(api.nvim_set_keymap, '', '', '', {})) + eq('Invalid (empty) LHS', pcall_err(api.nvim_del_keymap, '', '')) end) it('error if LHS longer than MAXMAPLEN', function() @@ -536,16 +534,19 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end -- exactly 50 chars should be fine - meths.set_keymap('', lhs, 'rhs', {}) + api.nvim_set_keymap('', lhs, 'rhs', {}) -- del_keymap should unmap successfully - meths.del_keymap('', lhs) + api.nvim_del_keymap('', lhs) eq({}, get_mapargs('', lhs)) -- 51 chars should produce an error lhs = lhs .. '1' - eq('LHS exceeds maximum map length: ' .. lhs, pcall_err(meths.set_keymap, '', lhs, 'rhs', {})) - eq('LHS exceeds maximum map length: ' .. lhs, pcall_err(meths.del_keymap, '', lhs)) + eq( + 'LHS exceeds maximum map length: ' .. lhs, + pcall_err(api.nvim_set_keymap, '', lhs, 'rhs', {}) + ) + eq('LHS exceeds maximum map length: ' .. lhs, pcall_err(api.nvim_del_keymap, '', lhs)) end) it('does not throw errors when rhs is longer than MAXMAPLEN', function() @@ -555,56 +556,65 @@ describe('nvim_set_keymap, nvim_del_keymap', function() rhs = rhs .. (i % 10) end rhs = rhs .. '1' - meths.set_keymap('', 'lhs', rhs, {}) + api.nvim_set_keymap('', 'lhs', rhs, {}) eq(generate_mapargs('', 'lhs', rhs), get_mapargs('', 'lhs')) end) it('error on invalid mode shortname', function() - eq('Invalid mode shortname: " "', pcall_err(meths.set_keymap, ' ', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "m"', pcall_err(meths.set_keymap, 'm', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "?"', pcall_err(meths.set_keymap, '?', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "y"', pcall_err(meths.set_keymap, 'y', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "p"', pcall_err(meths.set_keymap, 'p', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "a"', pcall_err(meths.set_keymap, 'a', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "oa"', pcall_err(meths.set_keymap, 'oa', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "!o"', pcall_err(meths.set_keymap, '!o', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "!i"', pcall_err(meths.set_keymap, '!i', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "!!"', pcall_err(meths.set_keymap, '!!', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "map"', pcall_err(meths.set_keymap, 'map', 'lhs', 'rhs', {})) - eq('Invalid mode shortname: "vmap"', pcall_err(meths.set_keymap, 'vmap', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: " "', pcall_err(api.nvim_set_keymap, ' ', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "m"', pcall_err(api.nvim_set_keymap, 'm', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "?"', pcall_err(api.nvim_set_keymap, '?', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "y"', pcall_err(api.nvim_set_keymap, 'y', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "p"', pcall_err(api.nvim_set_keymap, 'p', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "a"', pcall_err(api.nvim_set_keymap, 'a', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "oa"', pcall_err(api.nvim_set_keymap, 'oa', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "!o"', pcall_err(api.nvim_set_keymap, '!o', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "!i"', pcall_err(api.nvim_set_keymap, '!i', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "!!"', pcall_err(api.nvim_set_keymap, '!!', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "map"', pcall_err(api.nvim_set_keymap, 'map', 'lhs', 'rhs', {})) + eq('Invalid mode shortname: "vmap"', pcall_err(api.nvim_set_keymap, 'vmap', 'lhs', 'rhs', {})) eq( 'Invalid mode shortname: "xnoremap"', - pcall_err(meths.set_keymap, 'xnoremap', 'lhs', 'rhs', {}) + pcall_err(api.nvim_set_keymap, 'xnoremap', 'lhs', 'rhs', {}) ) - eq('Invalid mode shortname: " "', pcall_err(meths.del_keymap, ' ', 'lhs')) - eq('Invalid mode shortname: "m"', pcall_err(meths.del_keymap, 'm', 'lhs')) - eq('Invalid mode shortname: "?"', pcall_err(meths.del_keymap, '?', 'lhs')) - eq('Invalid mode shortname: "y"', pcall_err(meths.del_keymap, 'y', 'lhs')) - eq('Invalid mode shortname: "p"', pcall_err(meths.del_keymap, 'p', 'lhs')) - eq('Invalid mode shortname: "a"', pcall_err(meths.del_keymap, 'a', 'lhs')) - eq('Invalid mode shortname: "oa"', pcall_err(meths.del_keymap, 'oa', 'lhs')) - eq('Invalid mode shortname: "!o"', pcall_err(meths.del_keymap, '!o', 'lhs')) - eq('Invalid mode shortname: "!i"', pcall_err(meths.del_keymap, '!i', 'lhs')) - eq('Invalid mode shortname: "!!"', pcall_err(meths.del_keymap, '!!', 'lhs')) - eq('Invalid mode shortname: "map"', pcall_err(meths.del_keymap, 'map', 'lhs')) - eq('Invalid mode shortname: "vmap"', pcall_err(meths.del_keymap, 'vmap', 'lhs')) - eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.del_keymap, 'xnoremap', 'lhs')) + eq('Invalid mode shortname: " "', pcall_err(api.nvim_del_keymap, ' ', 'lhs')) + eq('Invalid mode shortname: "m"', pcall_err(api.nvim_del_keymap, 'm', 'lhs')) + eq('Invalid mode shortname: "?"', pcall_err(api.nvim_del_keymap, '?', 'lhs')) + eq('Invalid mode shortname: "y"', pcall_err(api.nvim_del_keymap, 'y', 'lhs')) + eq('Invalid mode shortname: "p"', pcall_err(api.nvim_del_keymap, 'p', 'lhs')) + eq('Invalid mode shortname: "a"', pcall_err(api.nvim_del_keymap, 'a', 'lhs')) + eq('Invalid mode shortname: "oa"', pcall_err(api.nvim_del_keymap, 'oa', 'lhs')) + eq('Invalid mode shortname: "!o"', pcall_err(api.nvim_del_keymap, '!o', 'lhs')) + eq('Invalid mode shortname: "!i"', pcall_err(api.nvim_del_keymap, '!i', 'lhs')) + eq('Invalid mode shortname: "!!"', pcall_err(api.nvim_del_keymap, '!!', 'lhs')) + eq('Invalid mode shortname: "map"', pcall_err(api.nvim_del_keymap, 'map', 'lhs')) + eq('Invalid mode shortname: "vmap"', pcall_err(api.nvim_del_keymap, 'vmap', 'lhs')) + eq('Invalid mode shortname: "xnoremap"', pcall_err(api.nvim_del_keymap, 'xnoremap', 'lhs')) end) it('error on invalid optnames', function() - eq("Invalid key: 'silentt'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { silentt = true })) - eq("Invalid key: 'sidd'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { sidd = false })) - eq("Invalid key: 'nowaiT'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { nowaiT = false })) + eq( + "Invalid key: 'silentt'", + pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { silentt = true }) + ) + eq("Invalid key: 'sidd'", pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { sidd = false })) + eq( + "Invalid key: 'nowaiT'", + pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { nowaiT = false }) + ) end) it('error on <buffer> option key', function() - eq("Invalid key: 'buffer'", pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { buffer = true })) + eq( + "Invalid key: 'buffer'", + pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { buffer = true }) + ) end) it('error when "replace_keycodes" is used without "expr"', function() eq( '"replace_keycodes" requires "expr"', - pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', { replace_keycodes = true }) + pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { replace_keycodes = true }) ) end) @@ -614,45 +624,45 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('throws an error when given non-boolean value for ' .. opt, function() local opts = {} opts[opt] = 'fooo' - eq(opt .. ' is not a boolean', pcall_err(meths.set_keymap, 'n', 'lhs', 'rhs', opts)) + eq(opt .. ' is not a boolean', pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', opts)) end) end -- Perform tests of basic functionality it('sets ordinary mappings', function() - meths.set_keymap('n', 'lhs', 'rhs', {}) + api.nvim_set_keymap('n', 'lhs', 'rhs', {}) eq(generate_mapargs('n', 'lhs', 'rhs'), get_mapargs('n', 'lhs')) - meths.set_keymap('v', 'lhs', 'rhs', {}) + api.nvim_set_keymap('v', 'lhs', 'rhs', {}) eq(generate_mapargs('v', 'lhs', 'rhs'), get_mapargs('v', 'lhs')) end) it('does not throw when LHS or RHS have leading/trailing whitespace', function() - meths.set_keymap('n', ' lhs', 'rhs', {}) + api.nvim_set_keymap('n', ' lhs', 'rhs', {}) eq(generate_mapargs('n', '<Space><Space><Space>lhs', 'rhs'), get_mapargs('n', ' lhs')) - meths.set_keymap('n', 'lhs ', 'rhs', {}) + api.nvim_set_keymap('n', 'lhs ', 'rhs', {}) eq(generate_mapargs('n', 'lhs<Space><Space><Space><Space>', 'rhs'), get_mapargs('n', 'lhs ')) - meths.set_keymap('v', ' lhs ', '\trhs\t\f', {}) + api.nvim_set_keymap('v', ' lhs ', '\trhs\t\f', {}) eq(generate_mapargs('v', '<Space>lhs<Space><Space>', '\trhs\t\f'), get_mapargs('v', ' lhs ')) end) it('can set noremap mappings', function() - meths.set_keymap('x', 'lhs', 'rhs', { noremap = true }) + api.nvim_set_keymap('x', 'lhs', 'rhs', { noremap = true }) eq(generate_mapargs('x', 'lhs', 'rhs', { noremap = true }), get_mapargs('x', 'lhs')) - meths.set_keymap('t', 'lhs', 'rhs', { noremap = true }) + api.nvim_set_keymap('t', 'lhs', 'rhs', { noremap = true }) eq(generate_mapargs('t', 'lhs', 'rhs', { noremap = true }), get_mapargs('t', 'lhs')) end) it('can unmap mappings', function() - meths.set_keymap('v', 'lhs', 'rhs', {}) - meths.del_keymap('v', 'lhs') + api.nvim_set_keymap('v', 'lhs', 'rhs', {}) + api.nvim_del_keymap('v', 'lhs') eq({}, get_mapargs('v', 'lhs')) - meths.set_keymap('t', 'lhs', 'rhs', { noremap = true }) - meths.del_keymap('t', 'lhs') + api.nvim_set_keymap('t', 'lhs', 'rhs', { noremap = true }) + api.nvim_del_keymap('t', 'lhs') eq({}, get_mapargs('t', 'lhs')) end) @@ -660,8 +670,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function() it('"!" and empty string are synonyms for mapmode-nvo', function() local nvo_shortnames = { '', '!' } for _, name in ipairs(nvo_shortnames) do - meths.set_keymap(name, 'lhs', 'rhs', {}) - meths.del_keymap(name, 'lhs') + api.nvim_set_keymap(name, 'lhs', 'rhs', {}) + api.nvim_del_keymap(name, 'lhs') eq({}, get_mapargs(name, 'lhs')) end end) @@ -671,48 +681,48 @@ describe('nvim_set_keymap, nvim_del_keymap', function() for _, rhs in ipairs(special_chars) do local mapmode = '!' it('can set mappings with special characters, lhs: ' .. lhs .. ', rhs: ' .. rhs, function() - meths.set_keymap(mapmode, lhs, rhs, {}) + api.nvim_set_keymap(mapmode, lhs, rhs, {}) eq(generate_mapargs(mapmode, lhs, rhs), get_mapargs(mapmode, lhs)) end) end end it('can set mappings containing literal keycodes', function() - meths.set_keymap('n', '\n\r\n', 'rhs', {}) + api.nvim_set_keymap('n', '\n\r\n', 'rhs', {}) local expected = generate_mapargs('n', '<NL><CR><NL>', 'rhs') eq(expected, get_mapargs('n', '<NL><CR><NL>')) end) it('can set mappings whose RHS is a <Nop>', function() - meths.set_keymap('i', 'lhs', '<Nop>', {}) + api.nvim_set_keymap('i', 'lhs', '<Nop>', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) -- imap to <Nop> does nothing + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0)) -- imap to <Nop> does nothing eq(generate_mapargs('i', 'lhs', '<Nop>', {}), get_mapargs('i', 'lhs')) -- also test for case insensitivity - meths.set_keymap('i', 'lhs', '<nOp>', {}) + api.nvim_set_keymap('i', 'lhs', '<nOp>', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0)) -- note: RHS in returned mapargs() dict reflects the original RHS -- provided by the user eq(generate_mapargs('i', 'lhs', '<nOp>', {}), get_mapargs('i', 'lhs')) - meths.set_keymap('i', 'lhs', '<NOP>', {}) + api.nvim_set_keymap('i', 'lhs', '<NOP>', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0)) eq(generate_mapargs('i', 'lhs', '<NOP>', {}), get_mapargs('i', 'lhs')) -- a single ^V in RHS is also <Nop> (see :h map-empty-rhs) - meths.set_keymap('i', 'lhs', '\022', {}) + api.nvim_set_keymap('i', 'lhs', '\022', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0)) eq(generate_mapargs('i', 'lhs', '\022', {}), get_mapargs('i', 'lhs')) end) it('treats an empty RHS in a mapping like a <Nop>', function() - meths.set_keymap('i', 'lhs', '', {}) + api.nvim_set_keymap('i', 'lhs', '', {}) command('normal ilhs') - eq({ '' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0)) eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) end) @@ -720,8 +730,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- Taken from the legacy test: test_mapping.vim. Exposes a bug in which -- replace_termcodes changes the length of the mapping's LHS, but -- do_map continues to use the *old* length of LHS. - meths.set_keymap('i', '<M-">', 'foo', {}) - meths.del_keymap('i', '<M-">') + api.nvim_set_keymap('i', '<M-">', 'foo', {}) + api.nvim_del_keymap('i', '<M-">') eq({}, get_mapargs('i', '<M-">')) end) @@ -731,18 +741,18 @@ describe('nvim_set_keymap, nvim_del_keymap', function() command([[call nvim_set_keymap('i', "\<space>", "\<tab>", {})]]) eq(generate_mapargs('i', '<Space>', '\t', { sid = 0 }), get_mapargs('i', '<Space>')) feed('i ') - eq({ '\t' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '\t' }, api.nvim_buf_get_lines(0, 0, -1, 0)) end ) it('throws appropriate error messages when setting <unique> maps', function() - meths.set_keymap('l', 'lhs', 'rhs', {}) + api.nvim_set_keymap('l', 'lhs', 'rhs', {}) eq( 'E227: mapping already exists for lhs', - pcall_err(meths.set_keymap, 'l', 'lhs', 'rhs', { unique = true }) + pcall_err(api.nvim_set_keymap, 'l', 'lhs', 'rhs', { unique = true }) ) -- different mapmode, no error should be thrown - meths.set_keymap('t', 'lhs', 'rhs', { unique = true }) + api.nvim_set_keymap('t', 'lhs', 'rhs', { unique = true }) end) it('can set <expr> mappings whose RHS change dynamically', function() @@ -753,50 +763,50 @@ describe('nvim_set_keymap, nvim_del_keymap', function() return g:flip endfunction ]]) - eq(1, meths.call_function('FlipFlop', {})) - eq(0, meths.call_function('FlipFlop', {})) - eq(1, meths.call_function('FlipFlop', {})) - eq(0, meths.call_function('FlipFlop', {})) + eq(1, api.nvim_call_function('FlipFlop', {})) + eq(0, api.nvim_call_function('FlipFlop', {})) + eq(1, api.nvim_call_function('FlipFlop', {})) + eq(0, api.nvim_call_function('FlipFlop', {})) - meths.set_keymap('i', 'lhs', 'FlipFlop()', { expr = true }) + api.nvim_set_keymap('i', 'lhs', 'FlipFlop()', { expr = true }) command('normal ilhs') - eq({ '1' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '1' }, api.nvim_buf_get_lines(0, 0, -1, 0)) command('normal! ggVGd') command('normal ilhs') - eq({ '0' }, curbufmeths.get_lines(0, -1, 0)) + eq({ '0' }, api.nvim_buf_get_lines(0, 0, -1, 0)) end) it('can set mappings that do trigger other mappings', function() - meths.set_keymap('i', 'mhs', 'rhs', {}) - meths.set_keymap('i', 'lhs', 'mhs', {}) + api.nvim_set_keymap('i', 'mhs', 'rhs', {}) + api.nvim_set_keymap('i', 'lhs', 'mhs', {}) command('normal imhs') - eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, -1, 0)) command('normal! ggVGd') command('normal ilhs') - eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, -1, 0)) end) it("can set noremap mappings that don't trigger other mappings", function() - meths.set_keymap('i', 'mhs', 'rhs', {}) - meths.set_keymap('i', 'lhs', 'mhs', { noremap = true }) + api.nvim_set_keymap('i', 'mhs', 'rhs', {}) + api.nvim_set_keymap('i', 'lhs', 'mhs', { noremap = true }) command('normal imhs') - eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, -1, 0)) command('normal! ggVGd') command('normal ilhs') -- shouldn't trigger mhs-to-rhs mapping - eq({ 'mhs' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'mhs' }, api.nvim_buf_get_lines(0, 0, -1, 0)) end) it('can set nowait mappings that fire without waiting', function() - meths.set_keymap('i', '123456', 'longer', {}) - meths.set_keymap('i', '123', 'shorter', { nowait = true }) + api.nvim_set_keymap('i', '123456', 'longer', {}) + api.nvim_set_keymap('i', '123', 'shorter', { nowait = true }) -- feed keys one at a time; if all keys arrive atomically, the longer -- mapping will trigger @@ -805,29 +815,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed(c) sleep(5) end - eq({ 'shorter456' }, curbufmeths.get_lines(0, -1, 0)) + eq({ 'shorter456' }, api.nvim_buf_get_lines(0, 0, -1, 0)) end) -- Perform exhaustive tests of basic functionality local mapmodes = { 'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', '', 'ia', 'ca', '!a' } for _, mapmode in ipairs(mapmodes) do it('can set/unset normal mappings in mapmode ' .. mapmode, function() - meths.set_keymap(mapmode, 'lhs', 'rhs', {}) + api.nvim_set_keymap(mapmode, 'lhs', 'rhs', {}) eq(generate_mapargs(mapmode, 'lhs', 'rhs'), get_mapargs(mapmode, 'lhs')) -- some mapmodes (like 'o') will prevent other mapmodes (like '!') from -- taking effect, so unmap after each mapping - meths.del_keymap(mapmode, 'lhs') + api.nvim_del_keymap(mapmode, 'lhs') eq({}, get_mapargs(mapmode, 'lhs')) end) end for _, mapmode in ipairs(mapmodes) do it('can set/unset noremap mappings using mapmode ' .. mapmode, function() - meths.set_keymap(mapmode, 'lhs', 'rhs', { noremap = true }) + api.nvim_set_keymap(mapmode, 'lhs', 'rhs', { noremap = true }) eq(generate_mapargs(mapmode, 'lhs', 'rhs', { noremap = true }), get_mapargs(mapmode, 'lhs')) - meths.del_keymap(mapmode, 'lhs') + api.nvim_del_keymap(mapmode, 'lhs') eq({}, get_mapargs(mapmode, 'lhs')) end) end @@ -839,12 +849,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function() -- Test with single mappings for _, maparg in ipairs(optnames) do it('can set/unset ' .. mapmode .. '-mappings with maparg: ' .. maparg, function() - meths.set_keymap(mapmode, 'lhs', 'rhs', { [maparg] = true }) + api.nvim_set_keymap(mapmode, 'lhs', 'rhs', { [maparg] = true }) eq( generate_mapargs(mapmode, 'lhs', 'rhs', { [maparg] = true }), get_mapargs(mapmode, 'lhs') ) - meths.del_keymap(mapmode, 'lhs') + api.nvim_del_keymap(mapmode, 'lhs') eq({}, get_mapargs(mapmode, 'lhs')) end) it( @@ -854,9 +864,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() .. maparg .. ', whose value is false', function() - meths.set_keymap(mapmode, 'lhs', 'rhs', { [maparg] = false }) + api.nvim_set_keymap(mapmode, 'lhs', 'rhs', { [maparg] = false }) eq(generate_mapargs(mapmode, 'lhs', 'rhs'), get_mapargs(mapmode, 'lhs')) - meths.del_keymap(mapmode, 'lhs') + api.nvim_del_keymap(mapmode, 'lhs') eq({}, get_mapargs(mapmode, 'lhs')) end ) @@ -876,9 +886,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() .. opt3, function() local opts = { [opt1] = true, [opt2] = false, [opt3] = true } - meths.set_keymap(mapmode, 'lhs', 'rhs', opts) + api.nvim_set_keymap(mapmode, 'lhs', 'rhs', opts) eq(generate_mapargs(mapmode, 'lhs', 'rhs', opts), get_mapargs(mapmode, 'lhs')) - meths.del_keymap(mapmode, 'lhs') + api.nvim_del_keymap(mapmode, 'lhs') eq({}, get_mapargs(mapmode, 'lhs')) end ) @@ -916,7 +926,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() exec_lua [[ vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) ]] - assert.truthy(string.match(funcs.mapcheck('asdf', 'n'), '^<Lua %d+>')) + assert.truthy(string.match(fn.mapcheck('asdf', 'n'), '^<Lua %d+>')) end) it('maparg() returns lua mapping correctly', function() @@ -929,9 +939,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function() ]]) ) - assert.truthy(string.match(funcs.maparg('asdf', 'n'), '^<Lua %d+>')) + assert.truthy(string.match(fn.maparg('asdf', 'n'), '^<Lua %d+>')) - local mapargs = funcs.maparg('asdf', 'n', false, true) + local mapargs = fn.maparg('asdf', 'n', false, true) mapargs.callback = nil mapargs.lhsraw = nil mapargs.lhsrawalt = nil @@ -958,7 +968,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('aa') - eq({ 'π<M-π>foo<' }, meths.buf_get_lines(0, 0, -1, false)) + eq({ 'π<M-π>foo<' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('can make lua expr mappings without replacing keycodes', function() @@ -968,7 +978,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('iaa<esc>') - eq({ '<space>' }, meths.buf_get_lines(0, 0, -1, false)) + eq({ '<space>' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('lua expr mapping returning nil is equivalent to returning an empty string', function() @@ -978,7 +988,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() feed('iaa<esc>') - eq({ '' }, meths.buf_get_lines(0, 0, -1, false)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('does not reset pum in lua mapping', function() @@ -1081,7 +1091,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function() end) it('can set descriptions on mappings', function() - meths.set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) + api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) eq(generate_mapargs('n', 'lhs', 'rhs', { desc = 'map description' }), get_mapargs('n', 'lhs')) eq('\nn lhs rhs\n map description', helpers.exec_capture('nmap lhs')) end) @@ -1096,10 +1106,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function() ]] feed 'iThe foo and the bar and the foo again<esc>' - eq('The 1 and the bar and the 2 again', meths.get_current_line()) + eq('The 1 and the bar and the 2 again', api.nvim_get_current_line()) feed ':let x = "The foo is the one"<cr>' - eq('The 3 is the one', meths.eval 'x') + eq('The 3 is the one', api.nvim_eval 'x') end) it('can define insert mode abbreviations with lua callbacks', function() @@ -1112,10 +1122,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function() ]] feed 'iThe foo and the bar and the foo again<esc>' - eq('The 1 and the bar and the 2 again', meths.get_current_line()) + eq('The 1 and the bar and the 2 again', api.nvim_get_current_line()) feed ':let x = "The foo is the one"<cr>' - eq('The foo is the one', meths.eval 'x') + eq('The foo is the one', api.nvim_eval 'x') end) it('can define cmdline mode abbreviations with lua callbacks', function() @@ -1128,10 +1138,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function() ]] feed 'iThe foo and the bar and the foo again<esc>' - eq('The foo and the bar and the foo again', meths.get_current_line()) + eq('The foo and the bar and the foo again', api.nvim_get_current_line()) feed ':let x = "The foo is the one"<cr>' - eq('The 1 is the one', meths.eval 'x') + eq('The 1 is the one', api.nvim_eval 'x') end) end) @@ -1154,9 +1164,9 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() local function make_two_buffers(start_from_first) command('set hidden') - local first_buf = meths.call_function('bufnr', { '%' }) + local first_buf = api.nvim_call_function('bufnr', { '%' }) command('new') - local second_buf = meths.call_function('bufnr', { '%' }) + local second_buf = api.nvim_call_function('bufnr', { '%' }) neq(second_buf, first_buf) -- sanity check if start_from_first then @@ -1169,66 +1179,66 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() it('rejects negative bufnr values', function() eq( 'Wrong type for argument 1 when calling nvim_buf_set_keymap, expecting Buffer', - pcall_err(bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {}) + pcall_err(api.nvim_buf_set_keymap, -1, '', 'lhs', 'rhs', {}) ) end) it('can set mappings active in the current buffer but not others', function() local first, second = make_two_buffers(true) - bufmeths.set_keymap(0, '', 'lhs', 'irhs<Esc>', {}) + api.nvim_buf_set_keymap(0, '', 'lhs', 'irhs<Esc>', {}) command('normal lhs') - eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, 1, 1)) -- mapping should have no effect in new buffer switch_to_buf(second) command('normal lhs') - eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, 1, 1)) -- mapping should remain active in old buffer switch_to_buf(first) command('normal ^lhs') - eq({ 'rhsrhs' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhsrhs' }, api.nvim_buf_get_lines(0, 0, 1, 1)) end) it('can set local mappings in buffer other than current', function() local first = make_two_buffers(false) - bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) + api.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) -- shouldn't do anything command('normal lhs') - eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, 1, 1)) -- should take effect switch_to_buf(first) command('normal lhs') - eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, 1, 1)) end) it('can disable mappings made in another buffer, inside that buffer', function() local first = make_two_buffers(false) - bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) - bufmeths.del_keymap(first, '', 'lhs') + api.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) + api.nvim_buf_del_keymap(first, '', 'lhs') switch_to_buf(first) -- shouldn't do anything command('normal lhs') - eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, 1, 1)) end) it("can't disable mappings given wrong buffer handle", function() local first, second = make_two_buffers(false) - bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) - eq('E31: No such mapping', pcall_err(bufmeths.del_keymap, second, '', 'lhs')) + api.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) + eq('E31: No such mapping', pcall_err(api.nvim_buf_del_keymap, second, '', 'lhs')) -- should still work switch_to_buf(first) command('normal lhs') - eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) + eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, 1, 1)) end) it('does not crash when setting mapping in a non-existing buffer #13541', function() - pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs<Esc>', {}) + pcall_err(api.nvim_buf_set_keymap, 100, '', 'lsh', 'irhs<Esc>', {}) helpers.assert_alive() end) @@ -1254,7 +1264,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('aa') - eq({ 'π<M-π>foo<' }, meths.buf_get_lines(0, 0, -1, false)) + eq({ 'π<M-π>foo<' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('can make lua expr mappings without replacing keycodes', function() @@ -1264,7 +1274,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function() feed('iaa<esc>') - eq({ '<space>' }, meths.buf_get_lines(0, 0, -1, false)) + eq({ '<space>' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('can overwrite lua mappings', function() diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua index 4f99a69ce6..50c441792c 100644 --- a/test/functional/api/proc_spec.lua +++ b/test/functional/api/proc_spec.lua @@ -2,12 +2,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local neq = helpers.neq local nvim_argv = helpers.nvim_argv local request = helpers.request local retry = helpers.retry -local NIL = helpers.NIL +local NIL = vim.NIL local is_os = helpers.is_os describe('API', function() @@ -15,28 +15,28 @@ describe('API', function() describe('nvim_get_proc_children', function() it('returns child process ids', function() - local this_pid = funcs.getpid() + local this_pid = fn.getpid() -- Might be non-zero already (left-over from some other test?), -- but this is not what is tested here. local initial_children = request('nvim_get_proc_children', this_pid) - local job1 = funcs.jobstart(nvim_argv) + local job1 = fn.jobstart(nvim_argv) retry(nil, nil, function() eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid)) end) - local job2 = funcs.jobstart(nvim_argv) + local job2 = fn.jobstart(nvim_argv) retry(nil, nil, function() eq(#initial_children + 2, #request('nvim_get_proc_children', this_pid)) end) - funcs.jobstop(job1) + fn.jobstop(job1) retry(nil, nil, function() eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid)) end) - funcs.jobstop(job2) + fn.jobstop(job2) retry(nil, nil, function() eq(#initial_children, #request('nvim_get_proc_children', this_pid)) end) @@ -60,7 +60,7 @@ describe('API', function() describe('nvim_get_proc', function() it('returns process info', function() - local pid = funcs.getpid() + local pid = fn.getpid() local pinfo = request('nvim_get_proc', pid) eq((is_os('win') and 'nvim.exe' or 'nvim'), pinfo.name) eq(pid, pinfo.pid) diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index d75bfd5324..f6058b14ee 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log -local eq, clear, eval, command, nvim, next_msg = - helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.nvim, helpers.next_msg -local meths = helpers.meths +local eq, clear, eval, command, next_msg = + helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.next_msg +local api = helpers.api local exec_lua = helpers.exec_lua local retry = helpers.retry local assert_alive = helpers.assert_alive @@ -14,7 +14,7 @@ describe('notify', function() before_each(function() clear() - channel = nvim('get_api_info')[1] + channel = api.nvim_get_api_info()[1] end) after_each(function() @@ -33,23 +33,23 @@ describe('notify', function() describe('passing 0 as the channel id', function() it('sends the notification/args to all subscribed channels', function() - nvim('subscribe', 'event2') + api.nvim_subscribe('event2') eval('rpcnotify(0, "event1", 1, 2, 3)') eval('rpcnotify(0, "event2", 4, 5, 6)') eval('rpcnotify(0, "event2", 7, 8, 9)') eq({ 'notification', 'event2', { 4, 5, 6 } }, next_msg()) eq({ 'notification', 'event2', { 7, 8, 9 } }, next_msg()) - nvim('unsubscribe', 'event2') - nvim('subscribe', 'event1') + api.nvim_unsubscribe('event2') + api.nvim_subscribe('event1') eval('rpcnotify(0, "event2", 10, 11, 12)') eval('rpcnotify(0, "event1", 13, 14, 15)') eq({ 'notification', 'event1', { 13, 14, 15 } }, next_msg()) end) it('does not crash for deeply nested variable', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) local nest_level = 1000 - meths.command(('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1)) + command(('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1)) eval('rpcnotify(' .. channel .. ', "event", g:l)') local msg = next_msg() eq('notification', msg[1]) @@ -79,10 +79,10 @@ describe('notify', function() clear { env = { NVIM_LOG_FILE = testlog, } } - nvim('subscribe', 'event1') - nvim('unsubscribe', 'doesnotexist') + api.nvim_subscribe('event1') + api.nvim_unsubscribe('doesnotexist') assert_log("tried to unsubscribe unknown event 'doesnotexist'", testlog, 10) - nvim('unsubscribe', 'event1') + api.nvim_unsubscribe('event1') assert_alive() end) @@ -106,7 +106,7 @@ describe('notify', function() exec_lua([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan) ) retry(nil, 3000, function() - eq({}, meths.get_chan_info(catchan)) + eq({}, api.nvim_get_chan_info(catchan)) end) -- cat be dead :( end) end) diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 421e0b5c9a..5e508e7513 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -2,12 +2,12 @@ -- `rpcrequest` calls we need the client event loop to be running. local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval +local clear, eval = helpers.clear, helpers.eval local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop -local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs +local nvim_prog, command, fn = helpers.nvim_prog, helpers.command, helpers.fn local source, next_msg = helpers.source, helpers.next_msg local ok = helpers.ok -local meths = helpers.meths +local api = helpers.api local spawn, merge_args = helpers.spawn, helpers.merge_args local set_session = helpers.set_session local pcall_err = helpers.pcall_err @@ -18,7 +18,7 @@ describe('server -> client', function() before_each(function() clear() - cid = nvim('get_api_info')[1] + cid = api.nvim_get_api_info()[1] end) it('handles unexpected closed stream while preparing RPC response', function() @@ -47,7 +47,7 @@ describe('server -> client', function() local function on_request(method, args) eq('scall', method) eq({ 1, 2, 3 }, args) - nvim('command', 'let g:result = [4, 5, 6]') + command('let g:result = [4, 5, 6]') return eval('g:result') end run(on_request, nil, on_setup) @@ -77,15 +77,15 @@ describe('server -> client', function() describe('recursive call', function() it('works', function() local function on_setup() - nvim('set_var', 'result1', 0) - nvim('set_var', 'result2', 0) - nvim('set_var', 'result3', 0) - nvim('set_var', 'result4', 0) - nvim('command', 'let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') - eq(4, nvim('get_var', 'result1')) - eq(8, nvim('get_var', 'result2')) - eq(16, nvim('get_var', 'result3')) - eq(32, nvim('get_var', 'result4')) + api.nvim_set_var('result1', 0) + api.nvim_set_var('result2', 0) + api.nvim_set_var('result3', 0) + api.nvim_set_var('result4', 0) + command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') + eq(4, api.nvim_get_var('result1')) + eq(8, api.nvim_get_var('result2')) + eq(16, api.nvim_get_var('result3')) + eq(32, api.nvim_get_var('result4')) stop() end @@ -101,7 +101,7 @@ describe('server -> client', function() elseif n == 16 then cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' end - nvim('command', cmd) + command(cmd) end return n end @@ -113,12 +113,12 @@ describe('server -> client', function() it('does not delay notifications during pending request', function() local received = false local function on_setup() - eq('retval', funcs.rpcrequest(cid, 'doit')) + eq('retval', fn.rpcrequest(cid, 'doit')) stop() end local function on_request(method) if method == 'doit' then - funcs.rpcnotify(cid, 'headsup') + fn.rpcnotify(cid, 'headsup') eq(true, received) return 'retval' end @@ -195,10 +195,10 @@ describe('server -> client', function() end) it('can send/receive notifications and make requests', function() - nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") + command("call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") -- Wait for the notification to complete. - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") + command("call rpcrequest(vim, 'vim_eval', '0')") eq('SOME TEXT', eval("rpcrequest(vim, 'vim_get_current_line')")) end) @@ -212,7 +212,7 @@ describe('server -> client', function() eq(1, buf) eval("rpcnotify(vim, 'buffer_set_line', " .. buf .. ", 0, 'SOME TEXT')") - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait + command("call rpcrequest(vim, 'vim_eval', '0')") -- wait eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', " .. buf .. ', 0)')) @@ -231,8 +231,8 @@ describe('server -> client', function() describe('jobstart()', function() local jobid before_each(function() - local channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + local channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) source([[ function! s:OnEvent(id, data, event) call rpcnotify(g:channel, a:event, 0, a:data) @@ -244,7 +244,7 @@ describe('server -> client', function() \ 'rpc': v:true \ } ]]) - meths.set_var('args', { + api.nvim_set_var('args', { nvim_prog, '-ll', 'test/functional/api/rpc_fixture.lua', @@ -256,7 +256,7 @@ describe('server -> client', function() end) after_each(function() - pcall(funcs.jobstop, jobid) + pcall(fn.jobstop, jobid) end) if helpers.skip(helpers.is_os('win')) then @@ -264,16 +264,16 @@ describe('server -> client', function() end it('rpc and text stderr can be combined', function() - local status, rv = pcall(funcs.rpcrequest, jobid, 'poll') + local status, rv = pcall(fn.rpcrequest, jobid, 'poll') if not status then error(string.format('missing nvim Lua module? (%s)', rv)) end eq('ok', rv) - funcs.rpcnotify(jobid, 'ping') + fn.rpcnotify(jobid, 'ping') eq({ 'notification', 'pong', {} }, next_msg()) - eq('done!', funcs.rpcrequest(jobid, 'write_stderr', 'fluff\n')) + eq('done!', fn.rpcrequest(jobid, 'write_stderr', 'fluff\n')) eq({ 'notification', 'stderr', { 0, { 'fluff', '' } } }, next_msg()) - pcall(funcs.rpcrequest, jobid, 'exit') + pcall(fn.rpcrequest, jobid, 'exit') eq({ 'notification', 'stderr', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) @@ -282,29 +282,29 @@ describe('server -> client', function() describe('connecting to another (peer) nvim', function() local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' }) local function connect_test(server, mode, address) - local serverpid = funcs.getpid() + local serverpid = fn.getpid() local client = spawn(nvim_argv, false, nil, true) set_session(client) - local clientpid = funcs.getpid() + local clientpid = fn.getpid() neq(serverpid, clientpid) - local id = funcs.sockconnect(mode, address, { rpc = true }) + local id = fn.sockconnect(mode, address, { rpc = true }) ok(id > 0) - funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') - local client_id = funcs.rpcrequest(id, 'nvim_get_api_info')[1] + fn.rpcrequest(id, 'nvim_set_current_line', 'hello') + local client_id = fn.rpcrequest(id, 'nvim_get_api_info')[1] set_session(server) - eq(serverpid, funcs.getpid()) - eq('hello', meths.get_current_line()) + eq(serverpid, fn.getpid()) + eq('hello', api.nvim_get_current_line()) -- method calls work both ways - funcs.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') - eq(id, funcs.rpcrequest(client_id, 'nvim_get_api_info')[1]) + fn.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') + eq(id, fn.rpcrequest(client_id, 'nvim_get_api_info')[1]) set_session(client) - eq(clientpid, funcs.getpid()) - eq('howdy!', meths.get_current_line()) + eq(clientpid, fn.getpid()) + eq('howdy!', api.nvim_get_current_line()) server:close() client:close() @@ -313,7 +313,7 @@ describe('server -> client', function() it('via named pipe', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local first = string.sub(address, 1, 1) ok(first == '/' or first == '\\') connect_test(server, 'pipe', address) @@ -322,7 +322,7 @@ describe('server -> client', function() it('via ipv4 address', function() local server = spawn(nvim_argv) set_session(server) - local status, address = pcall(funcs.serverstart, '127.0.0.1:') + local status, address = pcall(fn.serverstart, '127.0.0.1:') if not status then pending('no ipv4 stack') end @@ -333,7 +333,7 @@ describe('server -> client', function() it('via ipv6 address', function() local server = spawn(nvim_argv) set_session(server) - local status, address = pcall(funcs.serverstart, '::1:') + local status, address = pcall(fn.serverstart, '::1:') if not status then pending('no ipv6 stack') end @@ -344,7 +344,7 @@ describe('server -> client', function() it('via hostname', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverstart('localhost:') + local address = fn.serverstart('localhost:') eq('localhost:', string.sub(address, 1, 10)) connect_test(server, 'tcp', address) end) @@ -352,12 +352,12 @@ describe('server -> client', function() it('does not crash on receiving UI events', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local client = spawn(nvim_argv, false, nil, true) set_session(client) - local id = funcs.sockconnect('pipe', address, { rpc = true }) - funcs.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) + local id = fn.sockconnect('pipe', address, { rpc = true }) + fn.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) assert_alive() server:close() @@ -367,18 +367,18 @@ describe('server -> client', function() describe('connecting to its own pipe address', function() it('does not deadlock', function() - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local first = string.sub(address, 1, 1) ok(first == '/' or first == '\\') - local serverpid = funcs.getpid() + local serverpid = fn.getpid() - local id = funcs.sockconnect('pipe', address, { rpc = true }) + local id = fn.sockconnect('pipe', address, { rpc = true }) - funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') - eq('hello', meths.get_current_line()) - eq(serverpid, funcs.rpcrequest(id, 'nvim_eval', 'getpid()')) + fn.rpcrequest(id, 'nvim_set_current_line', 'hello') + eq('hello', api.nvim_get_current_line()) + eq(serverpid, fn.rpcrequest(id, 'nvim_eval', 'getpid()')) - eq(id, funcs.rpcrequest(id, 'nvim_get_api_info')[1]) + eq(id, fn.rpcrequest(id, 'nvim_get_api_info')[1]) end) end) end) diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua index d6fc041e83..65b030fc60 100644 --- a/test/functional/api/tabpage_spec.lua +++ b/test/functional/api/tabpage_spec.lua @@ -1,10 +1,9 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, tabpage, curtab, eq, ok = - helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq, helpers.ok -local curtabmeths = helpers.curtabmeths -local funcs = helpers.funcs +local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok +local api = helpers.api +local fn = helpers.fn local request = helpers.request -local NIL = helpers.NIL +local NIL = vim.NIL local pcall_err = helpers.pcall_err local command = helpers.command @@ -13,35 +12,35 @@ describe('api/tabpage', function() describe('list_wins and get_win', function() it('works', function() - nvim('command', 'tabnew') - nvim('command', 'vsplit') - local tab1, tab2 = unpack(nvim('list_tabpages')) - local win1, win2, win3 = unpack(nvim('list_wins')) - eq({ win1 }, tabpage('list_wins', tab1)) - eq({ win2, win3 }, tabpage('list_wins', tab2)) - eq(win2, tabpage('get_win', tab2)) - nvim('set_current_win', win3) - eq(win3, tabpage('get_win', tab2)) + helpers.command('tabnew') + helpers.command('vsplit') + local tab1, tab2 = unpack(api.nvim_list_tabpages()) + local win1, win2, win3 = unpack(api.nvim_list_wins()) + eq({ win1 }, api.nvim_tabpage_list_wins(tab1)) + eq({ win2, win3 }, api.nvim_tabpage_list_wins(tab2)) + eq(win2, api.nvim_tabpage_get_win(tab2)) + api.nvim_set_current_win(win3) + eq(win3, api.nvim_tabpage_get_win(tab2)) end) it('validates args', function() - eq('Invalid tabpage id: 23', pcall_err(tabpage, 'list_wins', 23)) + eq('Invalid tabpage id: 23', pcall_err(api.nvim_tabpage_list_wins, 23)) end) end) describe('{get,set,del}_var', function() it('works', function() - curtab('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) - eq({ 1, 2, { ['3'] = 1 } }, curtab('get_var', 'lua')) - eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 't:lua')) - eq(1, funcs.exists('t:lua')) - curtabmeths.del_var('lua') - eq(0, funcs.exists('t:lua')) - eq('Key not found: lua', pcall_err(curtabmeths.del_var, 'lua')) - curtabmeths.set_var('lua', 1) + api.nvim_tabpage_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_tabpage_get_var(0, 'lua')) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_eval('t:lua')) + eq(1, fn.exists('t:lua')) + api.nvim_tabpage_del_var(0, 'lua') + eq(0, fn.exists('t:lua')) + eq('Key not found: lua', pcall_err(api.nvim_tabpage_del_var, 0, 'lua')) + api.nvim_tabpage_set_var(0, 'lua', 1) command('lockvar t:lua') - eq('Key is locked: lua', pcall_err(curtabmeths.del_var, 'lua')) - eq('Key is locked: lua', pcall_err(curtabmeths.set_var, 'lua', 1)) + eq('Key is locked: lua', pcall_err(api.nvim_tabpage_del_var, 0, 'lua')) + eq('Key is locked: lua', pcall_err(api.nvim_tabpage_set_var, 0, 'lua', 1)) end) it('tabpage_set_var returns the old value', function() @@ -62,28 +61,28 @@ describe('api/tabpage', function() describe('get_number', function() it('works', function() - local tabs = nvim('list_tabpages') - eq(1, tabpage('get_number', tabs[1])) + local tabs = api.nvim_list_tabpages() + eq(1, api.nvim_tabpage_get_number(tabs[1])) - nvim('command', 'tabnew') - local tab1, tab2 = unpack(nvim('list_tabpages')) - eq(1, tabpage('get_number', tab1)) - eq(2, tabpage('get_number', tab2)) + helpers.command('tabnew') + local tab1, tab2 = unpack(api.nvim_list_tabpages()) + eq(1, api.nvim_tabpage_get_number(tab1)) + eq(2, api.nvim_tabpage_get_number(tab2)) - nvim('command', '-tabmove') - eq(2, tabpage('get_number', tab1)) - eq(1, tabpage('get_number', tab2)) + helpers.command('-tabmove') + eq(2, api.nvim_tabpage_get_number(tab1)) + eq(1, api.nvim_tabpage_get_number(tab2)) end) end) describe('is_valid', function() it('works', function() - nvim('command', 'tabnew') - local tab = nvim('list_tabpages')[2] - nvim('set_current_tabpage', tab) - ok(tabpage('is_valid', tab)) - nvim('command', 'tabclose') - ok(not tabpage('is_valid', tab)) + helpers.command('tabnew') + local tab = api.nvim_list_tabpages()[2] + api.nvim_set_current_tabpage(tab) + ok(api.nvim_tabpage_is_valid(tab)) + helpers.command('tabclose') + ok(not api.nvim_tabpage_is_valid(tab)) end) end) end) diff --git a/test/functional/api/ui_spec.lua b/test/functional/api/ui_spec.lua index dafbbe550f..3e1f1ec965 100644 --- a/test/functional/api/ui_spec.lua +++ b/test/functional/api/ui_spec.lua @@ -6,7 +6,7 @@ local eq = helpers.eq local eval = helpers.eval local exec = helpers.exec local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local request = helpers.request local pcall_err = helpers.pcall_err @@ -23,39 +23,39 @@ describe('nvim_ui_attach()', function() end) it('validation', function() - eq('No such UI option: foo', pcall_err(meths.ui_attach, 80, 24, { foo = { 'foo' } })) + eq('No such UI option: foo', pcall_err(api.nvim_ui_attach, 80, 24, { foo = { 'foo' } })) eq( "Invalid 'ext_linegrid': expected Boolean, got Array", - pcall_err(meths.ui_attach, 80, 24, { ext_linegrid = {} }) + pcall_err(api.nvim_ui_attach, 80, 24, { ext_linegrid = {} }) ) eq( "Invalid 'override': expected Boolean, got Array", - pcall_err(meths.ui_attach, 80, 24, { override = {} }) + pcall_err(api.nvim_ui_attach, 80, 24, { override = {} }) ) eq( "Invalid 'rgb': expected Boolean, got Array", - pcall_err(meths.ui_attach, 80, 24, { rgb = {} }) + pcall_err(api.nvim_ui_attach, 80, 24, { rgb = {} }) ) eq( "Invalid 'term_name': expected String, got Boolean", - pcall_err(meths.ui_attach, 80, 24, { term_name = true }) + pcall_err(api.nvim_ui_attach, 80, 24, { term_name = true }) ) eq( "Invalid 'term_colors': expected Integer, got Boolean", - pcall_err(meths.ui_attach, 80, 24, { term_colors = true }) + pcall_err(api.nvim_ui_attach, 80, 24, { term_colors = true }) ) eq( "Invalid 'stdin_fd': expected Integer, got String", - pcall_err(meths.ui_attach, 80, 24, { stdin_fd = 'foo' }) + pcall_err(api.nvim_ui_attach, 80, 24, { stdin_fd = 'foo' }) ) eq( "Invalid 'stdin_tty': expected Boolean, got String", - pcall_err(meths.ui_attach, 80, 24, { stdin_tty = 'foo' }) + pcall_err(api.nvim_ui_attach, 80, 24, { stdin_tty = 'foo' }) ) eq( "Invalid 'stdout_tty': expected Boolean, got String", - pcall_err(meths.ui_attach, 80, 24, { stdout_tty = 'foo' }) + pcall_err(api.nvim_ui_attach, 80, 24, { stdout_tty = 'foo' }) ) eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_try_resize', 40, 10)) @@ -117,17 +117,17 @@ it('autocmds VimSuspend/VimResume #22041', function() end) eq({ 's', 'r', 's' }, eval('g:ev')) screen.suspended = false - meths.input_mouse('move', '', '', 0, 0, 0) + api.nvim_input_mouse('move', '', '', 0, 0, 0) eq({ 's', 'r', 's', 'r' }, eval('g:ev')) feed('<C-Z><C-Z><C-Z>') screen:expect(function() eq(true, screen.suspended) end) - meths.ui_set_focus(false) + api.nvim_ui_set_focus(false) eq({ 's', 'r', 's', 'r', 's' }, eval('g:ev')) screen.suspended = false - meths.ui_set_focus(true) + api.nvim_ui_set_focus(true) eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) command('suspend | suspend | suspend') diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index 76cdb9cbca..c304f1aa88 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -1,8 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local mpack = require('mpack') -local clear, funcs, eq = helpers.clear, helpers.funcs, helpers.eq -local call = helpers.call -local meths = helpers.meths +local clear, fn, eq = helpers.clear, helpers.fn, helpers.eq +local api = helpers.api local function read_mpack_file(fname) local fd = io.open(fname, 'rb') @@ -12,7 +10,7 @@ local function read_mpack_file(fname) local data = fd:read('*a') fd:close() - local unpack = mpack.Unpacker() + local unpack = vim.mpack.Unpacker() return unpack(data) end @@ -20,7 +18,7 @@ describe("api_info()['version']", function() before_each(clear) it('returns API level', function() - local version = call('api_info')['version'] + local version = fn.api_info()['version'] local current = version['api_level'] local compat = version['api_compatible'] eq('number', type(current)) @@ -29,7 +27,7 @@ describe("api_info()['version']", function() end) it('returns Nvim version', function() - local version = call('api_info')['version'] + local version = fn.api_info()['version'] local major = version['major'] local minor = version['minor'] local patch = version['patch'] @@ -39,10 +37,10 @@ describe("api_info()['version']", function() eq('number', type(minor)) eq('number', type(patch)) eq('boolean', type(prerelease)) - eq(1, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. patch)) - eq(0, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1))) - eq(0, funcs.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch)) - eq(0, funcs.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch)) + eq(1, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. patch)) + eq(0, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1))) + eq(0, fn.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch)) + eq(0, fn.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch)) assert(build == nil or type(build) == 'string') end) end) @@ -91,14 +89,14 @@ describe('api metadata', function() end end - local api, compat, stable, api_level + local api_info, compat, stable, api_level local old_api = {} setup(function() clear() -- Ensure a session before requesting api_info. - api = meths.get_api_info()[2] - compat = api.version.api_compatible - api_level = api.version.api_level - if api.version.api_prerelease then + api_info = api.nvim_get_api_info()[2] + compat = api_info.version.api_compatible + api_level = api_info.version.api_level + if api_info.version.api_prerelease then stable = api_level - 1 else stable = api_level @@ -109,7 +107,7 @@ describe('api metadata', function() old_api[level] = read_mpack_file(path) if old_api[level] == nil then local errstr = 'missing metadata fixture for stable level ' .. level .. '. ' - if level == api_level and not api.version.api_prerelease then + if level == api_level and not api_info.version.api_prerelease then errstr = ( errstr .. 'If NVIM_API_CURRENT was bumped, ' @@ -126,7 +124,7 @@ describe('api metadata', function() end) it('functions are compatible with old metadata or have new level', function() - local funcs_new = name_table(api.functions) + local funcs_new = name_table(api_info.functions) local funcs_compat = {} for level = compat, stable do for _, f in ipairs(old_api[level].functions) do @@ -147,7 +145,7 @@ describe('api metadata', function() funcs_compat[level] = name_table(old_api[level].functions) end - for _, f in ipairs(api.functions) do + for _, f in ipairs(api_info.functions) do if f.since <= stable then local f_old = funcs_compat[f.since][f.name] if f_old == nil then @@ -160,7 +158,7 @@ describe('api metadata', function() .. (stable + 1) .. '.' ) - if not api.version.api_prerelease then + if not api_info.version.api_prerelease then errstr = ( errstr .. ' Also bump NVIM_API_CURRENT and set ' @@ -173,7 +171,7 @@ describe('api metadata', function() end end elseif f.since > api_level then - if api.version.api_prerelease then + if api_info.version.api_prerelease then error('New function ' .. f.name .. ' should use since value ' .. api_level) else error( @@ -189,7 +187,7 @@ describe('api metadata', function() end) it('UI events are compatible with old metadata or have new level', function() - local ui_events_new = name_table(api.ui_events) + local ui_events_new = name_table(api_info.ui_events) local ui_events_compat = {} -- UI events were formalized in level 3 @@ -203,7 +201,7 @@ describe('api metadata', function() ui_events_compat[level] = name_table(old_api[level].ui_events) end - for _, e in ipairs(api.ui_events) do + for _, e in ipairs(api_info.ui_events) do if e.since <= stable then local e_old = ui_events_compat[e.since][e.name] if e_old == nil then @@ -215,7 +213,7 @@ describe('api metadata', function() .. (stable + 1) .. '.' ) - if not api.version.api_prerelease then + if not api_info.version.api_prerelease then errstr = ( errstr .. ' Also bump NVIM_API_CURRENT and set ' @@ -225,7 +223,7 @@ describe('api metadata', function() error(errstr) end elseif e.since > api_level then - if api.version.api_prerelease then + if api_info.version.api_prerelease then error('New UI event ' .. e.name .. ' should use since value ' .. api_level) else error( @@ -242,7 +240,7 @@ describe('api metadata', function() it('ui_options are preserved from older levels', function() local available_options = {} - for _, option in ipairs(api.ui_options) do + for _, option in ipairs(api_info.ui_options) do available_options[option] = true end -- UI options were versioned from level 4 diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ce2838879b..aa3b4419cc 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1,21 +1,22 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local luv = require('luv') +local uv = vim.uv local fmt = string.format local dedent = helpers.dedent local assert_alive = helpers.assert_alive -local NIL = helpers.NIL -local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq +local NIL = vim.NIL +local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq local command = helpers.command +local command_output = helpers.api.command_output local exec = helpers.exec local exec_capture = helpers.exec_capture local eval = helpers.eval local expect = helpers.expect -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local matches = helpers.matches -local pesc = helpers.pesc +local pesc = vim.pesc local mkdir_p = helpers.mkdir_p local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed local is_os = helpers.is_os @@ -35,7 +36,7 @@ local pcall_err = helpers.pcall_err local format_string = helpers.format_string local intchar2lua = helpers.intchar2lua local mergedicts_copy = helpers.mergedicts_copy -local endswith = helpers.endswith +local endswith = vim.endswith describe('API', function() before_each(clear) @@ -70,7 +71,7 @@ describe('API', function() end) it('handles errors in async requests', function() - local error_types = meths.get_api_info()[2].error_types + local error_types = api.nvim_get_api_info()[2].error_types nvim_async('bogus') eq({ 'notification', @@ -82,7 +83,7 @@ describe('API', function() end) it('failed async request emits nvim_error_event', function() - local error_types = meths.get_api_info()[2].error_types + local error_types = api.nvim_get_api_info()[2].error_types nvim_async('command', 'bogus') eq({ 'notification', @@ -94,41 +95,40 @@ describe('API', function() end) it('does not set CA_COMMAND_BUSY #7254', function() - nvim('command', 'split') - nvim('command', 'autocmd WinEnter * startinsert') - nvim('command', 'wincmd w') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + command('split') + command('autocmd WinEnter * startinsert') + command('wincmd w') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) end) describe('nvim_exec2', function() it('always returns table', function() -- In built version this results into `vim.empty_dict()` - eq({}, nvim('exec2', 'echo "Hello"', {})) - eq({}, nvim('exec2', 'echo "Hello"', { output = false })) - eq({ output = 'Hello' }, nvim('exec2', 'echo "Hello"', { output = true })) + eq({}, api.nvim_exec2('echo "Hello"', {})) + eq({}, api.nvim_exec2('echo "Hello"', { output = false })) + eq({ output = 'Hello' }, api.nvim_exec2('echo "Hello"', { output = true })) end) it('default options', function() -- Should be equivalent to { output = false } - nvim('exec2', "let x0 = 'a'", {}) - eq('a', nvim('get_var', 'x0')) + api.nvim_exec2("let x0 = 'a'", {}) + eq('a', api.nvim_get_var('x0')) end) it('one-line input', function() - nvim('exec2', "let x1 = 'a'", { output = false }) - eq('a', nvim('get_var', 'x1')) + api.nvim_exec2("let x1 = 'a'", { output = false }) + eq('a', api.nvim_get_var('x1')) end) it(':verbose set {option}?', function() - nvim('exec2', 'set nowrap', { output = false }) + api.nvim_exec2('set nowrap', { output = false }) eq( { output = 'nowrap\n\tLast set from anonymous :source' }, - nvim('exec2', 'verbose set wrap?', { output = true }) + api.nvim_exec2('verbose set wrap?', { output = true }) ) -- Using script var to force creation of a script item - nvim( - 'exec2', + api.nvim_exec2( [[ let s:a = 1 set nowrap @@ -137,40 +137,39 @@ describe('API', function() ) eq( { output = 'nowrap\n\tLast set from anonymous :source (script id 1)' }, - nvim('exec2', 'verbose set wrap?', { output = true }) + api.nvim_exec2('verbose set wrap?', { output = true }) ) end) it('multiline input', function() -- Heredoc + empty lines. - nvim('exec2', "let x2 = 'a'\n", { output = false }) - eq('a', nvim('get_var', 'x2')) - nvim('exec2', 'lua <<EOF\n\n\n\ny=3\n\n\nEOF', { output = false }) - eq(3, nvim('eval', "luaeval('y')")) + api.nvim_exec2("let x2 = 'a'\n", { output = false }) + eq('a', api.nvim_get_var('x2')) + api.nvim_exec2('lua <<EOF\n\n\n\ny=3\n\n\nEOF', { output = false }) + eq(3, api.nvim_eval("luaeval('y')")) - eq({}, nvim('exec2', 'lua <<EOF\ny=3\nEOF', { output = false })) - eq(3, nvim('eval', "luaeval('y')")) + eq({}, api.nvim_exec2('lua <<EOF\ny=3\nEOF', { output = false })) + eq(3, api.nvim_eval("luaeval('y')")) -- Multiple statements - nvim('exec2', 'let x1=1\nlet x2=2\nlet x3=3\n', { output = false }) - eq(1, nvim('eval', 'x1')) - eq(2, nvim('eval', 'x2')) - eq(3, nvim('eval', 'x3')) + api.nvim_exec2('let x1=1\nlet x2=2\nlet x3=3\n', { output = false }) + eq(1, api.nvim_eval('x1')) + eq(2, api.nvim_eval('x2')) + eq(3, api.nvim_eval('x3')) -- Functions - nvim('exec2', 'function Foo()\ncall setline(1,["xxx"])\nendfunction', { output = false }) - eq('', nvim('get_current_line')) - nvim('exec2', 'call Foo()', { output = false }) - eq('xxx', nvim('get_current_line')) + api.nvim_exec2('function Foo()\ncall setline(1,["xxx"])\nendfunction', { output = false }) + eq('', api.nvim_get_current_line()) + api.nvim_exec2('call Foo()', { output = false }) + eq('xxx', api.nvim_get_current_line()) -- Autocmds - nvim('exec2', 'autocmd BufAdd * :let x1 = "Hello"', { output = false }) - nvim('command', 'new foo') + api.nvim_exec2('autocmd BufAdd * :let x1 = "Hello"', { output = false }) + command('new foo') eq('Hello', request('nvim_eval', 'g:x1')) -- Line continuations - nvim( - 'exec2', + api.nvim_exec2( [[ let abc = #{ \ a: 1, @@ -182,14 +181,13 @@ describe('API', function() eq({ a = 1, c = 3 }, request('nvim_eval', 'g:abc')) -- try no spaces before continuations to catch off-by-one error - nvim('exec2', 'let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', { output = false }) + api.nvim_exec2('let ab = #{\n\\a: 98,\n"\\ b: 2\n\\}', { output = false }) eq({ a = 98 }, request('nvim_eval', 'g:ab')) -- Script scope (s:) eq( { output = 'ahoy! script-scoped varrrrr' }, - nvim( - 'exec2', + api.nvim_exec2( [[ let s:pirate = 'script-scoped varrrrr' function! s:avast_ye_hades(s) abort @@ -203,8 +201,7 @@ describe('API', function() eq( { output = "{'output': 'ahoy! script-scoped varrrrr'}" }, - nvim( - 'exec2', + api.nvim_exec2( [[ let s:pirate = 'script-scoped varrrrr' function! Avast_ye_hades(s) abort @@ -232,8 +229,7 @@ describe('API', function() -- Script items are created only on script var access eq( { output = '1\n0' }, - nvim( - 'exec2', + api.nvim_exec2( [[ echo expand("<SID>")->empty() let s:a = 123 @@ -245,8 +241,7 @@ describe('API', function() eq( { output = '1\n0' }, - nvim( - 'exec2', + api.nvim_exec2( [[ echo expand("<SID>")->empty() function s:a() abort @@ -259,8 +254,7 @@ describe('API', function() end) it('non-ASCII input', function() - nvim( - 'exec2', + api.nvim_exec2( [=[ new exe "normal! i ax \n Ax " @@ -268,13 +262,12 @@ describe('API', function() ]=], { output = false } ) - nvim('command', '1') - eq(' --a1234-- ', nvim('get_current_line')) - nvim('command', '2') - eq(' --A1234-- ', nvim('get_current_line')) + command('1') + eq(' --a1234-- ', api.nvim_get_current_line()) + command('2') + eq(' --A1234-- ', api.nvim_get_current_line()) - nvim( - 'exec2', + api.nvim_exec2( [[ new call setline(1,['xxx']) @@ -283,7 +276,7 @@ describe('API', function() ]], { output = false } ) - eq('ñxx', nvim('get_current_line')) + eq('ñxx', api.nvim_get_current_line()) end) it('execution error', function() @@ -291,7 +284,7 @@ describe('API', function() 'nvim_exec2(): Vim:E492: Not an editor command: bogus_command', pcall_err(request, 'nvim_exec2', 'bogus_command', {}) ) - eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated. + eq('', api.nvim_eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) eq( @@ -326,7 +319,7 @@ describe('API', function() write_file(fname, 'echo "hello"\n') local sourcing_fname = tmpname() write_file(sourcing_fname, 'call nvim_exec2("source ' .. fname .. '", {"output": v:false})\n') - meths.exec2('set verbose=2', { output = false }) + api.nvim_exec2('set verbose=2', { output = false }) local traceback_output = dedent([[ line 0: sourcing "%s" line 0: sourcing "%s" @@ -343,7 +336,7 @@ describe('API', function() ) eq( { output = traceback_output }, - meths.exec2( + api.nvim_exec2( 'call nvim_exec2("source ' .. sourcing_fname .. '", {"output": v:false})', { output = true } ) @@ -355,10 +348,10 @@ describe('API', function() it('returns output', function() eq( { output = 'this is spinal tap' }, - nvim('exec2', 'lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', { output = true }) + api.nvim_exec2('lua <<EOF\n\n\nprint("this is spinal tap")\n\n\nEOF', { output = true }) ) - eq({ output = '' }, nvim('exec2', 'echo', { output = true })) - eq({ output = 'foo 42' }, nvim('exec2', 'echo "foo" 42', { output = true })) + eq({ output = '' }, api.nvim_exec2('echo', { output = true })) + eq({ output = 'foo 42' }, api.nvim_exec2('echo "foo" 42', { output = true })) end) it('displays messages when opts.output=false', function() @@ -367,7 +360,7 @@ describe('API', function() screen:set_default_attr_ids({ [0] = { bold = true, foreground = Screen.colors.Blue }, }) - meths.exec2("echo 'hello'", { output = false }) + api.nvim_exec2("echo 'hello'", { output = false }) screen:expect { grid = [[ ^ | @@ -383,7 +376,7 @@ describe('API', function() screen:set_default_attr_ids({ [0] = { bold = true, foreground = Screen.colors.Blue }, }) - meths.exec2("echo 'hello'", { output = true }) + api.nvim_exec2("echo 'hello'", { output = true }) screen:expect { grid = [[ ^ | @@ -410,10 +403,10 @@ describe('API', function() describe('nvim_command', function() it('works', function() local fname = tmpname() - nvim('command', 'new') - nvim('command', 'edit ' .. fname) - nvim('command', 'normal itesting\napi') - nvim('command', 'w') + command('new') + command('edit ' .. fname) + command('normal itesting\napi') + command('w') local f = assert(io.open(fname)) if is_os('win') then eq('testing\r\napi\r\n', f:read('*a')) @@ -425,15 +418,15 @@ describe('API', function() end) it('Vimscript validation error: fails with specific error', function() - local status, rv = pcall(nvim, 'command', 'bogus_command') + local status, rv = pcall(command, 'bogus_command') eq(false, status) -- nvim_command() failed. eq('E492:', string.match(rv, 'E%d*:')) -- Vimscript error was returned. - eq('', nvim('eval', 'v:errmsg')) -- v:errmsg was not updated. + eq('', api.nvim_eval('v:errmsg')) -- v:errmsg was not updated. eq('', eval('v:exception')) end) it('Vimscript execution error: fails with specific error', function() - local status, rv = pcall(nvim, 'command', 'buffer 23487') + local status, rv = pcall(command, 'buffer 23487') eq(false, status) -- nvim_command() failed. eq('E86: Buffer 23487 does not exist', string.match(rv, 'E%d*:.*')) eq('', eval('v:errmsg')) -- v:errmsg was not updated. @@ -451,92 +444,89 @@ describe('API', function() describe('nvim_command_output', function() it('does not induce hit-enter prompt', function() - nvim('ui_attach', 80, 20, {}) + api.nvim_ui_attach(80, 20, {}) -- Induce a hit-enter prompt use nvim_input (non-blocking). - nvim('command', 'set cmdheight=1') - nvim('input', [[:echo "hi\nhi2"<CR>]]) + command('set cmdheight=1') + api.nvim_input([[:echo "hi\nhi2"<CR>]]) -- Verify hit-enter prompt. - eq({ mode = 'r', blocking = true }, nvim('get_mode')) - nvim('input', [[<C-c>]]) + eq({ mode = 'r', blocking = true }, api.nvim_get_mode()) + api.nvim_input([[<C-c>]]) -- Verify NO hit-enter prompt. - nvim('command_output', [[echo "hi\nhi2"]]) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + command_output([[echo "hi\nhi2"]]) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('captures command output', function() - eq('this is\nspinal tap', nvim('command_output', [[echo "this is\nspinal tap"]])) - eq('no line ending!', nvim('command_output', [[echon "no line ending!"]])) + eq('this is\nspinal tap', command_output([[echo "this is\nspinal tap"]])) + eq('no line ending!', command_output([[echon "no line ending!"]])) end) it('captures empty command output', function() - eq('', nvim('command_output', 'echo')) + eq('', command_output('echo')) end) it('captures single-char command output', function() - eq('x', nvim('command_output', 'echo "x"')) + eq('x', command_output('echo "x"')) end) it('captures multiple commands', function() - eq( - 'foo\n 1 %a "[No Name]" line 1', - nvim('command_output', 'echo "foo" | ls') - ) + eq('foo\n 1 %a "[No Name]" line 1', command_output('echo "foo" | ls')) end) it('captures nested execute()', function() eq( '\nnested1\nnested2\n 1 %a "[No Name]" line 1', - nvim('command_output', [[echo execute('echo "nested1\nnested2"') | ls]]) + command_output([[echo execute('echo "nested1\nnested2"') | ls]]) ) end) it('captures nested nvim_command_output()', function() eq( 'nested1\nnested2\n 1 %a "[No Name]" line 1', - nvim('command_output', [[echo nvim_command_output('echo "nested1\nnested2"') | ls]]) + command_output([[echo nvim_command_output('echo "nested1\nnested2"') | ls]]) ) end) it('returns shell |:!| output', function() local win_lf = is_os('win') and '\r' or '' - eq(':!echo foo\r\n\nfoo' .. win_lf .. '\n', nvim('command_output', [[!echo foo]])) + eq(':!echo foo\r\n\nfoo' .. win_lf .. '\n', command_output([[!echo foo]])) end) it('Vimscript validation error: fails with specific error', function() - local status, rv = pcall(nvim, 'command_output', 'bogus commannnd') + local status, rv = pcall(command_output, 'bogus commannnd') eq(false, status) -- nvim_command_output() failed. eq('E492: Not an editor command: bogus commannnd', string.match(rv, 'E%d*:.*')) eq('', eval('v:errmsg')) -- v:errmsg was not updated. -- Verify NO hit-enter prompt. - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('Vimscript execution error: fails with specific error', function() - local status, rv = pcall(nvim, 'command_output', 'buffer 42') + local status, rv = pcall(command_output, 'buffer 42') eq(false, status) -- nvim_command_output() failed. eq('E86: Buffer 42 does not exist', string.match(rv, 'E%d*:.*')) eq('', eval('v:errmsg')) -- v:errmsg was not updated. -- Verify NO hit-enter prompt. - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('does not cause heap buffer overflow with large output', function() - eq(eval('string(range(1000000))'), nvim('command_output', 'echo range(1000000)')) + eq(eval('string(range(1000000))'), command_output('echo range(1000000)')) end) end) describe('nvim_eval', function() it('works', function() - nvim('command', 'let g:v1 = "a"') - nvim('command', 'let g:v2 = [1, 2, {"v3": 3}]') - eq({ v1 = 'a', v2 = { 1, 2, { v3 = 3 } } }, nvim('eval', 'g:')) + command('let g:v1 = "a"') + command('let g:v2 = [1, 2, {"v3": 3}]') + eq({ v1 = 'a', v2 = { 1, 2, { v3 = 3 } } }, api.nvim_eval('g:')) end) it('handles NULL-initialized strings correctly', function() - eq(1, nvim('eval', "matcharg(1) == ['', '']")) - eq({ '', '' }, nvim('eval', 'matcharg(1)')) + eq(1, api.nvim_eval("matcharg(1) == ['', '']")) + eq({ '', '' }, api.nvim_eval('matcharg(1)')) end) it('works under deprecated name', function() @@ -551,10 +541,10 @@ describe('API', function() describe('nvim_call_function', function() it('works', function() - nvim('call_function', 'setqflist', { { { filename = 'something', lnum = 17 } }, 'r' }) - eq(17, nvim('call_function', 'getqflist', {})[1].lnum) - eq(17, nvim('call_function', 'eval', { 17 })) - eq('foo', nvim('call_function', 'simplify', { 'this/./is//redundant/../../../foo' })) + api.nvim_call_function('setqflist', { { { filename = 'something', lnum = 17 } }, 'r' }) + eq(17, api.nvim_call_function('getqflist', {})[1].lnum) + eq(17, api.nvim_call_function('eval', { 17 })) + eq('foo', api.nvim_call_function('simplify', { 'this/./is//redundant/../../../foo' })) end) it('Vimscript validation error: returns specific error, does NOT update v:errmsg', function() @@ -629,18 +619,18 @@ describe('API', function() ]]) -- :help Dictionary-function - eq('Hello, World!', nvim('call_dict_function', 'g:test_dict_fn', 'F', { 'World' })) + eq('Hello, World!', api.nvim_call_dict_function('g:test_dict_fn', 'F', { 'World' })) -- Funcref is sent as NIL over RPC. - eq({ greeting = 'Hello', F = NIL }, nvim('get_var', 'test_dict_fn')) + eq({ greeting = 'Hello', F = NIL }, api.nvim_get_var('test_dict_fn')) -- :help numbered-function - eq('Hi, Moon ...', nvim('call_dict_function', 'g:test_dict_fn2', 'F2', { 'Moon' })) + eq('Hi, Moon ...', api.nvim_call_dict_function('g:test_dict_fn2', 'F2', { 'Moon' })) -- Funcref is sent as NIL over RPC. - eq({ greeting = 'Hi', F2 = NIL }, nvim('get_var', 'test_dict_fn2')) + eq({ greeting = 'Hi', F2 = NIL }, api.nvim_get_var('test_dict_fn2')) -- Function specified via RPC dict. source('function! G() dict\n return "@".(self.result)."@"\nendfunction') - eq('@it works@', nvim('call_dict_function', { result = 'it works', G = 'G' }, 'G', {})) + eq('@it works@', api.nvim_call_dict_function({ result = 'it works', G = 'G' }, 'G', {})) end) it('validation', function() @@ -685,8 +675,8 @@ describe('API', function() local start_dir before_each(function() - funcs.mkdir('Xtestdir') - start_dir = funcs.getcwd() + fn.mkdir('Xtestdir') + start_dir = fn.getcwd() end) after_each(function() @@ -694,81 +684,84 @@ describe('API', function() end) it('works', function() - meths.set_current_dir('Xtestdir') - eq(funcs.getcwd(), start_dir .. helpers.get_pathsep() .. 'Xtestdir') + api.nvim_set_current_dir('Xtestdir') + eq(fn.getcwd(), start_dir .. helpers.get_pathsep() .. 'Xtestdir') end) it('sets previous directory', function() - meths.set_current_dir('Xtestdir') + api.nvim_set_current_dir('Xtestdir') command('cd -') - eq(funcs.getcwd(), start_dir) + eq(fn.getcwd(), start_dir) end) end) describe('nvim_exec_lua', function() it('works', function() - meths.exec_lua('vim.api.nvim_set_var("test", 3)', {}) - eq(3, meths.get_var('test')) + api.nvim_exec_lua('vim.api.nvim_set_var("test", 3)', {}) + eq(3, api.nvim_get_var('test')) - eq(17, meths.exec_lua('a, b = ...\nreturn a + b', { 10, 7 })) + eq(17, api.nvim_exec_lua('a, b = ...\nreturn a + b', { 10, 7 })) - eq(NIL, meths.exec_lua('function xx(a,b)\nreturn a..b\nend', {})) - eq('xy', meths.exec_lua('return xx(...)', { 'x', 'y' })) + eq(NIL, api.nvim_exec_lua('function xx(a,b)\nreturn a..b\nend', {})) + eq('xy', api.nvim_exec_lua('return xx(...)', { 'x', 'y' })) -- Deprecated name: nvim_execute_lua. - eq('xy', meths.execute_lua('return xx(...)', { 'x', 'y' })) + eq('xy', api.nvim_execute_lua('return xx(...)', { 'x', 'y' })) end) it('reports errors', function() eq( [[Error loading lua: [string "<nvim>"]:0: '=' expected near '+']], - pcall_err(meths.exec_lua, 'a+*b', {}) + pcall_err(api.nvim_exec_lua, 'a+*b', {}) ) eq( [[Error loading lua: [string "<nvim>"]:0: unexpected symbol near '1']], - pcall_err(meths.exec_lua, '1+2', {}) + pcall_err(api.nvim_exec_lua, '1+2', {}) ) eq( [[Error loading lua: [string "<nvim>"]:0: unexpected symbol]], - pcall_err(meths.exec_lua, 'aa=bb\0', {}) + pcall_err(api.nvim_exec_lua, 'aa=bb\0', {}) ) - eq([[attempt to call global 'bork' (a nil value)]], pcall_err(meths.exec_lua, 'bork()', {})) + eq( + [[attempt to call global 'bork' (a nil value)]], + pcall_err(api.nvim_exec_lua, 'bork()', {}) + ) - eq('did\nthe\nfail', pcall_err(meths.exec_lua, 'error("did\\nthe\\nfail")', {})) + eq('did\nthe\nfail', pcall_err(api.nvim_exec_lua, 'error("did\\nthe\\nfail")', {})) end) it('uses native float values', function() - eq(2.5, meths.exec_lua('return select(1, ...)', { 2.5 })) - eq('2.5', meths.exec_lua('return vim.inspect(...)', { 2.5 })) + eq(2.5, api.nvim_exec_lua('return select(1, ...)', { 2.5 })) + eq('2.5', api.nvim_exec_lua('return vim.inspect(...)', { 2.5 })) -- "special" float values are still accepted as return values. - eq(2.5, meths.exec_lua("return vim.api.nvim_eval('2.5')", {})) + eq(2.5, api.nvim_exec_lua("return vim.api.nvim_eval('2.5')", {})) eq( '{\n [false] = 2.5,\n [true] = 3\n}', - meths.exec_lua("return vim.inspect(vim.api.nvim_eval('2.5'))", {}) + api.nvim_exec_lua("return vim.inspect(vim.api.nvim_eval('2.5'))", {}) ) end) end) describe('nvim_notify', function() it('can notify a info message', function() - nvim('notify', 'hello world', 2, {}) + api.nvim_notify('hello world', 2, {}) end) it('can be overridden', function() command('lua vim.notify = function(...) return 42 end') - eq(42, meths.exec_lua("return vim.notify('Hello world')", {})) - nvim('notify', 'hello world', 4, {}) + eq(42, api.nvim_exec_lua("return vim.notify('Hello world')", {})) + api.nvim_notify('hello world', 4, {}) end) end) describe('nvim_input', function() it('Vimscript error: does NOT fail, updates v:errmsg', function() - local status, _ = pcall(nvim, 'input', ':call bogus_fn()<CR>') - local v_errnum = string.match(nvim('eval', 'v:errmsg'), 'E%d*:') + local status, _ = pcall(api.nvim_input, ':call bogus_fn()<CR>') + local v_errnum = string.match(api.nvim_eval('v:errmsg'), 'E%d*:') eq(true, status) -- nvim_input() did not fail. eq('E117:', v_errnum) -- v:errmsg was updated. end) @@ -786,23 +779,23 @@ describe('API', function() end) local function run_streamed_paste_tests() it('stream: multiple chunks form one undo-block', function() - nvim('paste', '1/chunk 1 (start)\n', true, 1) - nvim('paste', '1/chunk 2 (end)\n', true, 3) + api.nvim_paste('1/chunk 1 (start)\n', true, 1) + api.nvim_paste('1/chunk 2 (end)\n', true, 3) local expected1 = [[ 1/chunk 1 (start) 1/chunk 2 (end) ]] expect(expected1) - nvim('paste', '2/chunk 1 (start)\n', true, 1) - nvim('paste', '2/chunk 2\n', true, 2) + api.nvim_paste('2/chunk 1 (start)\n', true, 1) + api.nvim_paste('2/chunk 2\n', true, 2) expect([[ 1/chunk 1 (start) 1/chunk 2 (end) 2/chunk 1 (start) 2/chunk 2 ]]) - nvim('paste', '2/chunk 3\n', true, 2) - nvim('paste', '2/chunk 4 (end)\n', true, 3) + api.nvim_paste('2/chunk 3\n', true, 2) + api.nvim_paste('2/chunk 4 (end)\n', true, 3) expect([[ 1/chunk 1 (start) 1/chunk 2 (end) @@ -818,10 +811,10 @@ describe('API', function() -- If nvim_paste() calls :undojoin without making any changes, this makes it an error. feed('afoo<Esc>u') feed('i') - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('aaaaaabbbbbbccccccdddddd') feed('<Esc>u') expect('') @@ -837,17 +830,17 @@ describe('API', function() expect('') end) it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('aaaaaabbbbbbccccccdddddd') end) it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -867,17 +860,17 @@ describe('API', function() expect('||') end) it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('|aaaaaabbbbbbccccccdddddd|') end) it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ |aaaaaa bbbbbb @@ -897,17 +890,17 @@ describe('API', function() expect('||') end) it('pasting one line', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('pasting multiple lines', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ ||aaaaaa bbbbbb @@ -931,24 +924,24 @@ describe('API', function() xxx|]]) end) it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('|aaaaaabbbbbbccccccdddddd|') end) it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('|bbbbbbccccccdddddd|') end) it('with all chunks empty', function() - nvim('paste', '', false, 1) - nvim('paste', '', false, 2) - nvim('paste', '', false, 2) - nvim('paste', '', false, 3) + api.nvim_paste('', false, 1) + api.nvim_paste('', false, 2) + api.nvim_paste('', false, 2) + api.nvim_paste('', false, 3) expect('||') end) end) @@ -966,17 +959,17 @@ describe('API', function() xxx]]) end) it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||bbbbbbccccccdddddd') end) end) @@ -994,17 +987,17 @@ describe('API', function() xxx]]) end) it('with non-empty chunks', function() - nvim('paste', 'aaaaaa', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||aaaaaabbbbbbccccccdddddd') end) it('with empty first chunk', function() - nvim('paste', '', false, 1) - nvim('paste', 'bbbbbb', false, 2) - nvim('paste', 'cccccc', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('', false, 1) + api.nvim_paste('bbbbbb', false, 2) + api.nvim_paste('cccccc', false, 2) + api.nvim_paste('dddddd', false, 3) expect('||bbbbbbccccccdddddd') end) end) @@ -1027,10 +1020,10 @@ describe('API', function() feed('ggV') end) it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -1039,10 +1032,10 @@ describe('API', function() 123456789]]) end) it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd\n', false, 3) expect([[ aaaaaa bbbbbb @@ -1057,10 +1050,10 @@ describe('API', function() feed('2ggV') end) it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ 123456789 aaaaaa @@ -1069,10 +1062,10 @@ describe('API', function() dddddd123456789]]) end) it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd\n', false, 3) expect([[ 123456789 aaaaaa @@ -1087,10 +1080,10 @@ describe('API', function() feed('3ggV') end) it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ 123456789 987654321 @@ -1100,10 +1093,10 @@ describe('API', function() dddddd]]) end) it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd\n', false, 3) expect([[ 123456789 987654321 @@ -1119,10 +1112,10 @@ describe('API', function() feed('ggVG') end) it('pasting text without final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd', false, 3) expect([[ aaaaaa bbbbbb @@ -1130,10 +1123,10 @@ describe('API', function() dddddd]]) end) it('pasting text with final new line', function() - nvim('paste', 'aaaaaa\n', false, 1) - nvim('paste', 'bbbbbb\n', false, 2) - nvim('paste', 'cccccc\n', false, 2) - nvim('paste', 'dddddd\n', false, 3) + api.nvim_paste('aaaaaa\n', false, 1) + api.nvim_paste('bbbbbb\n', false, 2) + api.nvim_paste('cccccc\n', false, 2) + api.nvim_paste('dddddd\n', false, 3) expect([[ aaaaaa bbbbbb @@ -1155,71 +1148,71 @@ describe('API', function() end) it('non-streaming', function() -- With final "\n". - nvim('paste', 'line 1\nline 2\nline 3\n', true, -1) + api.nvim_paste('line 1\nline 2\nline 3\n', true, -1) expect([[ line 1 line 2 line 3 ]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) -- Cursor follows the paste. - eq(false, nvim('get_option_value', 'paste', {})) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) -- Cursor follows the paste. + eq(false, api.nvim_get_option_value('paste', {})) command('%delete _') -- Without final "\n". - nvim('paste', 'line 1\nline 2\nline 3', true, -1) + api.nvim_paste('line 1\nline 2\nline 3', true, -1) expect([[ line 1 line 2 line 3]]) - eq({ 0, 3, 6, 0 }, funcs.getpos('.')) + eq({ 0, 3, 6, 0 }, fn.getpos('.')) command('%delete _') -- CRLF #10872 - nvim('paste', 'line 1\r\nline 2\r\nline 3\r\n', true, -1) + api.nvim_paste('line 1\r\nline 2\r\nline 3\r\n', true, -1) expect([[ line 1 line 2 line 3 ]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) command('%delete _') -- CRLF without final "\n". - nvim('paste', 'line 1\r\nline 2\r\nline 3\r', true, -1) + api.nvim_paste('line 1\r\nline 2\r\nline 3\r', true, -1) expect([[ line 1 line 2 line 3 ]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) command('%delete _') -- CRLF without final "\r\n". - nvim('paste', 'line 1\r\nline 2\r\nline 3', true, -1) + api.nvim_paste('line 1\r\nline 2\r\nline 3', true, -1) expect([[ line 1 line 2 line 3]]) - eq({ 0, 3, 6, 0 }, funcs.getpos('.')) + eq({ 0, 3, 6, 0 }, fn.getpos('.')) command('%delete _') -- Various other junk. - nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1) + api.nvim_paste('line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1) expect('line 1\n\n\nline 2\nline 3\nline 4\n') - eq({ 0, 7, 1, 0 }, funcs.getpos('.')) - eq(false, nvim('get_option_value', 'paste', {})) + eq({ 0, 7, 1, 0 }, fn.getpos('.')) + eq(false, api.nvim_get_option_value('paste', {})) end) it('Replace-mode', function() -- Within single line - nvim('put', { 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) + api.nvim_put({ 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) command('normal l') command('startreplace') - nvim('paste', '123456', true, -1) + api.nvim_paste('123456', true, -1) expect([[ a123456d eeffgghh iijjkkll]]) command('%delete _') -- Across lines - nvim('put', { 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) + api.nvim_put({ 'aabbccdd', 'eeffgghh', 'iijjkkll' }, 'c', true, false) command('normal l') command('startreplace') - nvim('paste', '123\n456', true, -1) + api.nvim_paste('123\n456', true, -1) expect([[ a123 456d @@ -1228,30 +1221,30 @@ describe('API', function() end) it('when searching in Visual mode', function() feed('v/') - nvim('paste', 'aabbccdd', true, -1) - eq('aabbccdd', funcs.getcmdline()) + api.nvim_paste('aabbccdd', true, -1) + eq('aabbccdd', fn.getcmdline()) expect('') end) it('mappings are disabled in Cmdline mode', function() command('cnoremap a b') feed(':') - nvim('paste', 'a', true, -1) - eq('a', funcs.getcmdline()) + api.nvim_paste('a', true, -1) + eq('a', fn.getcmdline()) end) it('pasted text is saved in cmdline history when <CR> comes from mapping #20957', function() command('cnoremap <CR> <CR>') feed(':') - nvim('paste', 'echo', true, -1) - eq('', funcs.histget(':')) + api.nvim_paste('echo', true, -1) + eq('', fn.histget(':')) feed('<CR>') - eq('echo', funcs.histget(':')) + eq('echo', fn.histget(':')) end) it('pasting with empty last chunk in Cmdline mode', function() local screen = Screen.new(20, 4) screen:attach() feed(':') - nvim('paste', 'Foo', true, 1) - nvim('paste', '', true, 3) + api.nvim_paste('Foo', true, 1) + api.nvim_paste('', true, 3) screen:expect([[ | ~ |*2 @@ -1262,7 +1255,7 @@ describe('API', function() local screen = Screen.new(20, 4) screen:attach() feed(':') - nvim('paste', 'normal! \023\022\006\027', true, -1) + api.nvim_paste('normal! \023\022\006\027', true, -1) screen:expect([[ | ~ |*2 @@ -1270,12 +1263,12 @@ describe('API', function() ]]) end) it('crlf=false does not break lines at CR, CRLF', function() - nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) + api.nvim_paste('line 1\r\n\r\rline 2\nline 3\rline 4\r', false, -1) expect('line 1\r\n\r\rline 2\nline 3\rline 4\r') - eq({ 0, 3, 14, 0 }, funcs.getpos('.')) + eq({ 0, 3, 14, 0 }, fn.getpos('.')) end) it('vim.paste() failure', function() - nvim('exec_lua', 'vim.paste = (function(lines, phase) error("fake fail") end)', {}) + api.nvim_exec_lua('vim.paste = (function(lines, phase) error("fake fail") end)', {}) eq('fake fail', pcall_err(request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1)) end) end) @@ -1297,78 +1290,78 @@ describe('API', function() end) it('inserts text', function() -- linewise - nvim('put', { 'line 1', 'line 2', 'line 3' }, 'l', true, true) + api.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'l', true, true) expect([[ line 1 line 2 line 3]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) command('%delete _') -- charwise - nvim('put', { 'line 1', 'line 2', 'line 3' }, 'c', true, false) + api.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'c', true, false) expect([[ line 1 line 2 line 3]]) - eq({ 0, 1, 1, 0 }, funcs.getpos('.')) -- follow=false + eq({ 0, 1, 1, 0 }, fn.getpos('.')) -- follow=false -- blockwise - nvim('put', { 'AA', 'BB' }, 'b', true, true) + api.nvim_put({ 'AA', 'BB' }, 'b', true, true) expect([[ lAAine 1 lBBine 2 line 3]]) - eq({ 0, 2, 4, 0 }, funcs.getpos('.')) + eq({ 0, 2, 4, 0 }, fn.getpos('.')) command('%delete _') -- Empty lines list. - nvim('put', {}, 'c', true, true) - eq({ 0, 1, 1, 0 }, funcs.getpos('.')) + api.nvim_put({}, 'c', true, true) + eq({ 0, 1, 1, 0 }, fn.getpos('.')) expect([[]]) -- Single empty line. - nvim('put', { '' }, 'c', true, true) - eq({ 0, 1, 1, 0 }, funcs.getpos('.')) + api.nvim_put({ '' }, 'c', true, true) + eq({ 0, 1, 1, 0 }, fn.getpos('.')) expect([[ ]]) - nvim('put', { 'AB' }, 'c', true, true) + api.nvim_put({ 'AB' }, 'c', true, true) -- after=false, follow=true - nvim('put', { 'line 1', 'line 2' }, 'c', false, true) + api.nvim_put({ 'line 1', 'line 2' }, 'c', false, true) expect([[ Aline 1 line 2B]]) - eq({ 0, 2, 7, 0 }, funcs.getpos('.')) + eq({ 0, 2, 7, 0 }, fn.getpos('.')) command('%delete _') - nvim('put', { 'AB' }, 'c', true, true) + api.nvim_put({ 'AB' }, 'c', true, true) -- after=false, follow=false - nvim('put', { 'line 1', 'line 2' }, 'c', false, false) + api.nvim_put({ 'line 1', 'line 2' }, 'c', false, false) expect([[ Aline 1 line 2B]]) - eq({ 0, 1, 2, 0 }, funcs.getpos('.')) - eq('', nvim('eval', 'v:errmsg')) + eq({ 0, 1, 2, 0 }, fn.getpos('.')) + eq('', api.nvim_eval('v:errmsg')) end) it('detects charwise/linewise text (empty {type})', function() -- linewise (final item is empty string) - nvim('put', { 'line 1', 'line 2', 'line 3', '' }, '', true, true) + api.nvim_put({ 'line 1', 'line 2', 'line 3', '' }, '', true, true) expect([[ line 1 line 2 line 3]]) - eq({ 0, 4, 1, 0 }, funcs.getpos('.')) + eq({ 0, 4, 1, 0 }, fn.getpos('.')) command('%delete _') -- charwise (final item is non-empty) - nvim('put', { 'line 1', 'line 2', 'line 3' }, '', true, true) + api.nvim_put({ 'line 1', 'line 2', 'line 3' }, '', true, true) expect([[ line 1 line 2 line 3]]) - eq({ 0, 3, 6, 0 }, funcs.getpos('.')) + eq({ 0, 3, 6, 0 }, fn.getpos('.')) end) it('allows block width', function() -- behave consistently with setreg(); support "\022{NUM}" return by getregtype() - meths.put({ 'line 1', 'line 2', 'line 3' }, 'l', false, false) + api.nvim_put({ 'line 1', 'line 2', 'line 3' }, 'l', false, false) expect([[ line 1 line 2 @@ -1376,69 +1369,69 @@ describe('API', function() ]]) -- larger width create spaces - meths.put({ 'a', 'bc' }, 'b3', false, false) + api.nvim_put({ 'a', 'bc' }, 'b3', false, false) expect([[ a line 1 bc line 2 line 3 ]]) -- smaller width is ignored - meths.put({ 'xxx', 'yyy' }, '\0221', false, true) + api.nvim_put({ 'xxx', 'yyy' }, '\0221', false, true) expect([[ xxxa line 1 yyybc line 2 line 3 ]]) - eq("Invalid 'type': 'bx'", pcall_err(meths.put, { 'xxx', 'yyy' }, 'bx', false, true)) - eq("Invalid 'type': 'b3x'", pcall_err(meths.put, { 'xxx', 'yyy' }, 'b3x', false, true)) + eq("Invalid 'type': 'bx'", pcall_err(api.nvim_put, { 'xxx', 'yyy' }, 'bx', false, true)) + eq("Invalid 'type': 'b3x'", pcall_err(api.nvim_put, { 'xxx', 'yyy' }, 'b3x', false, true)) end) end) describe('nvim_strwidth', function() it('works', function() - eq(3, nvim('strwidth', 'abc')) + eq(3, api.nvim_strwidth('abc')) -- 6 + (neovim) -- 19 * 2 (each japanese character occupies two cells) - eq(44, nvim('strwidth', 'neovimのデザインかなりまともなのになってる。')) + eq(44, api.nvim_strwidth('neovimのデザインかなりまともなのになってる。')) end) it('cannot handle NULs', function() - eq(0, nvim('strwidth', '\0abc')) + eq(0, api.nvim_strwidth('\0abc')) end) end) describe('nvim_get_current_line, nvim_set_current_line', function() it('works', function() - eq('', nvim('get_current_line')) - nvim('set_current_line', 'abc') - eq('abc', nvim('get_current_line')) + eq('', api.nvim_get_current_line()) + api.nvim_set_current_line('abc') + eq('abc', api.nvim_get_current_line()) end) end) describe('set/get/del variables', function() it('validation', function() - eq('Key not found: bogus', pcall_err(meths.get_var, 'bogus')) - eq('Key not found: bogus', pcall_err(meths.del_var, 'bogus')) + eq('Key not found: bogus', pcall_err(api.nvim_get_var, 'bogus')) + eq('Key not found: bogus', pcall_err(api.nvim_del_var, 'bogus')) end) it('nvim_get_var, nvim_set_var, nvim_del_var', function() - nvim('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) - eq({ 1, 2, { ['3'] = 1 } }, nvim('get_var', 'lua')) - eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'g:lua')) - eq(1, funcs.exists('g:lua')) - meths.del_var('lua') - eq(0, funcs.exists('g:lua')) - eq('Key not found: lua', pcall_err(meths.del_var, 'lua')) - meths.set_var('lua', 1) + api.nvim_set_var('lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_get_var('lua')) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_eval('g:lua')) + eq(1, fn.exists('g:lua')) + api.nvim_del_var('lua') + eq(0, fn.exists('g:lua')) + eq('Key not found: lua', pcall_err(api.nvim_del_var, 'lua')) + api.nvim_set_var('lua', 1) -- Empty keys are allowed in Vim dicts (and msgpack). - nvim('set_var', 'dict_empty_key', { [''] = 'empty key' }) - eq({ [''] = 'empty key' }, nvim('get_var', 'dict_empty_key')) + api.nvim_set_var('dict_empty_key', { [''] = 'empty key' }) + eq({ [''] = 'empty key' }, api.nvim_get_var('dict_empty_key')) -- Set locked g: var. command('lockvar lua') - eq('Key is locked: lua', pcall_err(meths.del_var, 'lua')) - eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1)) + eq('Key is locked: lua', pcall_err(api.nvim_del_var, 'lua')) + eq('Key is locked: lua', pcall_err(api.nvim_set_var, 'lua', 1)) exec([[ function Test() @@ -1448,8 +1441,8 @@ describe('API', function() let g:Unknown_func = function('Test') let g:Unknown_script_func = function('s:Test') ]]) - eq(NIL, meths.get_var('Unknown_func')) - eq(NIL, meths.get_var('Unknown_script_func')) + eq(NIL, api.nvim_get_var('Unknown_func')) + eq(NIL, api.nvim_get_var('Unknown_script_func')) -- Check if autoload works properly local pathsep = helpers.get_pathsep() @@ -1461,37 +1454,40 @@ describe('API', function() write_file(autoload_file, [[let testload#value = 2]]) clear { args_rm = { '-u' }, env = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } } - eq(2, meths.get_var('testload#value')) + eq(2, api.nvim_get_var('testload#value')) rmdir('Xhome') end) it('nvim_get_vvar, nvim_set_vvar', function() eq('Key is read-only: count', pcall_err(request, 'nvim_set_vvar', 'count', 42)) eq('Dictionary is locked', pcall_err(request, 'nvim_set_vvar', 'nosuchvar', 42)) - meths.set_vvar('errmsg', 'set by API') - eq('set by API', meths.get_vvar('errmsg')) - meths.set_vvar('errmsg', 42) + api.nvim_set_vvar('errmsg', 'set by API') + eq('set by API', api.nvim_get_vvar('errmsg')) + api.nvim_set_vvar('errmsg', 42) eq('42', eval('v:errmsg')) - meths.set_vvar('oldfiles', { 'one', 'two' }) + api.nvim_set_vvar('oldfiles', { 'one', 'two' }) eq({ 'one', 'two' }, eval('v:oldfiles')) - meths.set_vvar('oldfiles', {}) + api.nvim_set_vvar('oldfiles', {}) eq({}, eval('v:oldfiles')) - eq('Setting v:oldfiles to value with wrong type', pcall_err(meths.set_vvar, 'oldfiles', 'a')) + eq( + 'Setting v:oldfiles to value with wrong type', + pcall_err(api.nvim_set_vvar, 'oldfiles', 'a') + ) eq({}, eval('v:oldfiles')) feed('i foo foo foo<Esc>0/foo<CR>') - eq({ 1, 1 }, meths.win_get_cursor(0)) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) eq(1, eval('v:searchforward')) feed('n') - eq({ 1, 5 }, meths.win_get_cursor(0)) - meths.set_vvar('searchforward', 0) + eq({ 1, 5 }, api.nvim_win_get_cursor(0)) + api.nvim_set_vvar('searchforward', 0) eq(0, eval('v:searchforward')) feed('n') - eq({ 1, 1 }, meths.win_get_cursor(0)) - meths.set_vvar('searchforward', 1) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) + api.nvim_set_vvar('searchforward', 1) eq(1, eval('v:searchforward')) feed('n') - eq({ 1, 5 }, meths.win_get_cursor(0)) + eq({ 1, 5 }, api.nvim_win_get_cursor(0)) local screen = Screen.new(60, 3) screen:set_default_attr_ids({ @@ -1507,7 +1503,7 @@ describe('API', function() | ]], } - meths.set_vvar('hlsearch', 0) + api.nvim_set_vvar('hlsearch', 0) eq(0, eval('v:hlsearch')) screen:expect { grid = [[ @@ -1516,7 +1512,7 @@ describe('API', function() | ]], } - meths.set_vvar('hlsearch', 1) + api.nvim_set_vvar('hlsearch', 1) eq(1, eval('v:hlsearch')) screen:expect { grid = [[ @@ -1543,182 +1539,182 @@ describe('API', function() end) it('truncates values with NULs in them', function() - nvim('set_var', 'xxx', 'ab\0cd') - eq('ab', nvim('get_var', 'xxx')) + api.nvim_set_var('xxx', 'ab\0cd') + eq('ab', api.nvim_get_var('xxx')) end) end) describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - ok(nvim('get_option_value', 'equalalways', {})) - nvim('set_option_value', 'equalalways', false, {}) - ok(not nvim('get_option_value', 'equalalways', {})) + ok(api.nvim_get_option_value('equalalways', {})) + api.nvim_set_option_value('equalalways', false, {}) + ok(not api.nvim_get_option_value('equalalways', {})) end) it('works to get global value of local options', function() - eq(false, nvim('get_option_value', 'lisp', {})) - eq(8, nvim('get_option_value', 'shiftwidth', {})) + eq(false, api.nvim_get_option_value('lisp', {})) + eq(8, api.nvim_get_option_value('shiftwidth', {})) end) it('works to set global value of local options', function() - nvim('set_option_value', 'lisp', true, { scope = 'global' }) - eq(true, nvim('get_option_value', 'lisp', { scope = 'global' })) - eq(false, nvim('get_option_value', 'lisp', {})) - eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp')) - eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp')) - nvim('set_option_value', 'shiftwidth', 20, { scope = 'global' }) - eq('20', nvim('command_output', 'setglobal shiftwidth?'):match('%d+')) - eq('8', nvim('command_output', 'setlocal shiftwidth?'):match('%d+')) + api.nvim_set_option_value('lisp', true, { scope = 'global' }) + eq(true, api.nvim_get_option_value('lisp', { scope = 'global' })) + eq(false, api.nvim_get_option_value('lisp', {})) + eq(nil, command_output('setglobal lisp?'):match('nolisp')) + eq('nolisp', command_output('setlocal lisp?'):match('nolisp')) + api.nvim_set_option_value('shiftwidth', 20, { scope = 'global' }) + eq('20', command_output('setglobal shiftwidth?'):match('%d+')) + eq('8', command_output('setlocal shiftwidth?'):match('%d+')) end) it('updates where the option was last set from', function() - nvim('set_option_value', 'equalalways', false, {}) - local status, rv = pcall(nvim, 'command_output', 'verbose set equalalways?') + api.nvim_set_option_value('equalalways', false, {}) + local status, rv = pcall(command_output, 'verbose set equalalways?') eq(true, status) ok( nil ~= string.find(rv, 'noequalalways\n' .. '\tLast set from API client %(channel id %d+%)') ) - nvim('exec_lua', 'vim.api.nvim_set_option_value("equalalways", true, {})', {}) - status, rv = pcall(nvim, 'command_output', 'verbose set equalalways?') + api.nvim_exec_lua('vim.api.nvim_set_option_value("equalalways", true, {})', {}) + status, rv = pcall(command_output, 'verbose set equalalways?') eq(true, status) eq(' equalalways\n\tLast set from Lua', rv) end) it('updates whether the option has ever been set #25025', function() - eq(false, nvim('get_option_info2', 'autochdir', {}).was_set) - nvim('set_option_value', 'autochdir', true, {}) - eq(true, nvim('get_option_info2', 'autochdir', {}).was_set) + eq(false, api.nvim_get_option_info2('autochdir', {}).was_set) + api.nvim_set_option_value('autochdir', true, {}) + eq(true, api.nvim_get_option_info2('autochdir', {}).was_set) - eq(false, nvim('get_option_info2', 'cmdwinheight', {}).was_set) - nvim('set_option_value', 'cmdwinheight', 10, {}) - eq(true, nvim('get_option_info2', 'cmdwinheight', {}).was_set) + eq(false, api.nvim_get_option_info2('cmdwinheight', {}).was_set) + api.nvim_set_option_value('cmdwinheight', 10, {}) + eq(true, api.nvim_get_option_info2('cmdwinheight', {}).was_set) - eq(false, nvim('get_option_info2', 'debug', {}).was_set) - nvim('set_option_value', 'debug', 'beep', {}) - eq(true, nvim('get_option_info2', 'debug', {}).was_set) + eq(false, api.nvim_get_option_info2('debug', {}).was_set) + api.nvim_set_option_value('debug', 'beep', {}) + eq(true, api.nvim_get_option_info2('debug', {}).was_set) end) it('validation', function() eq( "Invalid 'scope': expected 'local' or 'global'", - pcall_err(nvim, 'get_option_value', 'scrolloff', { scope = 'bogus' }) + pcall_err(api.nvim_get_option_value, 'scrolloff', { scope = 'bogus' }) ) eq( "Invalid 'scope': expected 'local' or 'global'", - pcall_err(nvim, 'set_option_value', 'scrolloff', 1, { scope = 'bogus' }) + pcall_err(api.nvim_set_option_value, 'scrolloff', 1, { scope = 'bogus' }) ) eq( "Invalid 'scope': expected String, got Integer", - pcall_err(nvim, 'get_option_value', 'scrolloff', { scope = 42 }) + pcall_err(api.nvim_get_option_value, 'scrolloff', { scope = 42 }) ) eq( "Invalid 'value': expected valid option type, got Array", - pcall_err(nvim, 'set_option_value', 'scrolloff', {}, {}) + pcall_err(api.nvim_set_option_value, 'scrolloff', {}, {}) ) eq( "Invalid value for option 'scrolloff': expected number, got boolean true", - pcall_err(nvim, 'set_option_value', 'scrolloff', true, {}) + pcall_err(api.nvim_set_option_value, 'scrolloff', true, {}) ) eq( 'Invalid value for option \'scrolloff\': expected number, got string "wrong"', - pcall_err(nvim, 'set_option_value', 'scrolloff', 'wrong', {}) + pcall_err(api.nvim_set_option_value, 'scrolloff', 'wrong', {}) ) end) it('can get local values when global value is set', function() - eq(0, nvim('get_option_value', 'scrolloff', {})) - eq(-1, nvim('get_option_value', 'scrolloff', { scope = 'local' })) + eq(0, api.nvim_get_option_value('scrolloff', {})) + eq(-1, api.nvim_get_option_value('scrolloff', { scope = 'local' })) end) it('can set global and local values', function() - nvim('set_option_value', 'makeprg', 'hello', {}) - eq('hello', nvim('get_option_value', 'makeprg', {})) - eq('', nvim('get_option_value', 'makeprg', { scope = 'local' })) - nvim('set_option_value', 'makeprg', 'world', { scope = 'local' }) - eq('world', nvim('get_option_value', 'makeprg', { scope = 'local' })) - nvim('set_option_value', 'makeprg', 'goodbye', { scope = 'global' }) - eq('goodbye', nvim('get_option_value', 'makeprg', { scope = 'global' })) - nvim('set_option_value', 'makeprg', 'hello', {}) - eq('hello', nvim('get_option_value', 'makeprg', { scope = 'global' })) - eq('hello', nvim('get_option_value', 'makeprg', {})) - eq('', nvim('get_option_value', 'makeprg', { scope = 'local' })) + api.nvim_set_option_value('makeprg', 'hello', {}) + eq('hello', api.nvim_get_option_value('makeprg', {})) + eq('', api.nvim_get_option_value('makeprg', { scope = 'local' })) + api.nvim_set_option_value('makeprg', 'world', { scope = 'local' }) + eq('world', api.nvim_get_option_value('makeprg', { scope = 'local' })) + api.nvim_set_option_value('makeprg', 'goodbye', { scope = 'global' }) + eq('goodbye', api.nvim_get_option_value('makeprg', { scope = 'global' })) + api.nvim_set_option_value('makeprg', 'hello', {}) + eq('hello', api.nvim_get_option_value('makeprg', { scope = 'global' })) + eq('hello', api.nvim_get_option_value('makeprg', {})) + eq('', api.nvim_get_option_value('makeprg', { scope = 'local' })) end) it('clears the local value of an option with nil', function() -- Set global value - nvim('set_option_value', 'shiftwidth', 42, {}) - eq(42, nvim('get_option_value', 'shiftwidth', {})) + api.nvim_set_option_value('shiftwidth', 42, {}) + eq(42, api.nvim_get_option_value('shiftwidth', {})) -- Set local value - nvim('set_option_value', 'shiftwidth', 8, { scope = 'local' }) - eq(8, nvim('get_option_value', 'shiftwidth', {})) - eq(8, nvim('get_option_value', 'shiftwidth', { scope = 'local' })) - eq(42, nvim('get_option_value', 'shiftwidth', { scope = 'global' })) + api.nvim_set_option_value('shiftwidth', 8, { scope = 'local' }) + eq(8, api.nvim_get_option_value('shiftwidth', {})) + eq(8, api.nvim_get_option_value('shiftwidth', { scope = 'local' })) + eq(42, api.nvim_get_option_value('shiftwidth', { scope = 'global' })) -- Clear value without scope - nvim('set_option_value', 'shiftwidth', NIL, {}) - eq(42, nvim('get_option_value', 'shiftwidth', {})) - eq(42, nvim('get_option_value', 'shiftwidth', { scope = 'local' })) + api.nvim_set_option_value('shiftwidth', NIL, {}) + eq(42, api.nvim_get_option_value('shiftwidth', {})) + eq(42, api.nvim_get_option_value('shiftwidth', { scope = 'local' })) -- Clear value with explicit scope - nvim('set_option_value', 'shiftwidth', 8, { scope = 'local' }) - nvim('set_option_value', 'shiftwidth', NIL, { scope = 'local' }) - eq(42, nvim('get_option_value', 'shiftwidth', {})) - eq(42, nvim('get_option_value', 'shiftwidth', { scope = 'local' })) + api.nvim_set_option_value('shiftwidth', 8, { scope = 'local' }) + api.nvim_set_option_value('shiftwidth', NIL, { scope = 'local' }) + eq(42, api.nvim_get_option_value('shiftwidth', {})) + eq(42, api.nvim_get_option_value('shiftwidth', { scope = 'local' })) -- Now try with options with a special "local is unset" value (e.g. 'undolevels') - nvim('set_option_value', 'undolevels', 1000, {}) - nvim('set_option_value', 'undolevels', 1200, { scope = 'local' }) - eq(1200, nvim('get_option_value', 'undolevels', { scope = 'local' })) - nvim('set_option_value', 'undolevels', NIL, { scope = 'local' }) - eq(-123456, nvim('get_option_value', 'undolevels', { scope = 'local' })) - eq(1000, nvim('get_option_value', 'undolevels', {})) + api.nvim_set_option_value('undolevels', 1000, {}) + api.nvim_set_option_value('undolevels', 1200, { scope = 'local' }) + eq(1200, api.nvim_get_option_value('undolevels', { scope = 'local' })) + api.nvim_set_option_value('undolevels', NIL, { scope = 'local' }) + eq(-123456, api.nvim_get_option_value('undolevels', { scope = 'local' })) + eq(1000, api.nvim_get_option_value('undolevels', {})) - nvim('set_option_value', 'autoread', true, {}) - nvim('set_option_value', 'autoread', false, { scope = 'local' }) - eq(false, nvim('get_option_value', 'autoread', { scope = 'local' })) - nvim('set_option_value', 'autoread', NIL, { scope = 'local' }) - eq(NIL, nvim('get_option_value', 'autoread', { scope = 'local' })) - eq(true, nvim('get_option_value', 'autoread', {})) + api.nvim_set_option_value('autoread', true, {}) + api.nvim_set_option_value('autoread', false, { scope = 'local' }) + eq(false, api.nvim_get_option_value('autoread', { scope = 'local' })) + api.nvim_set_option_value('autoread', NIL, { scope = 'local' }) + eq(NIL, api.nvim_get_option_value('autoread', { scope = 'local' })) + eq(true, api.nvim_get_option_value('autoread', {})) end) it('set window options', function() - nvim('set_option_value', 'colorcolumn', '4,3', {}) - eq('4,3', nvim('get_option_value', 'colorcolumn', { scope = 'local' })) + api.nvim_set_option_value('colorcolumn', '4,3', {}) + eq('4,3', api.nvim_get_option_value('colorcolumn', { scope = 'local' })) command('set modified hidden') command('enew') -- edit new buffer, window option is preserved - eq('4,3', nvim('get_option_value', 'colorcolumn', { scope = 'local' })) + eq('4,3', api.nvim_get_option_value('colorcolumn', { scope = 'local' })) end) it('set local window options', function() - nvim('set_option_value', 'colorcolumn', '4,3', { win = 0, scope = 'local' }) - eq('4,3', nvim('get_option_value', 'colorcolumn', { win = 0, scope = 'local' })) + api.nvim_set_option_value('colorcolumn', '4,3', { win = 0, scope = 'local' }) + eq('4,3', api.nvim_get_option_value('colorcolumn', { win = 0, scope = 'local' })) command('set modified hidden') command('enew') -- edit new buffer, window option is reset - eq('', nvim('get_option_value', 'colorcolumn', { win = 0, scope = 'local' })) + eq('', api.nvim_get_option_value('colorcolumn', { win = 0, scope = 'local' })) end) it('get buffer or window-local options', function() - nvim('command', 'new') - local buf = nvim('get_current_buf').id - nvim('set_option_value', 'tagfunc', 'foobar', { buf = buf }) - eq('foobar', nvim('get_option_value', 'tagfunc', { buf = buf })) + command('new') + local buf = api.nvim_get_current_buf().id + api.nvim_set_option_value('tagfunc', 'foobar', { buf = buf }) + eq('foobar', api.nvim_get_option_value('tagfunc', { buf = buf })) - local win = nvim('get_current_win').id - nvim('set_option_value', 'number', true, { win = win }) - eq(true, nvim('get_option_value', 'number', { win = win })) + local win = api.nvim_get_current_win().id + api.nvim_set_option_value('number', true, { win = win }) + eq(true, api.nvim_get_option_value('number', { win = win })) end) it('getting current buffer option does not adjust cursor #19381', function() - nvim('command', 'new') - local buf = nvim('get_current_buf').id - local win = nvim('get_current_win').id + command('new') + local buf = api.nvim_get_current_buf().id + local win = api.nvim_get_current_win().id insert('some text') feed('0v$') - eq({ 1, 9 }, nvim('win_get_cursor', win)) - nvim('get_option_value', 'filetype', { buf = buf }) - eq({ 1, 9 }, nvim('win_get_cursor', win)) + eq({ 1, 9 }, api.nvim_win_get_cursor(win)) + api.nvim_get_option_value('filetype', { buf = buf }) + eq({ 1, 9 }, api.nvim_win_get_cursor(win)) end) it('can get default option values for filetypes', function() @@ -1730,156 +1726,156 @@ describe('API', function() xml = { formatexpr = 'xmlformat#Format()' }, } do for option, value in pairs(opts) do - eq(value, nvim('get_option_value', option, { filetype = ft })) + eq(value, api.nvim_get_option_value(option, { filetype = ft })) end end command 'au FileType lua setlocal commentstring=NEW\\ %s' - eq('NEW %s', nvim('get_option_value', 'commentstring', { filetype = 'lua' })) + eq('NEW %s', api.nvim_get_option_value('commentstring', { filetype = 'lua' })) end) it('errors for bad FileType autocmds', function() command 'au FileType lua setlocal commentstring=BAD' eq( [[FileType Autocommands for "lua": Vim(setlocal):E537: 'commentstring' must be empty or contain %s: commentstring=BAD]], - pcall_err(nvim, 'get_option_value', 'commentstring', { filetype = 'lua' }) + pcall_err(api.nvim_get_option_value, 'commentstring', { filetype = 'lua' }) ) end) it("value of 'modified' is always false for scratch buffers", function() - nvim('set_current_buf', nvim('create_buf', true, true)) + api.nvim_set_current_buf(api.nvim_create_buf(true, true)) insert([[ foo bar baz ]]) - eq(false, nvim('get_option_value', 'modified', {})) + eq(false, api.nvim_get_option_value('modified', {})) end) end) describe('nvim_{get,set}_current_buf, nvim_list_bufs', function() it('works', function() - eq(1, #nvim('list_bufs')) - eq(nvim('list_bufs')[1], nvim('get_current_buf')) - nvim('command', 'new') - eq(2, #nvim('list_bufs')) - eq(nvim('list_bufs')[2], nvim('get_current_buf')) - nvim('set_current_buf', nvim('list_bufs')[1]) - eq(nvim('list_bufs')[1], nvim('get_current_buf')) + eq(1, #api.nvim_list_bufs()) + eq(api.nvim_list_bufs()[1], api.nvim_get_current_buf()) + command('new') + eq(2, #api.nvim_list_bufs()) + eq(api.nvim_list_bufs()[2], api.nvim_get_current_buf()) + api.nvim_set_current_buf(api.nvim_list_bufs()[1]) + eq(api.nvim_list_bufs()[1], api.nvim_get_current_buf()) end) end) describe('nvim_{get,set}_current_win, nvim_list_wins', function() it('works', function() - eq(1, #nvim('list_wins')) - eq(nvim('list_wins')[1], nvim('get_current_win')) - nvim('command', 'vsplit') - nvim('command', 'split') - eq(3, #nvim('list_wins')) - eq(nvim('list_wins')[1], nvim('get_current_win')) - nvim('set_current_win', nvim('list_wins')[2]) - eq(nvim('list_wins')[2], nvim('get_current_win')) + eq(1, #api.nvim_list_wins()) + eq(api.nvim_list_wins()[1], api.nvim_get_current_win()) + command('vsplit') + command('split') + eq(3, #api.nvim_list_wins()) + eq(api.nvim_list_wins()[1], api.nvim_get_current_win()) + api.nvim_set_current_win(api.nvim_list_wins()[2]) + eq(api.nvim_list_wins()[2], api.nvim_get_current_win()) end) end) describe('nvim_{get,set}_current_tabpage, nvim_list_tabpages', function() it('works', function() - eq(1, #nvim('list_tabpages')) - eq(nvim('list_tabpages')[1], nvim('get_current_tabpage')) - nvim('command', 'tabnew') - eq(2, #nvim('list_tabpages')) - eq(2, #nvim('list_wins')) - eq(nvim('list_wins')[2], nvim('get_current_win')) - eq(nvim('list_tabpages')[2], nvim('get_current_tabpage')) - nvim('set_current_win', nvim('list_wins')[1]) + eq(1, #api.nvim_list_tabpages()) + eq(api.nvim_list_tabpages()[1], api.nvim_get_current_tabpage()) + command('tabnew') + eq(2, #api.nvim_list_tabpages()) + eq(2, #api.nvim_list_wins()) + eq(api.nvim_list_wins()[2], api.nvim_get_current_win()) + eq(api.nvim_list_tabpages()[2], api.nvim_get_current_tabpage()) + api.nvim_set_current_win(api.nvim_list_wins()[1]) -- Switching window also switches tabpages if necessary - eq(nvim('list_tabpages')[1], nvim('get_current_tabpage')) - eq(nvim('list_wins')[1], nvim('get_current_win')) - nvim('set_current_tabpage', nvim('list_tabpages')[2]) - eq(nvim('list_tabpages')[2], nvim('get_current_tabpage')) - eq(nvim('list_wins')[2], nvim('get_current_win')) + eq(api.nvim_list_tabpages()[1], api.nvim_get_current_tabpage()) + eq(api.nvim_list_wins()[1], api.nvim_get_current_win()) + api.nvim_set_current_tabpage(api.nvim_list_tabpages()[2]) + eq(api.nvim_list_tabpages()[2], api.nvim_get_current_tabpage()) + eq(api.nvim_list_wins()[2], api.nvim_get_current_win()) end) end) describe('nvim_get_mode', function() it('during normal-mode `g` returns blocking=true', function() - nvim('input', 'o') -- add a line - eq({ mode = 'i', blocking = false }, nvim('get_mode')) - nvim('input', [[<C-\><C-N>]]) - eq(2, nvim('eval', "line('.')")) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('o') -- add a line + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) + api.nvim_input([[<C-\><C-N>]]) + eq(2, api.nvim_eval("line('.')")) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) - nvim('input', 'g') - eq({ mode = 'n', blocking = true }, nvim('get_mode')) + api.nvim_input('g') + eq({ mode = 'n', blocking = true }, api.nvim_get_mode()) - nvim('input', 'k') -- complete the operator - eq(1, nvim('eval', "line('.')")) -- verify the completed operator - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('k') -- complete the operator + eq(1, api.nvim_eval("line('.')")) -- verify the completed operator + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('returns the correct result multiple consecutive times', function() for _ = 1, 5 do - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end - nvim('input', 'g') + api.nvim_input('g') for _ = 1, 4 do - eq({ mode = 'n', blocking = true }, nvim('get_mode')) + eq({ mode = 'n', blocking = true }, api.nvim_get_mode()) end - nvim('input', 'g') + api.nvim_input('g') for _ = 1, 7 do - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end end) it('during normal-mode CTRL-W, returns blocking=true', function() - nvim('input', '<C-W>') - eq({ mode = 'n', blocking = true }, nvim('get_mode')) + api.nvim_input('<C-W>') + eq({ mode = 'n', blocking = true }, api.nvim_get_mode()) - nvim('input', 's') -- complete the operator - eq(2, nvim('eval', "winnr('$')")) -- verify the completed operator - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('s') -- complete the operator + eq(2, api.nvim_eval("winnr('$')")) -- verify the completed operator + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('during press-enter prompt without UI returns blocking=false', function() - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) command("echom 'msg1'") command("echom 'msg2'") command("echom 'msg3'") command("echom 'msg4'") command("echom 'msg5'") - eq({ mode = 'n', blocking = false }, nvim('get_mode')) - nvim('input', ':messages<CR>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) + api.nvim_input(':messages<CR>') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('during press-enter prompt returns blocking=true', function() - nvim('ui_attach', 80, 20, {}) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_ui_attach(80, 20, {}) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) command("echom 'msg1'") command("echom 'msg2'") command("echom 'msg3'") command("echom 'msg4'") command("echom 'msg5'") - eq({ mode = 'n', blocking = false }, nvim('get_mode')) - nvim('input', ':messages<CR>') - eq({ mode = 'r', blocking = true }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) + api.nvim_input(':messages<CR>') + eq({ mode = 'r', blocking = true }, api.nvim_get_mode()) end) it('during getchar() returns blocking=false', function() - nvim('input', ':let g:test_input = nr2char(getchar())<CR>') + api.nvim_input(':let g:test_input = nr2char(getchar())<CR>') -- Events are enabled during getchar(), RPC calls are *not* blocked. #5384 - eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(0, nvim('eval', "exists('g:test_input')")) - nvim('input', 'J') - eq('J', nvim('eval', 'g:test_input')) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) + eq(0, api.nvim_eval("exists('g:test_input')")) + api.nvim_input('J') + eq('J', api.nvim_eval('g:test_input')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) -- TODO: bug #6247#issuecomment-286403810 it('batched with input', function() - nvim('ui_attach', 80, 20, {}) - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_ui_attach(80, 20, {}) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) command("echom 'msg1'") command("echom 'msg2'") command("echom 'msg3'") @@ -1900,35 +1896,35 @@ describe('API', function() 1, }, NIL, - }, meths.call_atomic(req)) - eq({ mode = 'r', blocking = true }, nvim('get_mode')) + }, api.nvim_call_atomic(req)) + eq({ mode = 'r', blocking = true }, api.nvim_get_mode()) end) it('during insert-mode map-pending, returns blocking=true #6166', function() command('inoremap xx foo') - nvim('input', 'ix') - eq({ mode = 'i', blocking = true }, nvim('get_mode')) + api.nvim_input('ix') + eq({ mode = 'i', blocking = true }, api.nvim_get_mode()) end) it('during normal-mode gU, returns blocking=false #6166', function() - nvim('input', 'gu') - eq({ mode = 'no', blocking = false }, nvim('get_mode')) + api.nvim_input('gu') + eq({ mode = 'no', blocking = false }, api.nvim_get_mode()) end) it("at '-- More --' prompt returns blocking=true #11899", function() command('set more') feed(':digraphs<cr>') - eq({ mode = 'rm', blocking = true }, nvim('get_mode')) + eq({ mode = 'rm', blocking = true }, api.nvim_get_mode()) end) it('after <Nop> mapping returns blocking=false #17257', function() command('nnoremap <F2> <Nop>') feed('<F2>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('after empty string <expr> mapping returns blocking=false #17257', function() command('nnoremap <expr> <F2> ""') feed('<F2>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) end) @@ -1937,16 +1933,16 @@ describe('API', function() helpers.insert([[ FIRST LINE SECOND LINE]]) - nvim('input', 'gg') - nvim('input', 'gu') + api.nvim_input('gg') + api.nvim_input('gu') -- Make any RPC request (can be non-async: op-pending does not block). - nvim('get_current_buf') + api.nvim_get_current_buf() -- Buffer should not change. expect([[ FIRST LINE SECOND LINE]]) -- Now send input to complete the operator. - nvim('input', 'j') + api.nvim_input('j') expect([[ first line second line]]) @@ -1960,7 +1956,7 @@ describe('API', function() feed('ia<cr>b<cr>c<cr><Esc>kkk') feed('d') -- Make any RPC request (can be non-async: op-pending does not block). - nvim('get_current_buf') + api.nvim_get_current_buf() screen:expect([[ ^a$ | b$ | @@ -1974,12 +1970,12 @@ describe('API', function() helpers.insert([[ FIRST LINE SECOND LINE]]) - nvim('input', 'gg') - nvim('input', 'd') + api.nvim_input('gg') + api.nvim_input('d') -- Make any RPC request (must be async, because map-pending blocks). - nvim('get_api_info') + api.nvim_get_api_info() -- Send input to complete the mapping. - nvim('input', 'd') + api.nvim_input('d') expect([[ FIRST LINE SECOND LINE]]) @@ -1992,11 +1988,11 @@ describe('API', function() helpers.insert([[ FIRST LINE SECOND LINE]]) - nvim('input', 'ix') + api.nvim_input('ix') -- Make any RPC request (must be async, because map-pending blocks). - nvim('get_api_info') + api.nvim_get_api_info() -- Send input to complete the mapping. - nvim('input', 'x') + api.nvim_input('x') expect([[ FIRST LINE SECOND LINfooE]]) @@ -2004,24 +2000,24 @@ describe('API', function() it('does not interrupt Insert mode i_CTRL-O #10035', function() feed('iHello World<c-o>') - eq({ mode = 'niI', blocking = false }, meths.get_mode()) -- fast event + eq({ mode = 'niI', blocking = false }, api.nvim_get_mode()) -- fast event eq(2, eval('1+1')) -- causes K_EVENT key - eq({ mode = 'niI', blocking = false }, meths.get_mode()) -- still in ctrl-o mode + eq({ mode = 'niI', blocking = false }, api.nvim_get_mode()) -- still in ctrl-o mode feed('dd') - eq({ mode = 'i', blocking = false }, meths.get_mode()) -- left ctrl-o mode + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- left ctrl-o mode expect('') -- executed the command end) it('does not interrupt Select mode v_CTRL-O #15688', function() feed('iHello World<esc>gh<c-o>') - eq({ mode = 'vs', blocking = false }, meths.get_mode()) -- fast event - eq({ mode = 'vs', blocking = false }, meths.get_mode()) -- again #15288 + eq({ mode = 'vs', blocking = false }, api.nvim_get_mode()) -- fast event + eq({ mode = 'vs', blocking = false }, api.nvim_get_mode()) -- again #15288 eq(2, eval('1+1')) -- causes K_EVENT key - eq({ mode = 'vs', blocking = false }, meths.get_mode()) -- still in ctrl-o mode + eq({ mode = 'vs', blocking = false }, api.nvim_get_mode()) -- still in ctrl-o mode feed('^') - eq({ mode = 's', blocking = false }, meths.get_mode()) -- left ctrl-o mode + eq({ mode = 's', blocking = false }, api.nvim_get_mode()) -- left ctrl-o mode feed('h') - eq({ mode = 'i', blocking = false }, meths.get_mode()) -- entered insert mode + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- entered insert mode expect('h') -- selection is the whole line and is replaced end) @@ -2047,34 +2043,34 @@ describe('API', function() feed('<BS>') eq(2, eval('1+1')) -- causes K_EVENT key feed('.') - eq('…', funcs.getcmdline()) -- digraph ",." worked + eq('…', fn.getcmdline()) -- digraph ",." worked end) end) describe('nvim_get_context', function() it('validation', function() - eq("Invalid key: 'blah'", pcall_err(nvim, 'get_context', { blah = {} })) + eq("Invalid key: 'blah'", pcall_err(api.nvim_get_context, { blah = {} })) eq( "Invalid 'types': expected Array, got Integer", - pcall_err(nvim, 'get_context', { types = 42 }) + pcall_err(api.nvim_get_context, { types = 42 }) ) eq( "Invalid 'type': 'zub'", - pcall_err(nvim, 'get_context', { types = { 'jumps', 'zub', 'zam' } }) + pcall_err(api.nvim_get_context, { types = { 'jumps', 'zub', 'zam' } }) ) end) it('returns map of current editor state', function() local opts = { types = { 'regs', 'jumps', 'bufs', 'gvars' } } - eq({}, parse_context(nvim('get_context', {}))) + eq({}, parse_context(api.nvim_get_context({}))) feed('i1<cr>2<cr>3<c-[>ddddddqahjklquuu') feed('gg') feed('G') command('edit! BUF1') command('edit BUF2') - nvim('set_var', 'one', 1) - nvim('set_var', 'Two', 2) - nvim('set_var', 'THREE', 3) + api.nvim_set_var('one', 1) + api.nvim_set_var('Two', 2) + api.nvim_set_var('THREE', 3) local expected_ctx = { ['regs'] = { @@ -2099,72 +2095,72 @@ describe('API', function() ['gvars'] = { { 'one', 1 }, { 'Two', 2 }, { 'THREE', 3 } }, } - eq(expected_ctx, parse_context(nvim('get_context', opts))) - eq(expected_ctx, parse_context(nvim('get_context', {}))) - eq(expected_ctx, parse_context(nvim('get_context', { types = {} }))) + eq(expected_ctx, parse_context(api.nvim_get_context(opts))) + eq(expected_ctx, parse_context(api.nvim_get_context({}))) + eq(expected_ctx, parse_context(api.nvim_get_context({ types = {} }))) end) end) describe('nvim_load_context', function() it('sets current editor state to given context dictionary', function() local opts = { types = { 'regs', 'jumps', 'bufs', 'gvars' } } - eq({}, parse_context(nvim('get_context', opts))) - - nvim('set_var', 'one', 1) - nvim('set_var', 'Two', 2) - nvim('set_var', 'THREE', 3) - local ctx = nvim('get_context', opts) - nvim('set_var', 'one', 'a') - nvim('set_var', 'Two', 'b') - nvim('set_var', 'THREE', 'c') + eq({}, parse_context(api.nvim_get_context(opts))) + + api.nvim_set_var('one', 1) + api.nvim_set_var('Two', 2) + api.nvim_set_var('THREE', 3) + local ctx = api.nvim_get_context(opts) + api.nvim_set_var('one', 'a') + api.nvim_set_var('Two', 'b') + api.nvim_set_var('THREE', 'c') eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) - nvim('load_context', ctx) + api.nvim_load_context(ctx) eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) end) it('errors when context dictionary is invalid', function() eq( 'E474: Failed to convert list to msgpack string buffer', - pcall_err(nvim, 'load_context', { regs = { {} }, jumps = { {} } }) + pcall_err(api.nvim_load_context, { regs = { {} }, jumps = { {} } }) ) eq( 'E474: Failed to convert list to msgpack string buffer', - pcall_err(nvim, 'load_context', { regs = { { [''] = '' } } }) + pcall_err(api.nvim_load_context, { regs = { { [''] = '' } } }) ) end) end) describe('nvim_replace_termcodes', function() it('escapes K_SPECIAL as K_SPECIAL KS_SPECIAL KE_FILLER', function() - eq('\128\254X', helpers.nvim('replace_termcodes', '\128', true, true, true)) + eq('\128\254X', helpers.api.nvim_replace_termcodes('\128', true, true, true)) end) it('leaves non-K_SPECIAL string unchanged', function() - eq('abc', helpers.nvim('replace_termcodes', 'abc', true, true, true)) + eq('abc', helpers.api.nvim_replace_termcodes('abc', true, true, true)) end) it('converts <expressions>', function() - eq('\\', helpers.nvim('replace_termcodes', '<Leader>', true, true, true)) + eq('\\', helpers.api.nvim_replace_termcodes('<Leader>', true, true, true)) end) it('converts <LeftMouse> to K_SPECIAL KS_EXTRA KE_LEFTMOUSE', function() -- K_SPECIAL KS_EXTRA KE_LEFTMOUSE -- 0x80 0xfd 0x2c -- 128 253 44 - eq('\128\253\44', helpers.nvim('replace_termcodes', '<LeftMouse>', true, true, true)) + eq('\128\253\44', helpers.api.nvim_replace_termcodes('<LeftMouse>', true, true, true)) end) it('converts keycodes', function() eq( '\nx\27x\rx<x', - helpers.nvim('replace_termcodes', '<NL>x<Esc>x<CR>x<lt>x', true, true, true) + helpers.api.nvim_replace_termcodes('<NL>x<Esc>x<CR>x<lt>x', true, true, true) ) end) it('does not convert keycodes if special=false', function() eq( '<NL>x<Esc>x<CR>x<lt>x', - helpers.nvim('replace_termcodes', '<NL>x<Esc>x<CR>x<lt>x', true, true, false) + helpers.api.nvim_replace_termcodes('<NL>x<Esc>x<CR>x<lt>x', true, true, false) ) end) @@ -2176,13 +2172,13 @@ describe('API', function() -- then `return str` in vim_replace_termcodes body will make Neovim free -- `str.data` twice: once when freeing arguments, then when freeing return -- value. - eq('', meths.replace_termcodes('', true, true, true)) + eq('', api.nvim_replace_termcodes('', true, true, true)) end) -- Not exactly the case, as nvim_replace_termcodes() escapes K_SPECIAL in Unicode it('translates the result of keytrans() on string with 0x80 byte back', function() local s = 'ff\128\253\097tt' - eq(s, meths.replace_termcodes(funcs.keytrans(s), true, true, true)) + eq(s, api.nvim_replace_termcodes(fn.keytrans(s), true, true, true)) end) end) @@ -2190,15 +2186,15 @@ describe('API', function() it('K_SPECIAL escaping', function() local function on_setup() -- notice the special char(…) \xe2\80\xa6 - nvim('feedkeys', ':let x1="…"\n', '', true) + api.nvim_feedkeys(':let x1="…"\n', '', true) -- Both nvim_replace_termcodes and nvim_feedkeys escape \x80 - local inp = helpers.nvim('replace_termcodes', ':let x2="…"<CR>', true, true, true) - nvim('feedkeys', inp, '', true) -- escape_ks=true + local inp = helpers.api.nvim_replace_termcodes(':let x2="…"<CR>', true, true, true) + api.nvim_feedkeys(inp, '', true) -- escape_ks=true -- nvim_feedkeys with K_SPECIAL escaping disabled - inp = helpers.nvim('replace_termcodes', ':let x3="…"<CR>', true, true, true) - nvim('feedkeys', inp, '', false) -- escape_ks=false + inp = helpers.api.nvim_replace_termcodes(':let x3="…"<CR>', true, true, true) + api.nvim_feedkeys(inp, '', false) -- escape_ks=false helpers.stop() end @@ -2206,10 +2202,10 @@ describe('API', function() -- spin the loop a bit helpers.run(nil, nil, on_setup) - eq('…', nvim('get_var', 'x1')) + eq('…', api.nvim_get_var('x1')) -- Because of the double escaping this is neq - neq('…', nvim('get_var', 'x2')) - eq('…', nvim('get_var', 'x3')) + neq('…', api.nvim_get_var('x2')) + eq('…', api.nvim_get_var('x3')) end) end) @@ -2244,7 +2240,7 @@ describe('API', function() silent! call nvim_out_write("\n") redir END ]]) - eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out')) + eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', api.nvim_get_var('out')) end) it('blank line in message', function() @@ -2430,18 +2426,18 @@ describe('API', function() } it('returns {} for invalid channel', function() - eq({}, meths.get_chan_info(0)) - eq({}, meths.get_chan_info(-1)) + eq({}, api.nvim_get_chan_info(0)) + eq({}, api.nvim_get_chan_info(-1)) -- more preallocated numbers might be added, try something high - eq({}, meths.get_chan_info(10)) + eq({}, api.nvim_get_chan_info(10)) end) it('stream=stdio channel', function() - eq({ [1] = testinfo, [2] = stderr }, meths.list_chans()) - eq(testinfo, meths.get_chan_info(1)) - eq(stderr, meths.get_chan_info(2)) + eq({ [1] = testinfo, [2] = stderr }, api.nvim_list_chans()) + eq(testinfo, api.nvim_get_chan_info(1)) + eq(stderr, api.nvim_get_chan_info(2)) - meths.set_client_info( + api.nvim_set_client_info( 'functionaltests', { major = 0, minor = 3, patch = 17 }, 'ui', @@ -2460,9 +2456,9 @@ describe('API', function() attributes = { license = 'Apache2' }, }, } - eq({ info = info }, meths.get_var('info_event')) - eq({ [1] = info, [2] = stderr }, meths.list_chans()) - eq(info, meths.get_chan_info(1)) + eq({ info = info }, api.nvim_get_var('info_event')) + eq({ [1] = info, [2] = stderr }, api.nvim_list_chans()) + eq(info, api.nvim_get_chan_info(1)) end) it('stream=job channel', function() @@ -2475,9 +2471,9 @@ describe('API', function() mode = 'rpc', client = {}, } - eq({ info = info }, meths.get_var('opened_event')) - eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.list_chans()) - eq(info, meths.get_chan_info(3)) + eq({ info = info }, api.nvim_get_var('opened_event')) + eq({ [1] = testinfo, [2] = stderr, [3] = info }, api.nvim_list_chans()) + eq(info, api.nvim_get_chan_info(3)) eval( 'rpcrequest(3, "nvim_set_client_info", "amazing-cat", {}, "remote",' .. '{"nvim_command":{"n_args":1}},' -- and so on @@ -2496,8 +2492,8 @@ describe('API', function() attributes = { description = 'The Amazing Cat' }, }, } - eq({ info = info }, meths.get_var('info_event')) - eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.list_chans()) + eq({ info = info }, api.nvim_get_var('info_event')) + eq({ [1] = testinfo, [2] = stderr, [3] = info }, api.nvim_list_chans()) eq( "Vim:Error invoking 'nvim_set_current_buf' on channel 3 (amazing-cat):\nWrong type for argument 1 when calling nvim_set_current_buf, expecting Buffer", @@ -2507,8 +2503,8 @@ describe('API', function() it('stream=job :terminal channel', function() command(':terminal') - eq({ id = 1 }, meths.get_current_buf()) - eq(3, meths.get_option_value('channel', { buf = 1 })) + eq({ id = 1 }, api.nvim_get_current_buf()) + eq(3, api.nvim_get_option_value('channel', { buf = 1 })) local info = { stream = 'job', @@ -2518,20 +2514,20 @@ describe('API', function() buffer = 1, pty = '?', } - local event = meths.get_var('opened_event') + local event = api.nvim_get_var('opened_event') if not is_os('win') then info.pty = event.info.pty neq(nil, string.match(info.pty, '^/dev/')) end eq({ info = info }, event) info.buffer = { id = 1 } - eq({ [1] = testinfo, [2] = stderr, [3] = info }, meths.list_chans()) - eq(info, meths.get_chan_info(3)) + eq({ [1] = testinfo, [2] = stderr, [3] = info }, api.nvim_list_chans()) + eq(info, api.nvim_get_chan_info(3)) -- :terminal with args + running process. command('enew') local progpath_esc = eval('shellescape(v:progpath)') - funcs.termopen(('%s -u NONE -i NONE'):format(progpath_esc), { + fn.termopen(('%s -u NONE -i NONE'):format(progpath_esc), { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) eq(-1, eval('jobwait([&channel], 0)[0]')) -- Running? @@ -2566,13 +2562,13 @@ describe('API', function() describe('nvim_call_atomic', function() it('works', function() - meths.buf_set_lines(0, 0, -1, true, { 'first' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'first' }) local req = { { 'nvim_get_current_line', {} }, { 'nvim_set_current_line', { 'second' } }, } - eq({ { 'first', NIL }, NIL }, meths.call_atomic(req)) - eq({ 'second' }, meths.buf_get_lines(0, 0, -1, true)) + eq({ { 'first', NIL }, NIL }, api.nvim_call_atomic(req)) + eq({ 'second' }, api.nvim_buf_get_lines(0, 0, -1, true)) end) it('allows multiple return values', function() @@ -2582,11 +2578,11 @@ describe('API', function() { 'nvim_get_var', { 'avar' } }, { 'nvim_get_var', { 'bvar' } }, } - eq({ { NIL, NIL, true, 'string' }, NIL }, meths.call_atomic(req)) + eq({ { NIL, NIL, true, 'string' }, NIL }, api.nvim_call_atomic(req)) end) it('is aborted by errors in call', function() - local error_types = meths.get_api_info()[2].error_types + local error_types = api.nvim_get_api_info()[2].error_types local req = { { 'nvim_set_var', { 'one', 1 } }, { 'nvim_buf_set_lines', {} }, @@ -2599,9 +2595,9 @@ describe('API', function() error_types.Exception.id, 'Wrong number of arguments: expecting 5 but got 0', }, - }, meths.call_atomic(req)) - eq(1, meths.get_var('one')) - eq(false, pcall(meths.get_var, 'two')) + }, api.nvim_call_atomic(req)) + eq(1, api.nvim_get_var('one')) + eq(false, pcall(api.nvim_get_var, 'two')) -- still returns all previous successful calls req = { @@ -2613,7 +2609,7 @@ describe('API', function() } eq( { { NIL, NIL, 5 }, { 3, error_types.Validation.id, 'Index out of bounds' } }, - meths.call_atomic(req) + api.nvim_call_atomic(req) ) req = { @@ -2622,9 +2618,9 @@ describe('API', function() } eq( { {}, { 0, error_types.Exception.id, 'Invalid method: i_am_not_a_method' } }, - meths.call_atomic(req) + api.nvim_call_atomic(req) ) - eq(5, meths.get_var('avar')) + eq(5, api.nvim_get_var('avar')) end) it('validation', function() @@ -2633,25 +2629,25 @@ describe('API', function() { 'nvim_set_var' }, { 'nvim_set_var', { 'avar', 2 } }, } - eq("Invalid 'calls' item: expected 2-item Array", pcall_err(meths.call_atomic, req)) + eq("Invalid 'calls' item: expected 2-item Array", pcall_err(api.nvim_call_atomic, req)) -- call before was done, but not after - eq(1, meths.get_var('avar')) + eq(1, api.nvim_get_var('avar')) req = { { 'nvim_set_var', { 'bvar', { 2, 3 } } }, 12, } - eq("Invalid 'calls' item: expected Array, got Integer", pcall_err(meths.call_atomic, req)) - eq({ 2, 3 }, meths.get_var('bvar')) + eq("Invalid 'calls' item: expected Array, got Integer", pcall_err(api.nvim_call_atomic, req)) + eq({ 2, 3 }, api.nvim_get_var('bvar')) req = { { 'nvim_set_current_line', 'little line' }, { 'nvim_set_var', { 'avar', 3 } }, } - eq('Invalid call args: expected Array, got String', pcall_err(meths.call_atomic, req)) + eq('Invalid call args: expected Array, got String', pcall_err(api.nvim_call_atomic, req)) -- call before was done, but not after - eq(1, meths.get_var('avar')) - eq({ '' }, meths.buf_get_lines(0, 0, -1, true)) + eq(1, api.nvim_get_var('avar')) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, true)) end) end) @@ -2665,55 +2661,55 @@ describe('API', function() rmdir 'Xtest' end) before_each(function() - meths.set_current_dir 'Xtest' + api.nvim_set_current_dir 'Xtest' end) it('returns nothing with empty &runtimepath', function() - meths.set_option_value('runtimepath', '', {}) - eq({}, meths.list_runtime_paths()) + api.nvim_set_option_value('runtimepath', '', {}) + eq({}, api.nvim_list_runtime_paths()) end) it('returns single runtimepath', function() - meths.set_option_value('runtimepath', 'a', {}) - eq({ 'a' }, meths.list_runtime_paths()) + api.nvim_set_option_value('runtimepath', 'a', {}) + eq({ 'a' }, api.nvim_list_runtime_paths()) end) it('returns two runtimepaths', function() - meths.set_option_value('runtimepath', 'a,b', {}) - eq({ 'a', 'b' }, meths.list_runtime_paths()) + api.nvim_set_option_value('runtimepath', 'a,b', {}) + eq({ 'a', 'b' }, api.nvim_list_runtime_paths()) end) it('returns empty strings when appropriate', function() - meths.set_option_value('runtimepath', 'a,,b', {}) - eq({ 'a', '', 'b' }, meths.list_runtime_paths()) - meths.set_option_value('runtimepath', ',a,b', {}) - eq({ '', 'a', 'b' }, meths.list_runtime_paths()) + api.nvim_set_option_value('runtimepath', 'a,,b', {}) + eq({ 'a', '', 'b' }, api.nvim_list_runtime_paths()) + api.nvim_set_option_value('runtimepath', ',a,b', {}) + eq({ '', 'a', 'b' }, api.nvim_list_runtime_paths()) -- Trailing "," is ignored. Use ",," if you really really want CWD. - meths.set_option_value('runtimepath', 'a,b,', {}) - eq({ 'a', 'b' }, meths.list_runtime_paths()) - meths.set_option_value('runtimepath', 'a,b,,', {}) - eq({ 'a', 'b', '' }, meths.list_runtime_paths()) + api.nvim_set_option_value('runtimepath', 'a,b,', {}) + eq({ 'a', 'b' }, api.nvim_list_runtime_paths()) + api.nvim_set_option_value('runtimepath', 'a,b,,', {}) + eq({ 'a', 'b', '' }, api.nvim_list_runtime_paths()) end) it('truncates too long paths', function() local long_path = ('/a'):rep(8192) - meths.set_option_value('runtimepath', long_path, {}) - local paths_list = meths.list_runtime_paths() + api.nvim_set_option_value('runtimepath', long_path, {}) + local paths_list = api.nvim_list_runtime_paths() eq({}, paths_list) end) end) it('can throw exceptions', function() - local status, err = pcall(nvim, 'get_option_value', 'invalid-option', {}) + local status, err = pcall(api.nvim_get_option_value, 'invalid-option', {}) eq(false, status) ok(err:match("Unknown option 'invalid%-option'") ~= nil) end) it('does not truncate error message <1 MB #5984', function() local very_long_name = 'A' .. ('x'):rep(10000) .. 'Z' - local status, err = pcall(nvim, 'get_option_value', very_long_name, {}) + local status, err = pcall(api.nvim_get_option_value, very_long_name, {}) eq(false, status) eq(very_long_name, err:match('Ax+Z?')) end) it('does not leak memory on incorrect argument types', function() - local status, err = pcall(nvim, 'set_current_dir', { 'not', 'a', 'dir' }) + local status, err = pcall(api.nvim_set_current_dir, { 'not', 'a', 'dir' }) eq(false, status) ok( err:match(': Wrong type for argument 1 when calling nvim_set_current_dir, expecting String') @@ -2723,7 +2719,7 @@ describe('API', function() describe('nvim_parse_expression', function() before_each(function() - meths.set_option_value('isident', '', {}) + api.nvim_set_option_value('isident', '', {}) end) local function simplify_east_api_node(line, east_api_node) @@ -2856,7 +2852,7 @@ describe('API', function() nz_flags_exps = nz_flags_exps or {} for _, flags in ipairs(opts.flags) do local err, msg = pcall(function() - local east_api = meths.parse_expression(str, FLAGS_TO_STR[flags], true) + local east_api = api.nvim_parse_expression(str, FLAGS_TO_STR[flags], true) local east_hl = east_api.highlight east_api.highlight = nil local ast = simplify_east_api(str, east_api) @@ -2936,7 +2932,7 @@ describe('API', function() describe('nvim_list_uis', function() it('returns empty if --headless', function() -- Test runner defaults to --headless. - eq({}, nvim('list_uis')) + eq({}, api.nvim_list_uis()) end) it('returns attached UIs', function() local screen = Screen.new(20, 4) @@ -2965,7 +2961,7 @@ describe('API', function() }, } - eq(expected, nvim('list_uis')) + eq(expected, api.nvim_list_uis()) screen:detach() screen = Screen.new(44, 99) @@ -2974,39 +2970,39 @@ describe('API', function() expected[1].override = false expected[1].width = 44 expected[1].height = 99 - eq(expected, nvim('list_uis')) + eq(expected, api.nvim_list_uis()) end) end) describe('nvim_create_namespace', function() it('works', function() - eq({}, meths.get_namespaces()) - eq(1, meths.create_namespace('ns-1')) - eq(2, meths.create_namespace('ns-2')) - eq(1, meths.create_namespace('ns-1')) - eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, meths.get_namespaces()) - eq(3, meths.create_namespace('')) - eq(4, meths.create_namespace('')) - eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, meths.get_namespaces()) + eq({}, api.nvim_get_namespaces()) + eq(1, api.nvim_create_namespace('ns-1')) + eq(2, api.nvim_create_namespace('ns-2')) + eq(1, api.nvim_create_namespace('ns-1')) + eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, api.nvim_get_namespaces()) + eq(3, api.nvim_create_namespace('')) + eq(4, api.nvim_create_namespace('')) + eq({ ['ns-1'] = 1, ['ns-2'] = 2 }, api.nvim_get_namespaces()) end) end) describe('nvim_create_buf', function() it('works', function() - eq({ id = 2 }, meths.create_buf(true, false)) - eq({ id = 3 }, meths.create_buf(false, false)) + eq({ id = 2 }, api.nvim_create_buf(true, false)) + eq({ id = 3 }, api.nvim_create_buf(false, false)) eq( ' 1 %a "[No Name]" line 1\n' .. ' 2 h "[No Name]" line 0', - meths.command_output('ls') + command_output('ls') ) -- current buffer didn't change - eq({ id = 1 }, meths.get_current_buf()) + eq({ id = 1 }, api.nvim_get_current_buf()) local screen = Screen.new(20, 4) screen:attach() - meths.buf_set_lines(2, 0, -1, true, { 'some text' }) - meths.set_current_buf(2) + api.nvim_buf_set_lines(2, 0, -1, true, { 'some text' }) + api.nvim_set_current_buf(2) screen:expect( [[ ^some text | @@ -3020,43 +3016,43 @@ describe('API', function() end) it('can change buftype before visiting', function() - meths.set_option_value('hidden', false, {}) - eq({ id = 2 }, meths.create_buf(true, false)) - meths.set_option_value('buftype', 'nofile', { buf = 2 }) - meths.buf_set_lines(2, 0, -1, true, { 'test text' }) + api.nvim_set_option_value('hidden', false, {}) + eq({ id = 2 }, api.nvim_create_buf(true, false)) + api.nvim_set_option_value('buftype', 'nofile', { buf = 2 }) + api.nvim_buf_set_lines(2, 0, -1, true, { 'test text' }) command('split | buffer 2') - eq({ id = 2 }, meths.get_current_buf()) + eq({ id = 2 }, api.nvim_get_current_buf()) -- if the buf_set_option("buftype") didn't work, this would error out. command('close') - eq({ id = 1 }, meths.get_current_buf()) + eq({ id = 1 }, api.nvim_get_current_buf()) end) it('does not trigger BufEnter, BufWinEnter', function() command('let g:fired = v:false') command('au BufEnter,BufWinEnter * let g:fired = v:true') - eq({ id = 2 }, meths.create_buf(true, false)) - meths.buf_set_lines(2, 0, -1, true, { 'test', 'text' }) + eq({ id = 2 }, api.nvim_create_buf(true, false)) + api.nvim_buf_set_lines(2, 0, -1, true, { 'test', 'text' }) eq(false, eval('g:fired')) end) it('TextChanged and TextChangedI do not trigger without changes', function() - local buf = meths.create_buf(true, false) + local buf = api.nvim_create_buf(true, false) command([[let g:changed = '']]) - meths.create_autocmd({ 'TextChanged', 'TextChangedI' }, { + api.nvim_create_autocmd({ 'TextChanged', 'TextChangedI' }, { buffer = buf, command = 'let g:changed ..= mode()', }) - meths.set_current_buf(buf) + api.nvim_set_current_buf(buf) feed('i') - eq('', meths.get_var('changed')) + eq('', api.nvim_get_var('changed')) end) it('scratch-buffer', function() - eq({ id = 2 }, meths.create_buf(false, true)) - eq({ id = 3 }, meths.create_buf(true, true)) - eq({ id = 4 }, meths.create_buf(true, true)) + eq({ id = 2 }, api.nvim_create_buf(false, true)) + eq({ id = 3 }, api.nvim_create_buf(true, true)) + eq({ id = 4 }, api.nvim_create_buf(true, true)) local scratch_bufs = { 2, 3, 4 } eq( ' 1 %a "[No Name]" line 1\n' @@ -3065,7 +3061,7 @@ describe('API', function() exec_capture('ls') ) -- current buffer didn't change - eq({ id = 1 }, meths.get_current_buf()) + eq({ id = 1 }, api.nvim_get_current_buf()) local screen = Screen.new(20, 4) screen:set_default_attr_ids({ @@ -3077,27 +3073,27 @@ describe('API', function() -- Editing a scratch-buffer does NOT change its properties. -- local edited_buf = 2 - meths.buf_set_lines(edited_buf, 0, -1, true, { 'some text' }) + api.nvim_buf_set_lines(edited_buf, 0, -1, true, { 'some text' }) for _, b in ipairs(scratch_bufs) do - eq('nofile', meths.get_option_value('buftype', { buf = b })) - eq('hide', meths.get_option_value('bufhidden', { buf = b })) - eq(false, meths.get_option_value('swapfile', { buf = b })) - eq(false, meths.get_option_value('modeline', { buf = b })) + eq('nofile', api.nvim_get_option_value('buftype', { buf = b })) + eq('hide', api.nvim_get_option_value('bufhidden', { buf = b })) + eq(false, api.nvim_get_option_value('swapfile', { buf = b })) + eq(false, api.nvim_get_option_value('modeline', { buf = b })) end -- -- Visiting a scratch-buffer DOES NOT change its properties. -- - meths.set_current_buf(edited_buf) + api.nvim_set_current_buf(edited_buf) screen:expect([[ ^some text | {1:~ }|*2 | ]]) - eq('nofile', meths.get_option_value('buftype', { buf = edited_buf })) - eq('hide', meths.get_option_value('bufhidden', { buf = edited_buf })) - eq(false, meths.get_option_value('swapfile', { buf = edited_buf })) - eq(false, meths.get_option_value('modeline', { buf = edited_buf })) + eq('nofile', api.nvim_get_option_value('buftype', { buf = edited_buf })) + eq('hide', api.nvim_get_option_value('bufhidden', { buf = edited_buf })) + eq(false, api.nvim_get_option_value('swapfile', { buf = edited_buf })) + eq(false, api.nvim_get_option_value('modeline', { buf = edited_buf })) -- Scratch buffer can be wiped without error. command('bwipe') @@ -3119,11 +3115,11 @@ describe('API', function() describe('nvim_get_runtime_file', function() local p = helpers.alter_slashes it('can find files', function() - eq({}, meths.get_runtime_file('bork.borkbork', false)) - eq({}, meths.get_runtime_file('bork.borkbork', true)) - eq(1, #meths.get_runtime_file('autoload/msgpack.vim', false)) - eq(1, #meths.get_runtime_file('autoload/msgpack.vim', true)) - local val = meths.get_runtime_file('autoload/remote/*.vim', true) + eq({}, api.nvim_get_runtime_file('bork.borkbork', false)) + eq({}, api.nvim_get_runtime_file('bork.borkbork', true)) + eq(1, #api.nvim_get_runtime_file('autoload/msgpack.vim', false)) + eq(1, #api.nvim_get_runtime_file('autoload/msgpack.vim', true)) + local val = api.nvim_get_runtime_file('autoload/remote/*.vim', true) eq(2, #val) if endswith(val[1], 'define.vim') then ok(endswith(val[1], p 'autoload/remote/define.vim')) @@ -3132,37 +3128,37 @@ describe('API', function() ok(endswith(val[1], p 'autoload/remote/host.vim')) ok(endswith(val[2], p 'autoload/remote/define.vim')) end - val = meths.get_runtime_file('autoload/remote/*.vim', false) + val = api.nvim_get_runtime_file('autoload/remote/*.vim', false) eq(1, #val) ok( endswith(val[1], p 'autoload/remote/define.vim') or endswith(val[1], p 'autoload/remote/host.vim') ) - val = meths.get_runtime_file('lua', true) + val = api.nvim_get_runtime_file('lua', true) eq(1, #val) ok(endswith(val[1], p 'lua')) - val = meths.get_runtime_file('lua/vim', true) + val = api.nvim_get_runtime_file('lua/vim', true) eq(1, #val) ok(endswith(val[1], p 'lua/vim')) end) it('can find directories', function() - local val = meths.get_runtime_file('lua/', true) + local val = api.nvim_get_runtime_file('lua/', true) eq(1, #val) ok(endswith(val[1], p 'lua/')) - val = meths.get_runtime_file('lua/vim/', true) + val = api.nvim_get_runtime_file('lua/vim/', true) eq(1, #val) ok(endswith(val[1], p 'lua/vim/')) - eq({}, meths.get_runtime_file('foobarlang/', true)) + eq({}, api.nvim_get_runtime_file('foobarlang/', true)) end) it('can handle bad patterns', function() skip(is_os('win')) - eq('Vim:E220: Missing }.', pcall_err(meths.get_runtime_file, '{', false)) + eq('Vim:E220: Missing }.', pcall_err(api.nvim_get_runtime_file, '{', false)) eq( 'Vim(echo):E5555: API call: Vim:E220: Missing }.', @@ -3173,25 +3169,25 @@ describe('API', function() describe('nvim_get_all_options_info', function() it('should have key value pairs of option names', function() - local options_info = meths.get_all_options_info() + local options_info = api.nvim_get_all_options_info() neq(nil, options_info.listchars) neq(nil, options_info.tabstop) - eq(meths.get_option_info 'winhighlight', options_info.winhighlight) + eq(api.nvim_get_option_info 'winhighlight', options_info.winhighlight) end) it('should not crash when echoed', function() - meths.exec2('echo nvim_get_all_options_info()', { output = true }) + api.nvim_exec2('echo nvim_get_all_options_info()', { output = true }) end) end) describe('nvim_get_option_info', function() it('should error for unknown options', function() - eq("Invalid option (not found): 'bogus'", pcall_err(meths.get_option_info, 'bogus')) + eq("Invalid option (not found): 'bogus'", pcall_err(api.nvim_get_option_info, 'bogus')) end) it('should return the same options for short and long name', function() - eq(meths.get_option_info 'winhl', meths.get_option_info 'winhighlight') + eq(api.nvim_get_option_info 'winhl', api.nvim_get_option_info 'winhighlight') end) it('should have information about window options', function() @@ -3209,7 +3205,7 @@ describe('API', function() shortname = 'winhl', type = 'string', was_set = false, - }, meths.get_option_info 'winhl') + }, api.nvim_get_option_info 'winhl') end) it('should have information about buffer options', function() @@ -3227,13 +3223,13 @@ describe('API', function() shortname = 'ft', type = 'string', was_set = false, - }, meths.get_option_info 'filetype') + }, api.nvim_get_option_info 'filetype') end) it('should have information about global options', function() -- precondition: the option was changed from its default -- in test setup. - eq(false, meths.get_option_value('showcmd', {})) + eq(false, api.nvim_get_option_value('showcmd', {})) eq({ allows_duplicates = true, @@ -3249,9 +3245,9 @@ describe('API', function() shortname = 'sc', type = 'boolean', was_set = true, - }, meths.get_option_info 'showcmd') + }, api.nvim_get_option_info 'showcmd') - meths.set_option_value('showcmd', true, {}) + api.nvim_set_option_value('showcmd', true, {}) eq({ allows_duplicates = true, @@ -3267,7 +3263,7 @@ describe('API', function() shortname = 'sc', type = 'boolean', was_set = true, - }, meths.get_option_info 'showcmd') + }, api.nvim_get_option_info 'showcmd') end) end) @@ -3294,18 +3290,18 @@ describe('API', function() ) exec_lua 'vim.cmd.vsplit()' - meths.create_buf(false, false) + api.nvim_create_buf(false, false) - bufs = meths.list_bufs() - wins = meths.list_wins() + bufs = api.nvim_list_bufs() + wins = api.nvim_list_wins() - meths.win_set_buf(wins[1].id, bufs[1].id) - meths.win_set_buf(wins[2].id, bufs[2].id) + api.nvim_win_set_buf(wins[1].id, bufs[1].id) + api.nvim_win_set_buf(wins[2].id, bufs[2].id) - meths.set_current_win(wins[2].id) - meths.exec('source ' .. fname, false) + api.nvim_set_current_win(wins[2].id) + api.nvim_exec('source ' .. fname, false) - meths.set_current_win(wins[1].id) + api.nvim_set_current_win(wins[1].id) end) after_each(function() @@ -3313,9 +3309,9 @@ describe('API', function() end) it('should return option information', function() - eq(meths.get_option_info('dictionary'), meths.get_option_info2('dictionary', {})) -- buffer - eq(meths.get_option_info('fillchars'), meths.get_option_info2('fillchars', {})) -- window - eq(meths.get_option_info('completeopt'), meths.get_option_info2('completeopt', {})) -- global + eq(api.nvim_get_option_info('dictionary'), api.nvim_get_option_info2('dictionary', {})) -- buffer + eq(api.nvim_get_option_info('fillchars'), api.nvim_get_option_info2('fillchars', {})) -- window + eq(api.nvim_get_option_info('completeopt'), api.nvim_get_option_info2('completeopt', {})) -- global end) describe('last set', function() @@ -3347,21 +3343,21 @@ describe('API', function() for _, t in pairs(tests) do it(t.desc, function() -- Switch to the target buffer/window so that curbuf/curwin are used. - meths.set_current_win(wins[2].id) - local info = meths.get_option_info2(unpack(t.args)) + api.nvim_set_current_win(wins[2].id) + local info = api.nvim_get_option_info2(unpack(t.args)) eq(t.linenr, info.last_set_linenr) eq(t.sid, info.last_set_sid) end) end it('is provided for cross-buffer requests', function() - local info = meths.get_option_info2('formatprg', { buf = bufs[2].id }) + local info = api.nvim_get_option_info2('formatprg', { buf = bufs[2].id }) eq(2, info.last_set_linenr) eq(1, info.last_set_sid) end) it('is provided for cross-window requests', function() - local info = meths.get_option_info2('listchars', { win = wins[2].id }) + local info = api.nvim_get_option_info2('listchars', { win = wins[2].id }) eq(6, info.last_set_linenr) eq(1, info.last_set_sid) end) @@ -3427,13 +3423,13 @@ describe('API', function() end) it('can save message history', function() - nvim('command', 'set cmdheight=2') -- suppress Press ENTER - nvim('echo', { { 'msg\nmsg' }, { 'msg' } }, true, {}) + command('set cmdheight=2') -- suppress Press ENTER + api.nvim_echo({ { 'msg\nmsg' }, { 'msg' } }, true, {}) eq('msg\nmsgmsg', exec_capture('messages')) end) it('can disable saving message history', function() - nvim('command', 'set cmdheight=2') -- suppress Press ENTER + command('set cmdheight=2') -- suppress Press ENTER nvim_async('echo', { { 'msg\nmsg' }, { 'msg' } }, false, {}) eq('', exec_capture('messages')) end) @@ -3466,11 +3462,15 @@ describe('API', function() end) it('can batch process sequences', function() - local b = meths.create_buf(true, true) - meths.open_win(b, false, { width = 79, height = 31, row = 1, col = 1, relative = 'editor' }) - local t = meths.open_term(b, {}) + local b = api.nvim_create_buf(true, true) + api.nvim_open_win( + b, + false, + { width = 79, height = 31, row = 1, col = 1, relative = 'editor' } + ) + local t = api.nvim_open_term(b, {}) - meths.chan_send(t, io.open('test/functional/fixtures/smile2.cat', 'r'):read('*a')) + api.nvim_chan_send(t, io.open('test/functional/fixtures/smile2.cat', 'r'):read('*a')) screen:expect { grid = [[ ^ | @@ -3576,50 +3576,53 @@ describe('API', function() describe('nvim_del_mark', function() it('works', function() - local buf = meths.create_buf(false, true) - meths.buf_set_lines(buf, -1, -1, true, { 'a', 'bit of', 'text' }) - eq(true, meths.buf_set_mark(buf, 'F', 2, 2, {})) - eq(true, meths.del_mark('F')) - eq({ 0, 0 }, meths.buf_get_mark(buf, 'F')) + local buf = api.nvim_create_buf(false, true) + api.nvim_buf_set_lines(buf, -1, -1, true, { 'a', 'bit of', 'text' }) + eq(true, api.nvim_buf_set_mark(buf, 'F', 2, 2, {})) + eq(true, api.nvim_del_mark('F')) + eq({ 0, 0 }, api.nvim_buf_get_mark(buf, 'F')) end) it('validation', function() - eq("Invalid mark name (must be file/uppercase): 'f'", pcall_err(meths.del_mark, 'f')) - eq("Invalid mark name (must be file/uppercase): '!'", pcall_err(meths.del_mark, '!')) - eq("Invalid mark name (must be a single char): 'fail'", pcall_err(meths.del_mark, 'fail')) + eq("Invalid mark name (must be file/uppercase): 'f'", pcall_err(api.nvim_del_mark, 'f')) + eq("Invalid mark name (must be file/uppercase): '!'", pcall_err(api.nvim_del_mark, '!')) + eq("Invalid mark name (must be a single char): 'fail'", pcall_err(api.nvim_del_mark, 'fail')) end) end) describe('nvim_get_mark', function() it('works', function() - local buf = meths.create_buf(false, true) - meths.buf_set_lines(buf, -1, -1, true, { 'a', 'bit of', 'text' }) - meths.buf_set_mark(buf, 'F', 2, 2, {}) - meths.buf_set_name(buf, 'mybuf') - local mark = meths.get_mark('F', {}) + local buf = api.nvim_create_buf(false, true) + api.nvim_buf_set_lines(buf, -1, -1, true, { 'a', 'bit of', 'text' }) + api.nvim_buf_set_mark(buf, 'F', 2, 2, {}) + api.nvim_buf_set_name(buf, 'mybuf') + local mark = api.nvim_get_mark('F', {}) -- Compare the path tail only assert(string.find(mark[4], 'mybuf$')) eq({ 2, 2, buf.id, mark[4] }, mark) end) it('validation', function() - eq("Invalid mark name (must be file/uppercase): 'f'", pcall_err(meths.get_mark, 'f', {})) - eq("Invalid mark name (must be file/uppercase): '!'", pcall_err(meths.get_mark, '!', {})) - eq("Invalid mark name (must be a single char): 'fail'", pcall_err(meths.get_mark, 'fail', {})) + eq("Invalid mark name (must be file/uppercase): 'f'", pcall_err(api.nvim_get_mark, 'f', {})) + eq("Invalid mark name (must be file/uppercase): '!'", pcall_err(api.nvim_get_mark, '!', {})) + eq( + "Invalid mark name (must be a single char): 'fail'", + pcall_err(api.nvim_get_mark, 'fail', {}) + ) end) it('returns the expected when mark is not set', function() - eq(true, meths.del_mark('A')) - eq({ 0, 0, 0, '' }, meths.get_mark('A', {})) + eq(true, api.nvim_del_mark('A')) + eq({ 0, 0, 0, '' }, api.nvim_get_mark('A', {})) end) it('works with deleted buffers', function() local fname = tmpname() write_file(fname, 'a\nbit of\text') - nvim('command', 'edit ' .. fname) - local buf = meths.get_current_buf() + command('edit ' .. fname) + local buf = api.nvim_get_current_buf() - meths.buf_set_mark(buf, 'F', 2, 2, {}) - nvim('command', 'new') -- Create new buf to avoid :bd failing - nvim('command', 'bd! ' .. buf.id) + api.nvim_buf_set_mark(buf, 'F', 2, 2, {}) + command('new') -- Create new buf to avoid :bd failing + command('bd! ' .. buf.id) os.remove(fname) - local mark = meths.get_mark('F', {}) + local mark = api.nvim_get_mark('F', {}) -- To avoid comparing relative vs absolute path local mfname = mark[4] local tail_patt = [[[\/][^\/]*$]] @@ -3633,72 +3636,72 @@ describe('API', function() eq({ str = '%StatusLineStringWithHighlights', width = 31, - }, meths.eval_statusline('%%StatusLineString%#WarningMsg#WithHighlights', {})) + }, api.nvim_eval_statusline('%%StatusLineString%#WarningMsg#WithHighlights', {})) end) it("doesn't exceed maxwidth", function() eq({ str = 'Should be trun>', width = 15, - }, meths.eval_statusline('Should be truncated%<', { maxwidth = 15 })) + }, api.nvim_eval_statusline('Should be truncated%<', { maxwidth = 15 })) end) it('supports ASCII fillchar', function() eq( { str = 'a~~~b', width = 5 }, - meths.eval_statusline('a%=b', { fillchar = '~', maxwidth = 5 }) + api.nvim_eval_statusline('a%=b', { fillchar = '~', maxwidth = 5 }) ) end) it('supports single-width multibyte fillchar', function() eq( { str = 'a━━━b', width = 5 }, - meths.eval_statusline('a%=b', { fillchar = '━', maxwidth = 5 }) + api.nvim_eval_statusline('a%=b', { fillchar = '━', maxwidth = 5 }) ) end) it('treats double-width fillchar as single-width', function() eq( { str = 'a哦哦哦b', width = 5 }, - meths.eval_statusline('a%=b', { fillchar = '哦', maxwidth = 5 }) + api.nvim_eval_statusline('a%=b', { fillchar = '哦', maxwidth = 5 }) ) end) it('treats control character fillchar as single-width', function() eq( { str = 'a\031\031\031b', width = 5 }, - meths.eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 }) + api.nvim_eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 }) ) end) it('rejects multiple-character fillchar', function() eq( "Invalid 'fillchar': expected single character", - pcall_err(meths.eval_statusline, '', { fillchar = 'aa' }) + pcall_err(api.nvim_eval_statusline, '', { fillchar = 'aa' }) ) end) it('rejects empty string fillchar', function() eq( "Invalid 'fillchar': expected single character", - pcall_err(meths.eval_statusline, '', { fillchar = '' }) + pcall_err(api.nvim_eval_statusline, '', { fillchar = '' }) ) end) it('rejects non-string fillchar', function() eq( "Invalid 'fillchar': expected String, got Integer", - pcall_err(meths.eval_statusline, '', { fillchar = 1 }) + pcall_err(api.nvim_eval_statusline, '', { fillchar = 1 }) ) end) it('rejects invalid string', function() - eq('E539: Illegal character <}>', pcall_err(meths.eval_statusline, '%{%}', {})) + eq('E539: Illegal character <}>', pcall_err(api.nvim_eval_statusline, '%{%}', {})) end) it('supports various items', function() - eq({ str = '0', width = 1 }, meths.eval_statusline('%l', { maxwidth = 5 })) + eq({ str = '0', width = 1 }, api.nvim_eval_statusline('%l', { maxwidth = 5 })) command('set readonly') - eq({ str = '[RO]', width = 4 }, meths.eval_statusline('%r', { maxwidth = 5 })) + eq({ str = '[RO]', width = 4 }, api.nvim_eval_statusline('%r', { maxwidth = 5 })) local screen = Screen.new(80, 24) screen:attach() command('set showcmd') feed('1234') screen:expect({ any = '1234' }) - eq({ str = '1234', width = 4 }, meths.eval_statusline('%S', { maxwidth = 5 })) + eq({ str = '1234', width = 4 }, api.nvim_eval_statusline('%S', { maxwidth = 5 })) feed('56') screen:expect({ any = '123456' }) - eq({ str = '<3456', width = 5 }, meths.eval_statusline('%S', { maxwidth = 5 })) + eq({ str = '<3456', width = 5 }, api.nvim_eval_statusline('%S', { maxwidth = 5 })) end) describe('highlight parsing', function() it('works', function() @@ -3711,7 +3714,7 @@ describe('API', function() { start = 24, group = 'User1' }, }, }, - meths.eval_statusline( + api.nvim_eval_statusline( '%#WarningMsg#TextWithWarningHighlight%1*TextWithUserHighlight', { highlights = true } ) @@ -3724,7 +3727,7 @@ describe('API', function() highlights = { { start = 0, group = 'StatusLine' }, }, - }, meths.eval_statusline('TextWithNoHighlight', { highlights = true })) + }, api.nvim_eval_statusline('TextWithNoHighlight', { highlights = true })) end) it('works with inactive statusline', function() command('split') @@ -3738,9 +3741,9 @@ describe('API', function() { start = 19, group = 'WarningMsg' }, }, }, - meths.eval_statusline( + api.nvim_eval_statusline( 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', - { winid = meths.list_wins()[2].id, highlights = true } + { winid = api.nvim_list_wins()[2].id, highlights = true } ) ) end) @@ -3754,7 +3757,7 @@ describe('API', function() { start = 19, group = 'WarningMsg' }, }, }, - meths.eval_statusline( + api.nvim_eval_statusline( 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', { use_tabline = true, highlights = true } ) @@ -3770,7 +3773,7 @@ describe('API', function() { start = 19, group = 'WarningMsg' }, }, }, - meths.eval_statusline( + api.nvim_eval_statusline( 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', { use_winbar = true, highlights = true } ) @@ -3798,25 +3801,28 @@ describe('API', function() { group = 'ErrorMsg', start = 8 }, { group = 'Normal', start = 10 }, }, - }, meths.eval_statusline('%C%s%=%l ', { use_statuscol_lnum = 4, highlights = true })) - eq({ - str = '3 ', - width = 2, - highlights = { - { group = 'LineNr', start = 0 }, - { group = 'ErrorMsg', start = 1 }, - }, - }, meths.eval_statusline( - '%l%#ErrorMsg# ', - { use_statuscol_lnum = 3, highlights = true } + }, api.nvim_eval_statusline( + '%C%s%=%l ', + { use_statuscol_lnum = 4, highlights = true } )) + eq( + { + str = '3 ', + width = 2, + highlights = { + { group = 'LineNr', start = 0 }, + { group = 'ErrorMsg', start = 1 }, + }, + }, + api.nvim_eval_statusline('%l%#ErrorMsg# ', { use_statuscol_lnum = 3, highlights = true }) + ) end) it('no memory leak with click functions', function() - meths.eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {}) + api.nvim_eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {}) eq({ str = 'StatusLineStringWithClickFunc', width = 29, - }, meths.eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {})) + }, api.nvim_eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {})) end) end) end) @@ -3859,7 +3865,7 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('echo foo', {})) + }, api.nvim_parse_cmd('echo foo', {})) end) it('works with ranges', function() eq({ @@ -3899,7 +3905,7 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('4,6s/math.random/math.max/', {})) + }, api.nvim_parse_cmd('4,6s/math.random/math.max/', {})) end) it('works with count', function() eq({ @@ -3940,7 +3946,7 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('buffer 1', {})) + }, api.nvim_parse_cmd('buffer 1', {})) end) it('works with register', function() eq({ @@ -3981,7 +3987,7 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('put +', {})) + }, api.nvim_parse_cmd('put +', {})) eq({ cmd = 'put', args = {}, @@ -4020,7 +4026,7 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('put', {})) + }, api.nvim_parse_cmd('put', {})) end) it('works with range, count and register', function() eq({ @@ -4062,7 +4068,7 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('1,3delete * 5', {})) + }, api.nvim_parse_cmd('1,3delete * 5', {})) end) it('works with bang', function() eq({ @@ -4102,91 +4108,97 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('w!', {})) + }, api.nvim_parse_cmd('w!', {})) end) it('works with modifiers', function() - eq({ - cmd = 'split', - args = { 'foo.txt' }, - bang = false, - range = {}, - addr = '?', - magic = { - file = true, - bar = true, - }, - nargs = '?', - nextcmd = '', - mods = { - browse = false, - confirm = false, - emsg_silent = true, - filter = { - pattern = 'foo', - force = false, + eq( + { + cmd = 'split', + args = { 'foo.txt' }, + bang = false, + range = {}, + addr = '?', + magic = { + file = true, + bar = true, + }, + nargs = '?', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = true, + filter = { + pattern = 'foo', + force = false, + }, + hide = false, + horizontal = true, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = true, + split = 'topleft', + tab = 1, + unsilent = false, + verbose = 15, + vertical = false, }, - hide = false, - horizontal = true, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = true, - split = 'topleft', - tab = 1, - unsilent = false, - verbose = 15, - vertical = false, - }, - }, meths.parse_cmd( - '15verbose silent! horizontal topleft tab filter /foo/ split foo.txt', - {} - )) - eq({ - cmd = 'split', - args = { 'foo.txt' }, - bang = false, - range = {}, - addr = '?', - magic = { - file = true, - bar = true, }, - nargs = '?', - nextcmd = '', - mods = { - browse = false, - confirm = true, - emsg_silent = false, - filter = { - pattern = 'foo', - force = true, + api.nvim_parse_cmd( + '15verbose silent! horizontal topleft tab filter /foo/ split foo.txt', + {} + ) + ) + eq( + { + cmd = 'split', + args = { 'foo.txt' }, + bang = false, + range = {}, + addr = '?', + magic = { + file = true, + bar = true, + }, + nargs = '?', + nextcmd = '', + mods = { + browse = false, + confirm = true, + emsg_silent = false, + filter = { + pattern = 'foo', + force = true, + }, + hide = false, + horizontal = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + split = 'botright', + tab = 0, + unsilent = true, + verbose = 0, + vertical = false, }, - hide = false, - horizontal = false, - keepalt = false, - keepjumps = false, - keepmarks = false, - keeppatterns = false, - lockmarks = false, - noautocmd = false, - noswapfile = false, - sandbox = false, - silent = false, - split = 'botright', - tab = 0, - unsilent = true, - verbose = 0, - vertical = false, }, - }, meths.parse_cmd( - '0verbose unsilent botright 0tab confirm filter! /foo/ split foo.txt', - {} - )) + api.nvim_parse_cmd( + '0verbose unsilent botright 0tab confirm filter! /foo/ split foo.txt', + {} + ) + ) end) it('works with user commands', function() command('command -bang -nargs=+ -range -addr=lines MyCommand echo foo') @@ -4227,7 +4239,7 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('4,6MyCommand! test it', {})) + }, api.nvim_parse_cmd('4,6MyCommand! test it', {})) end) it('works for commands separated by bar', function() eq({ @@ -4267,7 +4279,7 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('argadd a.txt | argadd b.txt', {})) + }, api.nvim_parse_cmd('argadd a.txt | argadd b.txt', {})) end) it('works for nargs=1', function() command('command -nargs=1 MyCommand echo <q-args>') @@ -4307,28 +4319,28 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('MyCommand test it', {})) + }, api.nvim_parse_cmd('MyCommand test it', {})) end) it('validates command', function() - eq('Error while parsing command line', pcall_err(meths.parse_cmd, '', {})) - eq('Error while parsing command line', pcall_err(meths.parse_cmd, '" foo', {})) + eq('Error while parsing command line', pcall_err(api.nvim_parse_cmd, '', {})) + eq('Error while parsing command line', pcall_err(api.nvim_parse_cmd, '" foo', {})) eq( 'Error while parsing command line: E492: Not an editor command: Fubar', - pcall_err(meths.parse_cmd, 'Fubar', {}) + pcall_err(api.nvim_parse_cmd, 'Fubar', {}) ) command('command! Fubar echo foo') eq( 'Error while parsing command line: E477: No ! allowed', - pcall_err(meths.parse_cmd, 'Fubar!', {}) + pcall_err(api.nvim_parse_cmd, 'Fubar!', {}) ) eq( 'Error while parsing command line: E481: No range allowed', - pcall_err(meths.parse_cmd, '4,6Fubar', {}) + pcall_err(api.nvim_parse_cmd, '4,6Fubar', {}) ) command('command! Foobar echo foo') eq( 'Error while parsing command line: E464: Ambiguous use of user-defined command', - pcall_err(meths.parse_cmd, 'F', {}) + pcall_err(api.nvim_parse_cmd, 'F', {}) ) end) it('does not interfere with printing line in Ex mode #19400', function() @@ -4350,7 +4362,7 @@ describe('API', function() Entering Ex mode. Type "visual" to go to Normal mode. | :1^ | ]]) - eq('Error while parsing command line', pcall_err(meths.parse_cmd, '', {})) + eq('Error while parsing command line', pcall_err(api.nvim_parse_cmd, '', {})) feed('<CR>') screen:expect([[ foo | @@ -4363,10 +4375,10 @@ describe('API', function() ]]) end) it('does not move cursor or change search history/pattern #19878 #19890', function() - meths.buf_set_lines(0, 0, -1, true, { 'foo', 'bar', 'foo', 'bar' }) - eq({ 1, 0 }, meths.win_get_cursor(0)) - eq('', funcs.getreg('/')) - eq('', funcs.histget('search')) + api.nvim_buf_set_lines(0, 0, -1, true, { 'foo', 'bar', 'foo', 'bar' }) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) + eq('', fn.getreg('/')) + eq('', fn.histget('search')) feed(':') -- call the API in cmdline mode to test whether it changes search history eq({ cmd = 'normal', @@ -4405,15 +4417,15 @@ describe('API', function() verbose = -1, vertical = false, }, - }, meths.parse_cmd('+2;/bar/normal! x', {})) - eq({ 1, 0 }, meths.win_get_cursor(0)) - eq('', funcs.getreg('/')) - eq('', funcs.histget('search')) + }, api.nvim_parse_cmd('+2;/bar/normal! x', {})) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) + eq('', fn.getreg('/')) + eq('', fn.histget('search')) end) it('result can be used directly by nvim_cmd #20051', function() - eq('foo', meths.cmd(meths.parse_cmd('echo "foo"', {}), { output = true })) - meths.cmd(meths.parse_cmd('set cursorline', {}), {}) - eq(true, meths.get_option_value('cursorline', {})) + eq('foo', api.nvim_cmd(api.nvim_parse_cmd('echo "foo"', {}), { output = true })) + api.nvim_cmd(api.nvim_parse_cmd('set cursorline', {}), {}) + eq(true, api.nvim_get_option_value('cursorline', {})) end) it('no side-effects (error messages) in pcall() #20339', function() eq( @@ -4426,80 +4438,83 @@ describe('API', function() describe('nvim_cmd', function() it('works', function() - meths.cmd({ cmd = 'set', args = { 'cursorline' } }, {}) - eq(true, meths.get_option_value('cursorline', {})) + api.nvim_cmd({ cmd = 'set', args = { 'cursorline' } }, {}) + eq(true, api.nvim_get_option_value('cursorline', {})) end) it('validation', function() - eq("Invalid 'cmd': expected non-empty String", pcall_err(meths.cmd, { cmd = '' }, {})) - eq("Invalid 'cmd': expected String, got Array", pcall_err(meths.cmd, { cmd = {} }, {})) + eq("Invalid 'cmd': expected non-empty String", pcall_err(api.nvim_cmd, { cmd = '' }, {})) + eq("Invalid 'cmd': expected String, got Array", pcall_err(api.nvim_cmd, { cmd = {} }, {})) eq( "Invalid 'args': expected Array, got Boolean", - pcall_err(meths.cmd, { cmd = 'set', args = true }, {}) + pcall_err(api.nvim_cmd, { cmd = 'set', args = true }, {}) ) eq( 'Invalid command arg: expected non-whitespace', - pcall_err(meths.cmd, { cmd = 'set', args = { ' ' } }, {}) + pcall_err(api.nvim_cmd, { cmd = 'set', args = { ' ' } }, {}) ) eq( 'Invalid command arg: expected valid type, got Array', - pcall_err(meths.cmd, { cmd = 'set', args = { {} } }, {}) + pcall_err(api.nvim_cmd, { cmd = 'set', args = { {} } }, {}) ) - eq('Wrong number of arguments', pcall_err(meths.cmd, { cmd = 'aboveleft', args = {} }, {})) + eq('Wrong number of arguments', pcall_err(api.nvim_cmd, { cmd = 'aboveleft', args = {} }, {})) eq( 'Command cannot accept bang: print', - pcall_err(meths.cmd, { cmd = 'print', args = {}, bang = true }, {}) + pcall_err(api.nvim_cmd, { cmd = 'print', args = {}, bang = true }, {}) ) eq( 'Command cannot accept range: set', - pcall_err(meths.cmd, { cmd = 'set', args = {}, range = { 1 } }, {}) + pcall_err(api.nvim_cmd, { cmd = 'set', args = {}, range = { 1 } }, {}) ) eq( "Invalid 'range': expected Array, got Boolean", - pcall_err(meths.cmd, { cmd = 'print', args = {}, range = true }, {}) + pcall_err(api.nvim_cmd, { cmd = 'print', args = {}, range = true }, {}) ) eq( "Invalid 'range': expected <=2 elements", - pcall_err(meths.cmd, { cmd = 'print', args = {}, range = { 1, 2, 3, 4 } }, {}) + pcall_err(api.nvim_cmd, { cmd = 'print', args = {}, range = { 1, 2, 3, 4 } }, {}) ) eq( 'Invalid range element: expected non-negative Integer', - pcall_err(meths.cmd, { cmd = 'print', args = {}, range = { -1 } }, {}) + pcall_err(api.nvim_cmd, { cmd = 'print', args = {}, range = { -1 } }, {}) ) eq( 'Command cannot accept count: set', - pcall_err(meths.cmd, { cmd = 'set', args = {}, count = 1 }, {}) + pcall_err(api.nvim_cmd, { cmd = 'set', args = {}, count = 1 }, {}) ) eq( "Invalid 'count': expected Integer, got Boolean", - pcall_err(meths.cmd, { cmd = 'print', args = {}, count = true }, {}) + pcall_err(api.nvim_cmd, { cmd = 'print', args = {}, count = true }, {}) ) eq( "Invalid 'count': expected non-negative Integer", - pcall_err(meths.cmd, { cmd = 'print', args = {}, count = -1 }, {}) + pcall_err(api.nvim_cmd, { cmd = 'print', args = {}, count = -1 }, {}) ) eq( 'Command cannot accept register: set', - pcall_err(meths.cmd, { cmd = 'set', args = {}, reg = 'x' }, {}) + pcall_err(api.nvim_cmd, { cmd = 'set', args = {}, reg = 'x' }, {}) + ) + eq( + 'Cannot use register "=', + pcall_err(api.nvim_cmd, { cmd = 'put', args = {}, reg = '=' }, {}) ) - eq('Cannot use register "=', pcall_err(meths.cmd, { cmd = 'put', args = {}, reg = '=' }, {})) eq( "Invalid 'reg': expected single character, got xx", - pcall_err(meths.cmd, { cmd = 'put', args = {}, reg = 'xx' }, {}) + pcall_err(api.nvim_cmd, { cmd = 'put', args = {}, reg = 'xx' }, {}) ) -- #20681 - eq('Invalid command: "win_getid"', pcall_err(meths.cmd, { cmd = 'win_getid' }, {})) - eq('Invalid command: "echo "hi""', pcall_err(meths.cmd, { cmd = 'echo "hi"' }, {})) + eq('Invalid command: "win_getid"', pcall_err(api.nvim_cmd, { cmd = 'win_getid' }, {})) + eq('Invalid command: "echo "hi""', pcall_err(api.nvim_cmd, { cmd = 'echo "hi"' }, {})) eq('Invalid command: "win_getid"', pcall_err(exec_lua, [[return vim.cmd.win_getid{}]])) -- Lua call allows empty {} for dict item. eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, magic = {} }]])) eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, mods = {} }]])) - eq('', meths.cmd({ cmd = 'set', args = {}, magic = {} }, {})) + eq('', api.nvim_cmd({ cmd = 'set', args = {}, magic = {} }, {})) -- Lua call does not allow non-empty list-like {} for dict item. eq( @@ -4517,11 +4532,11 @@ describe('API', function() end) it('captures output', function() - eq('foo', meths.cmd({ cmd = 'echo', args = { '"foo"' } }, { output = true })) + eq('foo', api.nvim_cmd({ cmd = 'echo', args = { '"foo"' } }, { output = true })) end) it('sets correct script context', function() - meths.cmd({ cmd = 'set', args = { 'cursorline' } }, {}) + api.nvim_cmd({ cmd = 'set', args = { 'cursorline' } }, {}) local str = exec_capture([[verbose set cursorline?]]) neq(nil, str:find('cursorline\n\tLast set from API client %(channel id %d+%)')) end) @@ -4536,7 +4551,7 @@ describe('API', function() line5 line6 ]] - meths.cmd({ cmd = 'del', range = { 2, 4 } }, {}) + api.nvim_cmd({ cmd = 'del', range = { 2, 4 } }, {}) expect [[ line1 you didn't expect this @@ -4554,7 +4569,7 @@ describe('API', function() line5 line6 ]] - meths.cmd({ cmd = 'del', range = { 2 }, count = 4 }, {}) + api.nvim_cmd({ cmd = 'del', range = { 2 }, count = 4 }, {}) expect [[ line1 line5 @@ -4571,7 +4586,7 @@ describe('API', function() line5 line6 ]] - meths.cmd({ cmd = 'del', range = { 2, 4 }, reg = 'a' }, {}) + api.nvim_cmd({ cmd = 'del', range = { 2, 4 }, reg = 'a' }, {}) command('1put a') expect [[ line1 @@ -4584,26 +4599,29 @@ describe('API', function() ]] end) it('works with bang', function() - meths.create_user_command('Foo', 'echo "<bang>"', { bang = true }) - eq('!', meths.cmd({ cmd = 'Foo', bang = true }, { output = true })) - eq('', meths.cmd({ cmd = 'Foo', bang = false }, { output = true })) + api.nvim_create_user_command('Foo', 'echo "<bang>"', { bang = true }) + eq('!', api.nvim_cmd({ cmd = 'Foo', bang = true }, { output = true })) + eq('', api.nvim_cmd({ cmd = 'Foo', bang = false }, { output = true })) end) it('works with modifiers', function() -- with silent = true output is still captured eq( '1', - meths.cmd({ cmd = 'echomsg', args = { '1' }, mods = { silent = true } }, { output = true }) + api.nvim_cmd( + { cmd = 'echomsg', args = { '1' }, mods = { silent = true } }, + { output = true } + ) ) -- but message isn't added to message history - eq('', meths.cmd({ cmd = 'messages' }, { output = true })) + eq('', api.nvim_cmd({ cmd = 'messages' }, { output = true })) - meths.create_user_command('Foo', 'set verbose', {}) - eq(' verbose=1', meths.cmd({ cmd = 'Foo', mods = { verbose = 1 } }, { output = true })) + api.nvim_create_user_command('Foo', 'set verbose', {}) + eq(' verbose=1', api.nvim_cmd({ cmd = 'Foo', mods = { verbose = 1 } }, { output = true })) - meths.create_user_command('Mods', "echo '<mods>'", {}) + api.nvim_create_user_command('Mods', "echo '<mods>'", {}) eq( 'keepmarks keeppatterns silent 3verbose aboveleft horizontal', - meths.cmd({ + api.nvim_cmd({ cmd = 'Mods', mods = { horizontal = true, @@ -4615,19 +4633,19 @@ describe('API', function() }, }, { output = true }) ) - eq(0, meths.get_option_value('verbose', {})) + eq(0, api.nvim_get_option_value('verbose', {})) command('edit foo.txt | edit bar.txt') eq( ' 1 #h "foo.txt" line 1', - meths.cmd( + api.nvim_cmd( { cmd = 'buffers', mods = { filter = { pattern = 'foo', force = false } } }, { output = true } ) ) eq( ' 2 %a "bar.txt" line 1', - meths.cmd( + api.nvim_cmd( { cmd = 'buffers', mods = { filter = { pattern = 'foo', force = true } } }, { output = true } ) @@ -4635,10 +4653,10 @@ describe('API', function() -- with emsg_silent = true error is suppressed feed([[:lua vim.api.nvim_cmd({ cmd = 'call', mods = { emsg_silent = true } }, {})<CR>]]) - eq('', meths.cmd({ cmd = 'messages' }, { output = true })) + eq('', api.nvim_cmd({ cmd = 'messages' }, { output = true })) -- error from the next command typed is not suppressed #21420 feed(':call<CR><CR>') - eq('E471: Argument required', meths.cmd({ cmd = 'messages' }, { output = true })) + eq('E471: Argument required', api.nvim_cmd({ cmd = 'messages' }, { output = true })) end) it('works with magic.file', function() exec_lua([[ @@ -4647,8 +4665,11 @@ describe('API', function() end, { nargs = 1 }) ]]) eq( - luv.cwd(), - meths.cmd({ cmd = 'Foo', args = { '%:p:h' }, magic = { file = true } }, { output = true }) + uv.cwd(), + api.nvim_cmd( + { cmd = 'Foo', args = { '%:p:h' }, magic = { file = true } }, + { output = true } + ) ) end) it('splits arguments correctly', function() @@ -4657,24 +4678,24 @@ describe('API', function() echo a:000 endfunction ]]) - meths.create_user_command('Foo', 'call FooFunc(<f-args>)', { nargs = '+' }) + api.nvim_create_user_command('Foo', 'call FooFunc(<f-args>)', { nargs = '+' }) eq( [=[['a quick', 'brown fox', 'jumps over the', 'lazy dog']]=], - meths.cmd( + api.nvim_cmd( { cmd = 'Foo', args = { 'a quick', 'brown fox', 'jumps over the', 'lazy dog' } }, { output = true } ) ) eq( [=[['test \ \\ \"""\', 'more\ tests\" ']]=], - meths.cmd( + api.nvim_cmd( { cmd = 'Foo', args = { [[test \ \\ \"""\]], [[more\ tests\" ]] } }, { output = true } ) ) end) it('splits arguments correctly for Lua callback', function() - meths.exec_lua( + api.nvim_exec_lua( [[ local function FooFunc(opts) vim.print(opts.fargs) @@ -4686,14 +4707,14 @@ describe('API', function() ) eq( [[{ "a quick", "brown fox", "jumps over the", "lazy dog" }]], - meths.cmd( + api.nvim_cmd( { cmd = 'Foo', args = { 'a quick', 'brown fox', 'jumps over the', 'lazy dog' } }, { output = true } ) ) eq( [[{ 'test \\ \\\\ \\"""\\', 'more\\ tests\\" ' }]], - meths.cmd( + api.nvim_cmd( { cmd = 'Foo', args = { [[test \ \\ \"""\]], [[more\ tests\" ]] } }, { output = true } ) @@ -4701,13 +4722,13 @@ describe('API', function() end) it('works with buffer names', function() command('edit foo.txt | edit bar.txt') - meths.cmd({ cmd = 'buffer', args = { 'foo.txt' } }, {}) - eq('foo.txt', funcs.fnamemodify(meths.buf_get_name(0), ':t')) - meths.cmd({ cmd = 'buffer', args = { 'bar.txt' } }, {}) - eq('bar.txt', funcs.fnamemodify(meths.buf_get_name(0), ':t')) + api.nvim_cmd({ cmd = 'buffer', args = { 'foo.txt' } }, {}) + eq('foo.txt', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) + api.nvim_cmd({ cmd = 'buffer', args = { 'bar.txt' } }, {}) + eq('bar.txt', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) it('triggers CmdUndefined event if command is not found', function() - meths.exec_lua( + api.nvim_exec_lua( [[ vim.api.nvim_create_autocmd("CmdUndefined", { pattern = "Foo", @@ -4718,17 +4739,17 @@ describe('API', function() ]], {} ) - eq('foo', meths.cmd({ cmd = 'Foo' }, { output = true })) + eq('foo', api.nvim_cmd({ cmd = 'Foo' }, { output = true })) end) it('errors if command is not implemented', function() - eq('Command not implemented: winpos', pcall_err(meths.cmd, { cmd = 'winpos' }, {})) + eq('Command not implemented: winpos', pcall_err(api.nvim_cmd, { cmd = 'winpos' }, {})) end) it('works with empty arguments list', function() - meths.cmd({ cmd = 'update' }, {}) - meths.cmd({ cmd = 'buffer', count = 0 }, {}) + api.nvim_cmd({ cmd = 'update' }, {}) + api.nvim_cmd({ cmd = 'buffer', count = 0 }, {}) end) it("doesn't suppress errors when used in keymapping", function() - meths.exec_lua( + api.nvim_exec_lua( [[ vim.keymap.set("n", "[l", function() vim.api.nvim_cmd({ cmd = "echo", args = {"foo"} }, {}) end) @@ -4739,31 +4760,31 @@ describe('API', function() neq(nil, string.find(eval('v:errmsg'), 'E5108:')) end) it('handles 0 range #19608', function() - meths.buf_set_lines(0, 0, -1, false, { 'aa' }) - meths.cmd({ cmd = 'delete', range = { 0 } }, {}) + api.nvim_buf_set_lines(0, 0, -1, false, { 'aa' }) + api.nvim_cmd({ cmd = 'delete', range = { 0 } }, {}) command('undo') - eq({ 'aa' }, meths.buf_get_lines(0, 0, 1, false)) + eq({ 'aa' }, api.nvim_buf_get_lines(0, 0, 1, false)) assert_alive() end) it('supports filename expansion', function() - meths.cmd({ cmd = 'argadd', args = { '%:p:h:t', '%:p:h:t' } }, {}) - local arg = funcs.expand('%:p:h:t') - eq({ arg, arg }, funcs.argv()) + api.nvim_cmd({ cmd = 'argadd', args = { '%:p:h:t', '%:p:h:t' } }, {}) + local arg = fn.expand('%:p:h:t') + eq({ arg, arg }, fn.argv()) end) it("'make' command works when argument count isn't 1 #19696", function() command('set makeprg=echo') command('set shellquote=') - matches('^:!echo ', meths.cmd({ cmd = 'make' }, { output = true })) + matches('^:!echo ', api.nvim_cmd({ cmd = 'make' }, { output = true })) assert_alive() matches( '^:!echo foo bar', - meths.cmd({ cmd = 'make', args = { 'foo', 'bar' } }, { output = true }) + api.nvim_cmd({ cmd = 'make', args = { 'foo', 'bar' } }, { output = true }) ) assert_alive() - local arg_pesc = pesc(funcs.expand('%:p:h:t')) + local arg_pesc = pesc(fn.expand('%:p:h:t')) matches( ('^:!echo %s %s'):format(arg_pesc, arg_pesc), - meths.cmd({ cmd = 'make', args = { '%:p:h:t', '%:p:h:t' } }, { output = true }) + api.nvim_cmd({ cmd = 'make', args = { '%:p:h:t', '%:p:h:t' } }, { output = true }) ) assert_alive() end) @@ -4773,7 +4794,7 @@ describe('API', function() screen:set_default_attr_ids({ [0] = { bold = true, foreground = Screen.colors.Blue }, }) - meths.cmd({ cmd = 'echo', args = { [['hello']] } }, { output = true }) + api.nvim_cmd({ cmd = 'echo', args = { [['hello']] } }, { output = true }) screen:expect { grid = [[ ^ | @@ -4796,29 +4817,29 @@ describe('API', function() } end) it('works with non-String args', function() - eq('2', meths.cmd({ cmd = 'echo', args = { 2 } }, { output = true })) - eq('1', meths.cmd({ cmd = 'echo', args = { true } }, { output = true })) + eq('2', api.nvim_cmd({ cmd = 'echo', args = { 2 } }, { output = true })) + eq('1', api.nvim_cmd({ cmd = 'echo', args = { true } }, { output = true })) end) describe('first argument as count', function() it('works', function() command('vsplit | enew') - meths.cmd({ cmd = 'bdelete', args = { meths.get_current_buf() } }, {}) - eq(1, meths.get_current_buf().id) + api.nvim_cmd({ cmd = 'bdelete', args = { api.nvim_get_current_buf() } }, {}) + eq(1, api.nvim_get_current_buf().id) end) it('works with :sleep using milliseconds', function() - local start = luv.now() - meths.cmd({ cmd = 'sleep', args = { '100m' } }, {}) - ok(luv.now() - start <= 300) + local start = uv.now() + api.nvim_cmd({ cmd = 'sleep', args = { '100m' } }, {}) + ok(uv.now() - start <= 300) end) end) it(':call with unknown function does not crash #26289', function() eq( 'Vim:E117: Unknown function: UnknownFunc', - pcall_err(meths.cmd, { cmd = 'call', args = { 'UnknownFunc()' } }, {}) + pcall_err(api.nvim_cmd, { cmd = 'call', args = { 'UnknownFunc()' } }, {}) ) end) it(':throw does not crash #24556', function() - eq('42', pcall_err(meths.cmd, { cmd = 'throw', args = { '42' } }, {})) + eq('42', pcall_err(api.nvim_cmd, { cmd = 'throw', args = { '42' } }, {})) end) it('can use :return #24556', function() exec([[ @@ -4829,8 +4850,8 @@ describe('API', function() endfunc let g:result = Foo() ]]) - eq('before', meths.get_var('pos')) - eq({ 1, 2, 3 }, meths.get_var('result')) + eq('before', api.nvim_get_var('pos')) + eq({ 1, 2, 3 }, api.nvim_get_var('result')) end) end) end) diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 7e92dd6bf3..d30a6460a6 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1,26 +1,22 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, ok, feed, insert, eval, tabpage = +local clear, curbuf, curbuf_contents, curwin, eq, neq, ok, feed, insert, eval = helpers.clear, - helpers.nvim, - helpers.curbuf, + helpers.api.nvim_get_current_buf, helpers.curbuf_contents, - helpers.window, - helpers.curwin, + helpers.api.nvim_get_current_win, helpers.eq, helpers.neq, helpers.ok, helpers.feed, helpers.insert, - helpers.eval, - helpers.tabpage + helpers.eval local poke_eventloop = helpers.poke_eventloop -local curwinmeths = helpers.curwinmeths local exec = helpers.exec -local funcs = helpers.funcs +local fn = helpers.fn local request = helpers.request -local NIL = helpers.NIL -local meths = helpers.meths +local NIL = vim.NIL +local api = helpers.api local command = helpers.command local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -30,32 +26,35 @@ describe('API/win', function() describe('get_buf', function() it('works', function() - eq(curbuf(), window('get_buf', nvim('list_wins')[1])) - nvim('command', 'new') - nvim('set_current_win', nvim('list_wins')[2]) - eq(curbuf(), window('get_buf', nvim('list_wins')[2])) - neq(window('get_buf', nvim('list_wins')[1]), window('get_buf', nvim('list_wins')[2])) + eq(curbuf(), api.nvim_win_get_buf(api.nvim_list_wins()[1])) + command('new') + api.nvim_set_current_win(api.nvim_list_wins()[2]) + eq(curbuf(), api.nvim_win_get_buf(api.nvim_list_wins()[2])) + neq( + api.nvim_win_get_buf(api.nvim_list_wins()[1]), + api.nvim_win_get_buf(api.nvim_list_wins()[2]) + ) end) end) describe('set_buf', function() it('works', function() - nvim('command', 'new') - local windows = nvim('list_wins') - neq(window('get_buf', windows[2]), window('get_buf', windows[1])) - window('set_buf', windows[2], window('get_buf', windows[1])) - eq(window('get_buf', windows[2]), window('get_buf', windows[1])) + command('new') + local windows = api.nvim_list_wins() + neq(api.nvim_win_get_buf(windows[2]), api.nvim_win_get_buf(windows[1])) + api.nvim_win_set_buf(windows[2], api.nvim_win_get_buf(windows[1])) + eq(api.nvim_win_get_buf(windows[2]), api.nvim_win_get_buf(windows[1])) end) it('validates args', function() - eq('Invalid buffer id: 23', pcall_err(window, 'set_buf', nvim('get_current_win'), 23)) - eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf'))) + eq('Invalid buffer id: 23', pcall_err(api.nvim_win_set_buf, api.nvim_get_current_win(), 23)) + eq('Invalid window id: 23', pcall_err(api.nvim_win_set_buf, 23, api.nvim_get_current_buf())) end) it('disallowed in cmdwin if win={old_}curwin or buf=curbuf', function() - local new_buf = meths.create_buf(true, true) - local old_win = meths.get_current_win() - local new_win = meths.open_win(new_buf, false, { + local new_buf = api.nvim_create_buf(true, true) + local old_win = api.nvim_get_current_win() + local new_win = api.nvim_open_win(new_buf, false, { relative = 'editor', row = 10, col = 10, @@ -65,36 +64,36 @@ describe('API/win', function() feed('q:') eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.win_set_buf, 0, new_buf) + pcall_err(api.nvim_win_set_buf, 0, new_buf) ) eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.win_set_buf, old_win, new_buf) + pcall_err(api.nvim_win_set_buf, old_win, new_buf) ) eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.win_set_buf, new_win, 0) + pcall_err(api.nvim_win_set_buf, new_win, 0) ) - local next_buf = meths.create_buf(true, true) - meths.win_set_buf(new_win, next_buf) - eq(next_buf, meths.win_get_buf(new_win)) + local next_buf = api.nvim_create_buf(true, true) + api.nvim_win_set_buf(new_win, next_buf) + eq(next_buf, api.nvim_win_get_buf(new_win)) end) end) describe('{get,set}_cursor', function() it('works', function() - eq({ 1, 0 }, curwin('get_cursor')) - nvim('command', 'normal ityping\027o some text') + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) + command('normal ityping\027o some text') eq('typing\n some text', curbuf_contents()) - eq({ 2, 10 }, curwin('get_cursor')) - curwin('set_cursor', { 2, 6 }) - nvim('command', 'normal i dumb') + eq({ 2, 10 }, api.nvim_win_get_cursor(0)) + api.nvim_win_set_cursor(0, { 2, 6 }) + command('normal i dumb') eq('typing\n some dumb text', curbuf_contents()) end) it('does not leak memory when using invalid window ID with invalid pos', function() - eq('Invalid window id: 1', pcall_err(meths.win_set_cursor, 1, { 'b\na' })) + eq('Invalid window id: 1', pcall_err(api.nvim_win_set_cursor, 1, { 'b\na' })) end) it('updates the screen, and also when the window is unfocused', function() @@ -119,10 +118,10 @@ describe('API/win', function() ]], } -- cursor position is at beginning - eq({ 1, 0 }, window('get_cursor', win)) + eq({ 1, 0 }, api.nvim_win_get_cursor(win)) -- move cursor to end - window('set_cursor', win, { 101, 0 }) + api.nvim_win_set_cursor(win, { 101, 0 }) screen:expect { grid = [[ |*7 @@ -132,7 +131,7 @@ describe('API/win', function() } -- move cursor to the beginning again - window('set_cursor', win, { 1, 0 }) + api.nvim_win_set_cursor(win, { 1, 0 }) screen:expect { grid = [[ ^prologue | @@ -141,11 +140,11 @@ describe('API/win', function() } -- move focus to new window - nvim('command', 'new') + command('new') neq(win, curwin()) -- sanity check, cursor position is kept - eq({ 1, 0 }, window('get_cursor', win)) + eq({ 1, 0 }, api.nvim_win_get_cursor(win)) screen:expect { grid = [[ ^ | @@ -159,7 +158,7 @@ describe('API/win', function() } -- move cursor to end - window('set_cursor', win, { 101, 0 }) + api.nvim_win_set_cursor(win, { 101, 0 }) screen:expect { grid = [[ ^ | @@ -173,7 +172,7 @@ describe('API/win', function() } -- move cursor to the beginning again - window('set_cursor', win, { 1, 0 }) + api.nvim_win_set_cursor(win, { 1, 0 }) screen:expect { grid = [[ ^ | @@ -200,17 +199,17 @@ describe('API/win', function() -- cursor position is at beginning local win = curwin() - eq({ 1, 0 }, window('get_cursor', win)) + eq({ 1, 0 }, api.nvim_win_get_cursor(win)) -- move cursor to column 5 - window('set_cursor', win, { 1, 5 }) + api.nvim_win_set_cursor(win, { 1, 5 }) -- move down a line feed('j') poke_eventloop() -- let nvim process the 'j' command -- cursor is still in column 5 - eq({ 2, 5 }, window('get_cursor', win)) + eq({ 2, 5 }, api.nvim_win_get_cursor(win)) end) it('updates cursorline and statusline ruler in non-current window', function() @@ -240,7 +239,7 @@ describe('API/win', function() {3:[No Name] [+] 4,3 All }{4:[No Name] [+] 4,3 All}| | ]]) - window('set_cursor', oldwin, { 1, 0 }) + api.nvim_win_set_cursor(oldwin, { 1, 0 }) screen:expect([[ aaa │{2:aaa }| bbb │bbb | @@ -278,7 +277,7 @@ describe('API/win', function() {3:[No Name] [+] }{4:[No Name] [+] }| | ]]) - window('set_cursor', oldwin, { 2, 0 }) + api.nvim_win_set_cursor(oldwin, { 2, 0 }) screen:expect([[ aa{2:a} │{2:a}aa | bb{2:b} │bbb | @@ -293,32 +292,35 @@ describe('API/win', function() describe('{get,set}_height', function() it('works', function() - nvim('command', 'vsplit') - eq(window('get_height', nvim('list_wins')[2]), window('get_height', nvim('list_wins')[1])) - nvim('set_current_win', nvim('list_wins')[2]) - nvim('command', 'split') + command('vsplit') eq( - window('get_height', nvim('list_wins')[2]), - math.floor(window('get_height', nvim('list_wins')[1]) / 2) + api.nvim_win_get_height(api.nvim_list_wins()[2]), + api.nvim_win_get_height(api.nvim_list_wins()[1]) ) - window('set_height', nvim('list_wins')[2], 2) - eq(2, window('get_height', nvim('list_wins')[2])) + api.nvim_set_current_win(api.nvim_list_wins()[2]) + command('split') + eq( + api.nvim_win_get_height(api.nvim_list_wins()[2]), + math.floor(api.nvim_win_get_height(api.nvim_list_wins()[1]) / 2) + ) + api.nvim_win_set_height(api.nvim_list_wins()[2], 2) + eq(2, api.nvim_win_get_height(api.nvim_list_wins()[2])) end) it('correctly handles height=1', function() - nvim('command', 'split') - nvim('set_current_win', nvim('list_wins')[1]) - window('set_height', nvim('list_wins')[2], 1) - eq(1, window('get_height', nvim('list_wins')[2])) + command('split') + api.nvim_set_current_win(api.nvim_list_wins()[1]) + api.nvim_win_set_height(api.nvim_list_wins()[2], 1) + eq(1, api.nvim_win_get_height(api.nvim_list_wins()[2])) end) it('correctly handles height=1 with a winbar', function() - nvim('command', 'set winbar=foobar') - nvim('command', 'set winminheight=0') - nvim('command', 'split') - nvim('set_current_win', nvim('list_wins')[1]) - window('set_height', nvim('list_wins')[2], 1) - eq(1, window('get_height', nvim('list_wins')[2])) + command('set winbar=foobar') + command('set winminheight=0') + command('split') + api.nvim_set_current_win(api.nvim_list_wins()[1]) + api.nvim_win_set_height(api.nvim_list_wins()[2], 1) + eq(1, api.nvim_win_get_height(api.nvim_list_wins()[2])) end) it('do not cause ml_get errors with foldmethod=expr #19989', function() @@ -334,22 +336,25 @@ describe('API/win', function() call nvim_win_set_height(w, 5) ]]) feed('l') - eq('', meths.get_vvar('errmsg')) + eq('', api.nvim_get_vvar('errmsg')) end) end) describe('{get,set}_width', function() it('works', function() - nvim('command', 'split') - eq(window('get_width', nvim('list_wins')[2]), window('get_width', nvim('list_wins')[1])) - nvim('set_current_win', nvim('list_wins')[2]) - nvim('command', 'vsplit') + command('split') + eq( + api.nvim_win_get_width(api.nvim_list_wins()[2]), + api.nvim_win_get_width(api.nvim_list_wins()[1]) + ) + api.nvim_set_current_win(api.nvim_list_wins()[2]) + command('vsplit') eq( - window('get_width', nvim('list_wins')[2]), - math.floor(window('get_width', nvim('list_wins')[1]) / 2) + api.nvim_win_get_width(api.nvim_list_wins()[2]), + math.floor(api.nvim_win_get_width(api.nvim_list_wins()[1]) / 2) ) - window('set_width', nvim('list_wins')[2], 2) - eq(2, window('get_width', nvim('list_wins')[2])) + api.nvim_win_set_width(api.nvim_list_wins()[2], 2) + eq(2, api.nvim_win_get_width(api.nvim_list_wins()[2])) end) it('do not cause ml_get errors with foldmethod=expr #19989', function() @@ -365,23 +370,23 @@ describe('API/win', function() call nvim_win_set_width(w, 5) ]]) feed('l') - eq('', meths.get_vvar('errmsg')) + eq('', api.nvim_get_vvar('errmsg')) end) end) describe('{get,set,del}_var', function() it('works', function() - curwin('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) - eq({ 1, 2, { ['3'] = 1 } }, curwin('get_var', 'lua')) - eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'w:lua')) - eq(1, funcs.exists('w:lua')) - curwinmeths.del_var('lua') - eq(0, funcs.exists('w:lua')) - eq('Key not found: lua', pcall_err(curwinmeths.del_var, 'lua')) - curwinmeths.set_var('lua', 1) + api.nvim_win_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } }) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_win_get_var(0, 'lua')) + eq({ 1, 2, { ['3'] = 1 } }, api.nvim_eval('w:lua')) + eq(1, fn.exists('w:lua')) + api.nvim_win_del_var(0, 'lua') + eq(0, fn.exists('w:lua')) + eq('Key not found: lua', pcall_err(api.nvim_win_del_var, 0, 'lua')) + api.nvim_win_set_var(0, 'lua', 1) command('lockvar w:lua') - eq('Key is locked: lua', pcall_err(curwinmeths.del_var, 'lua')) - eq('Key is locked: lua', pcall_err(curwinmeths.set_var, 'lua', 1)) + eq('Key is locked: lua', pcall_err(api.nvim_win_del_var, 0, 'lua')) + eq('Key is locked: lua', pcall_err(api.nvim_win_set_var, 0, 'lua', 1)) end) it('window_set_var returns the old value', function() @@ -402,51 +407,51 @@ describe('API/win', function() describe('nvim_get_option_value, nvim_set_option_value', function() it('works', function() - nvim('set_option_value', 'colorcolumn', '4,3', {}) - eq('4,3', nvim('get_option_value', 'colorcolumn', {})) + api.nvim_set_option_value('colorcolumn', '4,3', {}) + eq('4,3', api.nvim_get_option_value('colorcolumn', {})) command('set modified hidden') command('enew') -- edit new buffer, window option is preserved - eq('4,3', nvim('get_option_value', 'colorcolumn', {})) + eq('4,3', api.nvim_get_option_value('colorcolumn', {})) -- global-local option - nvim('set_option_value', 'statusline', 'window-status', { win = 0 }) - eq('window-status', nvim('get_option_value', 'statusline', { win = 0 })) - eq('', nvim('get_option_value', 'statusline', { scope = 'global' })) + api.nvim_set_option_value('statusline', 'window-status', { win = 0 }) + eq('window-status', api.nvim_get_option_value('statusline', { win = 0 })) + eq('', api.nvim_get_option_value('statusline', { scope = 'global' })) command('set modified') command('enew') -- global-local: not preserved in new buffer -- confirm local value was not copied - eq('', nvim('get_option_value', 'statusline', { win = 0 })) + eq('', api.nvim_get_option_value('statusline', { win = 0 })) eq('', eval('&l:statusline')) end) it('after switching windows #15390', function() - nvim('command', 'tabnew') - local tab1 = unpack(nvim('list_tabpages')) - local win1 = unpack(tabpage('list_wins', tab1)) - nvim('set_option_value', 'statusline', 'window-status', { win = win1.id }) - nvim('command', 'split') - nvim('command', 'wincmd J') - nvim('command', 'wincmd j') - eq('window-status', nvim('get_option_value', 'statusline', { win = win1.id })) + command('tabnew') + local tab1 = unpack(api.nvim_list_tabpages()) + local win1 = unpack(api.nvim_tabpage_list_wins(tab1)) + api.nvim_set_option_value('statusline', 'window-status', { win = win1.id }) + command('split') + command('wincmd J') + command('wincmd j') + eq('window-status', api.nvim_get_option_value('statusline', { win = win1.id })) assert_alive() end) it('returns values for unset local options', function() - eq(-1, nvim('get_option_value', 'scrolloff', { win = 0, scope = 'local' })) + eq(-1, api.nvim_get_option_value('scrolloff', { win = 0, scope = 'local' })) end) end) describe('get_position', function() it('works', function() - local height = window('get_height', nvim('list_wins')[1]) - local width = window('get_width', nvim('list_wins')[1]) - nvim('command', 'split') - nvim('command', 'vsplit') - eq({ 0, 0 }, window('get_position', nvim('list_wins')[1])) + local height = api.nvim_win_get_height(api.nvim_list_wins()[1]) + local width = api.nvim_win_get_width(api.nvim_list_wins()[1]) + command('split') + command('vsplit') + eq({ 0, 0 }, api.nvim_win_get_position(api.nvim_list_wins()[1])) local vsplit_pos = math.floor(width / 2) local split_pos = math.floor(height / 2) - local win2row, win2col = unpack(window('get_position', nvim('list_wins')[2])) - local win3row, win3col = unpack(window('get_position', nvim('list_wins')[3])) + local win2row, win2col = unpack(api.nvim_win_get_position(api.nvim_list_wins()[2])) + local win3row, win3col = unpack(api.nvim_win_get_position(api.nvim_list_wins()[3])) eq(0, win2row) eq(0, win3col) ok(vsplit_pos - 1 <= win2col and win2col <= vsplit_pos + 1) @@ -456,93 +461,93 @@ describe('API/win', function() describe('get_position', function() it('works', function() - nvim('command', 'tabnew') - nvim('command', 'vsplit') - eq(window('get_tabpage', nvim('list_wins')[1]), nvim('list_tabpages')[1]) - eq(window('get_tabpage', nvim('list_wins')[2]), nvim('list_tabpages')[2]) - eq(window('get_tabpage', nvim('list_wins')[3]), nvim('list_tabpages')[2]) + command('tabnew') + command('vsplit') + eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[1]), api.nvim_list_tabpages()[1]) + eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[2]), api.nvim_list_tabpages()[2]) + eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[3]), api.nvim_list_tabpages()[2]) end) end) describe('get_number', function() it('works', function() - local wins = nvim('list_wins') - eq(1, window('get_number', wins[1])) + local wins = api.nvim_list_wins() + eq(1, api.nvim_win_get_number(wins[1])) - nvim('command', 'split') - local win1, win2 = unpack(nvim('list_wins')) - eq(1, window('get_number', win1)) - eq(2, window('get_number', win2)) + command('split') + local win1, win2 = unpack(api.nvim_list_wins()) + eq(1, api.nvim_win_get_number(win1)) + eq(2, api.nvim_win_get_number(win2)) - nvim('command', 'wincmd J') - eq(2, window('get_number', win1)) - eq(1, window('get_number', win2)) + command('wincmd J') + eq(2, api.nvim_win_get_number(win1)) + eq(1, api.nvim_win_get_number(win2)) - nvim('command', 'tabnew') - local win3 = nvim('list_wins')[3] + command('tabnew') + local win3 = api.nvim_list_wins()[3] -- First tab page - eq(2, window('get_number', win1)) - eq(1, window('get_number', win2)) + eq(2, api.nvim_win_get_number(win1)) + eq(1, api.nvim_win_get_number(win2)) -- Second tab page - eq(1, window('get_number', win3)) + eq(1, api.nvim_win_get_number(win3)) end) end) describe('is_valid', function() it('works', function() - nvim('command', 'split') - local win = nvim('list_wins')[2] - nvim('set_current_win', win) - ok(window('is_valid', win)) - nvim('command', 'close') - ok(not window('is_valid', win)) + command('split') + local win = api.nvim_list_wins()[2] + api.nvim_set_current_win(win) + ok(api.nvim_win_is_valid(win)) + command('close') + ok(not api.nvim_win_is_valid(win)) end) end) describe('close', function() it('can close current window', function() - local oldwin = meths.get_current_win() + local oldwin = api.nvim_get_current_win() command('split') - local newwin = meths.get_current_win() - meths.win_close(newwin, false) - eq({ oldwin }, meths.list_wins()) + local newwin = api.nvim_get_current_win() + api.nvim_win_close(newwin, false) + eq({ oldwin }, api.nvim_list_wins()) end) it('can close noncurrent window', function() - local oldwin = meths.get_current_win() + local oldwin = api.nvim_get_current_win() command('split') - local newwin = meths.get_current_win() - meths.win_close(oldwin, false) - eq({ newwin }, meths.list_wins()) + local newwin = api.nvim_get_current_win() + api.nvim_win_close(oldwin, false) + eq({ newwin }, api.nvim_list_wins()) end) it("handles changed buffer when 'hidden' is unset", function() command('set nohidden') - local oldwin = meths.get_current_win() + local oldwin = api.nvim_get_current_win() insert('text') command('new') - local newwin = meths.get_current_win() + local newwin = api.nvim_get_current_win() eq( 'Vim:E37: No write since last change (add ! to override)', - pcall_err(meths.win_close, oldwin, false) + pcall_err(api.nvim_win_close, oldwin, false) ) - eq({ newwin, oldwin }, meths.list_wins()) + eq({ newwin, oldwin }, api.nvim_list_wins()) end) it('handles changed buffer with force', function() - local oldwin = meths.get_current_win() + local oldwin = api.nvim_get_current_win() insert('text') command('new') - local newwin = meths.get_current_win() - meths.win_close(oldwin, true) - eq({ newwin }, meths.list_wins()) + local newwin = api.nvim_get_current_win() + api.nvim_win_close(oldwin, true) + eq({ newwin }, api.nvim_list_wins()) end) it('in cmdline-window #9767', function() command('split') - eq(2, #meths.list_wins()) - local oldwin = meths.get_current_win() - local otherwin = meths.open_win(0, false, { + eq(2, #api.nvim_list_wins()) + local oldwin = api.nvim_get_current_win() + local otherwin = api.nvim_open_win(0, false, { relative = 'editor', row = 10, col = 10, @@ -551,20 +556,20 @@ describe('API/win', function() }) -- Open cmdline-window. feed('q:') - eq(4, #meths.list_wins()) - eq(':', funcs.getcmdwintype()) + eq(4, #api.nvim_list_wins()) + eq(':', fn.getcmdwintype()) -- Not allowed to close previous window from cmdline-window. eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.win_close, oldwin, true) + pcall_err(api.nvim_win_close, oldwin, true) ) -- Closing other windows is fine. - meths.win_close(otherwin, true) - eq(false, meths.win_is_valid(otherwin)) + api.nvim_win_close(otherwin, true) + eq(false, api.nvim_win_is_valid(otherwin)) -- Close cmdline-window. - meths.win_close(0, true) - eq(2, #meths.list_wins()) - eq('', funcs.getcmdwintype()) + api.nvim_win_close(0, true) + eq(2, #api.nvim_list_wins()) + eq('', fn.getcmdwintype()) end) it('closing current (float) window of another tabpage #15313', function() @@ -572,7 +577,7 @@ describe('API/win', function() command('botright split') local prevwin = curwin().id eq(2, eval('tabpagenr()')) - local win = meths.open_win(0, true, { + local win = api.nvim_open_win(0, true, { relative = 'editor', row = 10, col = 10, @@ -582,67 +587,67 @@ describe('API/win', function() local tab = eval('tabpagenr()') command('tabprevious') eq(1, eval('tabpagenr()')) - meths.win_close(win, false) + api.nvim_win_close(win, false) - eq(prevwin, meths.tabpage_get_win(tab).id) + eq(prevwin, api.nvim_tabpage_get_win(tab).id) assert_alive() end) end) describe('hide', function() it('can hide current window', function() - local oldwin = meths.get_current_win() + local oldwin = api.nvim_get_current_win() command('split') - local newwin = meths.get_current_win() - meths.win_hide(newwin) - eq({ oldwin }, meths.list_wins()) + local newwin = api.nvim_get_current_win() + api.nvim_win_hide(newwin) + eq({ oldwin }, api.nvim_list_wins()) end) it('can hide noncurrent window', function() - local oldwin = meths.get_current_win() + local oldwin = api.nvim_get_current_win() command('split') - local newwin = meths.get_current_win() - meths.win_hide(oldwin) - eq({ newwin }, meths.list_wins()) + local newwin = api.nvim_get_current_win() + api.nvim_win_hide(oldwin) + eq({ newwin }, api.nvim_list_wins()) end) it('does not close the buffer', function() - local oldwin = meths.get_current_win() - local oldbuf = meths.get_current_buf() - local buf = meths.create_buf(true, false) - local newwin = meths.open_win(buf, true, { + local oldwin = api.nvim_get_current_win() + local oldbuf = api.nvim_get_current_buf() + local buf = api.nvim_create_buf(true, false) + local newwin = api.nvim_open_win(buf, true, { relative = 'win', row = 3, col = 3, width = 12, height = 3, }) - meths.win_hide(newwin) - eq({ oldwin }, meths.list_wins()) - eq({ oldbuf, buf }, meths.list_bufs()) + api.nvim_win_hide(newwin) + eq({ oldwin }, api.nvim_list_wins()) + eq({ oldbuf, buf }, api.nvim_list_bufs()) end) it('deletes the buffer when bufhidden=wipe', function() - local oldwin = meths.get_current_win() - local oldbuf = meths.get_current_buf() - local buf = meths.create_buf(true, false).id - local newwin = meths.open_win(buf, true, { + local oldwin = api.nvim_get_current_win() + local oldbuf = api.nvim_get_current_buf() + local buf = api.nvim_create_buf(true, false).id + local newwin = api.nvim_open_win(buf, true, { relative = 'win', row = 3, col = 3, width = 12, height = 3, }) - meths.set_option_value('bufhidden', 'wipe', { buf = buf }) - meths.win_hide(newwin) - eq({ oldwin }, meths.list_wins()) - eq({ oldbuf }, meths.list_bufs()) + api.nvim_set_option_value('bufhidden', 'wipe', { buf = buf }) + api.nvim_win_hide(newwin) + eq({ oldwin }, api.nvim_list_wins()) + eq({ oldbuf }, api.nvim_list_bufs()) end) it('in the cmdwin', function() feed('q:') -- Can close the cmdwin. - meths.win_hide(0) - eq('', funcs.getcmdwintype()) + api.nvim_win_hide(0) + eq('', fn.getcmdwintype()) - local old_win = meths.get_current_win() - local other_win = meths.open_win(0, false, { + local old_win = api.nvim_get_current_win() + local other_win = api.nvim_open_win(0, false, { relative = 'win', row = 3, col = 3, @@ -653,67 +658,68 @@ describe('API/win', function() -- Cannot close the previous window. eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.win_hide, old_win) + pcall_err(api.nvim_win_hide, old_win) ) -- Can close other windows. - meths.win_hide(other_win) - eq(false, meths.win_is_valid(other_win)) + api.nvim_win_hide(other_win) + eq(false, api.nvim_win_is_valid(other_win)) end) end) describe('text_height', function() it('validation', function() - local X = meths.get_vvar('maxcol') + local X = api.nvim_get_vvar('maxcol') insert([[ aaa bbb ccc ddd eee]]) - eq('Invalid window id: 23', pcall_err(meths.win_text_height, 23, {})) - eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { start_row = 5 })) - eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { start_row = -6 })) - eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { end_row = 5 })) - eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { end_row = -6 })) + eq('Invalid window id: 23', pcall_err(api.nvim_win_text_height, 23, {})) + eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { start_row = 5 })) + eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { start_row = -6 })) + eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { end_row = 5 })) + eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { end_row = -6 })) eq( "'start_row' is higher than 'end_row'", - pcall_err(curwinmeths.text_height, { start_row = 3, end_row = 1 }) + pcall_err(api.nvim_win_text_height, 0, { start_row = 3, end_row = 1 }) ) eq( "'start_vcol' specified without 'start_row'", - pcall_err(curwinmeths.text_height, { end_row = 2, start_vcol = 0 }) + pcall_err(api.nvim_win_text_height, 0, { end_row = 2, start_vcol = 0 }) ) eq( "'end_vcol' specified without 'end_row'", - pcall_err(curwinmeths.text_height, { start_row = 2, end_vcol = 0 }) + pcall_err(api.nvim_win_text_height, 0, { start_row = 2, end_vcol = 0 }) ) eq( "Invalid 'start_vcol': out of range", - pcall_err(curwinmeths.text_height, { start_row = 2, start_vcol = -1 }) + pcall_err(api.nvim_win_text_height, 0, { start_row = 2, start_vcol = -1 }) ) eq( "Invalid 'start_vcol': out of range", - pcall_err(curwinmeths.text_height, { start_row = 2, start_vcol = X + 1 }) + pcall_err(api.nvim_win_text_height, 0, { start_row = 2, start_vcol = X + 1 }) ) eq( "Invalid 'end_vcol': out of range", - pcall_err(curwinmeths.text_height, { end_row = 2, end_vcol = -1 }) + pcall_err(api.nvim_win_text_height, 0, { end_row = 2, end_vcol = -1 }) ) eq( "Invalid 'end_vcol': out of range", - pcall_err(curwinmeths.text_height, { end_row = 2, end_vcol = X + 1 }) + pcall_err(api.nvim_win_text_height, 0, { end_row = 2, end_vcol = X + 1 }) ) eq( "'start_vcol' is higher than 'end_vcol'", pcall_err( - curwinmeths.text_height, + api.nvim_win_text_height, + 0, { start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 } ) ) end) it('with two diff windows', function() - local X = meths.get_vvar('maxcol') + local X = api.nvim_get_vvar('maxcol') local screen = Screen.new(45, 22) screen:set_default_attr_ids({ [0] = { foreground = Screen.colors.Blue1, bold = true }, @@ -775,70 +781,79 @@ describe('API/win', function() | ]], } - eq({ all = 20, fill = 5 }, meths.win_text_height(1000, {})) - eq({ all = 20, fill = 5 }, meths.win_text_height(1001, {})) - eq({ all = 20, fill = 5 }, meths.win_text_height(1000, { start_row = 0 })) - eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { start_row = 0 })) - eq({ all = 15, fill = 0 }, meths.win_text_height(1000, { end_row = -1 })) - eq({ all = 15, fill = 0 }, meths.win_text_height(1000, { end_row = 40 })) - eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { end_row = -1 })) - eq({ all = 20, fill = 5 }, meths.win_text_height(1001, { end_row = 40 })) - eq({ all = 10, fill = 5 }, meths.win_text_height(1000, { start_row = 23 })) - eq({ all = 13, fill = 3 }, meths.win_text_height(1001, { start_row = 18 })) - eq({ all = 11, fill = 0 }, meths.win_text_height(1000, { end_row = 23 })) - eq({ all = 11, fill = 5 }, meths.win_text_height(1001, { end_row = 18 })) - eq({ all = 11, fill = 0 }, meths.win_text_height(1000, { start_row = 3, end_row = 39 })) - eq({ all = 11, fill = 3 }, meths.win_text_height(1001, { start_row = 1, end_row = 34 })) - eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 4, end_row = 38 })) - eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 2, end_row = 33 })) - eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 5, end_row = 37 })) - eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 3, end_row = 32 })) - eq({ all = 9, fill = 0 }, meths.win_text_height(1000, { start_row = 17, end_row = 25 })) - eq({ all = 9, fill = 3 }, meths.win_text_height(1001, { start_row = 15, end_row = 20 })) - eq({ all = 7, fill = 0 }, meths.win_text_height(1000, { start_row = 18, end_row = 24 })) - eq({ all = 7, fill = 3 }, meths.win_text_height(1001, { start_row = 16, end_row = 19 })) - eq({ all = 6, fill = 5 }, meths.win_text_height(1000, { start_row = -1 })) - eq({ all = 5, fill = 5 }, meths.win_text_height(1000, { start_row = -1, start_vcol = X })) + eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1000, {})) + eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, {})) + eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1000, { start_row = 0 })) + eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { start_row = 0 })) + eq({ all = 15, fill = 0 }, api.nvim_win_text_height(1000, { end_row = -1 })) + eq({ all = 15, fill = 0 }, api.nvim_win_text_height(1000, { end_row = 40 })) + eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { end_row = -1 })) + eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 40 })) + eq({ all = 10, fill = 5 }, api.nvim_win_text_height(1000, { start_row = 23 })) + eq({ all = 13, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 18 })) + eq({ all = 11, fill = 0 }, api.nvim_win_text_height(1000, { end_row = 23 })) + eq({ all = 11, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18 })) + eq({ all = 11, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 3, end_row = 39 })) + eq({ all = 11, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 1, end_row = 34 })) + eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 4, end_row = 38 })) + eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 2, end_row = 33 })) + eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 5, end_row = 37 })) + eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 3, end_row = 32 })) + eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 17, end_row = 25 })) + eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 15, end_row = 20 })) + eq({ all = 7, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 18, end_row = 24 })) + eq({ all = 7, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 16, end_row = 19 })) + eq({ all = 6, fill = 5 }, api.nvim_win_text_height(1000, { start_row = -1 })) + eq({ all = 5, fill = 5 }, api.nvim_win_text_height(1000, { start_row = -1, start_vcol = X })) eq( { all = 0, fill = 0 }, - meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1 }) + api.nvim_win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1 }) ) eq( { all = 0, fill = 0 }, - meths.win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1, end_vcol = X }) + api.nvim_win_text_height( + 1000, + { start_row = -1, start_vcol = X, end_row = -1, end_vcol = X } + ) ) eq( { all = 1, fill = 0 }, - meths.win_text_height(1000, { start_row = -1, start_vcol = 0, end_row = -1, end_vcol = X }) + api.nvim_win_text_height( + 1000, + { start_row = -1, start_vcol = 0, end_row = -1, end_vcol = X } + ) ) - eq({ all = 3, fill = 2 }, meths.win_text_height(1001, { end_row = 0 })) - eq({ all = 2, fill = 2 }, meths.win_text_height(1001, { end_row = 0, end_vcol = 0 })) + eq({ all = 3, fill = 2 }, api.nvim_win_text_height(1001, { end_row = 0 })) + eq({ all = 2, fill = 2 }, api.nvim_win_text_height(1001, { end_row = 0, end_vcol = 0 })) eq( { all = 2, fill = 2 }, - meths.win_text_height(1001, { start_row = 0, end_row = 0, end_vcol = 0 }) + api.nvim_win_text_height(1001, { start_row = 0, end_row = 0, end_vcol = 0 }) ) eq( { all = 0, fill = 0 }, - meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = 0 }) + api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = 0 }) ) eq( { all = 1, fill = 0 }, - meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = X }) + api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = X }) ) - eq({ all = 11, fill = 5 }, meths.win_text_height(1001, { end_row = 18 })) + eq({ all = 11, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18 })) eq( { all = 9, fill = 3 }, - meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18 }) + api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18 }) ) - eq({ all = 10, fill = 5 }, meths.win_text_height(1001, { end_row = 18, end_vcol = 0 })) + eq({ all = 10, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18, end_vcol = 0 })) eq( { all = 8, fill = 3 }, - meths.win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18, end_vcol = 0 }) + api.nvim_win_text_height( + 1001, + { start_row = 0, start_vcol = 0, end_row = 18, end_vcol = 0 } + ) ) end) it('with wrapped lines', function() - local X = meths.get_vvar('maxcol') + local X = api.nvim_get_vvar('maxcol') local screen = Screen.new(45, 22) screen:set_default_attr_ids({ [0] = { foreground = Screen.colors.Blue1, bold = true }, @@ -850,15 +865,15 @@ describe('API/win', function() set number cpoptions+=n call setline(1, repeat([repeat('foobar-', 36)], 3)) ]]) - local ns = meths.create_namespace('') - meths.buf_set_extmark( + local ns = api.nvim_create_namespace('') + api.nvim_buf_set_extmark( 0, ns, 1, 100, { virt_text = { { ('?'):rep(15), 'Search' } }, virt_text_pos = 'inline' } ) - meths.buf_set_extmark( + api.nvim_buf_set_extmark( 0, ns, 2, @@ -898,113 +913,122 @@ describe('API/win', function() | ]], } - eq({ all = 21, fill = 0 }, meths.win_text_height(0, {})) - eq({ all = 6, fill = 0 }, meths.win_text_height(0, { start_row = 0, end_row = 0 })) - eq({ all = 7, fill = 0 }, meths.win_text_height(0, { start_row = 1, end_row = 1 })) - eq({ all = 8, fill = 0 }, meths.win_text_height(0, { start_row = 2, end_row = 2 })) + eq({ all = 21, fill = 0 }, api.nvim_win_text_height(0, {})) + eq({ all = 6, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, end_row = 0 })) + eq({ all = 7, fill = 0 }, api.nvim_win_text_height(0, { start_row = 1, end_row = 1 })) + eq({ all = 8, fill = 0 }, api.nvim_win_text_height(0, { start_row = 2, end_row = 2 })) eq( { all = 0, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 0 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 0 }) ) eq( { all = 1, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 41 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 41 }) ) eq( { all = 2, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 42 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 42 }) ) eq( { all = 2, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 86 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 86 }) ) eq( { all = 3, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 87 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 87 }) ) eq( { all = 6, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 266 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 266 }) ) eq( { all = 7, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 267 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 267 }) ) eq( { all = 7, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 311 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 311 }) ) eq( { all = 7, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 312 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 312 }) ) eq( { all = 7, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = X }) ) eq( { all = 7, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 40, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 40, end_row = 1, end_vcol = X }) ) eq( { all = 6, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 41, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 41, end_row = 1, end_vcol = X }) ) eq( { all = 6, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 85, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 85, end_row = 1, end_vcol = X }) ) eq( { all = 5, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = X }) ) eq( { all = 2, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 265, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 265, end_row = 1, end_vcol = X }) ) eq( { all = 1, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 266, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 266, end_row = 1, end_vcol = X }) ) eq( { all = 1, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 310, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 310, end_row = 1, end_vcol = X }) ) eq( { all = 0, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 311, end_row = 1, end_vcol = X }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 311, end_row = 1, end_vcol = X }) ) eq( { all = 1, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = 131 }) + api.nvim_win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = 131 }) ) eq( { all = 1, fill = 0 }, - meths.win_text_height(0, { start_row = 1, start_vcol = 221, end_row = 1, end_vcol = 266 }) + api.nvim_win_text_height( + 0, + { start_row = 1, start_vcol = 221, end_row = 1, end_vcol = 266 } + ) ) - eq({ all = 18, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 131 })) - eq({ all = 19, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 130 })) - eq({ all = 20, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 311 })) - eq({ all = 21, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 312 })) + eq({ all = 18, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 131 })) + eq({ all = 19, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 130 })) + eq({ all = 20, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 311 })) + eq({ all = 21, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 312 })) eq( { all = 17, fill = 0 }, - meths.win_text_height(0, { start_row = 0, start_vcol = 131, end_row = 2, end_vcol = 311 }) + api.nvim_win_text_height( + 0, + { start_row = 0, start_vcol = 131, end_row = 2, end_vcol = 311 } + ) ) eq( { all = 19, fill = 0 }, - meths.win_text_height(0, { start_row = 0, start_vcol = 130, end_row = 2, end_vcol = 312 }) + api.nvim_win_text_height( + 0, + { start_row = 0, start_vcol = 130, end_row = 2, end_vcol = 312 } + ) ) - eq({ all = 16, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 221 })) - eq({ all = 17, fill = 0 }, meths.win_text_height(0, { start_row = 0, start_vcol = 220 })) - eq({ all = 14, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 41 })) - eq({ all = 15, fill = 0 }, meths.win_text_height(0, { end_row = 2, end_vcol = 42 })) + eq({ all = 16, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 221 })) + eq({ all = 17, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 220 })) + eq({ all = 14, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 41 })) + eq({ all = 15, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 42 })) eq( { all = 9, fill = 0 }, - meths.win_text_height(0, { start_row = 0, start_vcol = 221, end_row = 2, end_vcol = 41 }) + api.nvim_win_text_height(0, { start_row = 0, start_vcol = 221, end_row = 2, end_vcol = 41 }) ) eq( { all = 11, fill = 0 }, - meths.win_text_height(0, { start_row = 0, start_vcol = 220, end_row = 2, end_vcol = 42 }) + api.nvim_win_text_height(0, { start_row = 0, start_vcol = 220, end_row = 2, end_vcol = 42 }) ) end) end) @@ -1012,7 +1036,7 @@ describe('API/win', function() describe('open_win', function() it('noautocmd option works', function() command('autocmd BufEnter,BufLeave,BufWinEnter * let g:fired = 1') - meths.open_win(meths.create_buf(true, true), true, { + api.nvim_open_win(api.nvim_create_buf(true, true), true, { relative = 'win', row = 3, col = 3, @@ -1020,23 +1044,23 @@ describe('API/win', function() height = 3, noautocmd = true, }) - eq(0, funcs.exists('g:fired')) - meths.open_win(meths.create_buf(true, true), true, { + eq(0, fn.exists('g:fired')) + api.nvim_open_win(api.nvim_create_buf(true, true), true, { relative = 'win', row = 3, col = 3, width = 12, height = 3, }) - eq(1, funcs.exists('g:fired')) + eq(1, fn.exists('g:fired')) end) it('disallowed in cmdwin if enter=true or buf=curbuf', function() - local new_buf = meths.create_buf(true, true) + local new_buf = api.nvim_create_buf(true, true) feed('q:') eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.open_win, new_buf, true, { + pcall_err(api.nvim_open_win, new_buf, true, { relative = 'editor', row = 5, col = 5, @@ -1046,7 +1070,7 @@ describe('API/win', function() ) eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.open_win, 0, false, { + pcall_err(api.nvim_open_win, 0, false, { relative = 'editor', row = 5, col = 5, @@ -1057,7 +1081,7 @@ describe('API/win', function() eq( new_buf, - meths.win_get_buf(meths.open_win(new_buf, false, { + api.nvim_win_get_buf(api.nvim_open_win(new_buf, false, { relative = 'editor', row = 5, col = 5, @@ -1068,10 +1092,10 @@ describe('API/win', function() end) it('aborts if buffer is invalid', function() - local wins_before = meths.list_wins() + local wins_before = api.nvim_list_wins() eq( 'Invalid buffer id: 1337', - pcall_err(meths.open_win, 1337, false, { + pcall_err(api.nvim_open_win, 1337, false, { relative = 'editor', row = 5, col = 5, @@ -1079,14 +1103,14 @@ describe('API/win', function() height = 5, }) ) - eq(wins_before, meths.list_wins()) + eq(wins_before, api.nvim_list_wins()) end) end) describe('get_config', function() it('includes border', function() local b = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' } - local win = meths.open_win(0, true, { + local win = api.nvim_open_win(0, true, { relative = 'win', row = 3, col = 3, @@ -1095,7 +1119,7 @@ describe('API/win', function() border = b, }) - local cfg = meths.win_get_config(win) + local cfg = api.nvim_win_get_config(win) eq(b, cfg.border) end) @@ -1110,7 +1134,7 @@ describe('API/win', function() { 'g', 'Constant' }, { 'h', 'PreProc' }, } - local win = meths.open_win(0, true, { + local win = api.nvim_open_win(0, true, { relative = 'win', row = 3, col = 3, @@ -1119,14 +1143,14 @@ describe('API/win', function() border = b, }) - local cfg = meths.win_get_config(win) + local cfg = api.nvim_win_get_config(win) eq(b, cfg.border) end) it('includes title and footer', function() local title = { { 'A', { 'StatusLine', 'TabLine' } }, { 'B' }, { 'C', 'WinBar' } } local footer = { { 'A', 'WinBar' }, { 'B' }, { 'C', { 'StatusLine', 'TabLine' } } } - local win = meths.open_win(0, true, { + local win = api.nvim_open_win(0, true, { relative = 'win', row = 3, col = 3, @@ -1137,7 +1161,7 @@ describe('API/win', function() footer = footer, }) - local cfg = meths.win_get_config(win) + local cfg = api.nvim_win_get_config(win) eq(title, cfg.title) eq(footer, cfg.footer) end) @@ -1145,7 +1169,7 @@ describe('API/win', function() describe('set_config', function() it('no crash with invalid title', function() - local win = meths.open_win(0, true, { + local win = api.nvim_open_win(0, true, { width = 10, height = 10, relative = 'editor', @@ -1156,14 +1180,14 @@ describe('API/win', function() }) eq( 'title/footer cannot be an empty array', - pcall_err(meths.win_set_config, win, { title = {} }) + pcall_err(api.nvim_win_set_config, win, { title = {} }) ) command('redraw!') assert_alive() end) it('no crash with invalid footer', function() - local win = meths.open_win(0, true, { + local win = api.nvim_open_win(0, true, { width = 10, height = 10, relative = 'editor', @@ -1174,7 +1198,7 @@ describe('API/win', function() }) eq( 'title/footer cannot be an empty array', - pcall_err(meths.win_set_config, win, { footer = {} }) + pcall_err(api.nvim_win_set_config, win, { footer = {} }) ) command('redraw!') assert_alive() diff --git a/test/functional/autocmd/autocmd_oldtest_spec.lua b/test/functional/autocmd/autocmd_oldtest_spec.lua index 62f87bfd97..0243674f2d 100644 --- a/test/functional/autocmd/autocmd_oldtest_spec.lua +++ b/test/functional/autocmd/autocmd_oldtest_spec.lua @@ -3,8 +3,8 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local eq = helpers.eq -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local exec = helpers.exec local feed = helpers.feed @@ -12,7 +12,7 @@ describe('oldtests', function() before_each(clear) local exec_lines = function(str) - return funcs.split(funcs.execute(str), '\n') + return fn.split(fn.execute(str), '\n') end local add_an_autocmd = function() @@ -23,7 +23,7 @@ describe('oldtests', function() ]] eq(3, #exec_lines('au vimBarTest')) - eq(1, #meths.get_autocmds({ group = 'vimBarTest' })) + eq(1, #api.nvim_get_autocmds({ group = 'vimBarTest' })) end it('should recognize a bar before the {event}', function() @@ -31,7 +31,7 @@ describe('oldtests', function() add_an_autocmd() exec [[ augroup vimBarTest | au! | augroup END ]] eq(1, #exec_lines('au vimBarTest')) - eq({}, meths.get_autocmds({ group = 'vimBarTest' })) + eq({}, api.nvim_get_autocmds({ group = 'vimBarTest' })) -- Sad spacing add_an_autocmd() @@ -49,8 +49,8 @@ describe('oldtests', function() end) it('should fire on unload buf', function() - funcs.writefile({ 'Test file Xxx1' }, 'Xxx1') - funcs.writefile({ 'Test file Xxx2' }, 'Xxx2') + fn.writefile({ 'Test file Xxx1' }, 'Xxx1') + fn.writefile({ 'Test file Xxx2' }, 'Xxx2') local fname = 'Xtest_functional_autocmd_unload' local content = [[ @@ -71,16 +71,16 @@ describe('oldtests', function() q ]] - funcs.writefile(funcs.split(content, '\n'), fname) + fn.writefile(fn.split(content, '\n'), fname) - funcs.delete('Xout') - funcs.system(string.format('%s --clean -N -S %s', meths.get_vvar('progpath'), fname)) - eq(1, funcs.filereadable('Xout')) + fn.delete('Xout') + fn.system(string.format('%s --clean -N -S %s', api.nvim_get_vvar('progpath'), fname)) + eq(1, fn.filereadable('Xout')) - funcs.delete('Xxx1') - funcs.delete('Xxx2') - funcs.delete(fname) - funcs.delete('Xout') + fn.delete('Xxx1') + fn.delete('Xxx2') + fn.delete(fname) + fn.delete('Xout') end) -- oldtest: Test_delete_ml_get_errors() diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 2ae6277bd9..5fffb70095 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -10,14 +10,13 @@ local eval = helpers.eval local feed = helpers.feed local clear = helpers.clear local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local pcall_err = helpers.pcall_err -local funcs = helpers.funcs +local fn = helpers.fn local expect = helpers.expect local command = helpers.command local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua -local curbufmeths = helpers.curbufmeths local retry = helpers.retry local source = helpers.source @@ -143,8 +142,8 @@ describe('autocmd', function() describe('BufLeave autocommand', function() it('can wipe out the buffer created by :edit which triggered autocmd', function() - meths.set_option_value('hidden', true, {}) - curbufmeths.set_lines(0, 1, false, { + api.nvim_set_option_value('hidden', true, {}) + api.nvim_buf_set_lines(0, 0, 1, false, { 'start of test file xx', 'end of test file xx', }) @@ -189,7 +188,7 @@ describe('autocmd', function() :call add(g:foo, "Once2") :call add(g:foo, "Many2") :call add(g:foo, "Once3")]]), - funcs.execute('autocmd Tabnew') + fn.execute('autocmd Tabnew') ) command('tabnew') command('tabnew') @@ -202,7 +201,7 @@ describe('autocmd', function() TabNew * :call add(g:foo, "Many1") :call add(g:foo, "Many2")]]), - funcs.execute('autocmd Tabnew') + fn.execute('autocmd Tabnew') ) -- @@ -248,7 +247,7 @@ describe('autocmd', function() dedent([[ --- Autocommands ---]]), - funcs.execute('autocmd Tabnew') + fn.execute('autocmd Tabnew') ) end) @@ -416,7 +415,11 @@ describe('autocmd', function() end) it('gives E814 when there are other floating windows', function() - meths.open_win(0, true, { width = 10, height = 10, relative = 'editor', row = 10, col = 10 }) + api.nvim_open_win( + 0, + true, + { width = 10, height = 10, relative = 'editor', row = 10, col = 10 } + ) eq( 'BufAdd Autocommands for "Xa.txt": Vim(close):E814: Cannot close window, only autocmd window would remain', pcall_err(command, 'doautoall BufAdd') @@ -510,17 +513,17 @@ describe('autocmd', function() describe('v:event is readonly #18063', function() it('during ChanOpen event', function() command('autocmd ChanOpen * let v:event.info.id = 0') - funcs.jobstart({ 'cat' }) + fn.jobstart({ 'cat' }) retry(nil, nil, function() - eq('E46: Cannot change read-only variable "v:event.info"', meths.get_vvar('errmsg')) + eq('E46: Cannot change read-only variable "v:event.info"', api.nvim_get_vvar('errmsg')) end) end) it('during ChanOpen event', function() command('autocmd ChanInfo * let v:event.info.id = 0') - meths.set_client_info('foo', {}, 'remote', {}, {}) + api.nvim_set_client_info('foo', {}, 'remote', {}, {}) retry(nil, nil, function() - eq('E46: Cannot change read-only variable "v:event.info"', meths.get_vvar('errmsg')) + eq('E46: Cannot change read-only variable "v:event.info"', api.nvim_get_vvar('errmsg')) end) end) @@ -574,7 +577,7 @@ describe('autocmd', function() call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') ]] - meths.set_var('did_split', 0) + api.nvim_set_var('did_split', 0) source [[ augroup Testing @@ -586,11 +589,11 @@ describe('autocmd', function() split ]] - eq(2, meths.get_var('did_split')) - eq(1, funcs.exists('#WinNew')) + eq(2, api.nvim_get_var('did_split')) + eq(1, fn.exists('#WinNew')) -- Now with once - meths.set_var('did_split', 0) + api.nvim_set_var('did_split', 0) source [[ augroup Testing @@ -602,8 +605,8 @@ describe('autocmd', function() split ]] - eq(1, meths.get_var('did_split')) - eq(0, funcs.exists('#WinNew')) + eq(1, api.nvim_get_var('did_split')) + eq(0, fn.exists('#WinNew')) -- call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') local ok, msg = pcall( @@ -619,7 +622,7 @@ describe('autocmd', function() it('should have autocmds in filetypedetect group', function() source [[filetype on]] - neq({}, meths.get_autocmds { group = 'filetypedetect' }) + neq({}, api.nvim_get_autocmds { group = 'filetypedetect' }) end) it('should allow comma-separated patterns', function() @@ -631,7 +634,7 @@ describe('autocmd', function() augroup END ]] - eq(4, #meths.get_autocmds { event = 'BufReadCmd', group = 'TestingPatterns' }) + eq(4, #api.nvim_get_autocmds { event = 'BufReadCmd', group = 'TestingPatterns' }) end) end) diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua index 3502721ee0..5a5b16b438 100644 --- a/test/functional/autocmd/cmdline_spec.lua +++ b/test/functional/autocmd/cmdline_spec.lua @@ -8,14 +8,14 @@ local expect = helpers.expect local eval = helpers.eval local next_msg = helpers.next_msg local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api describe('cmdline autocommands', function() local channel before_each(function() clear() - channel = meths.get_api_info()[1] - meths.set_var('channel', channel) + channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) command("autocmd CmdlineEnter * call rpcnotify(g:channel, 'CmdlineEnter', v:event)") command("autocmd CmdlineLeave * call rpcnotify(g:channel, 'CmdlineLeave', v:event)") command("autocmd CmdWinEnter * call rpcnotify(g:channel, 'CmdWinEnter', v:event)") diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua index 535881b6cc..fc2b65f53a 100644 --- a/test/functional/autocmd/cursorhold_spec.lua +++ b/test/functional/autocmd/cursorhold_spec.lua @@ -5,8 +5,8 @@ local eq = helpers.eq local feed = helpers.feed local retry = helpers.retry local exec = helpers.source -local sleep = helpers.sleep -local meths = helpers.meths +local sleep = vim.uv.sleep +local api = helpers.api before_each(clear) @@ -26,47 +26,47 @@ describe('CursorHold', function() -- if testing with small 'updatetime' fails, double its value and test again retry(10, nil, function() ut = ut * 2 - meths.set_option_value('updatetime', ut, {}) + api.nvim_set_option_value('updatetime', ut, {}) feed('0') -- reset did_cursorhold - meths.set_var('cursorhold', 0) + api.nvim_set_var('cursorhold', 0) sleep(ut / 4) fn() - eq(0, meths.get_var('cursorhold')) + eq(0, api.nvim_get_var('cursorhold')) sleep(ut / 2) fn() - eq(0, meths.get_var('cursorhold')) + eq(0, api.nvim_get_var('cursorhold')) sleep(ut / 2) - eq(early, meths.get_var('cursorhold')) + eq(early, api.nvim_get_var('cursorhold')) sleep(ut / 4 * 3) - eq(1, meths.get_var('cursorhold')) + eq(1, api.nvim_get_var('cursorhold')) end) end - local ignore_key = meths.replace_termcodes('<Ignore>', true, true, true) + local ignore_key = api.nvim_replace_termcodes('<Ignore>', true, true, true) test_cursorhold(function() end, 1) test_cursorhold(function() feed('') end, 1) test_cursorhold(function() - meths.feedkeys('', 'n', true) + api.nvim_feedkeys('', 'n', true) end, 1) test_cursorhold(function() feed('<Ignore>') end, 0) test_cursorhold(function() - meths.feedkeys(ignore_key, 'n', true) + api.nvim_feedkeys(ignore_key, 'n', true) end, 0) end) it("reducing 'updatetime' while waiting for CursorHold #20241", function() - meths.set_option_value('updatetime', 10000, {}) + api.nvim_set_option_value('updatetime', 10000, {}) feed('0') -- reset did_cursorhold - meths.set_var('cursorhold', 0) + api.nvim_set_var('cursorhold', 0) sleep(50) - eq(0, meths.get_var('cursorhold')) - meths.set_option_value('updatetime', 20, {}) + eq(0, api.nvim_get_var('cursorhold')) + api.nvim_set_option_value('updatetime', 20, {}) sleep(10) - eq(1, meths.get_var('cursorhold')) + eq(1, api.nvim_get_var('cursorhold')) end) end) @@ -85,7 +85,7 @@ describe('CursorHoldI', function() feed('ifoo') retry(5, nil, function() sleep(1) - eq(1, meths.get_var('cursorhold')) + eq(1, api.nvim_get_var('cursorhold')) end) end) end) diff --git a/test/functional/autocmd/cursormoved_spec.lua b/test/functional/autocmd/cursormoved_spec.lua index 3ab5c3b9b1..302afe87b8 100644 --- a/test/functional/autocmd/cursormoved_spec.lua +++ b/test/functional/autocmd/cursormoved_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval -local meths = helpers.meths +local api = helpers.api local source = helpers.source local command = helpers.command @@ -41,9 +41,9 @@ describe('CursorMoved', function() vsplit foo autocmd CursorMoved * let g:cursormoved += 1 ]]) - meths.buf_set_lines(eval('g:buf'), 0, -1, true, { 'aaa' }) + api.nvim_buf_set_lines(eval('g:buf'), 0, -1, true, { 'aaa' }) eq(0, eval('g:cursormoved')) - eq({ 'aaa' }, meths.buf_get_lines(eval('g:buf'), 0, -1, true)) + eq({ 'aaa' }, api.nvim_buf_get_lines(eval('g:buf'), 0, -1, true)) eq(0, eval('g:cursormoved')) end) diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua index 208bd0f0e9..7ad529891f 100644 --- a/test/functional/autocmd/dirchanged_spec.lua +++ b/test/functional/autocmd/dirchanged_spec.lua @@ -1,4 +1,3 @@ -local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear @@ -9,7 +8,7 @@ local request = helpers.request local is_os = helpers.is_os describe('autocmd DirChanged and DirChangedPre', function() - local curdir = string.gsub(luv.cwd(), '\\', '/') + local curdir = vim.uv.cwd():gsub('\\', '/') local dirs = { curdir .. '/Xtest-functional-autocmd-dirchanged.dir1', curdir .. '/Xtest-functional-autocmd-dirchanged.dir2', diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua index cd9f2c96c1..b9bab206fc 100644 --- a/test/functional/autocmd/focus_spec.lua +++ b/test/functional/autocmd/focus_spec.lua @@ -1,6 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local luv = require('luv') local clear = helpers.clear local feed_command = helpers.feed_command local feed_data = thelpers.feed_data @@ -42,7 +41,7 @@ describe('autoread TUI FocusGained/FocusLost', function() helpers.write_file(path, '') local atime = os.time() - 10 - luv.fs_utime(path, atime, atime) + vim.uv.fs_utime(path, atime, atime) screen:expect { grid = [[ diff --git a/test/functional/autocmd/safestate_spec.lua b/test/functional/autocmd/safestate_spec.lua index 73693749e4..b5b7ab2f95 100644 --- a/test/functional/autocmd/safestate_spec.lua +++ b/test/functional/autocmd/safestate_spec.lua @@ -3,7 +3,7 @@ local clear = helpers.clear local eq = helpers.eq local exec = helpers.exec local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api before_each(clear) @@ -18,40 +18,40 @@ describe('SafeState autocommand', function() it('with pending operator', function() feed('d') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('d') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) it('with specified register', function() feed('"r') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('x') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) it('with i_CTRL-O', function() feed('i<C-O>') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('x') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) it('with Insert mode completion', function() feed('i<C-X><C-V>') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('<C-X><C-Z>') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) it('with Cmdline completion', function() feed(':<Tab>') create_autocmd() - eq(0, meths.get_var('safe')) + eq(0, api.nvim_get_var('safe')) feed('<C-E>') - eq(1, meths.get_var('safe')) + eq(1, api.nvim_get_var('safe')) end) end) diff --git a/test/functional/autocmd/searchwrapped_spec.lua b/test/functional/autocmd/searchwrapped_spec.lua index 83600f6689..0705b2d5de 100644 --- a/test/functional/autocmd/searchwrapped_spec.lua +++ b/test/functional/autocmd/searchwrapped_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command -local curbufmeths = helpers.curbufmeths +local api = helpers.api local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed @@ -13,7 +13,7 @@ describe('autocmd SearchWrapped', function() command('set ignorecase') command('let g:test = 0') command('autocmd! SearchWrapped * let g:test += 1') - curbufmeths.set_lines(0, 1, false, { + api.nvim_buf_set_lines(0, 0, 1, false, { 'The quick brown fox', 'jumps over the lazy dog', }) diff --git a/test/functional/autocmd/show_spec.lua b/test/functional/autocmd/show_spec.lua index f081c918fc..1a9dc8a337 100644 --- a/test/functional/autocmd/show_spec.lua +++ b/test/functional/autocmd/show_spec.lua @@ -5,7 +5,7 @@ local clear = helpers.clear local command = helpers.command local dedent = helpers.dedent local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local eval = helpers.eval local exec = helpers.exec local feed = helpers.feed @@ -36,7 +36,7 @@ describe(':autocmd', function() TestingOne BufEnter * :echo "Line 1" :echo "Line 2"]]), - funcs.execute('autocmd BufEnter') + fn.execute('autocmd BufEnter') ) end) @@ -160,7 +160,7 @@ describe(':autocmd', function() A echo "A2" test_3 User A echo "A3"]]), - funcs.execute('autocmd User A') + fn.execute('autocmd User A') ) eq( dedent([[ @@ -178,7 +178,7 @@ describe(':autocmd', function() B echo "B2" test_3 User B echo "B3"]]), - funcs.execute('autocmd * B') + fn.execute('autocmd * B') ) eq( dedent([[ @@ -188,7 +188,7 @@ describe(':autocmd', function() B echo "B3" test_3 User B echo "B3"]]), - funcs.execute('autocmd test_3 * B') + fn.execute('autocmd test_3 * B') ) end) diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua index 96924fb2fc..c7087254e7 100644 --- a/test/functional/autocmd/signal_spec.lua +++ b/test/functional/autocmd/signal_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local next_msg = helpers.next_msg local is_os = helpers.is_os local skip = helpers.skip @@ -21,25 +21,25 @@ describe('autocmd Signal', function() it('matches *', function() command('autocmd Signal * call rpcnotify(1, "foo")') - posix_kill('USR1', funcs.getpid()) + posix_kill('USR1', fn.getpid()) eq({ 'notification', 'foo', {} }, next_msg()) end) it('matches SIGUSR1', function() command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")') - posix_kill('USR1', funcs.getpid()) + posix_kill('USR1', fn.getpid()) eq({ 'notification', 'foo', {} }, next_msg()) end) it('matches SIGWINCH', function() command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")') - posix_kill('WINCH', funcs.getpid()) + posix_kill('WINCH', fn.getpid()) eq({ 'notification', 'foo', {} }, next_msg()) end) it('does not match unknown patterns', function() command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")') - posix_kill('USR1', funcs.getpid()) + posix_kill('USR1', fn.getpid()) eq(nil, next_msg(500)) end) end) diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua index c5a2b42273..d0b2ac6a8d 100644 --- a/test/functional/autocmd/tabclose_spec.lua +++ b/test/functional/autocmd/tabclose_spec.lua @@ -1,5 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq +local clear, eq = helpers.clear, helpers.eq +local api = helpers.api +local command = helpers.command describe('TabClosed', function() before_each(clear) @@ -7,75 +9,70 @@ describe('TabClosed', function() describe('au TabClosed', function() describe('with * as <afile>', function() it('matches when closing any tab', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) repeat - nvim('command', 'tabnew') - until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6 - eq('tabclosed:6:6:5', nvim('exec', 'tabclose', true)) -- close last 6, current tab is now 5 - eq('tabclosed:5:5:4', nvim('exec', 'close', true)) -- close last window on tab, closes tab - eq('tabclosed:2:2:3', nvim('exec', '2tabclose', true)) -- close tab 2, current tab is now 3 - eq('tabclosed:1:1:2\ntabclosed:1:1:1', nvim('exec', 'tabonly', true)) -- close tabs 1 and 2 + command('tabnew') + until api.nvim_eval('tabpagenr()') == 6 -- current tab is now 6 + eq('tabclosed:6:6:5', api.nvim_exec('tabclose', true)) -- close last 6, current tab is now 5 + eq('tabclosed:5:5:4', api.nvim_exec('close', true)) -- close last window on tab, closes tab + eq('tabclosed:2:2:3', api.nvim_exec('2tabclose', true)) -- close tab 2, current tab is now 3 + eq('tabclosed:1:1:2\ntabclosed:1:1:1', api.nvim_exec('tabonly', true)) -- close tabs 1 and 2 end) it('is triggered when closing a window via bdelete from another tab', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) - nvim('command', '1tabedit Xtestfile') - nvim('command', '1tabedit Xtestfile') - nvim('command', 'normal! 1gt') - eq({ 1, 3 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq('tabclosed:2:2:1\ntabclosed:2:2:1', nvim('exec', 'bdelete Xtestfile', true)) - eq({ 1, 1 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + command('1tabedit Xtestfile') + command('1tabedit Xtestfile') + command('normal! 1gt') + eq({ 1, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:1\ntabclosed:2:2:1', api.nvim_exec('bdelete Xtestfile', true)) + eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) end) it('is triggered when closing a window via bdelete from current tab', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) - nvim('command', 'file Xtestfile1') - nvim('command', '1tabedit Xtestfile2') - nvim('command', '1tabedit Xtestfile2') + command('file Xtestfile1') + command('1tabedit Xtestfile2') + command('1tabedit Xtestfile2') -- Only one tab is closed, and the alternate file is used for the other. - eq({ 2, 3 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq('tabclosed:2:2:2', nvim('exec', 'bdelete Xtestfile2', true)) - eq('Xtestfile1', nvim('eval', 'bufname("")')) + eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:2', api.nvim_exec('bdelete Xtestfile2', true)) + eq('Xtestfile1', api.nvim_eval('bufname("")')) end) end) describe('with NR as <afile>', function() it('matches when closing a tab whose index is NR', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) - nvim('command', 'au! TabClosed 2 echom "tabclosed:match"') + command('au! TabClosed 2 echom "tabclosed:match"') repeat - nvim('command', 'tabnew') - until nvim('eval', 'tabpagenr()') == 7 -- current tab is now 7 + command('tabnew') + until api.nvim_eval('tabpagenr()') == 7 -- current tab is now 7 -- sanity check, we shouldn't match on tabs with numbers other than 2 - eq('tabclosed:7:7:6', nvim('exec', 'tabclose', true)) + eq('tabclosed:7:7:6', api.nvim_exec('tabclose', true)) -- close tab page 2, current tab is now 5 - eq('tabclosed:2:2:5\ntabclosed:match', nvim('exec', '2tabclose', true)) + eq('tabclosed:2:2:5\ntabclosed:match', api.nvim_exec('2tabclose', true)) end) end) describe('with close', function() it('is triggered', function() - nvim( - 'command', + command( 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' ) - nvim('command', 'tabedit Xtestfile') - eq({ 2, 2 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) - eq('tabclosed:2:2:1', nvim('exec', 'close', true)) - eq({ 1, 1 }, nvim('eval', '[tabpagenr(), tabpagenr("$")]')) + command('tabedit Xtestfile') + eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + eq('tabclosed:2:2:1', api.nvim_exec('close', true)) + eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) end) end) end) diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua index fd4a16a298..b888845e3b 100644 --- a/test/functional/autocmd/tabnewentered_spec.lua +++ b/test/functional/autocmd/tabnewentered_spec.lua @@ -6,7 +6,7 @@ local dedent = helpers.dedent local eval = helpers.eval local eq = helpers.eq local feed = helpers.feed -local nvim = helpers.nvim +local api = helpers.api local exec_capture = helpers.exec_capture describe('TabNewEntered', function() @@ -14,33 +14,33 @@ describe('TabNewEntered', function() describe('with * as <afile>', function() it('matches when entering any new tab', function() clear() - nvim('command', 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")') - eq('tabnewentered:2:2', nvim('exec', 'tabnew', true)) - eq('tabnewentered:3:3', nvim('exec', 'tabnew test.x2', true)) + command('au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")') + eq('tabnewentered:2:2', api.nvim_exec('tabnew', true)) + eq('tabnewentered:3:3', api.nvim_exec('tabnew test.x2', true)) end) end) describe('with FILE as <afile>', function() it('matches when opening a new tab for FILE', function() clear() - nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"') - eq('tabnewentered:match', nvim('exec', 'tabnew Xtest-tabnewentered', true)) + command('au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"') + eq('tabnewentered:match', api.nvim_exec('tabnew Xtest-tabnewentered', true)) end) end) describe('with CTRL-W T', function() it('works when opening a new tab with CTRL-W T', function() clear() - nvim('command', 'au! TabNewEntered * echom "entered"') - nvim('command', 'tabnew test.x2') - nvim('command', 'split') - eq('entered', nvim('exec', 'execute "normal \\<C-W>T"', true)) + command('au! TabNewEntered * echom "entered"') + command('tabnew test.x2') + command('split') + eq('entered', api.nvim_exec('execute "normal \\<C-W>T"', true)) end) end) describe('with tab split #4334', function() it('works when create a tab by using tab split command', function() clear() - nvim('command', 'au! TabNewEntered * let b:entered = "entered"') - nvim('command', 'tab split') - eq('entered', nvim('exec', 'echo b:entered', true)) + command('au! TabNewEntered * let b:entered = "entered"') + command('tab split') + eq('entered', api.nvim_exec('echo b:entered', true)) end) end) end) @@ -50,20 +50,20 @@ describe('TabEnter', function() before_each(clear) it('has correct previous tab when entering any new tab', function() command('augroup TEMP') - nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') + command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') command('augroup END') - eq('tabenter:2:1', nvim('exec', 'tabnew', true)) - eq('tabenter:3:2', nvim('exec', 'tabnew test.x2', true)) + eq('tabenter:2:1', api.nvim_exec('tabnew', true)) + eq('tabenter:3:2', api.nvim_exec('tabnew test.x2', true)) command('augroup! TEMP') end) it('has correct previous tab when entering any preexisting tab', function() command('tabnew') command('tabnew') command('augroup TEMP') - nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') + command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') command('augroup END') - eq('tabenter:1:3', nvim('exec', 'tabnext', true)) - eq('tabenter:2:1', nvim('exec', 'tabnext', true)) + eq('tabenter:1:3', api.nvim_exec('tabnext', true)) + eq('tabenter:2:1', api.nvim_exec('tabnext', true)) command('augroup! TEMP') end) end) diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index 71ae7dfe9b..982edfa06a 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -1,13 +1,13 @@ -local luv = require('luv') +local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, command, nvim, testprg = helpers.clear, helpers.command, helpers.nvim, helpers.testprg +local clear, command, testprg = helpers.clear, helpers.command, helpers.testprg local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry local matches = helpers.matches local ok = helpers.ok local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive local skip = helpers.skip @@ -16,13 +16,13 @@ local is_os = helpers.is_os describe('autocmd TermClose', function() before_each(function() clear() - nvim('set_option_value', 'shell', testprg('shell-test'), {}) + api.nvim_set_option_value('shell', testprg('shell-test'), {}) command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') end) local function test_termclose_delete_own_buf() -- The terminal process needs to keep running so that TermClose isn't triggered immediately. - nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) + api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) command('autocmd TermClose * bdelete!') command('terminal') matches( @@ -56,7 +56,7 @@ describe('autocmd TermClose', function() it('triggers when long-running terminal job gets stopped', function() skip(is_os('win')) - nvim('set_option_value', 'shell', is_os('win') and 'cmd.exe' or 'sh', {}) + api.nvim_set_option_value('shell', is_os('win') and 'cmd.exe' or 'sh', {}) command('autocmd TermClose * let g:test_termclose = 23') command('terminal') command('call jobstop(b:terminal_job_id)') @@ -67,8 +67,8 @@ describe('autocmd TermClose', function() it('kills job trapping SIGTERM', function() skip(is_os('win')) - nvim('set_option_value', 'shell', 'sh', {}) - nvim('set_option_value', 'shellcmdflag', '-c', {}) + api.nvim_set_option_value('shell', 'sh', {}) + api.nvim_set_option_value('shellcmdflag', '-c', {}) command( [[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] @@ -78,14 +78,14 @@ describe('autocmd TermClose', function() eq(1, eval('get(g:, "test_job_started", 0)')) end) - luv.update_time() - local start = luv.now() + uv.update_time() + local start = uv.now() command('call jobstop(g:test_job)') retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end) - luv.update_time() - local duration = luv.now() - start + uv.update_time() + local duration = uv.now() - start -- Nvim begins SIGTERM after KILL_TIMEOUT_MS. ok(duration >= 2000) ok(duration <= 4000) -- Epsilon for slow CI @@ -93,8 +93,8 @@ describe('autocmd TermClose', function() it('kills PTY job trapping SIGHUP and SIGTERM', function() skip(is_os('win')) - nvim('set_option_value', 'shell', 'sh', {}) - nvim('set_option_value', 'shellcmdflag', '-c', {}) + api.nvim_set_option_value('shell', 'sh', {}) + api.nvim_set_option_value('shellcmdflag', '-c', {}) command( [[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] .. [[ 'pty': 1,]] @@ -105,14 +105,14 @@ describe('autocmd TermClose', function() eq(1, eval('get(g:, "test_job_started", 0)')) end) - luv.update_time() - local start = luv.now() + uv.update_time() + local start = uv.now() command('call jobstop(g:test_job)') retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end) - luv.update_time() - local duration = luv.now() - start + uv.update_time() + local duration = uv.now() - start -- Nvim begins SIGKILL after (2 * KILL_TIMEOUT_MS). ok(duration >= 4000) ok(duration <= 7000) -- Epsilon for slow CI @@ -204,7 +204,7 @@ describe('autocmd TextChangedT', function() command('autocmd TextChangedT * ++once let g:called = 1') thelpers.feed_data('a') retry(nil, nil, function() - eq(1, meths.get_var('called')) + eq(1, api.nvim_get_var('called')) end) end) @@ -212,6 +212,9 @@ describe('autocmd TextChangedT', function() command([[autocmd TextChangedT * call nvim_input('<CR>') | bwipe!]]) thelpers.feed_data('a') screen:expect({ any = 'E937: ' }) - matches('^E937: Attempt to delete a buffer that is in use: term://', meths.get_vvar('errmsg')) + matches( + '^E937: Attempt to delete a buffer that is in use: term://', + api.nvim_get_vvar('errmsg') + ) end) end) diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua index 4250c54834..29cd62f586 100644 --- a/test/functional/autocmd/textyankpost_spec.lua +++ b/test/functional/autocmd/textyankpost_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq local feed, command, expect = helpers.feed, helpers.command, helpers.expect -local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq +local api, fn, neq = helpers.api, helpers.fn, helpers.neq describe('TextYankPost', function() before_each(function() @@ -14,7 +14,7 @@ describe('TextYankPost', function() command('autocmd TextYankPost * let g:event = copy(v:event)') command('autocmd TextYankPost * let g:count += 1') - curbufmeths.set_lines(0, -1, true, { + api.nvim_buf_set_lines(0, 0, -1, true, { 'foo\0bar', 'baz text', }) @@ -100,7 +100,7 @@ describe('TextYankPost', function() visual = false, }, eval('g:event')) eq(1, eval('g:count')) - eq({ 'foo\nbar' }, funcs.getreg('+', 1, 1)) + eq({ 'foo\nbar' }, fn.getreg('+', 1, 1)) end) it('is executed after delete and change', function() diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua index 6f61ad7902..26d2b68ad4 100644 --- a/test/functional/autocmd/win_scrolled_resized_spec.lua +++ b/test/functional/autocmd/win_scrolled_resized_spec.lua @@ -7,7 +7,7 @@ local eval = helpers.eval local exec = helpers.exec local command = helpers.command local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local assert_alive = helpers.assert_alive before_each(clear) @@ -45,7 +45,7 @@ describe('WinScrolled', function() local win_id before_each(function() - win_id = meths.get_current_win().id + win_id = api.nvim_get_current_win().id command(string.format('autocmd WinScrolled %d let g:matched = v:true', win_id)) exec([[ let g:scrolled = 0 @@ -64,7 +64,7 @@ describe('WinScrolled', function() it('is triggered by scrolling vertically', function() local lines = { '123', '123' } - meths.buf_set_lines(0, 0, -1, true, lines) + api.nvim_buf_set_lines(0, 0, -1, true, lines) eq(0, eval('g:scrolled')) feed('<C-E>') @@ -84,10 +84,10 @@ describe('WinScrolled', function() it('is triggered by scrolling horizontally', function() command('set nowrap') - local width = meths.win_get_width(0) + local width = api.nvim_win_get_width(0) local line = '123' .. ('*'):rep(width * 2) local lines = { line, line } - meths.buf_set_lines(0, 0, -1, true, lines) + api.nvim_buf_set_lines(0, 0, -1, true, lines) eq(0, eval('g:scrolled')) feed('zl') @@ -108,8 +108,8 @@ describe('WinScrolled', function() it('is triggered by horizontal scrolling from cursor move', function() command('set nowrap') local lines = { '', '', 'Foo' } - meths.buf_set_lines(0, 0, -1, true, lines) - meths.win_set_cursor(0, { 3, 0 }) + api.nvim_buf_set_lines(0, 0, -1, true, lines) + api.nvim_win_set_cursor(0, { 3, 0 }) eq(0, eval('g:scrolled')) feed('zl') @@ -143,10 +143,10 @@ describe('WinScrolled', function() -- oldtest: Test_WinScrolled_long_wrapped() it('is triggered by scrolling on a long wrapped line #19968', function() - local height = meths.win_get_height(0) - local width = meths.win_get_width(0) - meths.buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) }) - meths.win_set_cursor(0, { 1, height * width - 1 }) + local height = api.nvim_win_get_height(0) + local width = api.nvim_win_get_width(0) + api.nvim_buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) }) + api.nvim_win_set_cursor(0, { 1, height * width - 1 }) eq(0, eval('g:scrolled')) feed('gj') @@ -168,12 +168,12 @@ describe('WinScrolled', function() end) it('is triggered when the window scrolls in Insert mode', function() - local height = meths.win_get_height(0) + local height = api.nvim_win_get_height(0) local lines = {} for i = 1, height * 2 do lines[i] = tostring(i) end - meths.buf_set_lines(0, 0, -1, true, lines) + api.nvim_buf_set_lines(0, 0, -1, true, lines) feed('M') eq(0, eval('g:scrolled')) @@ -220,12 +220,12 @@ describe('WinScrolled', function() eq(0, eval('g:scrolled')) -- With the upper split focused, send a scroll-down event to the unfocused one. - meths.input_mouse('wheel', 'down', '', 0, 6, 0) + api.nvim_input_mouse('wheel', 'down', '', 0, 6, 0) eq(1, eval('g:scrolled')) -- Again, but this time while we're in insert mode. feed('i') - meths.input_mouse('wheel', 'down', '', 0, 6, 0) + api.nvim_input_mouse('wheel', 'down', '', 0, 6, 0) feed('<Esc>') eq(2, eval('g:scrolled')) end) @@ -296,15 +296,15 @@ describe('WinScrolled', function() ]]) eq(0, eval('g:scrolled')) - local buf = meths.create_buf(true, true) - meths.buf_set_lines( + local buf = api.nvim_create_buf(true, true) + api.nvim_buf_set_lines( buf, 0, -1, false, { '@', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' } ) - local win = meths.open_win(buf, false, { + local win = api.nvim_open_win(buf, false, { height = 5, width = 10, col = 0, @@ -317,7 +317,7 @@ describe('WinScrolled', function() -- WinScrolled should not be triggered when creating a new floating window eq(0, eval('g:scrolled')) - meths.input_mouse('wheel', 'down', '', 0, 3, 3) + api.nvim_input_mouse('wheel', 'down', '', 0, 3, 3) eq(1, eval('g:scrolled')) eq(winid_str, eval('g:amatch')) eq({ @@ -325,7 +325,7 @@ describe('WinScrolled', function() [winid_str] = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 }, }, eval('g:v_event')) - meths.input_mouse('wheel', 'up', '', 0, 3, 3) + api.nvim_input_mouse('wheel', 'up', '', 0, 3, 3) eq(2, eval('g:scrolled')) eq(tostring(win.id), eval('g:amatch')) eq({ diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 0b58e8bc54..ce13c4755d 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source -local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths -local sleep = helpers.sleep +local command, fn, api = helpers.command, helpers.fn, helpers.api +local sleep = vim.uv.sleep local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv local set_session = helpers.set_session local nvim_prog = helpers.nvim_prog @@ -33,12 +33,12 @@ describe('channels', function() pending('can connect to socket', function() local server = spawn(nvim_argv, nil, nil, true) set_session(server) - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local client = spawn(nvim_argv, nil, nil, true) set_session(client) source(init) - meths.set_var('address', address) + api.nvim_set_var('address', address) command("let g:id = sockconnect('pipe', address, {'on_data':'OnEvent'})") local id = eval('g:id') ok(id > 0) @@ -46,7 +46,7 @@ describe('channels', function() command("call chansend(g:id, msgpackdump([[2,'nvim_set_var',['code',23]]]))") set_session(server) retry(nil, 1000, function() - eq(23, meths.get_var('code')) + eq(23, api.nvim_get_var('code')) end) set_session(client) @@ -67,8 +67,8 @@ describe('channels', function() \ 'on_exit': function('OnEvent'), \ } ]]) - meths.set_var('nvim_prog', nvim_prog) - meths.set_var( + api.nvim_set_var('nvim_prog', nvim_prog) + api.nvim_set_var( 'code', [[ function! OnEvent(id, data, event) dict @@ -117,8 +117,8 @@ describe('channels', function() \ 'on_exit': function('OnEvent'), \ } ]]) - meths.set_var('nvim_prog', nvim_prog) - meths.set_var( + api.nvim_set_var('nvim_prog', nvim_prog) + api.nvim_set_var( 'code', [[ function! OnStdin(id, data, event) dict @@ -165,8 +165,8 @@ describe('channels', function() \ 'pty': v:true, \ } ]]) - meths.set_var('nvim_prog', nvim_prog) - meths.set_var( + api.nvim_set_var('nvim_prog', nvim_prog) + api.nvim_set_var( 'code', [[ function! OnEvent(id, data, event) dict @@ -220,8 +220,8 @@ describe('channels', function() \ 'rpc': v:true, \ } ]]) - meths.set_var('nvim_prog', nvim_prog) - meths.set_var( + api.nvim_set_var('nvim_prog', nvim_prog) + api.nvim_set_var( 'code', [[ let id = stdioopen({'rpc':v:true}) @@ -250,7 +250,7 @@ describe('channels', function() end) it('can use buffered output mode', function() - skip(funcs.executable('grep') == 0, 'missing "grep" command') + skip(fn.executable('grep') == 0, 'missing "grep" command') source([[ let g:job_opts = { \ 'on_stdout': function('OnEvent'), @@ -285,7 +285,7 @@ describe('channels', function() end) it('can use buffered output mode with no stream callback', function() - skip(funcs.executable('grep') == 0, 'missing "grep" command') + skip(fn.executable('grep') == 0, 'missing "grep" command') source([[ function! OnEvent(id, data, event) dict call rpcnotify(1, a:event, a:id, a:data, self.stdout) diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index 2c3ebf62aa..b74ebb2367 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -7,7 +7,7 @@ local feed = helpers.feed local eval = helpers.eval local eq = helpers.eq local run = helpers.run -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local pcall_err = helpers.pcall_err local exec_capture = helpers.exec_capture @@ -18,7 +18,7 @@ describe('v:exiting', function() before_each(function() helpers.clear() - cid = helpers.nvim('get_api_info')[1] + cid = helpers.api.nvim_get_api_info()[1] end) it('defaults to v:null', function() @@ -68,7 +68,7 @@ describe(':cquit', function() poke_eventloop() assert_alive() else - funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline }) + fn.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline }) eq(exit_code, eval('v:shell_error')) end end diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 1b9a97648c..928cab525c 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -1,4 +1,4 @@ -local luv = require('luv') +local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log @@ -9,18 +9,18 @@ local eq = helpers.eq local neq = helpers.neq local ok = helpers.ok local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local request = helpers.request local retry = helpers.retry local rmdir = helpers.rmdir local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local mkdir = helpers.mkdir -local sleep = helpers.sleep +local sleep = vim.uv.sleep local read_file = helpers.read_file -local trim = helpers.trim -local currentdir = helpers.funcs.getcwd +local trim = vim.trim +local currentdir = helpers.fn.getcwd local assert_alive = helpers.assert_alive local check_close = helpers.check_close local expect_exit = helpers.expect_exit @@ -100,8 +100,8 @@ describe('fileio', function() eq('foozubbaz', trim(read_file('Xtest_startup_file1'))) -- 4. Exit caused by deadly signal (+ 'swapfile'). - local j = funcs.jobstart(vim.tbl_flatten({ args, '--embed' }), { rpc = true }) - funcs.rpcrequest( + local j = fn.jobstart(vim.tbl_flatten({ args, '--embed' }), { rpc = true }) + fn.rpcrequest( j, 'nvim_exec2', [[ @@ -112,8 +112,8 @@ describe('fileio', function() ]], {} ) - eq('Xtest_startup_swapdir', funcs.rpcrequest(j, 'nvim_eval', '&directory')) - funcs.jobstop(j) -- Send deadly signal. + eq('Xtest_startup_swapdir', fn.rpcrequest(j, 'nvim_eval', '&directory')) + fn.jobstop(j) -- Send deadly signal. local screen = startup() feed(':recover Xtest_startup_file2<cr>') @@ -210,7 +210,7 @@ describe('fileio', function() local backup_file_name = link_file_name .. '~' write_file('Xtest_startup_file1', initial_content, false) - luv.fs_symlink('Xtest_startup_file1', link_file_name) + uv.fs_symlink('Xtest_startup_file1', link_file_name) command('set backup') command('set backupcopy=yes') command('edit ' .. link_file_name) @@ -233,7 +233,7 @@ describe('fileio', function() local backup_file_name = backup_dir .. sep .. link_file_name .. '~' write_file('Xtest_startup_file1', initial_content, false) - luv.fs_symlink('Xtest_startup_file1', link_file_name) + uv.fs_symlink('Xtest_startup_file1', link_file_name) mkdir(backup_dir) command('set backup') command('set backupcopy=yes') @@ -258,9 +258,9 @@ describe('fileio', function() '', } local fname = 'Xtest_тест.md' - funcs.writefile(text, fname, 's') + fn.writefile(text, fname, 's') table.insert(text, '') - eq(text, funcs.readfile(fname, 'b')) + eq(text, fn.readfile(fname, 'b')) end) it("read invalid u8 over INT_MAX doesn't segfault", function() clear() @@ -295,7 +295,6 @@ describe('fileio', function() local future_time = cur_unix_time + 999999 -- Set the file's access/update time to be -- greater than the time at which it was created. - local uv = require('luv') uv.fs_utime('Xtest-overwrite-forced', future_time, future_time) -- use async feed_command because nvim basically hangs on the prompt feed_command('w') @@ -342,7 +341,7 @@ describe('tmpdir', function() -- Tempfiles typically look like: "…/nvim.<user>/xxx/0". -- - "…/nvim.<user>/xxx/" is the per-process tmpdir, not shared with other Nvims. -- - "…/nvim.<user>/" is the tmpdir root, shared by all Nvims (normally). - local tmproot = (funcs.tempname()):match(tmproot_pat) + local tmproot = (fn.tempname()):match(tmproot_pat) ok(tmproot:len() > 4, 'tmproot like "nvim.foo"', tmproot) return tmproot end @@ -361,7 +360,7 @@ describe('tmpdir', function() rmdir(tmproot) write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it. clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } }) - matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir(). -- Assert that broken tmpdir root was handled. assert_log('tempdir root not a directory', testlog, 100) @@ -370,9 +369,9 @@ describe('tmpdir', function() os.remove(testlog) os.remove(tmproot) mkdir(tmproot) - funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. + fn.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } }) - matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). + matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir(). -- Assert that broken tmpdir root was handled. assert_log('tempdir root has invalid permissions', testlog, 100) end) @@ -381,8 +380,8 @@ describe('tmpdir', function() local bigname = ('%s/%s'):format(os_tmpdir, ('x'):rep(666)) mkdir(bigname) clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = bigname } }) - matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). - local len = (funcs.tempname()):len() + matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir(). + local len = (fn.tempname()):len() ok(len > 4 and len < 256, '4 < len < 256', tostring(len)) end) @@ -391,33 +390,33 @@ describe('tmpdir', function() assert_nolog('tempdir disappeared', testlog) local function rm_tmpdir() - local tmpname1 = funcs.tempname() - local tmpdir1 = funcs.fnamemodify(tmpname1, ':h') - eq(funcs.stdpath('run'), tmpdir1) + local tmpname1 = fn.tempname() + local tmpdir1 = fn.fnamemodify(tmpname1, ':h') + eq(fn.stdpath('run'), tmpdir1) rmdir(tmpdir1) retry(nil, 1000, function() - eq(0, funcs.isdirectory(tmpdir1)) + eq(0, fn.isdirectory(tmpdir1)) end) - local tmpname2 = funcs.tempname() - local tmpdir2 = funcs.fnamemodify(tmpname2, ':h') + local tmpname2 = fn.tempname() + local tmpdir2 = fn.fnamemodify(tmpname2, ':h') neq(tmpdir1, tmpdir2) end -- Your antivirus hates you... rm_tmpdir() assert_log('tempdir disappeared', testlog, 100) - funcs.tempname() - funcs.tempname() - funcs.tempname() - eq('', meths.get_vvar('errmsg')) + fn.tempname() + fn.tempname() + fn.tempname() + eq('', api.nvim_get_vvar('errmsg')) rm_tmpdir() - funcs.tempname() - funcs.tempname() - funcs.tempname() - eq('E5431: tempdir disappeared (2 times)', meths.get_vvar('errmsg')) + fn.tempname() + fn.tempname() + fn.tempname() + eq('E5431: tempdir disappeared (2 times)', api.nvim_get_vvar('errmsg')) rm_tmpdir() - eq('E5431: tempdir disappeared (3 times)', meths.get_vvar('errmsg')) + eq('E5431: tempdir disappeared (3 times)', api.nvim_get_vvar('errmsg')) end) it('$NVIM_APPNAME relative path', function() @@ -428,6 +427,6 @@ describe('tmpdir', function() TMPDIR = os_tmpdir, }, }) - matches([=[.*[/\\]a%%b%.[^/\\]+]=], funcs.tempname()) + matches([=[.*[/\\]a%%b%.[^/\\]+]=], fn.tempname()) end) end) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 9c82d0bc7c..c6885d0b7c 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -1,29 +1,28 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, eq, eval, exc_exec, feed_command, feed, insert, neq, next_msg, nvim, testprg, ok, source, write_file, mkdir, rmdir = - helpers.clear, - helpers.eq, - helpers.eval, - helpers.exc_exec, - helpers.feed_command, - helpers.feed, - helpers.insert, - helpers.neq, - helpers.next_msg, - helpers.nvim, - helpers.testprg, - helpers.ok, - helpers.source, - helpers.write_file, - helpers.mkdir, - helpers.rmdir + +local clear = helpers.clear +local eq = helpers.eq +local eval = helpers.eval +local exc_exec = helpers.exc_exec +local feed_command = helpers.feed_command +local feed = helpers.feed +local insert = helpers.insert +local neq = helpers.neq +local next_msg = helpers.next_msg +local testprg = helpers.testprg +local ok = helpers.ok +local source = helpers.source +local write_file = helpers.write_file +local mkdir = helpers.mkdir +local rmdir = helpers.rmdir local assert_alive = helpers.assert_alive local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local os_kill = helpers.os_kill local retry = helpers.retry -local meths = helpers.meths -local NIL = helpers.NIL +local api = helpers.api +local NIL = vim.NIL local poke_eventloop = helpers.poke_eventloop local get_pathsep = helpers.get_pathsep local pathroot = helpers.pathroot @@ -43,8 +42,8 @@ describe('jobs', function() before_each(function() clear() - channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) source([[ function! Normalize(data) abort " Windows: remove ^M and term escape sequences @@ -69,22 +68,22 @@ describe('jobs', function() command('let g:job_opts.env = v:true') local _, err = pcall(function() if is_os('win') then - nvim('command', "let j = jobstart('set', g:job_opts)") + command("let j = jobstart('set', g:job_opts)") else - nvim('command', "let j = jobstart('env', g:job_opts)") + command("let j = jobstart('env', g:job_opts)") end end) ok(string.find(err, 'E475: Invalid argument: env') ~= nil) end) it('append environment #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command("let g:job_opts.env = {'TOTO': 'hello world'}") if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) end expect_msg_seq({ @@ -97,14 +96,14 @@ describe('jobs', function() end) it('append environment with pty #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', 'let g:job_opts.pty = v:true') - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command('let g:job_opts.pty = v:true') + command("let g:job_opts.env = {'TOTO': 'hello world'}") if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) else - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) end expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world abc' } } }, @@ -116,10 +115,10 @@ describe('jobs', function() end) it('replace environment #env', function() - nvim('command', "let $VAR = 'abc'") - nvim('command', "let $TOTO = 'goodbye world'") - nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") - nvim('command', 'let g:job_opts.clear_env = 1') + command("let $VAR = 'abc'") + command("let $TOTO = 'goodbye world'") + command("let g:job_opts.env = {'TOTO': 'hello world'}") + command('let g:job_opts.clear_env = 1') -- libuv ensures that certain "required" environment variables are -- preserved if the user doesn't provide them in a custom environment @@ -129,13 +128,13 @@ describe('jobs', function() -- Rather than expecting a completely empty environment, ensure that $VAR -- is *not* in the environment but $TOTO is. if is_os('win') then - nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) + command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world %VAR%', '' } } }, }) else - nvim('command', 'set shell=/bin/sh') - nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) + command('set shell=/bin/sh') + command([[call jobstart('echo $TOTO $VAR', g:job_opts)]]) expect_msg_seq({ { 'notification', 'stdout', { 0, { 'hello world', '' } } }, }) @@ -143,17 +142,17 @@ describe('jobs', function() end) it('handles case-insensitively matching #env vars', function() - nvim('command', "let $TOTO = 'abc'") + command("let $TOTO = 'abc'") -- Since $Toto is being set in the job, it should take precedence over the -- global $TOTO on Windows - nvim('command', "let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") + command("let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") if is_os('win') then - nvim('command', [[let j = jobstart('set | find /I "toto="', g:job_opts)]]) + command([[let j = jobstart('set | find /I "toto="', g:job_opts)]]) else - nvim('command', [[let j = jobstart('env | grep -i toto=', g:job_opts)]]) + command([[let j = jobstart('env | grep -i toto=', g:job_opts)]]) end - nvim('command', 'call jobwait([j])') - nvim('command', 'let g:output = Normalize(g:job_opts.stdout)') + command('call jobwait([j])') + command('let g:output = Normalize(g:job_opts.stdout)') local actual = eval('g:output') local expected if is_os('win') then @@ -169,11 +168,11 @@ describe('jobs', function() end) it('uses &shell and &shellcmdflag if passed a string', function() - nvim('command', "let $VAR = 'abc'") + command("let $VAR = 'abc'") if is_os('win') then - nvim('command', "let j = jobstart('echo %VAR%', g:job_opts)") + command("let j = jobstart('echo %VAR%', g:job_opts)") else - nvim('command', "let j = jobstart('echo $VAR', g:job_opts)") + command("let j = jobstart('echo $VAR', g:job_opts)") end eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) @@ -181,11 +180,11 @@ describe('jobs', function() end) it('changes to given / directory', function() - nvim('command', "let g:job_opts.cwd = '/'") + command("let g:job_opts.cwd = '/'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end eq({ 'notification', 'stdout', { 0, { pathroot(), '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) @@ -195,11 +194,11 @@ describe('jobs', function() it('changes to given `cwd` directory', function() local dir = eval('resolve(tempname())'):gsub('/', get_pathsep()) mkdir(dir) - nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") + command("let g:job_opts.cwd = '" .. dir .. "'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end expect_msg_seq( { @@ -221,11 +220,11 @@ describe('jobs', function() it('fails to change to invalid `cwd`', function() local dir = eval('resolve(tempname())."-bogus"') local _, err = pcall(function() - nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") + command("let g:job_opts.cwd = '" .. dir .. "'") if is_os('win') then - nvim('command', "let j = jobstart('cd', g:job_opts)") + command("let j = jobstart('cd', g:job_opts)") else - nvim('command', "let j = jobstart('pwd', g:job_opts)") + command("let j = jobstart('pwd', g:job_opts)") end end) ok(string.find(err, 'E475: Invalid argument: expected valid directory$') ~= nil) @@ -236,10 +235,10 @@ describe('jobs', function() local dir = 'Xtest_not_executable_dir' mkdir(dir) - funcs.setfperm(dir, 'rw-------') + fn.setfperm(dir, 'rw-------') matches( '^Vim%(call%):E903: Process failed to start: permission denied: .*', - pcall_err(nvim, 'command', "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") + pcall_err(command, "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") ) rmdir(dir) end) @@ -269,8 +268,8 @@ describe('jobs', function() end) it('invokes callbacks when the job writes and exits', function() - nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") - nvim('command', [[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]]) + command("let g:job_opts.on_stderr = function('OnEvent')") + command([[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]]) expect_twostreams({ { 'notification', 'stdout', { 0, { '', '' } } }, { 'notification', 'stdout', { 0, { '' } } }, @@ -279,11 +278,11 @@ describe('jobs', function() end) it('interactive commands', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) - nvim('command', 'call jobsend(j, "abc\\n")') + command('call jobsend(j, "abc\\n")') eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) - nvim('command', 'call jobsend(j, "123\\nxyz\\n")') + command('call jobsend(j, "123\\nxyz\\n")') expect_msg_seq( { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, -- Alternative sequence: @@ -292,7 +291,7 @@ describe('jobs', function() { 'notification', 'stdout', { 0, { 'xyz', '' } } }, } ) - nvim('command', 'call jobsend(j, [123, "xyz", ""])') + command('call jobsend(j, [123, "xyz", ""])') expect_msg_seq( { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, -- Alternative sequence: @@ -301,7 +300,7 @@ describe('jobs', function() { 'notification', 'stdout', { 0, { 'xyz', '' } } }, } ) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) @@ -311,75 +310,75 @@ describe('jobs', function() local filename = helpers.tmpname() write_file(filename, 'abc\0def\n') - nvim('command', "let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") + command("let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") eq({ 'notification', 'stdout', { 0, { 'abc\ndef', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) os.remove(filename) -- jobsend() preserves NULs. - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', [[call jobsend(j, ["123\n456",""])]]) + command("let j = jobstart(['cat', '-'], g:job_opts)") + command([[call jobsend(j, ["123\n456",""])]]) eq({ 'notification', 'stdout', { 0, { '123\n456', '' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') end) it('emits partial lines (does NOT buffer data lacking newlines)', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, "abc\\nxyz")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, "abc\\nxyz")') eq({ 'notification', 'stdout', { 0, { 'abc', 'xyz' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('preserves newlines', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') eq({ 'notification', 'stdout', { 0, { 'a', '', 'c', '', '', '', 'b', '', '' } } }, next_msg()) end) it('preserves NULs', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') eq({ 'notification', 'stdout', { 0, { '\n123\n', 'abc\nxyz\n', '' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('avoids sending final newline', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobsend(j, ["some data", "without\nfinal nl"])') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobsend(j, ["some data", "without\nfinal nl"])') eq({ 'notification', 'stdout', { 0, { 'some data', 'without\nfinal nl' } } }, next_msg()) - nvim('command', 'call jobstop(j)') + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) end) it('closes the job streams with jobclose', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobclose(j, "stdin")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobclose(j, "stdin")') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) it('disallows jobsend on a job that closed stdin', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('command', 'call jobclose(j, "stdin")') + command("let j = jobstart(['cat', '-'], g:job_opts)") + command('call jobclose(j, "stdin")') eq( false, pcall(function() - nvim('command', 'call jobsend(j, ["some data"])') + command('call jobsend(j, ["some data"])') end) ) command("let g:job_opts.stdin = 'null'") - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") eq( false, pcall(function() - nvim('command', 'call jobsend(j, ["some data"])') + command('call jobsend(j, ["some data"])') end) ) end) @@ -390,55 +389,53 @@ describe('jobs', function() end) it('jobstop twice on the stopped or exited job return 0', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) eq(1, eval('jobstop(j)')) eq(0, eval('jobstop(j)')) end) it('will not leak memory if we leave a job running', function() - nvim('command', "call jobstart(['cat', '-'], g:job_opts)") + command("call jobstart(['cat', '-'], g:job_opts)") end) it('can get the pid value using getpid', function() - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + command("let j = jobstart(['cat', '-'], g:job_opts)") local pid = eval('jobpid(j)') - neq(NIL, meths.get_proc(pid)) - nvim('command', 'call jobstop(j)') + neq(NIL, api.nvim_get_proc(pid)) + command('call jobstop(j)') eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) - eq(NIL, meths.get_proc(pid)) + eq(NIL, api.nvim_get_proc(pid)) end) it('disposed on Nvim exit', function() -- use sleep, which doesn't die on stdin close - nvim( - 'command', + command( "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" ) local pid = eval('jobpid(g:j)') - neq(NIL, meths.get_proc(pid)) + neq(NIL, api.nvim_get_proc(pid)) clear() - eq(NIL, meths.get_proc(pid)) + eq(NIL, api.nvim_get_proc(pid)) end) it('can survive the exit of nvim with "detach"', function() - nvim('command', 'let g:job_opts.detach = 1') - nvim( - 'command', + command('let g:job_opts.detach = 1') + command( "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" ) local pid = eval('jobpid(g:j)') - neq(NIL, meths.get_proc(pid)) + neq(NIL, api.nvim_get_proc(pid)) clear() - neq(NIL, meths.get_proc(pid)) + neq(NIL, api.nvim_get_proc(pid)) -- clean up after ourselves eq(0, os_kill(pid)) end) it('can pass user data to the callback', function() - nvim('command', 'let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') + command([[call jobstart('echo foo', g:job_opts)]]) local data = { n = 5, s = 'str', l = { 1 } } expect_msg_seq( { @@ -456,16 +453,16 @@ describe('jobs', function() end) it('can omit data callbacks', function() - nvim('command', 'unlet g:job_opts.on_stdout') - nvim('command', 'let g:job_opts.user = 5') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('unlet g:job_opts.on_stdout') + command('let g:job_opts.user = 5') + command([[call jobstart('echo foo', g:job_opts)]]) eq({ 'notification', 'exit', { 5, 0 } }, next_msg()) end) it('can omit exit callback', function() - nvim('command', 'unlet g:job_opts.on_exit') - nvim('command', 'let g:job_opts.user = 5') - nvim('command', [[call jobstart('echo foo', g:job_opts)]]) + command('unlet g:job_opts.on_exit') + command('let g:job_opts.user = 5') + command([[call jobstart('echo foo', g:job_opts)]]) expect_msg_seq( { { 'notification', 'stdout', { 5, { 'foo', '' } } }, @@ -481,8 +478,8 @@ describe('jobs', function() end) it('will pass return code with the exit event', function() - nvim('command', 'let g:job_opts.user = 5') - nvim('command', "call jobstart('exit 55', g:job_opts)") + command('let g:job_opts.user = 5') + command("call jobstart('exit 55', g:job_opts)") eq({ 'notification', 'stdout', { 5, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 5, 55 } }, next_msg()) end) @@ -883,7 +880,7 @@ describe('jobs', function() r = next_msg() eq('job ' .. i .. ' exited', r[3][1]) end - eq(10, nvim('eval', 'g:counter')) + eq(10, api.nvim_eval('g:counter')) end) describe('with timeout argument', function() @@ -948,15 +945,15 @@ describe('jobs', function() ]], } feed('<CR>') - funcs.jobstop(meths.get_var('id')) + fn.jobstop(api.nvim_get_var('id')) end) end) pending('exit event follows stdout, stderr', function() - nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") - nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") - nvim('eval', 'jobsend(j, "abcdef")') - nvim('eval', 'jobstop(j)') + command("let g:job_opts.on_stderr = function('OnEvent')") + command("let j = jobstart(['cat', '-'], g:job_opts)") + api.nvim_eval('jobsend(j, "abcdef")') + api.nvim_eval('jobstop(j)') expect_msg_seq( { { 'notification', 'stdout', { 0, { 'abcdef' } } }, @@ -1062,11 +1059,11 @@ describe('jobs', function() end local sleep_cmd = (is_os('win') and 'ping -n 31 127.0.0.1' or 'sleep 30') local j = eval("jobstart('" .. sleep_cmd .. ' | ' .. sleep_cmd .. ' | ' .. sleep_cmd .. "')") - local ppid = funcs.jobpid(j) + local ppid = fn.jobpid(j) local children if is_os('win') then local status, result = pcall(retry, nil, nil, function() - children = meths.get_proc_children(ppid) + children = api.nvim_get_proc_children(ppid) -- On Windows conhost.exe may exist, and -- e.g. vctip.exe might appear. #10783 ok(#children >= 3 and #children <= 5) @@ -1078,28 +1075,28 @@ describe('jobs', function() end else retry(nil, nil, function() - children = meths.get_proc_children(ppid) + children = api.nvim_get_proc_children(ppid) eq(3, #children) end) end -- Assert that nvim_get_proc() sees the children. for _, child_pid in ipairs(children) do - local info = meths.get_proc(child_pid) + local info = api.nvim_get_proc(child_pid) -- eq((is_os('win') and 'nvim.exe' or 'nvim'), info.name) eq(ppid, info.ppid) end -- Kill the root of the tree. - eq(1, funcs.jobstop(j)) + eq(1, fn.jobstop(j)) -- Assert that the children were killed. retry(nil, nil, function() for _, child_pid in ipairs(children) do - eq(NIL, meths.get_proc(child_pid)) + eq(NIL, api.nvim_get_proc(child_pid)) end end) end) it('jobstop on same id before stopped', function() - nvim('command', 'let j = jobstart(["cat", "-"], g:job_opts)') + command('let j = jobstart(["cat", "-"], g:job_opts)') neq(0, eval('j')) eq({ 1, 0 }, eval('[jobstop(j), jobstop(j)]')) @@ -1129,7 +1126,7 @@ describe('jobs', function() local j local function send(str) -- check no nvim_chan_free double free with pty job (#14198) - meths.chan_send(j, str) + api.nvim_chan_send(j, str) end before_each(function() @@ -1140,9 +1137,9 @@ describe('jobs', function() endfunction ]]) insert(testprg('tty-test')) - nvim('command', 'let g:job_opts.pty = 1') - nvim('command', 'let exec = [expand("<cfile>:p")]') - nvim('command', 'let j = jobstart(exec, g:job_opts)') + command('let g:job_opts.pty = 1') + command('let exec = [expand("<cfile>:p")]') + command('let j = jobstart(exec, g:job_opts)') j = eval 'j' eq('tty ready', next_chunk()) end) @@ -1153,14 +1150,14 @@ describe('jobs', function() end) it('resizing window', function() - nvim('command', 'call jobresize(j, 40, 10)') + command('call jobresize(j, 40, 10)') eq('rows: 10, cols: 40', next_chunk()) - nvim('command', 'call jobresize(j, 10, 40)') + command('call jobresize(j, 10, 40)') eq('rows: 40, cols: 10', next_chunk()) end) it('jobclose() sends SIGHUP', function() - nvim('command', 'call jobclose(j)') + command('call jobclose(j)') local msg = next_msg() msg = (msg[2] == 'stdout') and next_msg() or msg -- Skip stdout, if any. eq({ 'notification', 'exit', { 0, 42 } }, msg) @@ -1177,7 +1174,7 @@ describe('jobs', function() -- Have to wait so that the SIGHUP can be processed by tty-test on time. -- Can't wait for the next message in case this test fails, if it fails -- there won't be any more messages, and the test would hang. - helpers.sleep(100) + vim.uv.sleep(100) local err = exc_exec('call jobpid(j)') eq('Vim(call):E900: Invalid channel id', err) @@ -1244,7 +1241,7 @@ describe('pty process teardown', function() it('does not prevent/delay exit. #4798 #4900', function() skip(is_os('win')) -- Use a nested nvim (in :term) to test without --headless. - funcs.termopen({ + fn.termopen({ helpers.nvim_prog, '-u', 'NONE', diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 4a9943be20..1d2261ee05 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -1,4 +1,4 @@ -local luv = require('luv') +local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') @@ -7,7 +7,7 @@ local matches = helpers.matches local feed = helpers.feed local eval = helpers.eval local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog_abs = helpers.nvim_prog_abs local write_file = helpers.write_file local is_os = helpers.is_os @@ -32,8 +32,8 @@ describe('command-line option', function() end) it('treats - as stdin', function() - eq(nil, luv.fs_stat(fname)) - funcs.system({ + eq(nil, uv.fs_stat(fname)) + fn.system({ nvim_prog_abs(), '-u', 'NONE', @@ -47,15 +47,15 @@ describe('command-line option', function() fname, }, { ':call setline(1, "42")', ':wqall!', '' }) eq(0, eval('v:shell_error')) - local attrs = luv.fs_stat(fname) + local attrs = uv.fs_stat(fname) eq(#'42\n', attrs.size) end) it('does not expand $VAR', function() - eq(nil, luv.fs_stat(fname)) + eq(nil, uv.fs_stat(fname)) eq(true, not not dollar_fname:find('%$%w+')) write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n') - funcs.system({ + fn.system({ nvim_prog_abs(), '-u', 'NONE', @@ -69,7 +69,7 @@ describe('command-line option', function() fname, }) eq(0, eval('v:shell_error')) - local attrs = luv.fs_stat(fname) + local attrs = uv.fs_stat(fname) eq(#'100500\n', attrs.size) end) @@ -91,7 +91,7 @@ describe('command-line option', function() -- Need to explicitly pipe to stdin so that the embedded Nvim instance doesn't try to read -- data from the terminal #18181 - funcs.termopen(string.format([[echo "" | %s]], table.concat(args, ' ')), { + fn.termopen(string.format([[echo "" | %s]], table.concat(args, ' ')), { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) screen:expect( @@ -128,7 +128,7 @@ describe('command-line option', function() it('errors out when trying to use nonexistent file with -s', function() eq( 'Cannot open for reading: "' .. nonexistent_fname .. '": no such file or directory\n', - funcs.system({ + fn.system({ nvim_prog_abs(), '-u', 'NONE', @@ -151,7 +151,7 @@ describe('command-line option', function() write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n') eq( 'Attempt to open script file again: "-s ' .. dollar_fname .. '"\n', - funcs.system({ + fn.system({ nvim_prog_abs(), '-u', 'NONE', @@ -170,14 +170,14 @@ describe('command-line option', function() }) ) eq(2, eval('v:shell_error')) - eq(nil, luv.fs_stat(fname_2)) + eq(nil, uv.fs_stat(fname_2)) end) end) it('nvim -v, :version', function() - matches('Run ":verbose version"', funcs.execute(':version')) - matches('Compilation: .*Run :checkhealth', funcs.execute(':verbose version')) - matches('Run "nvim %-V1 %-v"', funcs.system({ nvim_prog_abs(), '-v' })) - matches('Compilation: .*Run :checkhealth', funcs.system({ nvim_prog_abs(), '-V1', '-v' })) + matches('Run ":verbose version"', fn.execute(':version')) + matches('Compilation: .*Run :checkhealth', fn.execute(':verbose version')) + matches('Run "nvim %-V1 %-v"', fn.system({ nvim_prog_abs(), '-v' })) + matches('Compilation: .*Run :checkhealth', fn.system({ nvim_prog_abs(), '-V1', '-v' })) end) end) diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 21364d7c03..e98bfc0d45 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -4,7 +4,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert local is_os = helpers.is_os local mkdir = helpers.mkdir @@ -167,7 +167,7 @@ describe('file search', function() else write_file(expected, '') end - eq(expected, funcs[funcname](item, d:gsub(' ', [[\ ]]))) + eq(expected, fn[funcname](item, d:gsub(' ', [[\ ]]))) end it('finddir()', function() diff --git a/test/functional/core/remote_spec.lua b/test/functional/core/remote_spec.lua index 5eb520ef4f..a48534f51b 100644 --- a/test/functional/core/remote_spec.lua +++ b/test/functional/core/remote_spec.lua @@ -6,7 +6,7 @@ local eq = helpers.eq local exec_capture = helpers.exec_capture local exec_lua = helpers.exec_lua local expect = helpers.expect -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert local nvim_prog = helpers.nvim_prog local new_argv = helpers.new_argv @@ -42,7 +42,7 @@ describe('Remote', function() -- Run a `nvim --remote*` command and return { stdout, stderr } of the process local function run_remote(...) set_session(server) - local addr = funcs.serverlist()[1] + local addr = fn.serverlist()[1] -- Create an nvim instance just to run the remote-invoking nvim. We want -- to wait for the remote instance to exit and calling jobwait blocks @@ -81,20 +81,20 @@ describe('Remote', function() it('edit a single file', function() eq({ '', '' }, run_remote('--remote', fname)) expect(contents) - eq(2, #funcs.getbufinfo()) + eq(2, #fn.getbufinfo()) end) it('tab edit a single file with a non-changed buffer', function() eq({ '', '' }, run_remote('--remote-tab', fname)) expect(contents) - eq(1, #funcs.gettabinfo()) + eq(1, #fn.gettabinfo()) end) it('tab edit a single file with a changed buffer', function() insert('hello') eq({ '', '' }, run_remote('--remote-tab', fname)) expect(contents) - eq(2, #funcs.gettabinfo()) + eq(2, #fn.gettabinfo()) end) it('edit multiple files', function() @@ -102,15 +102,15 @@ describe('Remote', function() expect(contents) command('next') expect(other_contents) - eq(3, #funcs.getbufinfo()) + eq(3, #fn.getbufinfo()) end) it('send keys', function() eq({ '', '' }, run_remote('--remote-send', ':edit ' .. fname .. '<CR><C-W>v')) expect(contents) - eq(2, #funcs.getwininfo()) + eq(2, #fn.getwininfo()) -- Only a single buffer as we're using edit and not drop like --remote does - eq(1, #funcs.getbufinfo()) + eq(1, #fn.getbufinfo()) end) it('evaluate expressions', function() @@ -127,7 +127,7 @@ describe('Remote', function() it('creates server if not found', function() clear('--remote', fname) expect(contents) - eq(1, #funcs.getbufinfo()) + eq(1, #fn.getbufinfo()) -- Since we didn't pass silent, we should get a complaint neq(nil, string.find(exec_capture('messages'), 'E247:')) end) @@ -135,8 +135,8 @@ describe('Remote', function() it('creates server if not found with tabs', function() clear('--remote-tab-silent', fname, other_fname) expect(contents) - eq(2, #funcs.gettabinfo()) - eq(2, #funcs.getbufinfo()) + eq(2, #fn.gettabinfo()) + eq(2, #fn.getbufinfo()) -- We passed silent, so no message should be issued about the server not being found eq(nil, string.find(exec_capture('messages'), 'E247:')) end) diff --git a/test/functional/core/spellfile_spec.lua b/test/functional/core/spellfile_spec.lua index 60cdf88fe3..7dcdfac315 100644 --- a/test/functional/core/spellfile_spec.lua +++ b/test/functional/core/spellfile_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local clear = helpers.clear -local meths = helpers.meths +local api = helpers.api local exc_exec = helpers.exc_exec local rmdir = helpers.rmdir local write_file = helpers.write_file @@ -24,7 +24,7 @@ describe('spellfile', function() -- │ ┌ Spell file version (#VIMSPELLVERSION) local spellheader = 'VIMspell\050' it('errors out when prefcond section is truncated', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) -- stylua: ignore write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_PREFCOND) @@ -35,11 +35,11 @@ describe('spellfile', function() -- │ ┌ Condition length (1 byte) -- │ │ ┌ Condition regex (missing!) .. '\000\001\001') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E758: Truncated spell file', exc_exec('set spell')) end) it('errors out when prefcond regexp contains NUL byte', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) -- stylua: ignore write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_PREFCOND) @@ -55,11 +55,11 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when region contains NUL byte', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) -- stylua: ignore write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_REGION) @@ -72,11 +72,11 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when SAL section contains NUL byte', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) -- stylua: ignore write_file(testdir .. '/spell/en.ascii.spl', -- ┌ Section identifier (#SN_SAL) @@ -96,13 +96,13 @@ describe('spellfile', function() -- │ ┌ KWORDTREE tree length (4 bytes) -- │ │ ┌ PREFIXTREE tree length .. '\000\000\000\000\000\000\000\000\000\000\000\000') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) end) it('errors out when spell header contains NUL bytes', function() - meths.set_option_value('runtimepath', testdir, {}) + api.nvim_set_option_value('runtimepath', testdir, {}) write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000') - meths.set_option_value('spelllang', 'en', {}) + api.nvim_set_option_value('spelllang', 'en', {}) eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell')) end) end) diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index ebf9deb86b..fd3748a985 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -13,8 +13,8 @@ local exec = helpers.exec local exec_capture = helpers.exec_capture local exec_lua = helpers.exec_lua local feed = helpers.feed -local funcs = helpers.funcs -local pesc = helpers.pesc +local fn = helpers.fn +local pesc = vim.pesc local mkdir = helpers.mkdir local mkdir_p = helpers.mkdir_p local nvim_prog = helpers.nvim_prog @@ -22,24 +22,24 @@ local nvim_set = helpers.nvim_set local read_file = helpers.read_file local retry = helpers.retry local rmdir = helpers.rmdir -local sleep = helpers.sleep -local startswith = helpers.startswith +local sleep = vim.uv.sleep +local startswith = vim.startswith local write_file = helpers.write_file -local meths = helpers.meths +local api = helpers.api local alter_slashes = helpers.alter_slashes local is_os = helpers.is_os local dedent = helpers.dedent -local tbl_map = helpers.tbl_map -local tbl_filter = helpers.tbl_filter -local endswith = helpers.endswith +local tbl_map = vim.tbl_map +local tbl_filter = vim.tbl_filter +local endswith = vim.endswith describe('startup', function() it('--clean', function() clear() ok( string.find( - alter_slashes(meths.get_option_value('runtimepath', {})), - funcs.stdpath('config'), + alter_slashes(api.nvim_get_option_value('runtimepath', {})), + fn.stdpath('config'), 1, true ) ~= nil @@ -47,8 +47,8 @@ describe('startup', function() clear('--clean') ok( string.find( - alter_slashes(meths.get_option_value('runtimepath', {})), - funcs.stdpath('config'), + alter_slashes(api.nvim_get_option_value('runtimepath', {})), + fn.stdpath('config'), 1, true ) == nil @@ -60,7 +60,7 @@ describe('startup', function() local screen screen = Screen.new(84, 3) screen:attach() - funcs.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' }) + fn.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' }) screen:expect([[ ^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) | |*2 @@ -82,7 +82,7 @@ describe('startup', function() local screen screen = Screen.new(60, 7) screen:attach() - local id = funcs.termopen({ + local id = fn.termopen({ nvim_prog, '-u', 'NONE', @@ -105,7 +105,7 @@ describe('startup', function() > | | ]]) - funcs.chansend(id, 'cont\n') + fn.chansend(id, 'cont\n') screen:expect([[ ^ | ~ |*3 @@ -124,13 +124,13 @@ describe('startup', function() vim.list_extend(args, nvim_args or {}) vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') }) vim.list_extend(args, lua_args or {}) - local out = funcs.system(args, input):gsub('\r\n', '\n') + local out = fn.system(args, input):gsub('\r\n', '\n') return eq(dedent(expected), out) end it('failure modes', function() -- nvim -l <empty> - matches('nvim%.?e?x?e?: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) + matches('nvim%.?e?x?e?: Argument missing after: "%-l"', fn.system({ nvim_prog, '-l' })) eq(1, eval('v:shell_error')) end) @@ -161,12 +161,12 @@ describe('startup', function() eq(0, eval('v:shell_error')) matches( 'E5113: .* my pearls!!', - funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' }) + fn.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' }) ) eq(1, eval('v:shell_error')) matches( 'E5113: .* %[string "error%("whoa"%)"%]:1: whoa', - funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")') + fn.system({ nvim_prog, '-l', '-' }, 'error("whoa")') ) eq(1, eval('v:shell_error')) end) @@ -286,7 +286,7 @@ describe('startup', function() end) it('--cmd/-c/+ do not truncate long Lua print() message with --headless', function() - local out = funcs.system({ + local out = fn.system({ nvim_prog, '-u', 'NONE', @@ -305,7 +305,7 @@ describe('startup', function() it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() -- system() puts a pipe at both ends. - local out = funcs.system({ + local out = fn.system({ nvim_prog, '-u', 'NONE', @@ -340,7 +340,7 @@ describe('startup', function() command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal - funcs.termopen({ + fn.termopen({ nvim_prog, '-u', 'NONE', @@ -372,7 +372,7 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) -- Running in :terminal - funcs.termopen( + fn.termopen( ( [["%s" -u NONE -i NONE --cmd "%s"]] .. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]] @@ -402,7 +402,7 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) -- Running in :terminal - funcs.termopen( + fn.termopen( ( [[echo foo | ]] -- Input from a pipe. .. [["%s" -u NONE -i NONE --cmd "%s"]] @@ -431,7 +431,7 @@ describe('startup', function() command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal - funcs.termopen( + fn.termopen( ( [[echo foo | ]] .. [["%s" -u NONE -i NONE --cmd "%s"]] @@ -454,7 +454,7 @@ describe('startup', function() it('input from pipe + file args #7679', function() eq( 'ohyeah\r\n0 0 bufs=3', - funcs.system({ + fn.system({ nvim_prog, '-n', '-u', @@ -475,7 +475,7 @@ describe('startup', function() it('if stdin is empty: selects buffer 2, deletes buffer 1 #8561', function() eq( '\r\n 2 %a "file1" line 0\r\n 3 "file2" line 0', - funcs.system({ + fn.system({ nvim_prog, '-n', '-u', @@ -501,7 +501,7 @@ describe('startup', function() -- eq( 'partylikeits1999\n', - funcs.system({ + fn.system({ nvim_prog, '-n', '-u', @@ -513,16 +513,16 @@ describe('startup', function() 'test/functional/fixtures/tty-test.c', }, { 'partylikeits1999', '' }) ) - eq(inputstr, funcs.system({ nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input)) + eq(inputstr, fn.system({ nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input)) -- with `-u NORC` eq( 'thepartycontinues\n', - funcs.system({ nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, { 'thepartycontinues', '' }) + fn.system({ nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, { 'thepartycontinues', '' }) ) -- without `-u` eq( 'thepartycontinues\n', - funcs.system({ nvim_prog, '-n', '-Es', '+.print' }, { 'thepartycontinues', '' }) + fn.system({ nvim_prog, '-n', '-Es', '+.print' }, { 'thepartycontinues', '' }) ) -- @@ -530,7 +530,7 @@ describe('startup', function() -- eq( ' encoding=utf-8\n', - funcs.system({ + fn.system({ nvim_prog, '-n', '-u', @@ -541,19 +541,19 @@ describe('startup', function() 'test/functional/fixtures/tty-test.c', }, { 'set encoding', '' }) ) - eq('line1\nline2\n', funcs.system({ nvim_prog, '-i', 'NONE', '-es', '-' }, input)) + eq('line1\nline2\n', fn.system({ nvim_prog, '-i', 'NONE', '-es', '-' }, input)) -- with `-u NORC` eq( ' encoding=utf-8\n', - funcs.system({ nvim_prog, '-n', '-u', 'NORC', '-es' }, { 'set encoding', '' }) + fn.system({ nvim_prog, '-n', '-u', 'NORC', '-es' }, { 'set encoding', '' }) ) -- without `-u` - eq(' encoding=utf-8\n', funcs.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' })) + eq(' encoding=utf-8\n', fn.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' })) end) it('-es/-Es disables swapfile, user config #8540', function() for _, arg in ipairs({ '-es', '-Es' }) do - local out = funcs.system({ + local out = fn.system({ nvim_prog, arg, '+set swapfile? updatecount? shadafile?', @@ -572,15 +572,15 @@ describe('startup', function() it('fails on --embed with -es/-Es/-l', function() matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - funcs.system({ nvim_prog, '--embed', '-es' }) + fn.system({ nvim_prog, '--embed', '-es' }) ) matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - funcs.system({ nvim_prog, '--embed', '-Es' }) + fn.system({ nvim_prog, '--embed', '-Es' }) ) matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - funcs.system({ nvim_prog, '--embed', '-l', 'foo.lua' }) + fn.system({ nvim_prog, '--embed', '-l', 'foo.lua' }) ) end) @@ -588,7 +588,7 @@ describe('startup', function() local screen screen = Screen.new(60, 6) screen:attach() - local id = funcs.termopen({ + local id = fn.termopen({ nvim_prog, '-u', 'NONE', @@ -611,7 +611,7 @@ describe('startup', function() Press ENTER or type command to continue | | ]]) - funcs.chansend(id, '\n') + fn.chansend(id, '\n') screen:expect([[ ^ | ~ |*2 @@ -651,7 +651,7 @@ describe('startup', function() expected, -- FIXME(codehex): We should really set a timeout for the system function. -- If this test fails, there will be a waiting input state. - funcs.system({ + fn.system({ nvim_prog, '-u', 'NONE', @@ -663,7 +663,7 @@ describe('startup', function() end) it('get command line arguments from v:argv', function() - local out = funcs.system({ + local out = fn.system({ nvim_prog, '-u', 'NONE', @@ -715,7 +715,7 @@ describe('startup', function() :put =mode(1) | ]]) - eq('cv\n', funcs.system({ nvim_prog, '-n', '-es' }, { 'put =mode(1)', 'print', '' })) + eq('cv\n', fn.system({ nvim_prog, '-n', '-es' }, { 'put =mode(1)', 'print', '' })) end) it('-d does not diff non-arglist windows #13720 #21289', function() @@ -737,11 +737,11 @@ describe('startup', function() os.remove('Xdiff.vim') end) clear { args = { '-u', 'Xdiff.vim', '-d', 'Xdiff.vim', 'Xdiff.vim' } } - eq(true, meths.get_option_value('diff', { win = funcs.win_getid(1) })) - eq(true, meths.get_option_value('diff', { win = funcs.win_getid(2) })) - local float_win = funcs.win_getid(3) - eq('editor', meths.win_get_config(float_win).relative) - eq(false, meths.get_option_value('diff', { win = float_win })) + eq(true, api.nvim_get_option_value('diff', { win = fn.win_getid(1) })) + eq(true, api.nvim_get_option_value('diff', { win = fn.win_getid(2) })) + local float_win = fn.win_getid(3) + eq('editor', api.nvim_win_get_config(float_win).relative) + eq(false, api.nvim_get_option_value('diff', { win = float_win })) end) it('does not crash if --embed is given twice', function() @@ -870,7 +870,7 @@ describe('startup', function() exec_lua [[ return _G.test_loadorder ]] ) - local rtp = meths.get_option_value('rtp', {}) + local rtp = api.nvim_get_option_value('rtp', {}) ok( startswith( rtp, @@ -963,9 +963,9 @@ describe('startup', function() os.remove('Xtab2.noft') end) clear({ args = { '-p', 'Xtab1.noft', 'Xtab2.noft' } }) - eq(81, meths.win_get_width(0)) + eq(81, api.nvim_win_get_width(0)) command('tabnext') - eq(81, meths.win_get_width(0)) + eq(81, api.nvim_win_get_width(0)) end) end) @@ -1062,7 +1062,7 @@ describe('user config init', function() clear { args_rm = { '-u' }, env = xenv } eq(1, eval('g:lua_rc')) - eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) + eq(fn.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) end) describe('loads existing', function() @@ -1122,7 +1122,7 @@ describe('user config init', function() local screen = Screen.new(50, 8) screen:attach() - funcs.termopen({ nvim_prog }, { + fn.termopen({ nvim_prog }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -1245,7 +1245,7 @@ describe('runtime:', function() -- Check if plugin_file_path is listed in getscriptinfo() local scripts = tbl_map(function(s) return s.name - end, funcs.getscriptinfo()) + end, fn.getscriptinfo()) ok(#tbl_filter(function(s) return endswith(s, plugin_file_path) end, scripts) > 0) @@ -1369,13 +1369,13 @@ describe('inccommand on ex mode', function() local screen screen = Screen.new(60, 10) screen:attach() - local id = funcs.termopen( + local id = fn.termopen( { nvim_prog, '-u', 'NONE', '-c', 'set termguicolors', '-E', 'test/README.md' }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, } ) - funcs.chansend(id, '%s/N') + fn.chansend(id, '%s/N') screen:expect { grid = [[ {1:^ }| diff --git a/test/functional/editor/K_spec.lua b/test/functional/editor/K_spec.lua index 92a00b28b6..1fbdd1c142 100644 --- a/test/functional/editor/K_spec.lua +++ b/test/functional/editor/K_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, eval, feed, meths, retry = - helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.meths, helpers.retry +local eq, clear, eval, feed, api, retry = + helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.api, helpers.retry describe('K', function() local test_file = 'K_spec_out' @@ -36,7 +36,7 @@ describe('K', function() end) eq({ 'fnord' }, eval("readfile('" .. test_file .. "')")) -- Confirm that Neovim is still in terminal mode after K is pressed (#16692). - helpers.sleep(500) + vim.uv.sleep(500) eq('t', eval('mode()')) feed('<space>') -- Any key, not just <space>, can be used here to escape. eq('n', eval('mode()')) @@ -50,7 +50,7 @@ describe('K', function() -- Confirm that an arbitrary keypress doesn't escape (i.e., the process is -- still running). If the process were no longer running, an arbitrary -- keypress would escape. - helpers.sleep(500) + vim.uv.sleep(500) feed('<space>') eq('t', eval('mode()')) -- Confirm that <esc> kills the buffer for the running command. @@ -61,9 +61,9 @@ describe('K', function() end) it('empty string falls back to :help #19298', function() - meths.set_option_value('keywordprg', '', {}) - meths.buf_set_lines(0, 0, -1, true, { 'doesnotexist' }) + api.nvim_set_option_value('keywordprg', '', {}) + api.nvim_buf_set_lines(0, 0, -1, true, { 'doesnotexist' }) feed('K') - eq('E149: Sorry, no help for doesnotexist', meths.get_vvar('errmsg')) + eq('E149: Sorry, no help for doesnotexist', api.nvim_get_vvar('errmsg')) end) end) diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index fbb63fdba6..a7704fe12b 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -4,10 +4,9 @@ local assert_alive = helpers.assert_alive local clear, feed = helpers.clear, helpers.feed local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq local feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect -local funcs = helpers.funcs -local curbufmeths = helpers.curbufmeths +local fn = helpers.fn local command = helpers.command -local meths = helpers.meths +local api = helpers.api local poke_eventloop = helpers.poke_eventloop describe('completion', function() @@ -691,7 +690,7 @@ describe('completion', function() ]]) -- Works for unindenting too. feed('ounin<C-X><C-N>') - helpers.poke_eventloop() + poke_eventloop() feed('<BS>d') screen:expect([[ inc uninc indent unindent | @@ -821,23 +820,23 @@ describe('completion', function() end) it('provides completion from `getcompletion()`', function() - eq({ 'vim' }, funcs.getcompletion('vi', 'lua')) - eq({ 'api' }, funcs.getcompletion('vim.ap', 'lua')) - eq({ 'tbl_filter' }, funcs.getcompletion('vim.tbl_fil', 'lua')) - eq({ 'vim' }, funcs.getcompletion('print(vi', 'lua')) + eq({ 'vim' }, fn.getcompletion('vi', 'lua')) + eq({ 'api' }, fn.getcompletion('vim.ap', 'lua')) + eq({ 'tbl_filter' }, fn.getcompletion('vim.tbl_fil', 'lua')) + eq({ 'vim' }, fn.getcompletion('print(vi', 'lua')) -- fuzzy completion is not supported, so the result should be the same command('set wildoptions+=fuzzy') - eq({ 'vim' }, funcs.getcompletion('vi', 'lua')) + eq({ 'vim' }, fn.getcompletion('vi', 'lua')) end) end) it('cmdline completion supports various string options', function() - eq('auto', funcs.getcompletion('set foldcolumn=', 'cmdline')[2]) - eq({ 'nosplit', 'split' }, funcs.getcompletion('set inccommand=', 'cmdline')) - eq({ 'ver:3,hor:6', 'hor:', 'ver:' }, funcs.getcompletion('set mousescroll=', 'cmdline')) - eq('BS', funcs.getcompletion('set termpastefilter=', 'cmdline')[2]) - eq('SpecialKey', funcs.getcompletion('set winhighlight=', 'cmdline')[1]) - eq('SpecialKey', funcs.getcompletion('set winhighlight=NonText:', 'cmdline')[1]) + eq('auto', fn.getcompletion('set foldcolumn=', 'cmdline')[2]) + eq({ 'nosplit', 'split' }, fn.getcompletion('set inccommand=', 'cmdline')) + eq({ 'ver:3,hor:6', 'hor:', 'ver:' }, fn.getcompletion('set mousescroll=', 'cmdline')) + eq('BS', fn.getcompletion('set termpastefilter=', 'cmdline')[2]) + eq('SpecialKey', fn.getcompletion('set winhighlight=', 'cmdline')[1]) + eq('SpecialKey', fn.getcompletion('set winhighlight=NonText:', 'cmdline')[1]) end) describe('from the commandline window', function() @@ -883,8 +882,8 @@ describe('completion', function() return '' endfunction ]]) - meths.set_option_value('completeopt', 'menuone,noselect', {}) - meths.set_var('_complist', { + api.nvim_set_option_value('completeopt', 'menuone,noselect', {}) + api.nvim_set_var('_complist', { { word = 0, abbr = 1, @@ -928,7 +927,7 @@ describe('completion', function() end) it('CompleteChanged autocommand', function() - curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar', '' }) + api.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'foobar', '' }) source([[ set complete=. completeopt=noinsert,noselect,menuone function! OnPumChange() @@ -1067,7 +1066,7 @@ describe('completion', function() {3:-- }{4:match 1 of 3} | ]]) command([[call timer_start(100, { -> execute('stopinsert') })]]) - helpers.sleep(200) + vim.uv.sleep(200) feed('k') -- cursor should move up in Normal mode screen:expect([[ hello | diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua index 0321a21b35..e6a6ea808a 100644 --- a/test/functional/editor/ctrl_c_spec.lua +++ b/test/functional/editor/ctrl_c_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear, feed, source = helpers.clear, helpers.feed, helpers.source local command = helpers.command local poke_eventloop = helpers.poke_eventloop -local sleep = helpers.sleep +local sleep = vim.uv.sleep describe('CTRL-C (mapped)', function() local screen diff --git a/test/functional/editor/fold_spec.lua b/test/functional/editor/fold_spec.lua index 3889067fd4..35632bb2f8 100644 --- a/test/functional/editor/fold_spec.lua +++ b/test/functional/editor/fold_spec.lua @@ -5,7 +5,7 @@ local insert = helpers.insert local feed = helpers.feed local expect = helpers.expect local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local eq = helpers.eq local neq = helpers.neq @@ -75,8 +75,8 @@ describe('Folds', function() local function get_folds() local rettab = {} - for i = 1, funcs.line('$') do - table.insert(rettab, funcs.foldlevel(i)) + for i = 1, fn.line('$') do + table.insert(rettab, fn.foldlevel(i)) end return rettab end @@ -140,21 +140,21 @@ a a a]]) -- lines are not closed, folds are correct - for i = 1, funcs.line('$') do - eq(-1, funcs.foldclosed(i)) + for i = 1, fn.line('$') do + eq(-1, fn.foldclosed(i)) if i == 1 or i == 7 or i == 13 then - eq(0, funcs.foldlevel(i)) + eq(0, fn.foldlevel(i)) elseif i == 4 then - eq(2, funcs.foldlevel(i)) + eq(2, fn.foldlevel(i)) else - eq(1, funcs.foldlevel(i)) + eq(1, fn.foldlevel(i)) end end -- folds are not corrupted feed('zM') - eq(6, funcs.foldclosedend(2)) - eq(12, funcs.foldclosedend(8)) - eq(18, funcs.foldclosedend(14)) + eq(6, fn.foldclosedend(2)) + eq(12, fn.foldclosedend(8)) + eq(18, fn.foldclosedend(14)) end) it("doesn't split a fold when the move is within it", function() @@ -330,13 +330,13 @@ a]], a ]]) for i = 1, 2 do - eq(1, funcs.foldlevel(i)) + eq(1, fn.foldlevel(i)) end for i = 3, 5 do - eq(0, funcs.foldlevel(i)) + eq(0, fn.foldlevel(i)) end for i = 6, 8 do - eq(1, funcs.foldlevel(i)) + eq(1, fn.foldlevel(i)) end end) @@ -354,7 +354,7 @@ a]], ]]) command('setlocal foldmethod=indent') command('3,5d') - eq(5, funcs.foldclosedend(1)) + eq(5, fn.foldclosedend(1)) end) it("doesn't combine folds that have a specified end", function() @@ -371,7 +371,7 @@ a]], command('setlocal foldmethod=marker') command('3,5d') command('%foldclose') - eq(2, funcs.foldclosedend(1)) + eq(2, fn.foldclosedend(1)) end) it('splits folds according to >N and <N with foldexpr', function() @@ -415,20 +415,20 @@ a]], command('foldopen') command('read ' .. tempfname) command('%foldclose') - eq(2, funcs.foldclosedend(1)) - eq(0, funcs.foldlevel(3)) - eq(0, funcs.foldlevel(4)) - eq(6, funcs.foldclosedend(5)) - eq(10, funcs.foldclosedend(7)) - eq(14, funcs.foldclosedend(11)) + eq(2, fn.foldclosedend(1)) + eq(0, fn.foldlevel(3)) + eq(0, fn.foldlevel(4)) + eq(6, fn.foldclosedend(5)) + eq(10, fn.foldclosedend(7)) + eq(14, fn.foldclosedend(11)) end) it('no folds remain if :delete makes buffer empty #19671', function() command('setlocal foldmethod=manual') - funcs.setline(1, { 'foo', 'bar', 'baz' }) + fn.setline(1, { 'foo', 'bar', 'baz' }) command('2,3fold') command('%delete') - eq(0, funcs.foldlevel(1)) + eq(0, fn.foldlevel(1)) end) it('multibyte fold markers work #20438', function() @@ -442,7 +442,7 @@ a]], bbbbb/*«*/ bbbbb bbbbb/*»*/]]) - eq(1, funcs.foldlevel(1)) + eq(1, fn.foldlevel(1)) end) it('updates correctly with indent method and visual blockwise insertion #22898', function() @@ -452,8 +452,8 @@ a]], ]]) command('setlocal foldmethod=indent shiftwidth=2') feed('gg0<C-v>jI <Esc>') -- indent both lines using visual blockwise mode - eq(1, funcs.foldlevel(1)) - eq(1, funcs.foldlevel(2)) + eq(1, fn.foldlevel(1)) + eq(1, fn.foldlevel(2)) end) it("doesn't open folds with indent method when inserting lower foldlevel line", function() @@ -464,22 +464,22 @@ a]], keep this line folded 2 ]]) command('set foldmethod=indent shiftwidth=2 noautoindent') - eq(1, funcs.foldlevel(1)) - eq(1, funcs.foldlevel(2)) - eq(2, funcs.foldlevel(3)) - eq(2, funcs.foldlevel(4)) + eq(1, fn.foldlevel(1)) + eq(1, fn.foldlevel(2)) + eq(2, fn.foldlevel(3)) + eq(2, fn.foldlevel(4)) feed('zo') -- open the outer fold - neq(-1, funcs.foldclosed(3)) -- make sure the inner fold is not open + neq(-1, fn.foldclosed(3)) -- make sure the inner fold is not open feed('gg0oa<Esc>') -- insert unindented line - eq(1, funcs.foldlevel(1)) --| insert an unindented line under this line - eq(0, funcs.foldlevel(2)) --|a - eq(1, funcs.foldlevel(3)) --| keep the lines under this line folded - eq(2, funcs.foldlevel(4)) --| keep this line folded 1 - eq(2, funcs.foldlevel(5)) --| keep this line folded 2 + eq(1, fn.foldlevel(1)) --| insert an unindented line under this line + eq(0, fn.foldlevel(2)) --|a + eq(1, fn.foldlevel(3)) --| keep the lines under this line folded + eq(2, fn.foldlevel(4)) --| keep this line folded 1 + eq(2, fn.foldlevel(5)) --| keep this line folded 2 - neq(-1, funcs.foldclosed(4)) -- make sure the inner fold is still not open + neq(-1, fn.foldclosed(4)) -- make sure the inner fold is still not open end) end) diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua index e063924018..717284b7d1 100644 --- a/test/functional/editor/jump_spec.lua +++ b/test/functional/editor/jump_spec.lua @@ -4,11 +4,11 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local feed = helpers.feed local exec_capture = helpers.exec_capture local write_file = helpers.write_file -local curbufmeths = helpers.curbufmeths +local api = helpers.api describe('jumplist', function() local fname1 = 'Xtest-functional-normal-jump' @@ -20,7 +20,7 @@ describe('jumplist', function() end) it('does not add a new entry on startup', function() - eq('\n jump line col file/text\n>', funcs.execute('jumps')) + eq('\n jump line col file/text\n>', fn.execute('jumps')) end) it('does not require two <C-O> strokes to jump back', function() @@ -28,25 +28,25 @@ describe('jumplist', function() write_file(fname2, 'second file contents') command('args ' .. fname1 .. ' ' .. fname2) - local buf1 = funcs.bufnr(fname1) - local buf2 = funcs.bufnr(fname2) + local buf1 = fn.bufnr(fname1) + local buf2 = fn.bufnr(fname2) command('next') feed('<C-O>') - eq(buf1, funcs.bufnr('%')) + eq(buf1, fn.bufnr('%')) command('first') command('snext') feed('<C-O>') - eq(buf1, funcs.bufnr('%')) + eq(buf1, fn.bufnr('%')) feed('<C-I>') - eq(buf2, funcs.bufnr('%')) + eq(buf2, fn.bufnr('%')) feed('<C-O>') - eq(buf1, funcs.bufnr('%')) + eq(buf1, fn.bufnr('%')) command('drop ' .. fname2) feed('<C-O>') - eq(buf1, funcs.bufnr('%')) + eq(buf1, fn.bufnr('%')) end) it('<C-O> scrolls cursor halfway when switching buffer #25763', function() @@ -284,7 +284,7 @@ describe('jumpoptions=view', function() screen:attach() command('edit ' .. file1) feed('7GzbG') - curbufmeths.set_lines(0, 2, true, {}) + api.nvim_buf_set_lines(0, 0, 2, true, {}) -- Move to line 7, and set it as the last line visible on the view with zb, meaning to recover -- the view it needs to put the cursor 7 lines from the top line. Then go to the end of the -- file, delete 2 lines before line 7, meaning the jump/mark is moved 2 lines up to line 5. diff --git a/test/functional/editor/langmap_spec.lua b/test/functional/editor/langmap_spec.lua index e697140889..b2a4b21a89 100644 --- a/test/functional/editor/langmap_spec.lua +++ b/test/functional/editor/langmap_spec.lua @@ -4,7 +4,7 @@ local eq, neq, call = helpers.eq, helpers.neq, helpers.call local eval, feed, clear = helpers.eval, helpers.feed, helpers.clear local command, insert, expect = helpers.command, helpers.insert, helpers.expect local feed_command = helpers.feed_command -local curwin = helpers.curwin +local curwin = helpers.api.nvim_get_current_win describe("'langmap'", function() before_each(function() @@ -215,7 +215,7 @@ describe("'langmap'", function() feed('qa' .. command_string .. 'q') expect(expect_string) eq( - expect_macro or helpers.funcs.nvim_replace_termcodes(command_string, true, true, true), + expect_macro or helpers.fn.nvim_replace_termcodes(command_string, true, true, true), eval('@a') ) if setup_function then diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua index 421bd3ebb8..c97befdf07 100644 --- a/test/functional/editor/macro_spec.lua +++ b/test/functional/editor/macro_spec.lua @@ -6,10 +6,9 @@ local feed = helpers.feed local clear = helpers.clear local expect = helpers.expect local command = helpers.command -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local insert = helpers.insert -local curbufmeths = helpers.curbufmeths describe('macros', function() before_each(function() @@ -41,16 +40,19 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>q]] - eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[Q]] - eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[G3Q]] - eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[ggV3jQ]] - eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) + eq( + { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, + api.nvim_buf_get_lines(0, 0, -1, false) + ) end) it('can be replayed with @', function() @@ -60,16 +62,19 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>q]] - eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[Q]] - eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[G3@@]] - eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[ggV2j@@]] - eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) + eq( + { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, + api.nvim_buf_get_lines(0, 0, -1, false) + ) end) it('can be replayed with @q and @w', function() @@ -79,17 +84,17 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[qwA123<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[V3j@q]] - eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[gg]] feed [[Vj@w]] - eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('can be replayed with @q and @w visual-block', function() @@ -99,17 +104,17 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[qwA123<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[<C-v>3j@q]] - eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) feed [[gg]] feed [[<C-v>j@w]] - eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) end) @@ -122,13 +127,13 @@ describe('immediately after a macro has finished executing,', function() describe('reg_executing() from RPC returns an empty string', function() it('if the macro does not end with a <Nop> mapping', function() feed('@a') - eq('', funcs.reg_executing()) + eq('', fn.reg_executing()) end) it('if the macro ends with a <Nop> mapping', function() command('nnoremap 0 <Nop>') feed('@a') - eq('', funcs.reg_executing()) + eq('', fn.reg_executing()) end) end) @@ -139,7 +144,7 @@ describe('immediately after a macro has finished executing,', function() it('if the macro does not end with a <Nop> mapping', function() feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op - eq({ mode = 'n', blocking = false }, meths.get_mode()) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) expect('') eq('', eval('@a')) end) @@ -147,7 +152,7 @@ describe('immediately after a macro has finished executing,', function() it('if the macro ends with a <Nop> mapping', function() command('nnoremap 0 <Nop>') feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op - eq({ mode = 'n', blocking = false }, meths.get_mode()) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) expect('') eq('', eval('@a')) end) diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 67d8cc58ad..de905a86ba 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -1,16 +1,15 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local meths = helpers.meths -local curbufmeths = helpers.curbufmeths +local api = helpers.api local clear = helpers.clear local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local eq = helpers.eq local feed = helpers.feed local write_file = helpers.write_file local pcall_err = helpers.pcall_err local cursor = function() - return helpers.meths.win_get_cursor(0) + return helpers.api.nvim_win_get_cursor(0) end describe('named marks', function() @@ -29,13 +28,13 @@ describe('named marks', function() it('can be set', function() command('edit ' .. file1) command('mark a') - eq({ 1, 0 }, curbufmeths.get_mark('a')) + eq({ 1, 0 }, api.nvim_buf_get_mark(0, 'a')) feed('jmb') - eq({ 2, 0 }, curbufmeths.get_mark('b')) + eq({ 2, 0 }, api.nvim_buf_get_mark(0, 'b')) feed('jmB') - eq({ 3, 0 }, curbufmeths.get_mark('B')) + eq({ 3, 0 }, api.nvim_buf_get_mark(0, 'B')) command('4kc') - eq({ 4, 0 }, curbufmeths.get_mark('c')) + eq({ 4, 0 }, api.nvim_buf_get_mark(0, 'c')) end) it('errors when set out of range with :mark', function() @@ -105,7 +104,7 @@ describe('named marks', function() feed('mA') command('next') feed("'A") - eq(1, meths.get_current_buf().id) + eq(1, api.nvim_get_current_buf().id) eq({ 2, 0 }, cursor()) end) @@ -118,7 +117,7 @@ describe('named marks', function() feed('mA') command('next') feed('`A') - eq(1, meths.get_current_buf().id) + eq(1, api.nvim_get_current_buf().id) eq({ 2, 2 }, cursor()) end) @@ -131,7 +130,7 @@ describe('named marks', function() feed('mA') command('next') feed("g'A") - eq(1, meths.get_current_buf().id) + eq(1, api.nvim_get_current_buf().id) eq({ 2, 0 }, cursor()) end) @@ -144,7 +143,7 @@ describe('named marks', function() feed('mA') command('next') feed('g`A') - eq(1, meths.get_current_buf().id) + eq(1, api.nvim_get_current_buf().id) eq({ 2, 2 }, cursor()) end) @@ -158,7 +157,7 @@ describe('named marks', function() feed('mA') command('next') command("'A") - eq(1, meths.get_current_buf().id) + eq(1, api.nvim_get_current_buf().id) eq({ 2, 0 }, cursor()) end) @@ -268,59 +267,59 @@ describe('named marks', function() feed('jzfG') -- Fold from the second line to the end command('3mark a') feed('G') -- On top of the fold - assert(funcs.foldclosed('.') ~= -1) -- folded + assert(fn.foldclosed('.') ~= -1) -- folded feed("'a") - eq(-1, funcs.foldclosed('.')) + eq(-1, fn.foldclosed('.')) feed('zc') - assert(funcs.foldclosed('.') ~= -1) -- folded + assert(fn.foldclosed('.') ~= -1) -- folded -- TODO: remove this workaround after fixing #15873 feed('k`a') - eq(-1, funcs.foldclosed('.')) + eq(-1, fn.foldclosed('.')) feed('zc') - assert(funcs.foldclosed('.') ~= -1) -- folded + assert(fn.foldclosed('.') ~= -1) -- folded feed("kg'a") - eq(-1, funcs.foldclosed('.')) + eq(-1, fn.foldclosed('.')) feed('zc') - assert(funcs.foldclosed('.') ~= -1) -- folded + assert(fn.foldclosed('.') ~= -1) -- folded feed('kg`a') - eq(-1, funcs.foldclosed('.')) + eq(-1, fn.foldclosed('.')) end) it("do not open folds when moving to them doesn't move the cursor", function() command('edit ' .. file1) feed('jzfG') -- Fold from the second line to the end - assert(funcs.foldclosed('.') == 2) -- folded + assert(fn.foldclosed('.') == 2) -- folded feed('ma') feed("'a") feed('`a') feed("g'a") feed('g`a') -- should still be folded - eq(2, funcs.foldclosed('.')) + eq(2, fn.foldclosed('.')) end) it("getting '{ '} '( ') does not move cursor", function() - meths.buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) - meths.win_set_cursor(0, { 2, 0 }) - funcs.getpos("'{") - eq({ 2, 0 }, meths.win_get_cursor(0)) - funcs.getpos("'}") - eq({ 2, 0 }, meths.win_get_cursor(0)) - funcs.getpos("'(") - eq({ 2, 0 }, meths.win_get_cursor(0)) - funcs.getpos("')") - eq({ 2, 0 }, meths.win_get_cursor(0)) + api.nvim_buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) + api.nvim_win_set_cursor(0, { 2, 0 }) + fn.getpos("'{") + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) + fn.getpos("'}") + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) + fn.getpos("'(") + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) + fn.getpos("')") + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) end) it('in command range does not move cursor #19248', function() - meths.create_user_command('Test', ':', { range = true }) - meths.buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) - meths.win_set_cursor(0, { 2, 0 }) + api.nvim_create_user_command('Test', ':', { range = true }) + api.nvim_buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) + api.nvim_win_set_cursor(0, { 2, 0 }) command([['{,'}Test]]) - eq({ 2, 0 }, meths.win_get_cursor(0)) + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) end) end) diff --git a/test/functional/editor/meta_key_spec.lua b/test/functional/editor/meta_key_spec.lua index 3b66c8fc05..b57f5c3c35 100644 --- a/test/functional/editor/meta_key_spec.lua +++ b/test/functional/editor/meta_key_spec.lua @@ -4,7 +4,7 @@ local command = helpers.command local exec_lua = helpers.exec_lua local eval = helpers.eval local expect = helpers.expect -local funcs = helpers.funcs +local fn = helpers.fn local eq = helpers.eq describe('meta-keys #8226 #13042', function() @@ -66,11 +66,11 @@ describe('meta-keys #8226 #13042', function() command('inoremap <A-j> alt-j') feed('i<M-l> xxx <A-j><M-h>a<A-h>') expect('meta-l xxx alt-j') - eq({ 0, 1, 14, 0 }, funcs.getpos('.')) + eq({ 0, 1, 14, 0 }, fn.getpos('.')) -- Unmapped ALT-chord behaves as ESC+c. command('iunmap <M-l>') feed('0i<M-l>') - eq({ 0, 1, 2, 0 }, funcs.getpos('.')) + eq({ 0, 1, 2, 0 }, fn.getpos('.')) -- Unmapped ALT-chord has same `undo` characteristics as ESC+<key> command('0,$d') feed('ahello<M-.>') @@ -101,7 +101,7 @@ describe('meta-keys #8226 #13042', function() eq(meta_l_seq .. 'yyy' .. meta_l_seq .. 'alt-j', exec_lua([[return _G.input_data]])) eq('t', eval('mode(1)')) feed('<Esc>j') - eq({ 0, 2, 1, 0 }, funcs.getpos('.')) + eq({ 0, 2, 1, 0 }, fn.getpos('.')) eq('nt', eval('mode(1)')) end) diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua index d36db80bdf..06efe53718 100644 --- a/test/functional/editor/mode_cmdline_spec.lua +++ b/test/functional/editor/mode_cmdline_spec.lua @@ -2,11 +2,11 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, insert, funcs, eq, feed = - helpers.clear, helpers.insert, helpers.funcs, helpers.eq, helpers.feed +local clear, insert, fn, eq, feed = + helpers.clear, helpers.insert, helpers.fn, helpers.eq, helpers.feed local eval = helpers.eval local command = helpers.command -local meths = helpers.meths +local api = helpers.api describe('cmdline', function() before_each(clear) @@ -20,22 +20,22 @@ describe('cmdline', function() -- Yank 2 lines linewise, then paste to cmdline. feed([[<C-\><C-N>gg0yj:<C-R>0]]) -- <CR> inserted between lines, NOT after the final line. - eq('line1abc\rline2somemoretext', funcs.getcmdline()) + eq('line1abc\rline2somemoretext', fn.getcmdline()) -- Yank 2 lines charwise, then paste to cmdline. feed([[<C-\><C-N>gg05lyvj:<C-R>0]]) -- <CR> inserted between lines, NOT after the final line. - eq('abc\rline2', funcs.getcmdline()) + eq('abc\rline2', fn.getcmdline()) -- Yank 1 line linewise, then paste to cmdline. feed([[<C-\><C-N>ggyy:<C-R>0]]) -- No <CR> inserted. - eq('line1abc', funcs.getcmdline()) + eq('line1abc', fn.getcmdline()) end) it('pasting special register inserts <CR>, <NL>', function() feed([[:<C-R>="foo\nbar\rbaz"<CR>]]) - eq('foo\nbar\rbaz', funcs.getcmdline()) + eq('foo\nbar\rbaz', fn.getcmdline()) end) end) @@ -77,30 +77,30 @@ describe('cmdline', function() it('correctly clears start of the history', function() -- Regression test: check absence of the memory leak when clearing start of -- the history using cmdhist.c/clr_history(). - eq(1, funcs.histadd(':', 'foo')) - eq(1, funcs.histdel(':')) - eq('', funcs.histget(':', -1)) + eq(1, fn.histadd(':', 'foo')) + eq(1, fn.histdel(':')) + eq('', fn.histget(':', -1)) end) it('correctly clears end of the history', function() -- Regression test: check absence of the memory leak when clearing end of -- the history using cmdhist.c/clr_history(). - meths.set_option_value('history', 1, {}) - eq(1, funcs.histadd(':', 'foo')) - eq(1, funcs.histdel(':')) - eq('', funcs.histget(':', -1)) + api.nvim_set_option_value('history', 1, {}) + eq(1, fn.histadd(':', 'foo')) + eq(1, fn.histdel(':')) + eq('', fn.histget(':', -1)) end) it('correctly removes item from history', function() -- Regression test: check that cmdhist.c/del_history_idx() correctly clears -- history index after removing history entry. If it does not then deleting -- history will result in a double free. - eq(1, funcs.histadd(':', 'foo')) - eq(1, funcs.histadd(':', 'bar')) - eq(1, funcs.histadd(':', 'baz')) - eq(1, funcs.histdel(':', -2)) - eq(1, funcs.histdel(':')) - eq('', funcs.histget(':', -1)) + eq(1, fn.histadd(':', 'foo')) + eq(1, fn.histadd(':', 'bar')) + eq(1, fn.histadd(':', 'baz')) + eq(1, fn.histdel(':', -2)) + eq(1, fn.histdel(':')) + eq('', fn.histget(':', -1)) end) end) end) diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua index 8e06794093..414b289222 100644 --- a/test/functional/editor/put_spec.lua +++ b/test/functional/editor/put_spec.lua @@ -6,12 +6,12 @@ local insert = helpers.insert local feed = helpers.feed local expect = helpers.expect local eq = helpers.eq -local map = helpers.tbl_map -local filter = helpers.tbl_filter +local map = vim.tbl_map +local filter = vim.tbl_filter local feed_command = helpers.feed_command local command = helpers.command local curbuf_contents = helpers.curbuf_contents -local funcs = helpers.funcs +local fn = helpers.fn local dedent = helpers.dedent local function reset() @@ -21,9 +21,9 @@ local function reset() Line of words 2]]) command('goto 1') feed('itest_string.<esc>u') - funcs.setreg('a', 'test_stringa', 'V') - funcs.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b') - funcs.setreg('"', 'test_string"', 'v') + fn.setreg('a', 'test_stringa', 'V') + fn.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b') + fn.setreg('"', 'test_string"', 'v') end -- We check the last inserted register ". in each of these tests because it is @@ -35,12 +35,12 @@ describe('put command', function() before_each(reset) local function visual_marks_zero() - for _, v in pairs(funcs.getpos("'<")) do + for _, v in pairs(fn.getpos("'<")) do if v ~= 0 then return false end end - for _, v in pairs(funcs.getpos("'>")) do + for _, v in pairs(fn.getpos("'>")) do if v ~= 0 then return false end @@ -55,7 +55,7 @@ describe('put command', function() extra_setup() end local init_contents = curbuf_contents() - local init_cursorpos = funcs.getcurpos() + local init_cursorpos = fn.getcurpos() local assert_no_change = function(exception_table, after_undo) expect(init_contents) -- When putting the ". register forwards, undo doesn't move @@ -65,7 +65,7 @@ describe('put command', function() -- one place to the right (unless we were at the end of the -- line when we pasted). if not (exception_table.undo_position and after_undo) then - eq(init_cursorpos, funcs.getcurpos()) + eq(init_cursorpos, fn.getcurpos()) end end @@ -74,7 +74,7 @@ describe('put command', function() if extra_setup then extra_setup() end - local orig_dotstr = funcs.getreg('.') + local orig_dotstr = fn.getreg('.') helpers.ok(visual_marks_zero()) -- Make sure every test starts from the same conditions assert_no_change(test.exception_table, false) @@ -89,7 +89,7 @@ describe('put command', function() -- If we paste the ". register with a count we can't avoid -- changing this register, hence avoid this check. if not test.exception_table.dot_reg_changed then - eq(orig_dotstr, funcs.getreg('.')) + eq(orig_dotstr, fn.getreg('.')) end -- Doing something, undoing it, and then redoing it should @@ -105,7 +105,7 @@ describe('put command', function() end if test.exception_table.undo_position then - funcs.setpos('.', init_cursorpos) + fn.setpos('.', init_cursorpos) end if was_cli then feed('@:') @@ -151,7 +151,7 @@ describe('put command', function() -- it was in. -- This returns the cursor position that would leave the 'x' in that -- place if we feed 'ix<esc>' and the string existed before it. - for linenum, line in pairs(funcs.split(expect_string, '\n', 1)) do + for linenum, line in pairs(fn.split(expect_string, '\n', 1)) do local column = line:find('x') if column then return { linenum, column }, expect_string:gsub('x', '') @@ -184,16 +184,16 @@ describe('put command', function() return function(exception_table, after_redo) expect(expect_string) - -- Have to use getcurpos() instead of curwinmeths.get_cursor() in + -- Have to use getcurpos() instead of api.nvim_win_get_cursor(0) in -- order to account for virtualedit. -- We always want the curswant element in getcurpos(), which is -- sometimes different to the column element in - -- curwinmeths.get_cursor(). + -- api.nvim_win_get_cursor(0). -- NOTE: The ".gp command leaves the cursor after the pasted text -- when running, but does not when the command is redone with the -- '.' command. if not (exception_table.redo_position and after_redo) then - local actual_position = funcs.getcurpos() + local actual_position = fn.getcurpos() eq(cursor_position, { actual_position[2], actual_position[5] }) end end @@ -349,7 +349,7 @@ describe('put command', function() local prev_line local rettab = {} local string_found = false - for _, line in pairs(funcs.split(string, '\n', 1)) do + for _, line in pairs(fn.split(string, '\n', 1)) do if line:find('test_string') then string_found = true table.insert(rettab, line) @@ -476,7 +476,7 @@ describe('put command', function() local prev_line local rettab = {} local prev_in_block = false - for _, line in pairs(funcs.split(expect_base, '\n', 1)) do + for _, line in pairs(fn.split(expect_base, '\n', 1)) do if line:find('test_string') then if prev_line then prev_line = prev_line:gsub('x', '') @@ -524,10 +524,10 @@ describe('put command', function() test_expect(exception_table, after_redo) if selection_string then if not conversion_table.put_backwards then - eq(selection_string, funcs.getreg('"')) + eq(selection_string, fn.getreg('"')) end else - eq('test_string"', funcs.getreg('"')) + eq('test_string"', fn.getreg('"')) end end end @@ -657,10 +657,10 @@ describe('put command', function() xtest_string"]], 'put', function() - funcs.setline('$', ' Line of words 2') + fn.setline('$', ' Line of words 2') -- Set curswant to '8' to be at the end of the tab character -- This is where the cursor is put back after the 'u' command. - funcs.setpos('.', { 0, 2, 1, 0, 8 }) + fn.setpos('.', { 0, 2, 1, 0, 8 }) command('set autoindent') end ) @@ -671,9 +671,9 @@ describe('put command', function() Line of words 1 test_stringx" Line of words 2]] run_normal_mode_tests(test_string, 'p', function() - funcs.setline('$', ' Line of words 2') + fn.setline('$', ' Line of words 2') command('setlocal virtualedit=all') - funcs.setpos('.', { 0, 2, 1, 2, 3 }) + fn.setpos('.', { 0, 2, 1, 2, 3 }) end) end) @@ -683,9 +683,9 @@ describe('put command', function() Line of words 1 test_stringx" Line of words 2]] run_normal_mode_tests(test_string, 'p', function() - funcs.setline('$', ' Line of words 2') + fn.setline('$', ' Line of words 2') command('setlocal virtualedit=all') - funcs.setpos('.', { 0, 1, 16, 1, 17 }) + fn.setpos('.', { 0, 1, 16, 1, 17 }) end, true) end) @@ -699,7 +699,7 @@ describe('put command', function() describe('over trailing newline', function() local test_string = 'Line of test_stringx"Line of words 2' run_normal_mode_tests(test_string, 'v$p', function() - funcs.setpos('.', { 0, 1, 9, 0, 9 }) + fn.setpos('.', { 0, 1, 9, 0, 9 }) end, nil, 'words 1\n') end) describe('linewise mode', function() @@ -720,7 +720,7 @@ describe('put command', function() expect_vis_linewise ), function() - funcs.setpos('.', { 0, 1, 1, 0, 1 }) + fn.setpos('.', { 0, 1, 1, 0, 1 }) end ) @@ -732,7 +732,7 @@ describe('put command', function() return function(exception_table, after_redo) test_expect(exception_table, after_redo) if not conversion_table.put_backwards then - eq('Line of words 1\n', funcs.getreg('"')) + eq('Line of words 1\n', fn.getreg('"')) end end end @@ -749,7 +749,7 @@ describe('put command', function() ), function() feed('i test_string.<esc>u') - funcs.setreg('"', ' test_string"', 'v') + fn.setreg('"', ' test_string"', 'v') end ) end) @@ -767,7 +767,7 @@ describe('put command', function() return function(e, c) test_expect(e, c) if not conversion_table.put_backwards then - eq('Lin\nLin', funcs.getreg('"')) + eq('Lin\nLin', fn.getreg('"')) end end end @@ -804,7 +804,7 @@ describe('put command', function() expect_block_creator ), function() - funcs.setpos('.', { 0, 2, 1, 0, 1 }) + fn.setpos('.', { 0, 2, 1, 0, 1 }) end ) @@ -820,16 +820,16 @@ describe('put command', function() feed('u') -- Have to use feed('u') here to set curswant, because -- ex_undo() doesn't do that. - eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos()) + eq({ 0, 1, 1, 0, 1 }, fn.getcurpos()) feed('<C-r>') - eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos()) + eq({ 0, 1, 1, 0, 1 }, fn.getcurpos()) end end run_test_variations( create_test_defs(undo_redo_no, '<C-v>kllp', create_p_action, test_base, assertion_creator), function() - funcs.setpos('.', { 0, 2, 1, 0, 1 }) + fn.setpos('.', { 0, 2, 1, 0, 1 }) end ) end) @@ -841,9 +841,9 @@ describe('put command', function() Line of words 1 test_stringx" Line of words 2]] run_normal_mode_tests(base_expect_string, 'vp', function() - funcs.setline('$', ' Line of words 2') + fn.setline('$', ' Line of words 2') command('setlocal virtualedit=all') - funcs.setpos('.', { 0, 2, 1, 2, 3 }) + fn.setpos('.', { 0, 2, 1, 2, 3 }) end, nil, ' ') end) describe('after end of line', function() @@ -852,7 +852,7 @@ describe('put command', function() Line of words 2]] run_normal_mode_tests(base_expect_string, 'vp', function() command('setlocal virtualedit=all') - funcs.setpos('.', { 0, 1, 16, 2, 18 }) + fn.setpos('.', { 0, 1, 16, 2, 18 }) end, true, ' ') end) end) @@ -917,14 +917,14 @@ describe('put command', function() -- Even if the last character is a multibyte character. reset() - funcs.setline(1, 'helloม') + fn.setline(1, 'helloม') bell_test(function() feed('$".gp') end) end) it('should not ring the bell with gp and end of file', function() - funcs.setpos('.', { 0, 2, 1, 0 }) + fn.setpos('.', { 0, 2, 1, 0 }) bell_test(function() feed('$vl".gp') end) @@ -942,9 +942,9 @@ describe('put command', function() end) it('should restore cursor position after undo of ".p', function() - local origpos = funcs.getcurpos() + local origpos = fn.getcurpos() feed('".pu') - eq(origpos, funcs.getcurpos()) + eq(origpos, fn.getcurpos()) end) it("should be unaffected by 'autoindent' with V\".2p", function() diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index f632bbb40f..f64e099344 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -8,9 +8,9 @@ local neq = helpers.neq local feed = helpers.feed local eval = helpers.eval local exec = helpers.exec -local funcs = helpers.funcs -local meths = helpers.meths -local curwin = helpers.curwin +local fn = helpers.fn +local api = helpers.api +local curwin = helpers.api.nvim_get_current_win local assert_alive = helpers.assert_alive describe('tabpage', function() @@ -74,29 +74,29 @@ describe('tabpage', function() end) it('nvim_win_close and nvim_win_hide update tabline #20285', function() - eq(1, #meths.list_tabpages()) - eq({ 1, 1 }, funcs.win_screenpos(0)) + eq(1, #api.nvim_list_tabpages()) + eq({ 1, 1 }, fn.win_screenpos(0)) local win1 = curwin().id command('tabnew') - eq(2, #meths.list_tabpages()) - eq({ 2, 1 }, funcs.win_screenpos(0)) + eq(2, #api.nvim_list_tabpages()) + eq({ 2, 1 }, fn.win_screenpos(0)) local win2 = curwin().id - meths.win_close(win1, true) + api.nvim_win_close(win1, true) eq(win2, curwin().id) - eq(1, #meths.list_tabpages()) - eq({ 1, 1 }, funcs.win_screenpos(0)) + eq(1, #api.nvim_list_tabpages()) + eq({ 1, 1 }, fn.win_screenpos(0)) command('tabnew') - eq(2, #meths.list_tabpages()) - eq({ 2, 1 }, funcs.win_screenpos(0)) + eq(2, #api.nvim_list_tabpages()) + eq({ 2, 1 }, fn.win_screenpos(0)) local win3 = curwin().id - meths.win_hide(win2) + api.nvim_win_hide(win2) eq(win3, curwin().id) - eq(1, #meths.list_tabpages()) - eq({ 1, 1 }, funcs.win_screenpos(0)) + eq(1, #api.nvim_list_tabpages()) + eq({ 1, 1 }, fn.win_screenpos(0)) end) it('switching tabpage after setting laststatus=3 #19591', function() @@ -135,15 +135,15 @@ describe('tabpage', function() it(':tabmove handles modifiers and addr', function() command('tabnew | tabnew | tabnew') - eq(4, funcs.nvim_tabpage_get_number(0)) + eq(4, fn.nvim_tabpage_get_number(0)) command(' silent :keepalt :: ::: silent! - tabmove') - eq(3, funcs.nvim_tabpage_get_number(0)) + eq(3, fn.nvim_tabpage_get_number(0)) command(' silent :keepalt :: ::: silent! -2 tabmove') - eq(1, funcs.nvim_tabpage_get_number(0)) + eq(1, fn.nvim_tabpage_get_number(0)) end) it(':tabs does not overflow IObuff with long path with comma #20850', function() - meths.buf_set_name(0, ('x'):rep(1024) .. ',' .. ('x'):rep(1024)) + api.nvim_buf_set_name(0, ('x'):rep(1024) .. ',' .. ('x'):rep(1024)) command('tabs') assert_alive() end) diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index a2dc34a6b9..c101bf02a0 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -8,12 +8,12 @@ local eq = helpers.eq local feed = helpers.feed local feed_command = helpers.feed_command local insert = helpers.insert -local funcs = helpers.funcs +local fn = helpers.fn local exec = helpers.exec local exec_lua = helpers.exec_lua local function lastmessage() - local messages = funcs.split(funcs.execute('messages'), '\n') + local messages = fn.split(fn.execute('messages'), '\n') return messages[#messages] end diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua index b3c0584568..5eb8d49c74 100644 --- a/test/functional/ex_cmds/append_spec.lua +++ b/test/functional/ex_cmds/append_spec.lua @@ -5,21 +5,20 @@ local dedent = helpers.dedent local exec = helpers.exec local feed = helpers.feed local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command -local curbufmeths = helpers.curbufmeths -local meths = helpers.meths +local api = helpers.api local Screen = require('test.functional.ui.screen') local cmdtest = function(cmd, prep, ret1) describe(':' .. cmd, function() before_each(function() clear() - curbufmeths.set_lines(0, 1, true, { 'foo', 'bar', 'baz' }) + api.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' }) end) local buffer_contents = function() - return curbufmeths.get_lines(0, -1, false) + return api.nvim_buf_get_lines(0, 0, -1, false) end it(cmd .. 's' .. prep .. ' the current line by default', function() @@ -39,15 +38,15 @@ local cmdtest = function(cmd, prep, ret1) feed(':' .. hisline .. '<CR>') feed(':' .. cmd .. '<CR>abc<CR>def<C-f>') eq({ 'def' }, buffer_contents()) - eq(hisline, funcs.histget(':', -2)) - eq(cmd, funcs.histget(':')) + eq(hisline, fn.histget(':', -2)) + eq(cmd, fn.histget(':')) -- Test that command-line window was launched - eq('nofile', meths.get_option_value('buftype', {})) - eq('n', funcs.mode(1)) + eq('nofile', api.nvim_get_option_value('buftype', {})) + eq('n', fn.mode(1)) feed('<CR>') - eq('c', funcs.mode(1)) + eq('c', fn.mode(1)) feed('.<CR>') - eq('n', funcs.mode(1)) + eq('n', fn.mode(1)) eq(ret1, buffer_contents()) end) end) diff --git a/test/functional/ex_cmds/arg_spec.lua b/test/functional/ex_cmds/arg_spec.lua index 1cb758cd23..810b001ec0 100644 --- a/test/functional/ex_cmds/arg_spec.lua +++ b/test/functional/ex_cmds/arg_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs +local eq, command, fn = helpers.eq, helpers.command, helpers.fn local ok = helpers.ok local clear = helpers.clear @@ -13,17 +13,17 @@ describe(':argument', function() helpers.feed([[<C-\><C-N>]]) command('argadd') helpers.feed([[<C-\><C-N>]]) - local bufname_before = funcs.bufname('%') - local bufnr_before = funcs.bufnr('%') + local bufname_before = fn.bufname('%') + local bufnr_before = fn.bufnr('%') helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity command('argument 1') helpers.feed([[<C-\><C-N>]]) - local bufname_after = funcs.bufname('%') - local bufnr_after = funcs.bufnr('%') + local bufname_after = fn.bufname('%') + local bufnr_after = fn.bufnr('%') eq('[' .. bufname_before .. ']', helpers.eval('trim(execute("args"))')) - ok(funcs.line('$') > 1) + ok(fn.line('$') > 1) eq(bufname_before, bufname_after) eq(bufnr_before, bufnr_after) end) diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index a6ee5afe49..1815c672dc 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -1,6 +1,5 @@ -- Specs for :cd, :tcd, :lcd and getcwd() -local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq @@ -56,7 +55,7 @@ for _, cmd in ipairs { 'cd', 'chdir' } do after_each(function() for _, d in pairs(directories) do - luv.fs_rmdir(d) + vim.uv.fs_rmdir(d) end end) diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua index c1a4fee38d..da7d686e5b 100644 --- a/test/functional/ex_cmds/cmd_map_spec.lua +++ b/test/functional/ex_cmds/cmd_map_spec.lua @@ -4,7 +4,7 @@ local feed = helpers.feed local eq = helpers.eq local expect = helpers.expect local eval = helpers.eval -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert local write_file = helpers.write_file local exc_exec = helpers.exc_exec @@ -329,12 +329,12 @@ describe('mappings with <Cmd>', function() {1:~ }|*5 {4:-- VISUAL --} | ]]) - eq('v', funcs.mode(1)) + eq('v', fn.mode(1)) -- can invoke operator, ending visual mode feed('<F5>') - eq('n', funcs.mode(1)) - eq({ 'some short l' }, funcs.getreg('a', 1, 1)) + eq('n', fn.mode(1)) + eq({ 'some short l' }, fn.getreg('a', 1, 1)) -- error doesn't interrupt visual mode feed('ggvw<F6>') @@ -356,7 +356,7 @@ describe('mappings with <Cmd>', function() {1:~ }|*5 {4:-- VISUAL --} | ]]) - eq('v', funcs.mode(1)) + eq('v', fn.mode(1)) feed('<F7>') screen:expect([[ so{5:me short lines} | @@ -364,7 +364,7 @@ describe('mappings with <Cmd>', function() {1:~ }|*5 {4:-- VISUAL --} | ]]) - eq('v', funcs.mode(1)) + eq('v', fn.mode(1)) -- startinsert gives "-- (insert) VISUAL --" mode feed('<F8>') @@ -390,17 +390,17 @@ describe('mappings with <Cmd>', function() {1:~ }|*5 {4:-- SELECT --} | ]]) - eq('s', funcs.mode(1)) + eq('s', fn.mode(1)) -- visual mapping in select mode restart select mode after operator feed('<F5>') - eq('s', funcs.mode(1)) - eq({ 'some short l' }, funcs.getreg('a', 1, 1)) + eq('s', fn.mode(1)) + eq({ 'some short l' }, fn.getreg('a', 1, 1)) -- select mode mapping works, and does not restart select mode feed('<F2>') - eq('n', funcs.mode(1)) - eq({ 'some short l' }, funcs.getreg('b', 1, 1)) + eq('n', fn.mode(1)) + eq({ 'some short l' }, fn.getreg('b', 1, 1)) -- error doesn't interrupt temporary visual mode feed('<esc>ggvw<c-g><F6>') @@ -423,7 +423,7 @@ describe('mappings with <Cmd>', function() {4:-- VISUAL --} | ]]) -- quirk: restoration of select mode is not performed - eq('v', funcs.mode(1)) + eq('v', fn.mode(1)) -- error doesn't interrupt select mode feed('<esc>ggvw<c-g><F1>') @@ -446,7 +446,7 @@ describe('mappings with <Cmd>', function() {4:-- SELECT --} | ]]) -- quirk: restoration of select mode is not performed - eq('s', funcs.mode(1)) + eq('s', fn.mode(1)) feed('<F7>') screen:expect([[ @@ -455,7 +455,7 @@ describe('mappings with <Cmd>', function() {1:~ }|*5 {4:-- SELECT --} | ]]) - eq('s', funcs.mode(1)) + eq('s', fn.mode(1)) -- startinsert gives "-- SELECT (insert) --" mode feed('<F8>') @@ -475,11 +475,11 @@ describe('mappings with <Cmd>', function() expect([[ lines of test text]]) - eq({ 'some short ' }, funcs.getreg('"', 1, 1)) + eq({ 'some short ' }, fn.getreg('"', 1, 1)) feed('.') expect([[ test text]]) - eq({ 'lines', 'of ' }, funcs.getreg('"', 1, 1)) + eq({ 'lines', 'of ' }, fn.getreg('"', 1, 1)) feed('uu') expect([[ some short lines @@ -505,7 +505,7 @@ describe('mappings with <Cmd>', function() feed('"bd<F7>') expect([[ soest text]]) - eq(funcs.getreg('b', 1, 1), { 'me short lines', 'of t' }) + eq(fn.getreg('b', 1, 1), { 'me short lines', 'of t' }) -- startinsert aborts operator feed('d<F8>') @@ -561,7 +561,7 @@ describe('mappings with <Cmd>', function() of stuff test text]]) feed('<F5>') - eq(funcs.getreg('a', 1, 1), { 'deed some short little lines', 'of stuff t' }) + eq(fn.getreg('a', 1, 1), { 'deed some short little lines', 'of stuff t' }) -- still in insert screen:expect([[ diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 821c8cf593..15fbb750f6 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local assert_alive = helpers.assert_alive -local clear, nvim, source = helpers.clear, helpers.nvim, helpers.source +local clear, source = helpers.clear, helpers.source +local api = helpers.api local insert = helpers.insert local eq, next_msg = helpers.eq, helpers.next_msg local exc_exec = helpers.exc_exec @@ -13,8 +14,8 @@ describe('Vimscript dictionary notifications', function() before_each(function() clear() - channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) end) -- the same set of tests are applied to top-level dictionaries(g:, b:, w: and @@ -59,7 +60,7 @@ describe('Vimscript dictionary notifications', function() local function verify_echo() -- helper to verify that no notifications are sent after certain change -- to a dict - nvim('command', "call rpcnotify(g:channel, 'echo')") + command("call rpcnotify(g:channel, 'echo')") eq({ 'notification', 'echo', {} }, next_msg()) end @@ -134,7 +135,7 @@ describe('Vimscript dictionary notifications', function() it('is triggered by remove()', function() update('= "test"') verify_value({ new = 'test' }) - nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + command('call remove(' .. dict_expr .. ', "watched")') verify_value({ old = 'test' }) end) @@ -142,14 +143,14 @@ describe('Vimscript dictionary notifications', function() it('is triggered by remove() when updated with nvim_*_var', function() update_with_api('"test"') verify_value({ new = 'test' }) - nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + command('call remove(' .. dict_expr .. ', "watched")') verify_value({ old = 'test' }) end) it('is triggered by remove() when updated with vim.g', function() update_with_vim_g('= "test"') verify_value({ new = 'test' }) - nvim('command', 'call remove(' .. dict_expr .. ', "watched")') + command('call remove(' .. dict_expr .. ', "watched")') verify_value({ old = 'test' }) end) end @@ -157,7 +158,7 @@ describe('Vimscript dictionary notifications', function() it('is triggered by extend()', function() update('= "xtend"') verify_value({ new = 'xtend' }) - nvim('command', [[ + command([[ call extend(]] .. dict_expr .. [[, {'watched': 'xtend2', 'watched2': 5, 'watched3': 'a'}) ]]) verify_value({ old = 'xtend', new = 'xtend2' }) @@ -293,17 +294,17 @@ describe('Vimscript dictionary notifications', function() end) it('invokes all callbacks when the key is changed', function() - nvim('command', 'let g:key = "value"') + command('let g:key = "value"') eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) end) it('only removes watchers that fully match dict, key and callback', function() - nvim('command', 'let g:key = "value"') + command('let g:key = "value"') eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) - nvim('command', 'call dictwatcherdel(g:, "key", "g:Watcher1")') - nvim('command', 'let g:key = "v2"') + command('call dictwatcherdel(g:, "key", "g:Watcher1")') + command('let g:key = "v2"') eq({ 'notification', '2', { 'key', { old = 'value', new = 'v2' } } }, next_msg()) end) end) diff --git a/test/functional/ex_cmds/echo_spec.lua b/test/functional/ex_cmds/echo_spec.lua index 4698d3de62..e9176a6204 100644 --- a/test/functional/ex_cmds/echo_spec.lua +++ b/test/functional/ex_cmds/echo_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq -local NIL = helpers.NIL +local NIL = vim.NIL local eval = helpers.eval local clear = helpers.clear -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local source = helpers.source local dedent = helpers.dedent local command = helpers.command @@ -17,12 +17,12 @@ describe(':echo :echon :echomsg :echoerr', function() local fn_tbl = { 'String', 'StringN', 'StringMsg', 'StringErr' } local function assert_same_echo_dump(expected, input, use_eval) for _, v in pairs(fn_tbl) do - eq(expected, use_eval and eval(v .. '(' .. input .. ')') or funcs[v](input)) + eq(expected, use_eval and eval(v .. '(' .. input .. ')') or fn[v](input)) end end local function assert_matches_echo_dump(expected, input, use_eval) for _, v in pairs(fn_tbl) do - matches(expected, use_eval and eval(v .. '(' .. input .. ')') or funcs[v](input)) + matches(expected, use_eval and eval(v .. '(' .. input .. ')') or fn[v](input)) end end @@ -68,21 +68,21 @@ describe(':echo :echon :echomsg :echoerr', function() eq('v:true', eval('String(v:true)')) eq('v:false', eval('String(v:false)')) eq('v:null', eval('String(v:null)')) - eq('v:true', funcs.String(true)) - eq('v:false', funcs.String(false)) - eq('v:null', funcs.String(NIL)) + eq('v:true', fn.String(true)) + eq('v:false', fn.String(false)) + eq('v:null', fn.String(NIL)) eq('v:true', eval('StringMsg(v:true)')) eq('v:false', eval('StringMsg(v:false)')) eq('v:null', eval('StringMsg(v:null)')) - eq('v:true', funcs.StringMsg(true)) - eq('v:false', funcs.StringMsg(false)) - eq('v:null', funcs.StringMsg(NIL)) + eq('v:true', fn.StringMsg(true)) + eq('v:false', fn.StringMsg(false)) + eq('v:null', fn.StringMsg(NIL)) eq('v:true', eval('StringErr(v:true)')) eq('v:false', eval('StringErr(v:false)')) eq('v:null', eval('StringErr(v:null)')) - eq('v:true', funcs.StringErr(true)) - eq('v:false', funcs.StringErr(false)) - eq('v:null', funcs.StringErr(NIL)) + eq('v:true', fn.StringErr(true)) + eq('v:false', fn.StringErr(false)) + eq('v:null', fn.StringErr(NIL)) end) it('dumps values with at most six digits after the decimal point', function() @@ -223,7 +223,7 @@ describe(':echo :echon :echomsg :echoerr', function() end) it('does not crash or halt when dumping partials with reference cycles in self', function() - meths.set_var('d', { v = true }) + api.nvim_set_var('d', { v = true }) eq( dedent( [[ @@ -251,7 +251,7 @@ describe(':echo :echon :echomsg :echoerr', function() end) it('does not crash or halt when dumping partials with reference cycles in arguments', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') -- Regression: the below line used to crash (add returns original list and -- there was error in dumping partials). Tested explicitly in @@ -269,8 +269,8 @@ describe(':echo :echon :echomsg :echoerr', function() it( 'does not crash or halt when dumping partials with reference cycles in self and arguments', function() - meths.set_var('d', { v = true }) - meths.set_var('l', {}) + api.nvim_set_var('d', { v = true }) + api.nvim_set_var('l', {}) eval('add(l, l)') eval('add(l, function("Test1", l))') eval('add(l, function("Test1", d))') @@ -305,13 +305,13 @@ describe(':echo :echon :echomsg :echoerr', function() end) it('does not error when dumping recursive lists', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') eq(0, exc_exec('echo String(l)')) end) it('dumps recursive lists without error', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') eq('[[...@0]]', exec_capture('echo String(l)')) eq('[[[...@1]]]', exec_capture('echo String([l])')) @@ -335,13 +335,13 @@ describe(':echo :echon :echomsg :echoerr', function() end) it('does not error when dumping recursive dictionaries', function() - meths.set_var('d', { d = 1 }) + api.nvim_set_var('d', { d = 1 }) eval('extend(d, {"d": d})') eq(0, exc_exec('echo String(d)')) end) it('dumps recursive dictionaries without the error', function() - meths.set_var('d', { d = 1 }) + api.nvim_set_var('d', { d = 1 }) eval('extend(d, {"d": d})') eq("{'d': {...@0}}", exec_capture('echo String(d)')) eq("{'out': {'d': {...@1}}}", exec_capture('echo String({"out": d})')) @@ -358,43 +358,43 @@ describe(':echo :echon :echomsg :echoerr', function() it('displays hex as hex', function() -- Regression: due to missing (uint8_t) cast \x80 was represented as -- ~@<80>. - eq('<80>', funcs.String(chr(0x80))) - eq('<81>', funcs.String(chr(0x81))) - eq('<8e>', funcs.String(chr(0x8e))) - eq('<c2>', funcs.String(('«'):sub(1, 1))) - eq('«', funcs.String(('«'):sub(1, 2))) - - eq('<80>', funcs.StringMsg(chr(0x80))) - eq('<81>', funcs.StringMsg(chr(0x81))) - eq('<8e>', funcs.StringMsg(chr(0x8e))) - eq('<c2>', funcs.StringMsg(('«'):sub(1, 1))) - eq('«', funcs.StringMsg(('«'):sub(1, 2))) + eq('<80>', fn.String(chr(0x80))) + eq('<81>', fn.String(chr(0x81))) + eq('<8e>', fn.String(chr(0x8e))) + eq('<c2>', fn.String(('«'):sub(1, 1))) + eq('«', fn.String(('«'):sub(1, 2))) + + eq('<80>', fn.StringMsg(chr(0x80))) + eq('<81>', fn.StringMsg(chr(0x81))) + eq('<8e>', fn.StringMsg(chr(0x8e))) + eq('<c2>', fn.StringMsg(('«'):sub(1, 1))) + eq('«', fn.StringMsg(('«'):sub(1, 2))) end) it('displays ASCII control characters using ^X notation', function() - eq('^C', funcs.String(ctrl('c'))) - eq('^A', funcs.String(ctrl('a'))) - eq('^F', funcs.String(ctrl('f'))) - eq('^C', funcs.StringMsg(ctrl('c'))) - eq('^A', funcs.StringMsg(ctrl('a'))) - eq('^F', funcs.StringMsg(ctrl('f'))) + eq('^C', fn.String(ctrl('c'))) + eq('^A', fn.String(ctrl('a'))) + eq('^F', fn.String(ctrl('f'))) + eq('^C', fn.StringMsg(ctrl('c'))) + eq('^A', fn.StringMsg(ctrl('a'))) + eq('^F', fn.StringMsg(ctrl('f'))) end) it('prints CR, NL and tab as-is', function() - eq('\n', funcs.String('\n')) - eq('\r', funcs.String('\r')) - eq('\t', funcs.String('\t')) + eq('\n', fn.String('\n')) + eq('\r', fn.String('\r')) + eq('\t', fn.String('\t')) end) it('prints non-printable UTF-8 in <> notation', function() -- SINGLE SHIFT TWO, unicode control - eq('<8e>', funcs.String(funcs.nr2char(0x8E))) - eq('<8e>', funcs.StringMsg(funcs.nr2char(0x8E))) + eq('<8e>', fn.String(fn.nr2char(0x8E))) + eq('<8e>', fn.StringMsg(fn.nr2char(0x8E))) -- Surrogate pair: U+1F0A0 PLAYING CARD BACK is represented in UTF-16 as -- 0xD83C 0xDCA0. This is not valid in UTF-8. - eq('<d83c>', funcs.String(funcs.nr2char(0xD83C))) - eq('<dca0>', funcs.String(funcs.nr2char(0xDCA0))) - eq('<d83c><dca0>', funcs.String(funcs.nr2char(0xD83C) .. funcs.nr2char(0xDCA0))) - eq('<d83c>', funcs.StringMsg(funcs.nr2char(0xD83C))) - eq('<dca0>', funcs.StringMsg(funcs.nr2char(0xDCA0))) - eq('<d83c><dca0>', funcs.StringMsg(funcs.nr2char(0xD83C) .. funcs.nr2char(0xDCA0))) + eq('<d83c>', fn.String(fn.nr2char(0xD83C))) + eq('<dca0>', fn.String(fn.nr2char(0xDCA0))) + eq('<d83c><dca0>', fn.String(fn.nr2char(0xD83C) .. fn.nr2char(0xDCA0))) + eq('<d83c>', fn.StringMsg(fn.nr2char(0xD83C))) + eq('<dca0>', fn.StringMsg(fn.nr2char(0xDCA0))) + eq('<d83c><dca0>', fn.StringMsg(fn.nr2char(0xD83C) .. fn.nr2char(0xDCA0))) end) end) end) diff --git a/test/functional/ex_cmds/edit_spec.lua b/test/functional/ex_cmds/edit_spec.lua index 48ae99a0fa..b927fa418a 100644 --- a/test/functional/ex_cmds/edit_spec.lua +++ b/test/functional/ex_cmds/edit_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs +local eq, command, fn = helpers.eq, helpers.command, helpers.fn local ok = helpers.ok local clear = helpers.clear local feed = helpers.feed @@ -12,15 +12,15 @@ describe(':edit', function() it('without arguments does not restart :terminal buffer', function() command('terminal') feed([[<C-\><C-N>]]) - local bufname_before = funcs.bufname('%') - local bufnr_before = funcs.bufnr('%') + local bufname_before = fn.bufname('%') + local bufnr_before = fn.bufnr('%') helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity command('edit') - local bufname_after = funcs.bufname('%') - local bufnr_after = funcs.bufnr('%') - ok(funcs.line('$') > 1) + local bufname_after = fn.bufname('%') + local bufnr_after = fn.bufnr('%') + ok(fn.line('$') > 1) eq(bufname_before, bufname_after) eq(bufnr_before, bufnr_after) end) diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua index 030816c6cb..d16a52ee62 100644 --- a/test/functional/ex_cmds/excmd_spec.lua +++ b/test/functional/ex_cmds/excmd_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local command = helpers.command local eq = helpers.eq local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -49,15 +49,15 @@ describe('Ex cmds', function() it(':def is an unknown command #23149', function() eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def')) - eq(1, funcs.exists(':d')) - eq('delete', funcs.fullcommand('d')) - eq(1, funcs.exists(':de')) - eq('delete', funcs.fullcommand('de')) - eq(0, funcs.exists(':def')) - eq('', funcs.fullcommand('def')) - eq(1, funcs.exists(':defe')) - eq('defer', funcs.fullcommand('defe')) - eq(2, funcs.exists(':defer')) - eq('defer', funcs.fullcommand('defer')) + eq(1, fn.exists(':d')) + eq('delete', fn.fullcommand('d')) + eq(1, fn.exists(':de')) + eq('delete', fn.fullcommand('de')) + eq(0, fn.exists(':def')) + eq('', fn.fullcommand('def')) + eq(1, fn.exists(':defe')) + eq('defer', fn.fullcommand('defe')) + eq(2, fn.exists(':defer')) + eq('defer', fn.fullcommand('defer')) end) end) diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua index bfcfccda7b..a48c408600 100644 --- a/test/functional/ex_cmds/file_spec.lua +++ b/test/functional/ex_cmds/file_spec.lua @@ -1,14 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local rmdir = helpers.rmdir local mkdir = helpers.mkdir describe(':file', function() - local swapdir = luv.cwd() .. '/Xtest-file_spec' + local swapdir = vim.uv.cwd() .. '/Xtest-file_spec' before_each(function() clear() rmdir(swapdir) @@ -30,6 +29,6 @@ describe(':file', function() command('edit! ' .. testfile) -- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows. command('file ' .. testfile_renamed) - eq(testfile_renamed .. '.swp', string.match(funcs.execute('swapname'), '[^%%]+$')) + eq(testfile_renamed .. '.swp', string.match(fn.execute('swapname'), '[^%%]+$')) end) end) diff --git a/test/functional/ex_cmds/help_spec.lua b/test/functional/ex_cmds/help_spec.lua index aca0cbbaa6..cee33de1a6 100644 --- a/test/functional/ex_cmds/help_spec.lua +++ b/test/functional/ex_cmds/help_spec.lua @@ -3,8 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local mkdir = helpers.mkdir local rmdir = helpers.rmdir local write_file = helpers.write_file @@ -15,19 +15,19 @@ describe(':help', function() it('window closed makes cursor return to a valid win/buf #9773', function() helpers.add_builddir_to_rtp() command('help help') - eq(1001, funcs.win_getid()) + eq(1001, fn.win_getid()) command('quit') - eq(1000, funcs.win_getid()) + eq(1000, fn.win_getid()) command('autocmd WinNew * wincmd p') command('help help') -- Window 1002 is opened, but the autocmd switches back to 1000 and -- creates the help buffer there instead. - eq(1000, funcs.win_getid()) + eq(1000, fn.win_getid()) command('quit') -- Before #9773, Nvim would crash on quitting the help window. - eq(1002, funcs.win_getid()) + eq(1002, fn.win_getid()) end) it('multibyte help tags work #23975', function() @@ -40,6 +40,6 @@ describe(':help', function() command('helptags Xhelptags/doc') command('set rtp+=Xhelptags') command('help …') - eq('*…*', meths.get_current_line()) + eq('*…*', api.nvim_get_current_line()) end) end) diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua index 6aac8c2e3a..897a2997bc 100644 --- a/test/functional/ex_cmds/highlight_spec.lua +++ b/test/functional/ex_cmds/highlight_spec.lua @@ -4,8 +4,8 @@ local eq, command = helpers.eq, helpers.command local clear = helpers.clear local eval, exc_exec = helpers.eval, helpers.exc_exec local exec = helpers.exec -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api describe(':highlight', function() local screen @@ -53,18 +53,18 @@ describe(':highlight', function() end) it('clear', function() - meths.set_var('colors_name', 'foo') - eq(1, funcs.exists('g:colors_name')) + api.nvim_set_var('colors_name', 'foo') + eq(1, fn.exists('g:colors_name')) command('hi clear') - eq(0, funcs.exists('g:colors_name')) - meths.set_var('colors_name', 'foo') - eq(1, funcs.exists('g:colors_name')) + eq(0, fn.exists('g:colors_name')) + api.nvim_set_var('colors_name', 'foo') + eq(1, fn.exists('g:colors_name')) exec([[ func HiClear() hi clear endfunc ]]) - funcs.HiClear() - eq(0, funcs.exists('g:colors_name')) + fn.HiClear() + eq(0, fn.exists('g:colors_name')) end) end) diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua index a2a95fbf3f..5f59402d10 100644 --- a/test/functional/ex_cmds/ls_spec.lua +++ b/test/functional/ex_cmds/ls_spec.lua @@ -4,7 +4,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local nvim = helpers.nvim +local api = helpers.api local testprg = helpers.testprg local retry = helpers.retry @@ -14,7 +14,7 @@ describe(':ls', function() end) it('R, F for :terminal buffers', function() - nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) + api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) command('edit foo') command('set hidden') diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua index 88fd0e14e1..dd47bdec58 100644 --- a/test/functional/ex_cmds/make_spec.lua +++ b/test/functional/ex_cmds/make_spec.lua @@ -3,7 +3,7 @@ local clear = helpers.clear local eval = helpers.eval local has_powershell = helpers.has_powershell local matches = helpers.matches -local nvim = helpers.nvim +local api = helpers.api local testprg = helpers.testprg describe(':make', function() @@ -22,7 +22,7 @@ describe(':make', function() end) it('captures stderr & non zero exit code #14349', function() - nvim('set_option_value', 'makeprg', testprg('shell-test') .. ' foo', {}) + api.nvim_set_option_value('makeprg', testprg('shell-test') .. ' foo', {}) local out = eval('execute("make")') -- Error message is captured in the file and printed in the footer matches( @@ -32,7 +32,7 @@ describe(':make', function() end) it('captures stderr & zero exit code #14349', function() - nvim('set_option_value', 'makeprg', testprg('shell-test'), {}) + api.nvim_set_option_value('makeprg', testprg('shell-test'), {}) local out = eval('execute("make")') -- Ensure there are no "shell returned X" messages between -- command and last line (indicating zero exit) diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index 934dac6a2d..d3b027e6f4 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -5,7 +5,7 @@ local eq = helpers.eq local exec = helpers.exec local exec_capture = helpers.exec_capture local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local command = helpers.command local expect = helpers.expect @@ -16,13 +16,13 @@ describe(':*map', function() before_each(clear) it('are not affected by &isident', function() - meths.set_var('counter', 0) + api.nvim_set_var('counter', 0) command('nnoremap <C-x> :let counter+=1<CR>') - meths.set_option_value('isident', ('%u'):format(('>'):byte()), {}) + api.nvim_set_option_value('isident', ('%u'):format(('>'):byte()), {}) command('nnoremap <C-y> :let counter+=1<CR>') -- &isident used to disable keycode parsing here as well feed('\24\25<C-x><C-y>') - eq(4, meths.get_var('counter')) + eq(4, api.nvim_get_var('counter')) end) it(':imap <M-">', function() @@ -42,9 +42,9 @@ n asdf <Nop>]], end) it('mappings with description can be filtered', function() - meths.set_keymap('n', 'asdf1', 'qwert', { desc = 'do the one thing' }) - meths.set_keymap('n', 'asdf2', 'qwert', { desc = 'doesnot really do anything' }) - meths.set_keymap('n', 'asdf3', 'qwert', { desc = 'do the other thing' }) + api.nvim_set_keymap('n', 'asdf1', 'qwert', { desc = 'do the one thing' }) + api.nvim_set_keymap('n', 'asdf2', 'qwert', { desc = 'doesnot really do anything' }) + api.nvim_set_keymap('n', 'asdf3', 'qwert', { desc = 'do the other thing' }) eq( [[ @@ -58,21 +58,21 @@ n asdf1 qwert it('<Plug> mappings ignore nore', function() command('let x = 0') - eq(0, meths.eval('x')) + eq(0, api.nvim_eval('x')) command [[ nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr> nmap increase_x_remap <Plug>(Increase_x) nnoremap increase_x_noremap <Plug>(Increase_x) ]] feed('increase_x_remap') - eq(1, meths.eval('x')) + eq(1, api.nvim_eval('x')) feed('increase_x_noremap') - eq(2, meths.eval('x')) + eq(2, api.nvim_eval('x')) end) it("Doesn't auto ignore nore for keys before or after <Plug> mapping", function() command('let x = 0') - eq(0, meths.eval('x')) + eq(0, api.nvim_eval('x')) command [[ nnoremap x <nop> nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr> @@ -83,10 +83,10 @@ n asdf1 qwert eq('Some text', eval("getline('.')")) feed('increase_x_remap') - eq(1, meths.eval('x')) + eq(1, api.nvim_eval('x')) eq('Some text', eval("getline('.')")) feed('increase_x_noremap') - eq(2, meths.eval('x')) + eq(2, api.nvim_eval('x')) eq('Some te', eval("getline('.')")) end) diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index d6d8cce161..bb6ef72787 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, command, nvim = helpers.clear, helpers.command, helpers.nvim +local clear, command = helpers.clear, helpers.command local expect, feed = helpers.expect, helpers.feed local eq, eval = helpers.eq, helpers.eval -local funcs = helpers.funcs +local fn = helpers.fn describe(':emenu', function() before_each(function() @@ -42,12 +42,12 @@ describe(':emenu', function() feed('ithis is a sentence<esc>^yiwo<esc>') -- Invoke "Edit.Paste" in normal-mode. - nvim('command', 'emenu Edit.Paste') + command('emenu Edit.Paste') -- Invoke "Edit.Paste" and "Test.Test" in command-mode. feed(':') - nvim('command', 'emenu Edit.Paste') - nvim('command', 'emenu Test.Test') + command('emenu Edit.Paste') + command('emenu Test.Test') expect([[ this is a sentence @@ -80,7 +80,7 @@ describe('menu_get', function() end) it("path='', modes='a'", function() - local m = funcs.menu_get('', 'a') + local m = fn.menu_get('', 'a') -- HINT: To print the expected table and regenerate the tests: -- print(require('vim.inspect')(m)) local expected = { @@ -308,7 +308,7 @@ describe('menu_get', function() end) it('matching path, all modes', function() - local m = funcs.menu_get('Export', 'a') + local m = fn.menu_get('Export', 'a') local expected = { { hidden = 0, @@ -337,7 +337,7 @@ describe('menu_get', function() end) it('no path, matching modes', function() - local m = funcs.menu_get('', 'i') + local m = fn.menu_get('', 'i') local expected = { { shortcut = 'T', @@ -366,7 +366,7 @@ describe('menu_get', function() end) it('matching path and modes', function() - local m = funcs.menu_get('Test', 'i') + local m = fn.menu_get('Test', 'i') local expected = { { shortcut = 'T', @@ -412,7 +412,7 @@ describe('menu_get', function() command('nnoremenu &Test.Test8 <NoP>') command('nnoremenu &Test.Test9 ""') - local m = funcs.menu_get('') + local m = fn.menu_get('') local expected = { { shortcut = 'T', @@ -565,7 +565,7 @@ describe('menu_get', function() command('nnoremenu &Test\\ 1.Test\\ 2 Wargl') command('nnoremenu &Test4.Test<Tab>3 i space<Esc>') - local m = funcs.menu_get('') + local m = fn.menu_get('') local expected = { { shortcut = 'T', diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 7d93b972d1..16c608b156 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -6,12 +6,12 @@ local command = helpers.command local get_pathsep = helpers.get_pathsep local eq = helpers.eq local neq = helpers.neq -local funcs = helpers.funcs +local fn = helpers.fn local matches = helpers.matches -local pesc = helpers.pesc +local pesc = vim.pesc local rmdir = helpers.rmdir -local sleep = helpers.sleep -local meths = helpers.meths +local sleep = vim.uv.sleep +local api = helpers.api local skip = helpers.skip local is_os = helpers.is_os local mkdir = helpers.mkdir @@ -54,8 +54,8 @@ describe(':mksession', function() -- Restore session. command('source ' .. session_file) - eq(funcs.winbufnr(1), funcs.winbufnr(2)) - neq(funcs.winbufnr(1), funcs.winbufnr(3)) + eq(fn.winbufnr(1), fn.winbufnr(2)) + neq(fn.winbufnr(1), fn.winbufnr(3)) end) -- common testing procedure for testing "sessionoptions-=terminal" @@ -70,7 +70,7 @@ describe(':mksession', function() -- Restore session. command('source ' .. session_file) - eq(expected_buf_count, #meths.list_bufs()) + eq(expected_buf_count, #api.nvim_list_bufs()) end it( @@ -80,54 +80,54 @@ describe(':mksession', function() command('edit ' .. tmpfile_base) command('terminal') - local buf_count = #meths.list_bufs() + local buf_count = #api.nvim_list_bufs() eq(2, buf_count) - eq('terminal', meths.get_option_value('buftype', {})) + eq('terminal', api.nvim_get_option_value('buftype', {})) test_terminal_session_disabled(2) -- no terminal should be set. As a side effect we end up with a blank buffer - eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[1] })) - eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[2] })) + eq('', api.nvim_get_option_value('buftype', { buf = api.nvim_list_bufs()[1] })) + eq('', api.nvim_get_option_value('buftype', { buf = api.nvim_list_bufs()[2] })) end ) it('do not restore :terminal if not set in sessionoptions, terminal hidden #13078', function() command('terminal') - local terminal_bufnr = meths.get_current_buf() + local terminal_bufnr = api.nvim_get_current_buf() local tmpfile_base = file_prefix .. '-tmpfile' -- make terminal hidden by opening a new file command('edit ' .. tmpfile_base .. '1') - local buf_count = #meths.list_bufs() + local buf_count = #api.nvim_list_bufs() eq(2, buf_count) - eq(1, funcs.getbufinfo(terminal_bufnr)[1].hidden) + eq(1, fn.getbufinfo(terminal_bufnr)[1].hidden) test_terminal_session_disabled(1) -- no terminal should exist here - neq('', meths.buf_get_name(meths.list_bufs()[1])) + neq('', api.nvim_buf_get_name(api.nvim_list_bufs()[1])) end) it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function() command('terminal') - eq('terminal', meths.get_option_value('buftype', {})) + eq('terminal', api.nvim_get_option_value('buftype', {})) - local buf_count = #meths.list_bufs() + local buf_count = #api.nvim_list_bufs() eq(1, buf_count) test_terminal_session_disabled(1) -- no terminal should be set - eq('', meths.get_option_value('buftype', {})) + eq('', api.nvim_get_option_value('buftype', {})) end) it('restores tab-local working directories', function() local tmpfile_base = file_prefix .. '-tmpfile' - local cwd_dir = funcs.getcwd() + local cwd_dir = fn.getcwd() -- :mksession does not save empty tabs, so create some buffers. command('edit ' .. tmpfile_base .. '1') @@ -143,15 +143,15 @@ describe(':mksession', function() command('source ' .. session_file) -- First tab should have the original working directory. command('tabnext 1') - eq(cwd_dir, funcs.getcwd()) + eq(cwd_dir, fn.getcwd()) -- Second tab should have the tab-local working directory. command('tabnext 2') - eq(cwd_dir .. get_pathsep() .. tab_dir, funcs.getcwd()) + eq(cwd_dir .. get_pathsep() .. tab_dir, fn.getcwd()) end) it('restores buffers with tab-local CWD', function() local tmpfile_base = file_prefix .. '-tmpfile' - local cwd_dir = funcs.getcwd() + local cwd_dir = fn.getcwd() local session_path = cwd_dir .. get_pathsep() .. session_file command('edit ' .. tmpfile_base .. '1') @@ -167,13 +167,13 @@ describe(':mksession', function() -- Use :silent to avoid press-enter prompt due to long path command('silent source ' .. session_path) command('tabnext 1') - eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '1', funcs.expand('%:p')) + eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '1', fn.expand('%:p')) command('tabnext 2') - eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '2', funcs.expand('%:p')) + eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '2', fn.expand('%:p')) end) it('restores CWD for :terminal buffers #11288', function() - local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') + local cwd_dir = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes. local session_path = cwd_dir .. '/' .. session_file @@ -191,7 +191,7 @@ describe(':mksession', function() command('silent source ' .. session_path) local expected_cwd = cwd_dir .. '/' .. tab_dir - matches('^term://' .. pesc(expected_cwd) .. '//%d+:', funcs.expand('%')) + matches('^term://' .. pesc(expected_cwd) .. '//%d+:', fn.expand('%')) command('%bwipeout!') if is_os('win') then sleep(100) -- Make sure all child processes have exited. @@ -202,7 +202,7 @@ describe(':mksession', function() skip(is_os('win'), 'N/A for Windows') local screen - local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') + local cwd_dir = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') local session_path = cwd_dir .. '/' .. session_file screen = Screen.new(50, 6) @@ -238,7 +238,7 @@ describe(':mksession', function() local tmpfile = file_prefix .. '-tmpfile-float' command('edit ' .. tmpfile) - local buf = meths.create_buf(false, true) + local buf = api.nvim_create_buf(false, true) local config = { relative = 'editor', focusable = false, @@ -248,8 +248,8 @@ describe(':mksession', function() col = 1, style = 'minimal', } - meths.open_win(buf, false, config) - local cmdheight = meths.get_option_value('cmdheight', {}) + api.nvim_open_win(buf, false, config) + local cmdheight = api.nvim_get_option_value('cmdheight', {}) command('mksession ' .. session_file) -- Create a new test instance of Nvim. @@ -257,12 +257,12 @@ describe(':mksession', function() command('source ' .. session_file) - eq(tmpfile, funcs.expand('%')) + eq(tmpfile, fn.expand('%')) -- Check that there is only a single window, which indicates the floating -- window was not restored. - eq(1, funcs.winnr('$')) + eq(1, fn.winnr('$')) -- The command-line height should remain the same as it was. - eq(cmdheight, meths.get_option_value('cmdheight', {})) + eq(cmdheight, api.nvim_get_option_value('cmdheight', {})) os.remove(tmpfile) end) diff --git a/test/functional/ex_cmds/mkview_spec.lua b/test/functional/ex_cmds/mkview_spec.lua index fa8da6e981..de0a4fe0ea 100644 --- a/test/functional/ex_cmds/mkview_spec.lua +++ b/test/functional/ex_cmds/mkview_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local command = helpers.command local get_pathsep = helpers.get_pathsep local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local rmdir = helpers.rmdir local mkdir = helpers.mkdir @@ -28,7 +28,7 @@ describe(':mkview', function() end) it('viewoption curdir restores local current directory', function() - local cwd_dir = funcs.getcwd() + local cwd_dir = fn.getcwd() local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir -- By default the local current directory should save @@ -55,11 +55,11 @@ describe(':mkview', function() command('edit ' .. tmp_file_base .. '2') command('loadview') -- The view's current directory should not have changed - eq(cwd_dir, funcs.getcwd()) + eq(cwd_dir, fn.getcwd()) -- Load the view with a saved local current directory command('edit ' .. tmp_file_base .. '1') command('loadview') -- The view's local directory should have been saved - eq(cwd_dir .. get_pathsep() .. local_dir, funcs.getcwd()) + eq(cwd_dir .. get_pathsep() .. local_dir, fn.getcwd()) end) end) diff --git a/test/functional/ex_cmds/normal_spec.lua b/test/functional/ex_cmds/normal_spec.lua index 009f1d6516..723bfefcf4 100644 --- a/test/functional/ex_cmds/normal_spec.lua +++ b/test/functional/ex_cmds/normal_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local feed = helpers.feed local expect = helpers.expect local eq = helpers.eq @@ -29,10 +29,10 @@ describe(':normal!', function() it('can stop Visual mode without closing cmdwin vim-patch:9.0.0234', function() feed('q:') feed('v') - eq('v', funcs.mode(1)) - eq(':', funcs.getcmdwintype()) + eq('v', fn.mode(1)) + eq(':', fn.getcmdwintype()) command('normal! \027') - eq('n', funcs.mode(1)) - eq(':', funcs.getcmdwintype()) + eq('n', fn.mode(1)) + eq(':', fn.getcmdwintype()) end) end) diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 11bebb3793..8d1469f343 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local expect_exit = helpers.expect_exit -local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command +local api, eq, feed_command = helpers.api, helpers.eq, helpers.feed_command local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop local ok = helpers.ok local eval = helpers.eval @@ -42,7 +42,7 @@ describe(':oldfiles', function() feed_command('edit testfile2') feed_command('wshada') feed_command('rshada!') - local oldfiles = helpers.meths.get_vvar('oldfiles') + local oldfiles = api.nvim_get_vvar('oldfiles') feed_command('oldfiles') screen:expect([[ | @@ -56,11 +56,11 @@ describe(':oldfiles', function() it('can be filtered with :filter', function() feed_command('edit file_one.txt') - local file1 = buf.get_name() + local file1 = api.nvim_buf_get_name(0) feed_command('edit file_two.txt') - local file2 = buf.get_name() + local file2 = api.nvim_buf_get_name(0) feed_command('edit another.txt') - local another = buf.get_name() + local another = api.nvim_buf_get_name(0) feed_command('wshada') feed_command('rshada!') @@ -95,9 +95,9 @@ describe(':browse oldfiles', function() before_each(function() _clear() feed_command('edit testfile1') - filename = buf.get_name() + filename = api.nvim_buf_get_name(0) feed_command('edit testfile2') - filename2 = buf.get_name() + filename2 = api.nvim_buf_get_name(0) feed_command('wshada') poke_eventloop() _clear() @@ -108,7 +108,7 @@ describe(':browse oldfiles', function() -- Ensure v:oldfiles isn't busted. Since things happen so fast, -- the ordering of v:oldfiles is unstable (it uses qsort() under-the-hood). -- Let's verify the contents and the length of v:oldfiles before moving on. - oldfiles = helpers.meths.get_vvar('oldfiles') + oldfiles = helpers.api.nvim_get_vvar('oldfiles') eq(2, #oldfiles) ok(filename == oldfiles[1] or filename == oldfiles[2]) ok(filename2 == oldfiles[1] or filename2 == oldfiles[2]) @@ -123,16 +123,16 @@ describe(':browse oldfiles', function() it('provides a prompt and edits the chosen file', function() feed('2<cr>') - eq(oldfiles[2], buf.get_name()) + eq(oldfiles[2], api.nvim_buf_get_name(0)) end) it('provides a prompt and does nothing on <cr>', function() feed('<cr>') - eq('', buf.get_name()) + eq('', api.nvim_buf_get_name(0)) end) it('provides a prompt and does nothing if choice is out-of-bounds', function() feed('3<cr>') - eq('', buf.get_name()) + eq('', api.nvim_buf_get_name(0)) end) end) diff --git a/test/functional/ex_cmds/print_commands_spec.lua b/test/functional/ex_cmds/print_commands_spec.lua index bcb3c437ed..ba5ec7d2d1 100644 --- a/test/functional/ex_cmds/print_commands_spec.lua +++ b/test/functional/ex_cmds/print_commands_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, eq, command, funcs = helpers.clear, helpers.eq, helpers.command, helpers.funcs +local clear, eq, command, fn = helpers.clear, helpers.eq, helpers.command, helpers.fn describe(':z^', function() before_each(clear) it('correctly sets the cursor after :z^', function() command('z^') - eq(1, funcs.line('.')) + eq(1, fn.line('.')) end) end) diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua index fb594c70e6..f85dcc60ff 100644 --- a/test/functional/ex_cmds/profile_spec.lua +++ b/test/functional/ex_cmds/profile_spec.lua @@ -1,5 +1,5 @@ require('os') -local luv = require('luv') +local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local eval = helpers.eval @@ -12,16 +12,16 @@ local read_file = helpers.read_file -- tmpname() also creates the file on POSIX systems. Remove it again. -- We just need the name, ignoring any race conditions. -if luv.fs_stat(tempfile).uid then +if uv.fs_stat(tempfile).uid then os.remove(tempfile) end local function assert_file_exists(filepath) - neq(nil, luv.fs_stat(filepath).uid) + neq(nil, uv.fs_stat(filepath).uid) end local function assert_file_exists_not(filepath) - eq(nil, luv.fs_stat(filepath)) + eq(nil, uv.fs_stat(filepath)) end describe(':profile', function() @@ -29,7 +29,7 @@ describe(':profile', function() after_each(function() helpers.expect_exit(command, 'qall!') - if luv.fs_stat(tempfile).uid ~= nil then + if uv.fs_stat(tempfile).uid ~= nil then os.remove(tempfile) end end) diff --git a/test/functional/ex_cmds/quickfix_commands_spec.lua b/test/functional/ex_cmds/quickfix_commands_spec.lua index e694f5d1da..5af0198ffe 100644 --- a/test/functional/ex_cmds/quickfix_commands_spec.lua +++ b/test/functional/ex_cmds/quickfix_commands_spec.lua @@ -4,11 +4,11 @@ local Screen = require('test.functional.ui.screen') local feed = helpers.feed local eq = helpers.eq local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command local exc_exec = helpers.exc_exec local write_file = helpers.write_file -local curbufmeths = helpers.curbufmeths +local api = helpers.api local source = helpers.source local file_base = 'Xtest-functional-ex_cmds-quickfix_commands' @@ -20,8 +20,8 @@ for _, c in ipairs({ 'l', 'c' }) do local filecmd = c .. 'file' local getfcmd = c .. 'getfile' local addfcmd = c .. 'addfile' - local getlist = (c == 'c') and funcs.getqflist or function() - return funcs.getloclist(0) + local getlist = (c == 'c') and fn.getqflist or function() + return fn.getloclist(0) end describe((':%s*file commands'):format(c), function() @@ -73,13 +73,13 @@ for _, c in ipairs({ 'l', 'c' }) do }, } eq(list, getlist()) - eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) - eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr)) + eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr)) + eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr)) -- Run cfile/lfile from a modified buffer command('set nohidden') command('enew!') - curbufmeths.set_lines(1, 1, true, { 'Quickfix' }) + api.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' }) eq( ('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd), exc_exec(('%s %s'):format(filecmd, file)) @@ -107,7 +107,7 @@ for _, c in ipairs({ 'l', 'c' }) do ['type'] = '', } eq(list, getlist()) - eq(('%s-3.res'):format(file), funcs.bufname(list[3].bufnr)) + eq(('%s-3.res'):format(file), fn.bufname(list[3].bufnr)) write_file( file, @@ -149,8 +149,8 @@ for _, c in ipairs({ 'l', 'c' }) do }, } eq(list, getlist()) - eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) - eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr)) + eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr)) + eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr)) end) end) end @@ -178,7 +178,7 @@ describe('quickfix', function() call append(0, ['New line 1', 'New line 2', 'New line 3']) silent ll ]]) - eq({ 0, 6, 1, 0, 1 }, funcs.getcurpos()) + eq({ 0, 6, 1, 0, 1 }, fn.getcurpos()) end) it('BufAdd does not cause E16 when reusing quickfix buffer #18135', function() diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua index 465397169a..ebdaa0f656 100644 --- a/test/functional/ex_cmds/script_spec.lua +++ b/test/functional/ex_cmds/script_spec.lua @@ -5,7 +5,7 @@ local neq = helpers.neq local command = helpers.command local exec_capture = helpers.exec_capture local write_file = helpers.write_file -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local dedent = helpers.dedent local exc_exec = helpers.exc_exec @@ -83,7 +83,7 @@ describe('script_get-based command', function() ]])):format(cmd, garbage) ) ) - neq(0, meths.get_var('exc')) + neq(0, api.nvim_get_var('exc')) end end) end) diff --git a/test/functional/ex_cmds/sign_spec.lua b/test/functional/ex_cmds/sign_spec.lua index 30c6f9ac47..06de7f23a9 100644 --- a/test/functional/ex_cmds/sign_spec.lua +++ b/test/functional/ex_cmds/sign_spec.lua @@ -1,5 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eq, assert_alive = helpers.clear, helpers.nvim, helpers.eq, helpers.assert_alive +local clear, eq, assert_alive = helpers.clear, helpers.eq, helpers.assert_alive +local command = helpers.command +local api = helpers.api describe('sign', function() before_each(clear) @@ -7,24 +9,24 @@ describe('sign', function() describe('without specifying buffer', function() it('deletes the sign from all buffers', function() -- place a sign with id 34 to first buffer - nvim('command', 'sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') - local buf1 = nvim('eval', 'bufnr("%")') - nvim('command', 'sign place 34 line=3 name=Foo buffer=' .. buf1) + command('sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') + local buf1 = api.nvim_eval('bufnr("%")') + command('sign place 34 line=3 name=Foo buffer=' .. buf1) -- create a second buffer and place the sign on it as well - nvim('command', 'new') - local buf2 = nvim('eval', 'bufnr("%")') - nvim('command', 'sign place 34 line=3 name=Foo buffer=' .. buf2) + command('new') + local buf2 = api.nvim_eval('bufnr("%")') + command('sign place 34 line=3 name=Foo buffer=' .. buf2) -- now unplace without specifying a buffer - nvim('command', 'sign unplace 34') - eq('--- Signs ---\n', nvim('exec', 'sign place buffer=' .. buf1, true)) - eq('--- Signs ---\n', nvim('exec', 'sign place buffer=' .. buf2, true)) + command('sign unplace 34') + eq('--- Signs ---\n', api.nvim_exec('sign place buffer=' .. buf1, true)) + eq('--- Signs ---\n', api.nvim_exec('sign place buffer=' .. buf2, true)) end) end) end) describe('define {id}', function() it('does not leak memory when specifying multiple times the same argument', function() - nvim('command', 'sign define Foo culhl=Normal culhl=Normal') + command('sign define Foo culhl=Normal culhl=Normal') assert_alive() end) end) diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index e822fe78b8..5ce0e395bd 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -3,7 +3,7 @@ local command = helpers.command local insert = helpers.insert local eq = helpers.eq local clear = helpers.clear -local meths = helpers.meths +local api = helpers.api local feed = helpers.feed local feed_command = helpers.feed_command local write_file = helpers.write_file @@ -49,7 +49,7 @@ describe(':source', function() pending("'shellslash' only works on Windows") return end - meths.set_option_value('shellslash', false, {}) + api.nvim_set_option_value('shellslash', false, {}) mkdir('Xshellslash') write_file( @@ -65,9 +65,9 @@ describe(':source', function() for _ = 1, 2 do command([[source Xshellslash/Xstack.vim]]) - matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack1')) - matches([[Xshellslash/Xstack%.vim]], meths.get_var('stack2')) - matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack3')) + matches([[Xshellslash\Xstack%.vim]], api.nvim_get_var('stack1')) + matches([[Xshellslash/Xstack%.vim]], api.nvim_get_var('stack2')) + matches([[Xshellslash\Xstack%.vim]], api.nvim_get_var('stack3')) end write_file( @@ -83,9 +83,9 @@ describe(':source', function() for _ = 1, 2 do command([[source Xshellslash/Xstack.lua]]) - matches([[Xshellslash\Xstack%.lua]], meths.get_var('stack1')) - matches([[Xshellslash/Xstack%.lua]], meths.get_var('stack2')) - matches([[Xshellslash\Xstack%.lua]], meths.get_var('stack3')) + matches([[Xshellslash\Xstack%.lua]], api.nvim_get_var('stack1')) + matches([[Xshellslash/Xstack%.lua]], api.nvim_get_var('stack2')) + matches([[Xshellslash\Xstack%.lua]], api.nvim_get_var('stack3')) end rmdir('Xshellslash') @@ -182,9 +182,9 @@ describe(':source', function() command('set shellslash') command('source ' .. test_file) eq(1, eval('g:sourced_lua')) - matches([[/test%.lua$]], meths.get_var('sfile_value')) - matches([[/test%.lua$]], meths.get_var('stack_value')) - matches([[/test%.lua$]], meths.get_var('script_value')) + matches([[/test%.lua$]], api.nvim_get_var('sfile_value')) + matches([[/test%.lua$]], api.nvim_get_var('stack_value')) + matches([[/test%.lua$]], api.nvim_get_var('script_value')) os.remove(test_file) end) @@ -229,9 +229,9 @@ describe(':source', function() eq(12, eval('g:c')) eq(' \\ 1\n "\\ 2', exec_lua('return _G.a')) - eq(':source (no file)', meths.get_var('sfile_value')) - eq(':source (no file)', meths.get_var('stack_value')) - eq(':source (no file)', meths.get_var('script_value')) + eq(':source (no file)', api.nvim_get_var('sfile_value')) + eq(':source (no file)', api.nvim_get_var('stack_value')) + eq(':source (no file)', api.nvim_get_var('script_value')) end) end diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua index ffecbe0841..4c2e54cc6b 100644 --- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua +++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -1,18 +1,18 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') +local uv = vim.uv local eq, eval, expect, exec = helpers.eq, helpers.eval, helpers.expect, helpers.exec local assert_alive = helpers.assert_alive local clear = helpers.clear local command = helpers.command local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local ok = helpers.ok local rmdir = helpers.rmdir local new_argv = helpers.new_argv local new_pipename = helpers.new_pipename -local pesc = helpers.pesc +local pesc = vim.pesc local os_kill = helpers.os_kill local set_session = helpers.set_session local spawn = helpers.spawn @@ -21,7 +21,7 @@ local expect_msg_seq = helpers.expect_msg_seq local pcall_err = helpers.pcall_err local mkdir = helpers.mkdir local poke_eventloop = helpers.poke_eventloop -local meths = helpers.meths +local api = helpers.api local retry = helpers.retry local write_file = helpers.write_file @@ -42,7 +42,7 @@ describe(':recover', function() end) describe("preserve and (R)ecover with custom 'directory'", function() - local swapdir = luv.cwd() .. '/Xtest_recover_dir' + local swapdir = uv.cwd() .. '/Xtest_recover_dir' local testfile = 'Xtest_recover_file1' -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may @@ -114,7 +114,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() local screen0 = Screen.new() screen0:attach() local child_server = new_pipename() - funcs.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server }, { + fn.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) screen0:expect({ any = pesc('[No Name]') }) -- Wait for the child process to start. @@ -129,7 +129,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() end) describe('swapfile detection', function() - local swapdir = luv.cwd() .. '/Xtest_swapdialog_dir' + local swapdir = uv.cwd() .. '/Xtest_swapdialog_dir' local nvim0 -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may @@ -246,7 +246,7 @@ describe('swapfile detection', function() command('edit Xfile1') command("put ='some text...'") command('preserve') -- Make sure the swap file exists. - local nvimpid = funcs.getpid() + local nvimpid = fn.getpid() local nvim1 = spawn(new_argv(), true, nil, true) set_session(nvim1) @@ -352,7 +352,7 @@ describe('swapfile detection', function() edit Xswaptest call setline(1, ['a', 'b', 'c']) ]]) - local swname = funcs.CopySwapfile() + local swname = fn.CopySwapfile() -- Forget we edited this file exec([[ @@ -376,8 +376,8 @@ describe('swapfile detection', function() ]]) -- pretend that the swapfile was created before boot - local atime = os.time() - luv.uptime() - 10 - luv.fs_utime(swname, atime, atime) + local atime = os.time() - uv.uptime() - 10 + uv.fs_utime(swname, atime, atime) feed(':edit Xswaptest<CR>') screen:expect({ @@ -412,7 +412,7 @@ describe('swapfile detection', function() end) describe('quitting swapfile dialog on startup stops TUI properly', function() - local swapdir = luv.cwd() .. '/Xtest_swapquit_dir' + local swapdir = uv.cwd() .. '/Xtest_swapquit_dir' local testfile = 'Xtest_swapquit_file1' local otherfile = 'Xtest_swapquit_file2' -- Put swapdir at the start of the 'directory' list. #1836 @@ -438,7 +438,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function() feed('Gisometext<esc>') poke_eventloop() clear() -- Leaves a swap file behind - meths.ui_attach(80, 30, {}) + api.nvim_ui_attach(80, 30, {}) end) after_each(function() rmdir(swapdir) @@ -447,7 +447,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function() end) it('(Q)uit at first file argument', function() - local chan = funcs.termopen( + local chan = fn.termopen( { nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', init_dir, '--cmd', init_set, testfile }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, @@ -459,7 +459,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function() eval("getline('$')->trim(' ', 2)") ) end) - meths.chan_send(chan, 'q') + api.nvim_chan_send(chan, 'q') retry(nil, nil, function() eq( { '', '[Process exited 1]', '' }, @@ -469,7 +469,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function() end) it('(A)bort at second file argument with -p', function() - local chan = funcs.termopen({ + local chan = fn.termopen({ nvim_prog, '-u', 'NONE', @@ -491,7 +491,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function() eval("getline('$')->trim(' ', 2)") ) end) - meths.chan_send(chan, 'a') + api.nvim_chan_send(chan, 'a') retry(nil, nil, function() eq( { '', '[Process exited 1]', '' }, @@ -509,7 +509,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function() second %s /^ \zssecond$/ third %s /^ \zsthird$/]]):format(testfile, testfile, testfile) ) - local chan = funcs.termopen({ + local chan = fn.termopen({ nvim_prog, '-u', 'NONE', @@ -531,11 +531,11 @@ describe('quitting swapfile dialog on startup stops TUI properly', function() eval("getline('$')->trim(' ', 2)") ) end) - meths.chan_send(chan, 'q') + api.nvim_chan_send(chan, 'q') retry(nil, nil, function() eq('Press ENTER or type command to continue', eval("getline('$')->trim(' ', 2)")) end) - meths.chan_send(chan, '\r') + api.nvim_chan_send(chan, '\r') retry(nil, nil, function() eq( { '', '[Process exited 1]', '' }, diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua index 953b25ba35..2997b504fa 100644 --- a/test/functional/ex_cmds/trust_spec.lua +++ b/test/functional/ex_cmds/trust_spec.lua @@ -7,7 +7,7 @@ local exec_capture = helpers.exec_capture local matches = helpers.matches local pathsep = helpers.get_pathsep() local is_os = helpers.is_os -local funcs = helpers.funcs +local fn = helpers.fn describe(':trust', function() local xstate = 'Xstate' @@ -30,53 +30,53 @@ describe(':trust', function() end) it('trust then deny then remove a file using current buffer', function() - local cwd = funcs.getcwd() - local hash = funcs.sha256(helpers.read_file('test_file')) + local cwd = fn.getcwd() + local hash = fn.sha256(helpers.read_file('test_file')) command('edit test_file') matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then trust then remove a file using current buffer', function() - local cwd = funcs.getcwd() - local hash = funcs.sha256(helpers.read_file('test_file')) + local cwd = fn.getcwd() + local hash = fn.sha256(helpers.read_file('test_file')) command('edit test_file') matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then remove a file using file path', function() - local cwd = funcs.getcwd() + local cwd = fn.getcwd() matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file')) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches( '^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove test_file') ) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) end) diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua index 17f13e0090..7ceb2460d3 100644 --- a/test/functional/ex_cmds/verbose_spec.lua +++ b/test/functional/ex_cmds/verbose_spec.lua @@ -5,7 +5,7 @@ local eq = helpers.eq local exec = helpers.exec local exec_capture = helpers.exec_capture local write_file = helpers.write_file -local call_viml_function = helpers.meths.call_function +local call_viml_function = helpers.api.nvim_call_function local function last_set_tests(cmd) local script_location, script_file diff --git a/test/functional/ex_cmds/wincmd_spec.lua b/test/functional/ex_cmds/wincmd_spec.lua index 1948cf017a..98c6358f45 100644 --- a/test/functional/ex_cmds/wincmd_spec.lua +++ b/test/functional/ex_cmds/wincmd_spec.lua @@ -1,13 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command it(':wincmd accepts a count', function() clear() command('vsplit') - eq(1, funcs.winnr()) + eq(1, fn.winnr()) command('wincmd 2 w') - eq(2, funcs.winnr()) + eq(2, fn.winnr()) end) diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index e1cb33f060..f711731072 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -1,12 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local eq, eval, clear, write_file, source, insert = helpers.eq, helpers.eval, helpers.clear, helpers.write_file, helpers.source, helpers.insert local pcall_err = helpers.pcall_err local command = helpers.command local feed_command = helpers.feed_command -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local skip = helpers.skip local is_os = helpers.is_os local is_ci = helpers.is_ci @@ -113,11 +112,11 @@ describe(':write', function() eq('Vim(write):E32: No file name', pcall_err(command, 'write ++p test_write/')) if not is_os('win') then eq( - ('Vim(write):E17: "' .. funcs.fnamemodify('.', ':p:h') .. '" is a directory'), + ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'), pcall_err(command, 'write ++p .') ) eq( - ('Vim(write):E17: "' .. funcs.fnamemodify('.', ':p:h') .. '" is a directory'), + ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'), pcall_err(command, 'write ++p ./') ) end @@ -126,26 +125,26 @@ describe(':write', function() it('errors out correctly', function() skip(is_ci('cirrus')) command('let $HOME=""') - eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) + eq(fn.fnamemodify('.', ':p:h'), fn.fnamemodify('.', ':p:h:~')) -- Message from check_overwrite if not is_os('win') then eq( - ('Vim(write):E17: "' .. funcs.fnamemodify('.', ':p:h') .. '" is a directory'), + ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'), pcall_err(command, 'write .') ) end - meths.set_option_value('writeany', true, {}) + api.nvim_set_option_value('writeany', true, {}) -- Message from buf_write eq('Vim(write):E502: "." is a directory', pcall_err(command, 'write .')) - funcs.mkdir(fname_bak) - meths.set_option_value('backupdir', '.', {}) - meths.set_option_value('backup', true, {}) + fn.mkdir(fname_bak) + api.nvim_set_option_value('backupdir', '.', {}) + api.nvim_set_option_value('backup', true, {}) write_file(fname, 'content0') command('edit ' .. fname) - funcs.setline(1, 'TTY') + fn.setline(1, 'TTY') eq("Vim(write):E510: Can't make backup file (add ! to override)", pcall_err(command, 'write')) - meths.set_option_value('backup', false, {}) - funcs.setfperm(fname, 'r--------') + api.nvim_set_option_value('backup', false, {}) + fn.setfperm(fname, 'r--------') eq( 'Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', pcall_err(command, 'write') @@ -159,7 +158,7 @@ describe(':write', function() end write_file(fname_bak, 'TTYX') skip(is_os('win'), [[FIXME: exc_exec('write!') outputs 0 in Windows]]) - luv.fs_symlink(fname_bak .. ('/xxxxx'):rep(20), fname) + vim.uv.fs_symlink(fname_bak .. ('/xxxxx'):rep(20), fname) eq("Vim(write):E166: Can't open linked file for writing", pcall_err(command, 'write!')) end) end) diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index 5e840c2ab5..23ae1440e6 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local clear = helpers.clear local command, eq, neq, write_file = helpers.command, helpers.eq, helpers.neq, helpers.write_file local read_file = helpers.read_file @@ -26,10 +25,10 @@ describe(':wshada', function() it('creates a shada file', function() -- file should _not_ exist - eq(nil, luv.fs_stat(shada_file)) + eq(nil, vim.uv.fs_stat(shada_file)) command('wsh! ' .. shada_file) -- file _should_ exist - neq(nil, luv.fs_stat(shada_file)) + neq(nil, vim.uv.fs_stat(shada_file)) end) it('overwrites existing files', function() @@ -40,7 +39,7 @@ describe(':wshada', function() -- sanity check eq(text, read_file(shada_file)) - neq(nil, luv.fs_stat(shada_file)) + neq(nil, vim.uv.fs_stat(shada_file)) command('wsh! ' .. shada_file) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 9b75603d39..e9f8f30aa0 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -1,4 +1,4 @@ -local luv = require('luv') +local uv = vim.uv local global_helpers = require('test.helpers') local Session = require('test.client.session') @@ -10,17 +10,13 @@ local check_cores = global_helpers.check_cores local check_logs = global_helpers.check_logs local dedent = global_helpers.dedent local eq = global_helpers.eq -local filter = global_helpers.tbl_filter local is_os = global_helpers.is_os -local map = global_helpers.tbl_map local ok = global_helpers.ok -local sleep = global_helpers.sleep -local tbl_contains = global_helpers.tbl_contains +local sleep = uv.sleep local fail = global_helpers.fail local module = {} -local start_dir = luv.cwd() local runtime_set = 'set runtimepath^=./build/lib/nvim/' module.nvim_prog = (os.getenv('NVIM_PRG') or global_helpers.test_build_dir .. '/bin/nvim') -- Default settings for the test session. @@ -98,8 +94,8 @@ end local session, loop_running, last_error, method_error if not is_os('win') then - local sigpipe_handler = luv.new_signal() - luv.signal_start(sigpipe_handler, 'sigpipe', function() + local sigpipe_handler = uv.new_signal() + uv.signal_start(sigpipe_handler, 'sigpipe', function() print('warning: got SIGPIPE signal. Likely related to a crash in nvim') end) end @@ -204,7 +200,7 @@ function module.expect_msg_seq(...) ) ) ) - elseif tbl_contains(ignore, msg_type) then + elseif vim.tbl_contains(ignore, msg_type) then nr_ignored = nr_ignored + 1 else table.insert(actual_seq, msg) @@ -294,12 +290,6 @@ function module.nvim_prog_abs() end end --- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but --- v:errmsg will not be updated. -function module.command(cmd) - module.request('nvim_command', cmd) -end - -- Use for commands which expect nvim to quit. -- The first argument can also be a timeout. function module.expect_exit(fn_or_timeout, ...) @@ -408,11 +398,11 @@ local function remove_args(args, args_rm) end local last = '' for _, arg in ipairs(args) do - if tbl_contains(skip_following, last) then + if vim.tbl_contains(skip_following, last) then last = '' - elseif tbl_contains(args_rm, arg) then + elseif vim.tbl_contains(args_rm, arg) then last = arg - elseif arg == runtime_set and tbl_contains(args_rm, 'runtimepath') then + elseif arg == runtime_set and vim.tbl_contains(args_rm, 'runtimepath') then table.remove(new_args) -- Remove the preceding "--cmd". last = '' else @@ -426,10 +416,10 @@ function module.check_close() if not session then return end - local start_time = luv.now() + local start_time = uv.now() session:close() - luv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). - local end_time = luv.now() + uv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). + local end_time = uv.now() local delta = end_time - start_time if delta > 500 then print( @@ -632,64 +622,22 @@ end module.async_meths = module.create_callindex(module.nvim_async) module.uimeths = module.create_callindex(ui) -local function create_api(request, call) - local m = {} - function m.nvim(method, ...) - return request('nvim_' .. method, ...) - end - - function m.buffer(method, ...) - return request('nvim_buf_' .. method, ...) - end - - function m.window(method, ...) - return request('nvim_win_' .. method, ...) - end - - function m.tabpage(method, ...) - return request('nvim_tabpage_' .. method, ...) - end - - function m.curbuf(method, ...) - if not method then - return m.nvim('get_current_buf') - end - return m.buffer(method, 0, ...) - end - - function m.curwin(method, ...) - if not method then - return m.nvim('get_current_win') - end - return m.window(method, 0, ...) - end - - function m.curtab(method, ...) - if not method then - return m.nvim('get_current_tabpage') +local function create_bridge(request, call) + local function nvim(method, ...) + if vim.startswith(method, 'nvim_') then + return request(method, ...) end - return m.tabpage(method, 0, ...) + return request('nvim_' .. method, ...) end - m.funcs = module.create_callindex(call) - m.meths = module.create_callindex(m.nvim) - m.bufmeths = module.create_callindex(m.buffer) - m.winmeths = module.create_callindex(m.window) - m.tabmeths = module.create_callindex(m.tabpage) - m.curbufmeths = module.create_callindex(m.curbuf) - m.curwinmeths = module.create_callindex(m.curwin) - m.curtabmeths = module.create_callindex(m.curtab) - - return m + return { + fn = module.create_callindex(call), + api = module.create_callindex(nvim), + } end -module.rpc = { - api = create_api(module.request, module.call), -} - -module.lua = { - api = create_api(module.request_lua, module.call_lua), -} +module.rpc = create_bridge(module.request, module.call) +module.lua = create_bridge(module.request_lua, module.call_lua) module.describe_lua_and_rpc = function(describe) return function(what, tests) @@ -704,10 +652,18 @@ module.describe_lua_and_rpc = function(describe) end end -for name, fn in pairs(module.rpc.api) do - module[name] = fn +--- add for typing. The for loop after will overwrite this +module.api = vim.api +module.fn = vim.fn + +for name, fns in pairs(module.rpc) do + module[name] = fns end +-- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but +-- v:errmsg will not be updated. +module.command = module.api.nvim_command + function module.poke_eventloop() -- Execute 'nvim_eval' (a deferred function) to -- force at least one main_loop iteration @@ -721,7 +677,7 @@ end ---@see buf_lines() function module.curbuf_contents() module.poke_eventloop() -- Before inspecting the buffer, do whatever. - return table.concat(module.curbuf('get_lines', 0, -1, true), '\n') + return table.concat(module.api.nvim_buf_get_lines(0, 0, -1, true), '\n') end function module.expect(contents) @@ -734,17 +690,16 @@ function module.expect_any(contents) end function module.expect_events(expected, received, kind) - local inspect = require 'vim.inspect' if not pcall(eq, expected, received) then local msg = 'unexpected ' .. kind .. ' received.\n\n' msg = msg .. 'received events:\n' for _, e in ipairs(received) do - msg = msg .. ' ' .. inspect(e) .. ';\n' + msg = msg .. ' ' .. vim.inspect(e) .. ';\n' end msg = msg .. '\nexpected events:\n' for _, e in ipairs(expected) do - msg = msg .. ' ' .. inspect(e) .. ';\n' + msg = msg .. ' ' .. vim.inspect(e) .. ';\n' end fail(msg) end @@ -759,22 +714,22 @@ end -- Asserts that buffer is loaded and visible in the current tabpage. function module.assert_visible(bufnr, visible) assert(type(visible) == 'boolean') - eq(visible, module.bufmeths.is_loaded(bufnr)) + eq(visible, module.api.nvim_buf_is_loaded(bufnr)) if visible then assert( - -1 ~= module.funcs.bufwinnr(bufnr), + -1 ~= module.fn.bufwinnr(bufnr), 'expected buffer to be visible in current tabpage: ' .. tostring(bufnr) ) else assert( - -1 == module.funcs.bufwinnr(bufnr), + -1 == module.fn.bufwinnr(bufnr), 'expected buffer NOT visible in current tabpage: ' .. tostring(bufnr) ) end end local function do_rmdir(path) - local stat = luv.fs_stat(path) + local stat = uv.fs_stat(path) if stat == nil then return end @@ -803,12 +758,14 @@ local function do_rmdir(path) end end end - local ret, err = luv.fs_rmdir(path) + local ret, err = uv.fs_rmdir(path) if not ret then error('luv.fs_rmdir(' .. path .. '): ' .. err) end end +local start_dir = uv.cwd() + function module.rmdir(path) local ret, _ = pcall(do_rmdir, path) if not ret and is_os('win') then @@ -865,17 +822,17 @@ function module.skip_fragile(pending_fn, cond) end function module.exec(code) - module.meths.exec2(code, {}) + module.api.nvim_exec2(code, {}) end function module.exec_capture(code) - return module.meths.exec2(code, { output = true }).output + return module.api.nvim_exec2(code, { output = true }).output end --- @param code string --- @return any function module.exec_lua(code, ...) - return module.meths.exec_lua(code, { ... }) + return module.api.exec_lua(code, { ... }) end function module.get_pathsep() @@ -907,7 +864,7 @@ end function module.new_pipename() -- HACK: Start a server temporarily, get the name, then stop it. local pipename = module.eval('serverstart()') - module.funcs.serverstop(pipename) + module.fn.serverstop(pipename) -- Remove the pipe so that trying to connect to it without a server listening -- will be an error instead of a hang. os.remove(pipename) @@ -916,11 +873,11 @@ end function module.missing_provider(provider) if provider == 'ruby' or provider == 'node' or provider == 'perl' then - local e = module.funcs['provider#' .. provider .. '#Detect']()[2] + local e = module.fn['provider#' .. provider .. '#Detect']()[2] return e ~= '' and e or false elseif provider == 'python' or provider == 'python3' then local py_major_version = (provider == 'python3' and 3 or 2) - local e = module.funcs['provider#pythonx#Detect'](py_major_version)[2] + local e = module.fn['provider#pythonx#Detect'](py_major_version)[2] return e ~= '' and e or false else assert(false, 'Unknown provider: ' .. provider) @@ -959,12 +916,12 @@ end function module.parse_context(ctx) local parsed = {} for _, item in ipairs({ 'regs', 'jumps', 'bufs', 'gvars' }) do - parsed[item] = filter(function(v) + parsed[item] = vim.tbl_filter(function(v) return type(v) == 'table' end, module.call('msgpackparse', ctx[item])) end parsed['bufs'] = parsed['bufs'][1] - return map(function(v) + return vim.tbl_map(function(v) if #v == 0 then return nil end @@ -993,7 +950,7 @@ function module.mkdir_p(path) end --- @class test.functional.helpers: test.helpers -module = global_helpers.tbl_extend('error', module, global_helpers) +module = vim.tbl_extend('error', module, global_helpers) --- @return test.functional.helpers return function(after_each) diff --git a/test/functional/legacy/011_autocommands_spec.lua b/test/functional/legacy/011_autocommands_spec.lua index 0cce6bcd11..eba878b99a 100644 --- a/test/functional/legacy/011_autocommands_spec.lua +++ b/test/functional/legacy/011_autocommands_spec.lua @@ -13,7 +13,6 @@ -- being modified outside of Vim (noticed on Solaris). local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local clear, feed_command, expect, eq, neq, dedent, write_file, feed = helpers.clear, helpers.feed_command, @@ -37,8 +36,8 @@ local function prepare_gz_file(name, text) -- Compress the file with gzip. command([[call system(['gzip', '--force', ']] .. name .. [['])]]) -- This should create the .gz file and delete the original. - neq(nil, luv.fs_stat(name .. '.gz')) - eq(nil, luv.fs_stat(name)) + neq(nil, vim.uv.fs_stat(name .. '.gz')) + eq(nil, vim.uv.fs_stat(name)) end describe('file reading, writing and bufnew and filter autocommands', function() diff --git a/test/functional/legacy/012_directory_spec.lua b/test/functional/legacy/012_directory_spec.lua index f78648a328..b428318e3f 100644 --- a/test/functional/legacy/012_directory_spec.lua +++ b/test/functional/legacy/012_directory_spec.lua @@ -4,13 +4,12 @@ -- - "dir", in directory relative to current dir local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local eq = helpers.eq local neq = helpers.neq local poke_eventloop = helpers.poke_eventloop -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local clear = helpers.clear local insert = helpers.insert local command = helpers.command @@ -57,33 +56,33 @@ describe("'directory' option", function() line 3 Abcdefghij end of testfile]]) - meths.set_option_value('swapfile', true, {}) - meths.set_option_value('swapfile', true, {}) - meths.set_option_value('directory', '.', {}) + api.nvim_set_option_value('swapfile', true, {}) + api.nvim_set_option_value('swapfile', true, {}) + api.nvim_set_option_value('directory', '.', {}) -- sanity check: files should not exist yet. - eq(nil, luv.fs_stat('.Xtest1.swp')) + eq(nil, vim.uv.fs_stat('.Xtest1.swp')) command('edit! Xtest1') poke_eventloop() - eq('Xtest1', funcs.buffer_name('%')) + eq('Xtest1', fn.buffer_name('%')) -- Verify that the swapfile exists. In the legacy test this was done by -- reading the output from :!ls. - neq(nil, luv.fs_stat('.Xtest1.swp')) + neq(nil, vim.uv.fs_stat('.Xtest1.swp')) - meths.set_option_value('directory', './Xtest2,.', {}) + api.nvim_set_option_value('directory', './Xtest2,.', {}) command('edit Xtest1') poke_eventloop() -- swapfile should no longer exist in CWD. - eq(nil, luv.fs_stat('.Xtest1.swp')) + eq(nil, vim.uv.fs_stat('.Xtest1.swp')) eq({ 'Xtest1.swp', 'Xtest3' }, ls_dir_sorted('Xtest2')) - meths.set_option_value('directory', 'Xtest.je', {}) + api.nvim_set_option_value('directory', 'Xtest.je', {}) command('bdelete') command('edit Xtest2/Xtest3') - eq(true, meths.get_option_value('swapfile', {})) + eq(true, api.nvim_get_option_value('swapfile', {})) poke_eventloop() eq({ 'Xtest3' }, ls_dir_sorted('Xtest2')) diff --git a/test/functional/legacy/039_visual_block_mode_commands_spec.lua b/test/functional/legacy/039_visual_block_mode_commands_spec.lua index ae2cc1abbe..626035d74c 100644 --- a/test/functional/legacy/039_visual_block_mode_commands_spec.lua +++ b/test/functional/legacy/039_visual_block_mode_commands_spec.lua @@ -2,7 +2,7 @@ -- And test "U" in Visual mode, also on German sharp S. local helpers = require('test.functional.helpers')(after_each) -local nvim, eq = helpers.meths, helpers.eq +local nvim, eq = helpers.api, helpers.eq local insert, feed = helpers.insert, helpers.feed local clear, expect = helpers.clear, helpers.expect local feed_command = helpers.feed_command @@ -204,7 +204,7 @@ describe('Visual block mode', function() feed('G2l') feed('2k<C-v>$gj<ESC>') feed_command([[let cpos=getpos("'>")]]) - local cpos = nvim.get_var('cpos') + local cpos = nvim.nvim_get_var('cpos') local expected = { col = 4, off = 0, diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua index 3a4ab31bea..0a9ad330c2 100644 --- a/test/functional/legacy/074_global_var_in_viminfo_spec.lua +++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua @@ -1,7 +1,6 @@ -- Tests for storing global variables in the .shada file local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local clear, command, eq, neq, eval, poke_eventloop = helpers.clear, helpers.command, helpers.eq, helpers.neq, helpers.eval, helpers.poke_eventloop @@ -134,7 +133,7 @@ describe('storing global variables in ShaDa files', function() poke_eventloop() -- Assert that the shada file exists. - neq(nil, luv.fs_stat(tempname)) + neq(nil, vim.uv.fs_stat(tempname)) command('unlet MY_GLOBAL_DICT') command('unlet MY_GLOBAL_LIST') -- Assert that the variables where deleted. diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua index 006f71aa4f..04c90281a7 100644 --- a/test/functional/legacy/assert_spec.lua +++ b/test/functional/legacy/assert_spec.lua @@ -1,16 +1,16 @@ local helpers = require('test.functional.helpers')(after_each) -local nvim, call = helpers.meths, helpers.call +local nvim, call = helpers.api, helpers.call local clear, eq = helpers.clear, helpers.eq local source, command = helpers.source, helpers.command local exc_exec = helpers.exc_exec local eval = helpers.eval local function expected_errors(errors) - eq(errors, nvim.get_vvar('errors')) + eq(errors, nvim.nvim_get_vvar('errors')) end local function expected_empty() - eq({}, nvim.get_vvar('errors')) + eq({}, nvim.nvim_get_vvar('errors')) end describe('assert function:', function() diff --git a/test/functional/legacy/autochdir_spec.lua b/test/functional/legacy/autochdir_spec.lua index c6517a20aa..e5980f5942 100644 --- a/test/functional/legacy/autochdir_spec.lua +++ b/test/functional/legacy/autochdir_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, matches = helpers.clear, helpers.eq, helpers.matches -local eval, command, call, meths = helpers.eval, helpers.command, helpers.call, helpers.meths +local eval, command, call, api = helpers.eval, helpers.command, helpers.call, helpers.api local source, exec_capture = helpers.source, helpers.exec_capture local mkdir = helpers.mkdir local function expected_empty() - eq({}, meths.get_vvar('errors')) + eq({}, api.nvim_get_vvar('errors')) end describe('autochdir behavior', function() diff --git a/test/functional/legacy/autocmd_option_spec.lua b/test/functional/legacy/autocmd_option_spec.lua index 88618aeb2c..9966df263b 100644 --- a/test/functional/legacy/autocmd_option_spec.lua +++ b/test/functional/legacy/autocmd_option_spec.lua @@ -1,8 +1,9 @@ local helpers = require('test.functional.helpers')(after_each) -local nvim = helpers.meths +local nvim = helpers.api local clear, eq, neq, eval = helpers.clear, helpers.eq, helpers.neq, helpers.eval -local curbuf, buf = helpers.curbuf, helpers.bufmeths -local curwin = helpers.curwin +local api = helpers.api +local curbuf = helpers.api.nvim_get_current_buf +local curwin = helpers.api.nvim_get_current_win local exec_capture = helpers.exec_capture local source, command = helpers.source, helpers.command @@ -38,7 +39,7 @@ local function init_var() end local function get_result() - local ret = nvim.get_var('ret') + local ret = nvim.nvim_get_var('ret') init_var() return ret end @@ -210,7 +211,7 @@ describe('au OptionSet', function() it('should trigger if the current buffer is different from the targeted buffer', function() local new_buffer = make_buffer() - local new_bufnr = buf.get_number(new_buffer) + local new_bufnr = api.nvim_buf_get_number(new_buffer) command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")') expected_combination({ @@ -647,7 +648,7 @@ describe('au OptionSet', function() set_hook('buftype') local new_buffer = make_buffer() - local new_bufnr = buf.get_number(new_buffer) + local new_bufnr = api.nvim_buf_get_number(new_buffer) command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")') expected_combination({ @@ -696,24 +697,24 @@ describe('au OptionSet', function() it('should trigger if a boolean option be set globally', function() set_hook('autochdir') - nvim.set_option_value('autochdir', true, { scope = 'global' }) - eq(true, nvim.get_option_value('autochdir', { scope = 'global' })) + nvim.nvim_set_option_value('autochdir', true, { scope = 'global' }) + eq(true, nvim.nvim_get_option_value('autochdir', { scope = 'global' })) expected_combination({ 'autochdir', false, '', false, true, 'global', 'setglobal' }) end) it('should trigger if a number option be set globally', function() set_hook('cmdheight') - nvim.set_option_value('cmdheight', 5, { scope = 'global' }) - eq(5, nvim.get_option_value('cmdheight', { scope = 'global' })) + nvim.nvim_set_option_value('cmdheight', 5, { scope = 'global' }) + eq(5, nvim.nvim_get_option_value('cmdheight', { scope = 'global' })) expected_combination({ 'cmdheight', 1, '', 1, 5, 'global', 'setglobal' }) end) it('should trigger if a string option be set globally', function() set_hook('ambiwidth') - nvim.set_option_value('ambiwidth', 'double', { scope = 'global' }) - eq('double', nvim.get_option_value('ambiwidth', { scope = 'global' })) + nvim.nvim_set_option_value('ambiwidth', 'double', { scope = 'global' }) + eq('double', nvim.nvim_get_option_value('ambiwidth', { scope = 'global' })) expected_combination({ 'ambiwidth', 'single', diff --git a/test/functional/legacy/buffer_spec.lua b/test/functional/legacy/buffer_spec.lua index 1e8909f0d0..b3964540f0 100644 --- a/test/functional/legacy/buffer_spec.lua +++ b/test/functional/legacy/buffer_spec.lua @@ -1,16 +1,16 @@ local helpers = require('test.functional.helpers')(after_each) local clear, source = helpers.clear, helpers.source -local call, eq, meths = helpers.call, helpers.eq, helpers.meths +local call, eq, api = helpers.call, helpers.eq, helpers.api local function expected_empty() - eq({}, meths.get_vvar('errors')) + eq({}, api.nvim_get_vvar('errors')) end describe('buffer', function() before_each(function() clear() - meths.ui_attach(80, 24, {}) - meths.set_option_value('hidden', false, {}) + api.nvim_ui_attach(80, 24, {}) + api.nvim_set_option_value('hidden', false, {}) end) it('deleting a modified buffer with :confirm', function() diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua index 99731bb80b..8c94451f9a 100644 --- a/test/functional/legacy/cmdline_spec.lua +++ b/test/functional/legacy/cmdline_spec.lua @@ -5,8 +5,8 @@ local command = helpers.command local feed = helpers.feed local feed_command = helpers.feed_command local exec = helpers.exec -local meths = helpers.meths -local pesc = helpers.pesc +local api = helpers.api +local pesc = vim.pesc describe('cmdline', function() before_each(clear) @@ -198,9 +198,9 @@ describe('cmdline', function() [3] = { reverse = true }, -- TabLineFill }) screen:attach() - meths.set_option_value('laststatus', 2, {}) - meths.set_option_value('showtabline', 2, {}) - meths.set_option_value('cmdheight', 1, {}) + api.nvim_set_option_value('laststatus', 2, {}) + api.nvim_set_option_value('showtabline', 2, {}) + api.nvim_set_option_value('cmdheight', 1, {}) screen:expect([[ {2: [No Name] }{3: }| ^ | @@ -217,10 +217,10 @@ describe('cmdline', function() [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText } screen:attach() - meths.set_option_value('ruler', true, {}) - meths.set_option_value('rulerformat', 'longish', {}) - meths.set_option_value('laststatus', 0, {}) - meths.set_option_value('winwidth', 1, {}) + api.nvim_set_option_value('ruler', true, {}) + api.nvim_set_option_value('rulerformat', 'longish', {}) + api.nvim_set_option_value('laststatus', 0, {}) + api.nvim_set_option_value('winwidth', 1, {}) feed [[<C-W>v<C-W>|<C-W>p]] screen:expect [[ │^ | diff --git a/test/functional/legacy/edit_spec.lua b/test/functional/legacy/edit_spec.lua index 59e9805a91..0762e5e671 100644 --- a/test/functional/legacy/edit_spec.lua +++ b/test/functional/legacy/edit_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local command = helpers.command local expect = helpers.expect local feed = helpers.feed -local sleep = helpers.sleep +local sleep = vim.uv.sleep before_each(clear) diff --git a/test/functional/legacy/ex_mode_spec.lua b/test/functional/legacy/ex_mode_spec.lua index 90abf9ebd7..ae4c4309d1 100644 --- a/test/functional/legacy/ex_mode_spec.lua +++ b/test/functional/legacy/ex_mode_spec.lua @@ -5,7 +5,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local poke_eventloop = helpers.poke_eventloop before_each(clear) @@ -16,7 +16,7 @@ describe('Ex mode', function() feed('gQ' .. cmd .. '<C-b>"<CR>') local ret = eval('@:[1:]') -- Remove leading quote. feed('visual<CR>') - eq(meths.replace_termcodes(expected, true, true, true), ret) + eq(api.nvim_replace_termcodes(expected, true, true, true), ret) end command('set sw=2') test_ex_edit('bar', 'foo bar<C-u>bar') diff --git a/test/functional/legacy/excmd_spec.lua b/test/functional/legacy/excmd_spec.lua index ba41a983e2..41f14c4645 100644 --- a/test/functional/legacy/excmd_spec.lua +++ b/test/functional/legacy/excmd_spec.lua @@ -6,8 +6,8 @@ local exec = helpers.exec local exec_lua = helpers.exec_lua local expect_exit = helpers.expect_exit local feed = helpers.feed -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local read_file = helpers.read_file local source = helpers.source local eq = helpers.eq @@ -24,7 +24,7 @@ end describe('Ex command', function() before_each(clear) after_each(function() - eq({}, meths.get_vvar('errors')) + eq({}, api.nvim_get_vvar('errors')) end) it('checks for address line overflow', function() @@ -340,7 +340,7 @@ describe(':confirm command dialog', function() feed('<CR>') -- suppress hit-enter prompt -- Try to write with read-only file permissions. - funcs.setfperm('Xconfirm_write_ro', 'r--r--r--') + fn.setfperm('Xconfirm_write_ro', 'r--r--r--') feed(':set noro | silent undo | confirm w\n') screen:expect([[ foobar | diff --git a/test/functional/legacy/filechanged_spec.lua b/test/functional/legacy/filechanged_spec.lua index c8e772f597..46ecfdcd63 100644 --- a/test/functional/legacy/filechanged_spec.lua +++ b/test/functional/legacy/filechanged_spec.lua @@ -1,19 +1,19 @@ local helpers = require('test.functional.helpers')(after_each) local clear, source = helpers.clear, helpers.source -local call, eq, meths = helpers.call, helpers.eq, helpers.meths +local call, eq, api = helpers.call, helpers.eq, helpers.api local is_os = helpers.is_os local skip = helpers.skip local function expected_empty() - eq({}, meths.get_vvar('errors')) + eq({}, api.nvim_get_vvar('errors')) end describe('file changed dialog', function() before_each(function() clear() - meths.ui_attach(80, 24, {}) - meths.set_option_value('autoread', false, {}) - meths.set_option_value('fsync', true, {}) + api.nvim_ui_attach(80, 24, {}) + api.nvim_set_option_value('autoread', false, {}) + api.nvim_set_option_value('fsync', true, {}) end) it('works', function() diff --git a/test/functional/legacy/fnamemodify_spec.lua b/test/functional/legacy/fnamemodify_spec.lua index 6262db3a2f..570b523d92 100644 --- a/test/functional/legacy/fnamemodify_spec.lua +++ b/test/functional/legacy/fnamemodify_spec.lua @@ -2,10 +2,10 @@ local helpers = require('test.functional.helpers')(after_each) local clear, source = helpers.clear, helpers.source -local call, eq, nvim = helpers.call, helpers.eq, helpers.meths +local call, eq, nvim = helpers.call, helpers.eq, helpers.api local function expected_empty() - eq({}, nvim.get_vvar('errors')) + eq({}, nvim.nvim_get_vvar('errors')) end describe('filename modifiers', function() diff --git a/test/functional/legacy/increment_spec.lua b/test/functional/legacy/increment_spec.lua index 212ad041c0..a81044114c 100644 --- a/test/functional/legacy/increment_spec.lua +++ b/test/functional/legacy/increment_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local source, command = helpers.source, helpers.command local call, clear = helpers.call, helpers.clear -local eq, nvim = helpers.eq, helpers.meths +local eq, nvim = helpers.eq, helpers.api describe('Ctrl-A/Ctrl-X on visual selections', function() before_each(function() @@ -743,18 +743,18 @@ describe('Ctrl-A/Ctrl-X on visual selections', function() it('works on Test ' .. id, function() command('set nrformats&vi') -- &vi makes Vim compatible call('Test_visual_increment_' .. id) - eq({}, nvim.get_vvar('errors')) + eq({}, nvim.nvim_get_vvar('errors')) end) end it('does not drop leading zeroes', function() command('set nrformats&vi') -- &vi makes Vim compatible call('Test_normal_increment_01') - eq({}, nvim.get_vvar('errors')) + eq({}, nvim.nvim_get_vvar('errors')) end) it('maintains correct column after CTRL-A', function() call('Test_normal_increment_02') - eq({}, nvim.get_vvar('errors')) + eq({}, nvim.nvim_get_vvar('errors')) end) end) diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index 28efb912f8..9eddec40f7 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -3,8 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local expect, poke_eventloop = helpers.expect, helpers.poke_eventloop -local command, eq, eval, meths = helpers.command, helpers.eq, helpers.eval, helpers.meths -local sleep = helpers.sleep +local command, eq, eval, api = helpers.command, helpers.eq, helpers.eval, helpers.api +local sleep = vim.uv.sleep describe('mapping', function() before_each(clear) @@ -134,9 +134,9 @@ describe('mapping', function() command('nnoremap <LeftDrag> <LeftDrag><Cmd><CR>') poke_eventloop() - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 0, 1) + api.nvim_input_mouse('left', 'drag', '', 0, 0, 1) poke_eventloop() eq('s', eval('mode()')) end) @@ -147,9 +147,9 @@ describe('mapping', function() command('inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>') feed('i') poke_eventloop() - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 0, 1) + api.nvim_input_mouse('left', 'drag', '', 0, 0, 1) poke_eventloop() eq(1, eval('g:dragged')) eq('v', eval('mode()')) @@ -158,9 +158,9 @@ describe('mapping', function() command([[inoremap <LeftDrag> <LeftDrag><C-\><C-N>]]) feed('i') poke_eventloop() - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 0, 1) + api.nvim_input_mouse('left', 'drag', '', 0, 0, 1) poke_eventloop() eq('n', eval('mode()')) end) diff --git a/test/functional/legacy/messages_spec.lua b/test/functional/legacy/messages_spec.lua index 97c6d23494..593d03fa90 100644 --- a/test/functional/legacy/messages_spec.lua +++ b/test/functional/legacy/messages_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local command = helpers.command local exec = helpers.exec local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local nvim_dir = helpers.nvim_dir local assert_alive = helpers.assert_alive @@ -410,9 +410,9 @@ describe('messages', function() screen:attach() command('cd ' .. nvim_dir) - meths.set_option_value('shell', './shell-test', {}) - meths.set_option_value('shellcmdflag', 'REP 20', {}) - meths.set_option_value('shellxquote', '', {}) -- win: avoid extra quotes + api.nvim_set_option_value('shell', './shell-test', {}) + api.nvim_set_option_value('shellcmdflag', 'REP 20', {}) + api.nvim_set_option_value('shellxquote', '', {}) -- win: avoid extra quotes -- display a page and go back, results in exactly the same view feed([[:4 verbose echo system('foo')<CR>]]) diff --git a/test/functional/legacy/mksession_spec.lua b/test/functional/legacy/mksession_spec.lua index bca9cd833c..689d918cd9 100644 --- a/test/functional/legacy/mksession_spec.lua +++ b/test/functional/legacy/mksession_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local eq = helpers.eq describe('mksession', function() @@ -18,7 +18,7 @@ describe('mksession', function() command('mksession! Xtest_mks.out') local found_rtp = 0 local found_pp = 0 - for _, line in pairs(funcs.readfile('Xtest_mks.out', 'b')) do + for _, line in pairs(fn.readfile('Xtest_mks.out', 'b')) do if line:find('set runtimepath') then found_rtp = found_rtp + 1 end @@ -32,7 +32,7 @@ describe('mksession', function() command('set sessionoptions+=skiprtp') command('mksession! Xtest_mks.out') local found_rtp_or_pp = 0 - for _, line in pairs(funcs.readfile('Xtest_mks.out', 'b')) do + for _, line in pairs(fn.readfile('Xtest_mks.out', 'b')) do if line:find('set runtimepath') or line:find('set packpath') then found_rtp_or_pp = found_rtp_or_pp + 1 end diff --git a/test/functional/legacy/move_spec.lua b/test/functional/legacy/move_spec.lua index 512823be6c..1500d48ad9 100644 --- a/test/functional/legacy/move_spec.lua +++ b/test/functional/legacy/move_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn before_each(clear) @@ -15,7 +15,7 @@ describe(':move', function() }) screen:attach() - funcs.setline(1, { 'First', 'Second', 'Third', 'Fourth' }) + fn.setline(1, { 'First', 'Second', 'Third', 'Fourth' }) feed('gg:move +1<CR>') screen:expect([[ Second | diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua index 76c57a23b9..0c6898526e 100644 --- a/test/functional/legacy/prompt_buffer_spec.lua +++ b/test/functional/legacy/prompt_buffer_spec.lua @@ -5,7 +5,7 @@ local source = helpers.source local clear = helpers.clear local command = helpers.command local poke_eventloop = helpers.poke_eventloop -local meths = helpers.meths +local api = helpers.api local eq = helpers.eq local neq = helpers.neq @@ -180,12 +180,12 @@ describe('prompt buffer', function() call timer_start(0, {-> nvim_buf_set_lines(s:buf, -1, -1, 0, ['walrus'])}) ]] poke_eventloop() - eq({ mode = 'i', blocking = false }, meths.get_mode()) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) end) -- oldtest: Test_prompt_appending_while_hidden() it('accessing hidden prompt buffer does not start insert mode', function() - local prev_win = meths.get_current_win() + local prev_win = api.nvim_get_current_win() source([[ new prompt set buftype=prompt @@ -205,16 +205,16 @@ describe('prompt buffer', function() endfunc ]]) feed('asomething<CR>') - eq('something', meths.get_var('entered')) - neq(prev_win, meths.get_current_win()) + eq('something', api.nvim_get_var('entered')) + neq(prev_win, api.nvim_get_current_win()) feed('exit<CR>') - eq(prev_win, meths.get_current_win()) - eq({ mode = 'n', blocking = false }, meths.get_mode()) + eq(prev_win, api.nvim_get_current_win()) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) command('call DoAppend()') - eq({ mode = 'n', blocking = false }, meths.get_mode()) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) feed('i') - eq({ mode = 'i', blocking = false }, meths.get_mode()) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) command('call DoAppend()') - eq({ mode = 'i', blocking = false }, meths.get_mode()) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) end) end) diff --git a/test/functional/legacy/put_spec.lua b/test/functional/legacy/put_spec.lua index 791656cc03..c78946d690 100644 --- a/test/functional/legacy/put_spec.lua +++ b/test/functional/legacy/put_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local exec_lua = helpers.exec_lua -local meths = helpers.meths +local api = helpers.api local source = helpers.source local eq = helpers.eq @@ -16,7 +16,7 @@ end describe('put', function() before_each(clear) after_each(function() - eq({}, meths.get_vvar('errors')) + eq({}, api.nvim_get_vvar('errors')) end) it('very large count 64-bit', function() diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua index 7ddf81cff8..70748c9d27 100644 --- a/test/functional/legacy/search_spec.lua +++ b/test/functional/legacy/search_spec.lua @@ -5,7 +5,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn local poke_eventloop = helpers.poke_eventloop local exec = helpers.exec @@ -27,7 +27,7 @@ describe('search cmdline', function() end) local function tenlines() - funcs.setline(1, { + fn.setline(1, { ' 1', ' 2 these', ' 3 the', @@ -68,7 +68,7 @@ describe('search cmdline', function() 3 {inc:the} | /the^ | ]]) - eq({ 0, 0, 0, 0 }, funcs.getpos('"')) + eq({ 0, 0, 0, 0 }, fn.getpos('"')) feed('<C-G>') screen:expect([[ 3 the | @@ -125,7 +125,7 @@ describe('search cmdline', function() end, } feed('<CR>') - eq({ 0, 0, 0, 0 }, funcs.getpos('"')) + eq({ 0, 0, 0, 0 }, fn.getpos('"')) end end @@ -368,7 +368,7 @@ describe('search cmdline', function() end) it('can traverse matches in the same line with <C-G>/<C-T>', function() - funcs.setline(1, { ' 1', ' 2 these', ' 3 the theother' }) + fn.setline(1, { ' 1', ' 2 these', ' 3 the theother' }) command('1') command('set incsearch') @@ -465,7 +465,7 @@ describe('search cmdline', function() coladd = 0, skipcol = 0, curswant = 4, - }, funcs.winsaveview()) + }, fn.winsaveview()) end) it('restores original view after failed search', function() @@ -500,14 +500,14 @@ describe('search cmdline', function() coladd = 0, skipcol = 0, curswant = 0, - }, funcs.winsaveview()) + }, fn.winsaveview()) end) -- oldtest: Test_search_cmdline4(). it("CTRL-G with 'incsearch' and ? goes in the right direction", function() screen:try_resize(40, 4) command('enew!') - funcs.setline(1, { ' 1 the first', ' 2 the second', ' 3 the third' }) + fn.setline(1, { ' 1 the first', ' 2 the second', ' 3 the third' }) command('set laststatus=0 shortmess+=s') command('set incsearch') command('$') @@ -608,7 +608,7 @@ describe('search cmdline', function() it('incsearch works with :sort', function() screen:try_resize(20, 4) command('set incsearch hlsearch scrolloff=0') - funcs.setline(1, { 'another one 2', 'that one 3', 'the one 1' }) + fn.setline(1, { 'another one 2', 'that one 3', 'the one 1' }) feed(':sort ni u /on') screen:expect([[ @@ -624,7 +624,7 @@ describe('search cmdline', function() it('incsearch works with :vimgrep family', function() screen:try_resize(30, 4) command('set incsearch hlsearch scrolloff=0') - funcs.setline(1, { 'another one 2', 'that one 3', 'the one 1' }) + fn.setline(1, { 'another one 2', 'that one 3', 'the one 1' }) feed(':vimgrep on') screen:expect([[ diff --git a/test/functional/legacy/undolevels_spec.lua b/test/functional/legacy/undolevels_spec.lua index 1dfc4c17ba..e8badc6864 100644 --- a/test/functional/legacy/undolevels_spec.lua +++ b/test/functional/legacy/undolevels_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local source, clear = helpers.source, helpers.clear -local eq, nvim = helpers.eq, helpers.meths +local eq, nvim = helpers.eq, helpers.api describe('undolevel', function() setup(clear) @@ -57,6 +57,6 @@ describe('undolevel', function() call Test_global_local_undolevels() ]]) - eq({}, nvim.get_vvar('errors')) + eq({}, nvim.nvim_get_vvar('errors')) end) end) diff --git a/test/functional/legacy/vimscript_spec.lua b/test/functional/legacy/vimscript_spec.lua index c97208059b..8b0a920a3e 100644 --- a/test/functional/legacy/vimscript_spec.lua +++ b/test/functional/legacy/vimscript_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local exec = helpers.exec local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api before_each(clear) @@ -12,7 +12,7 @@ describe('Vim script', function() it('Error when if/for/while/try/function is nested too deep', function() local screen = Screen.new(80, 24) screen:attach() - meths.set_option_value('laststatus', 2, {}) + api.nvim_set_option_value('laststatus', 2, {}) exec([[ " Deep nesting of if ... endif func Test1() diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index 55f9ba7e13..acd56a0ddb 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -3,10 +3,10 @@ local helpers = require('test.functional.helpers')(after_each) local exc_exec = helpers.exc_exec local remove_trace = helpers.remove_trace -local funcs = helpers.funcs +local fn = helpers.fn local clear = helpers.clear local eval = helpers.eval -local NIL = helpers.NIL +local NIL = vim.NIL local eq = helpers.eq local exec_lua = helpers.exec_lua local pcall_err = helpers.pcall_err @@ -17,39 +17,39 @@ describe('luaeval(vim.api.…)', function() describe('with channel_id and buffer handle', function() describe('nvim_buf_get_lines', function() it('works', function() - funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) - eq({ 'a\000b' }, funcs.luaeval('vim.api.nvim_buf_get_lines(1, 2, 3, false)')) + fn.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) + eq({ 'a\000b' }, fn.luaeval('vim.api.nvim_buf_get_lines(1, 2, 3, false)')) end) end) describe('nvim_buf_set_lines', function() it('works', function() - funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) - eq(NIL, funcs.luaeval('vim.api.nvim_buf_set_lines(1, 1, 2, false, {"b\\0a"})')) + fn.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) + eq(NIL, fn.luaeval('vim.api.nvim_buf_set_lines(1, 1, 2, false, {"b\\0a"})')) eq( { 'abc', 'b\000a', 'a\000b', 'ttt' }, - funcs.luaeval('vim.api.nvim_buf_get_lines(1, 0, 4, false)') + fn.luaeval('vim.api.nvim_buf_get_lines(1, 0, 4, false)') ) end) end) end) describe('with errors', function() it('transforms API error from nvim_buf_set_lines into lua error', function() - funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) + fn.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) eq( { false, "'replacement string' item contains newlines" }, - funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}') + fn.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}') ) end) it('transforms API error from nvim_win_set_cursor into lua error', function() eq( { false, 'Argument "pos" must be a [row, col] array' }, - funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {1, 2, 3})}') + fn.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {1, 2, 3})}') ) -- Used to produce a memory leak due to a bug in nvim_win_set_cursor eq( { false, 'Invalid window id: -1' }, - funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, -1, {1, 2, 3})}') + fn.luaeval('{pcall(vim.api.nvim_win_set_cursor, -1, {1, 2, 3})}') ) end) @@ -58,7 +58,7 @@ describe('luaeval(vim.api.…)', function() function() eq( { false, 'Argument "pos" must be a [row, col] array' }, - funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {"b\\na"})}') + fn.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {"b\\na"})}') ) end ) @@ -74,20 +74,20 @@ describe('luaeval(vim.api.…)', function() ]=])') ]==])]===]):gsub('\n', ' ') ) - eq(1, funcs.luaeval(str)) + eq(1, fn.luaeval(str)) end) it('correctly converts from API objects', function() - eq(1, funcs.luaeval('vim.api.nvim_eval("1")')) - eq('1', funcs.luaeval([[vim.api.nvim_eval('"1"')]])) - eq('Blobby', funcs.luaeval('vim.api.nvim_eval("0z426c6f626279")')) - eq({}, funcs.luaeval('vim.api.nvim_eval("[]")')) - eq({}, funcs.luaeval('vim.api.nvim_eval("{}")')) - eq(1, funcs.luaeval('vim.api.nvim_eval("1.0")')) - eq('\000', funcs.luaeval('vim.api.nvim_eval("0z00")')) - eq(true, funcs.luaeval('vim.api.nvim_eval("v:true")')) - eq(false, funcs.luaeval('vim.api.nvim_eval("v:false")')) - eq(NIL, funcs.luaeval('vim.api.nvim_eval("v:null")')) + eq(1, fn.luaeval('vim.api.nvim_eval("1")')) + eq('1', fn.luaeval([[vim.api.nvim_eval('"1"')]])) + eq('Blobby', fn.luaeval('vim.api.nvim_eval("0z426c6f626279")')) + eq({}, fn.luaeval('vim.api.nvim_eval("[]")')) + eq({}, fn.luaeval('vim.api.nvim_eval("{}")')) + eq(1, fn.luaeval('vim.api.nvim_eval("1.0")')) + eq('\000', fn.luaeval('vim.api.nvim_eval("0z00")')) + eq(true, fn.luaeval('vim.api.nvim_eval("v:true")')) + eq(false, fn.luaeval('vim.api.nvim_eval("v:false")')) + eq(NIL, fn.luaeval('vim.api.nvim_eval("v:null")')) eq(0, eval([[type(luaeval('vim.api.nvim_eval("1")'))]])) eq(1, eval([[type(luaeval('vim.api.nvim_eval("''1''")'))]])) @@ -99,25 +99,25 @@ describe('luaeval(vim.api.…)', function() eq(6, eval([[type(luaeval('vim.api.nvim_eval("v:false")'))]])) eq(7, eval([[type(luaeval('vim.api.nvim_eval("v:null")'))]])) - eq({ foo = 42 }, funcs.luaeval([[vim.api.nvim_eval('{"foo": 42}')]])) - eq({ 42 }, funcs.luaeval([[vim.api.nvim_eval('[42]')]])) + eq({ foo = 42 }, fn.luaeval([[vim.api.nvim_eval('{"foo": 42}')]])) + eq({ 42 }, fn.luaeval([[vim.api.nvim_eval('[42]')]])) eq( { foo = { bar = 42 }, baz = 50 }, - funcs.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]]) + fn.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]]) ) - eq({ { 42 }, {} }, funcs.luaeval([=[vim.api.nvim_eval('[[42], []]')]=])) + eq({ { 42 }, {} }, fn.luaeval([=[vim.api.nvim_eval('[[42], []]')]=])) end) it('correctly converts to API objects', function() - eq(1, funcs.luaeval('vim.api.nvim__id(1)')) - eq('1', funcs.luaeval('vim.api.nvim__id("1")')) - eq({ 1 }, funcs.luaeval('vim.api.nvim__id({1})')) - eq({ foo = 1 }, funcs.luaeval('vim.api.nvim__id({foo=1})')) - eq(1.5, funcs.luaeval('vim.api.nvim__id(1.5)')) - eq(true, funcs.luaeval('vim.api.nvim__id(true)')) - eq(false, funcs.luaeval('vim.api.nvim__id(false)')) - eq(NIL, funcs.luaeval('vim.api.nvim__id(nil)')) + eq(1, fn.luaeval('vim.api.nvim__id(1)')) + eq('1', fn.luaeval('vim.api.nvim__id("1")')) + eq({ 1 }, fn.luaeval('vim.api.nvim__id({1})')) + eq({ foo = 1 }, fn.luaeval('vim.api.nvim__id({foo=1})')) + eq(1.5, fn.luaeval('vim.api.nvim__id(1.5)')) + eq(true, fn.luaeval('vim.api.nvim__id(true)')) + eq(false, fn.luaeval('vim.api.nvim__id(false)')) + eq(NIL, fn.luaeval('vim.api.nvim__id(nil)')) -- API strings from Blobs can work as NUL-terminated C strings eq( @@ -138,10 +138,10 @@ describe('luaeval(vim.api.…)', function() eq( { foo = 1, bar = { 42, { { baz = true }, 5 } } }, - funcs.luaeval('vim.api.nvim__id({foo=1, bar={42, {{baz=true}, 5}}})') + fn.luaeval('vim.api.nvim__id({foo=1, bar={42, {{baz=true}, 5}}})') ) - eq(true, funcs.luaeval('vim.api.nvim__id(vim.api.nvim__id)(true)')) + eq(true, fn.luaeval('vim.api.nvim__id(vim.api.nvim__id)(true)')) eq( 42, exec_lua [[ @@ -159,30 +159,30 @@ describe('luaeval(vim.api.…)', function() eq(4, eval([[type(luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary})'))]])) eq(3, eval([[type(luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})'))]])) - eq({}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})')) + eq({}, fn.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})')) -- Presence of type_idx makes Vim ignore some keys eq( { 42 }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' ) ) eq( { foo = 2 }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' ) ) eq( 10, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' ) ) eq( {}, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})' ) ) @@ -191,34 +191,34 @@ describe('luaeval(vim.api.…)', function() it('correctly converts arrays with type_idx to API objects', function() eq(3, eval([[type(luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})'))]])) - eq({}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})')) + eq({}, fn.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})')) eq( { 42 }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' ) ) eq( { { foo = 2 } }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})' ) ) eq( { 10 }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})' ) ) eq( {}, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})' ) ) - eq({}, funcs.luaeval('vim.api.nvim__id_array({})')) + eq({}, fn.luaeval('vim.api.nvim__id_array({})')) eq(3, eval([[type(luaeval('vim.api.nvim__id_array({})'))]])) end) @@ -228,36 +228,36 @@ describe('luaeval(vim.api.…)', function() eval([[type(luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]]) ) - eq({}, funcs.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})')) + eq({}, fn.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})')) eq( { v = { 42 } }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})' ) ) eq( { foo = 2 }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' ) ) eq( { v = 10 }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})' ) ) eq( { v = {} }, - funcs.luaeval( + fn.luaeval( 'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})' ) ) -- If API requests dictionary, then empty table will be the one. This is not -- the case normally because empty table is an empty array. - eq({}, funcs.luaeval('vim.api.nvim__id_dictionary({})')) + eq({}, fn.luaeval('vim.api.nvim__id_dictionary({})')) eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({})'))]])) end) @@ -384,13 +384,11 @@ describe('luaeval(vim.api.…)', function() end) it('accepts any value as API Boolean', function() - eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", vim, false, nil)')) - eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", 0, 1.5, "test")')) + eq('', fn.luaeval('vim.api.nvim_replace_termcodes("", vim, false, nil)')) + eq('', fn.luaeval('vim.api.nvim_replace_termcodes("", 0, 1.5, "test")')) eq( '', - funcs.luaeval( - 'vim.api.nvim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})' - ) + fn.luaeval('vim.api.nvim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})') ) end) diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 447c1ee345..714e1b951f 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -1,10 +1,9 @@ -- Test suite for testing interactions with API bindings local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local command = helpers.command -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local clear = helpers.clear local eq = helpers.eq local fail = helpers.fail @@ -55,9 +54,9 @@ end) describe('lua buffer event callbacks: on_lines', function() local function setup_eventcheck(verify, utf_sizes, lines) local lastsize - meths.buf_set_lines(0, 0, -1, true, lines) + api.nvim_buf_set_lines(0, 0, -1, true, lines) if verify then - lastsize = meths.buf_get_offset(0, meths.buf_line_count(0)) + lastsize = api.nvim_buf_get_offset(0, api.nvim_buf_line_count(0)) end exec_lua('return test_register(...)', 0, 'on_lines', 'test1', false, utf_sizes) local verify_name = 'test1' @@ -77,8 +76,9 @@ describe('lua buffer event callbacks: on_lines', function() for _, event in ipairs(events) do if event[1] == verify_name and event[2] == 'lines' then local startline, endline = event[5], event[7] - local newrange = meths.buf_get_offset(0, endline) - meths.buf_get_offset(0, startline) - local newsize = meths.buf_get_offset(0, meths.buf_line_count(0)) + local newrange = api.nvim_buf_get_offset(0, endline) + - api.nvim_buf_get_offset(0, startline) + local newsize = api.nvim_buf_get_offset(0, api.nvim_buf_line_count(0)) local oldrange = newrange + lastsize - newsize eq(oldrange, event[8]) lastsize = newsize @@ -98,13 +98,13 @@ describe('lua buffer event callbacks: on_lines', function() local function check(verify, utf_sizes) local check_events, verify_name = setup_eventcheck(verify, utf_sizes, origlines) - local tick = meths.buf_get_changedtick(0) + local tick = api.nvim_buf_get_changedtick(0) command('set autoindent') command('normal! GyyggP') tick = tick + 1 check_events { { 'test1', 'lines', 1, tick, 0, 0, 1, 0 } } - meths.buf_set_lines(0, 3, 5, true, { 'changed line' }) + api.nvim_buf_set_lines(0, 3, 5, true, { 'changed line' }) tick = tick + 1 check_events { { 'test1', 'lines', 1, tick, 3, 5, 4, 32 } } @@ -142,7 +142,7 @@ describe('lua buffer event callbacks: on_lines', function() -- simulate next callback returning true exec_lua("test_unreg = 'test1'") - meths.buf_set_lines(0, 6, 7, true, { 'x1', 'x2', 'x3' }) + api.nvim_buf_set_lines(0, 6, 7, true, { 'x1', 'x2', 'x3' }) tick = tick + 1 -- plugins can opt in to receive changedtick events, or choose @@ -154,7 +154,7 @@ describe('lua buffer event callbacks: on_lines', function() verify_name 'test2' - meths.buf_set_lines(0, 1, 1, true, { 'added' }) + api.nvim_buf_set_lines(0, 1, 1, true, { 'added' }) tick = tick + 1 check_events { { 'test2', 'lines', 1, tick, 1, 1, 2, 0 } } @@ -206,7 +206,7 @@ describe('lua buffer event callbacks: on_lines', function() } local check_events, verify_name = setup_eventcheck(verify, true, unicode_text) - local tick = meths.buf_get_changedtick(0) + local tick = api.nvim_buf_get_changedtick(0) feed('ggdd') tick = tick + 1 @@ -254,7 +254,7 @@ describe('lua buffer event callbacks: on_lines', function() end) it('has valid cursor position while shifting', function() - meths.buf_set_lines(0, 0, -1, true, { 'line1' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'line1' }) exec_lua([[ vim.api.nvim_buf_attach(0, false, { on_lines = function() @@ -263,15 +263,15 @@ describe('lua buffer event callbacks: on_lines', function() }) ]]) feed('>>') - eq(1, meths.get_var('listener_cursor_line')) + eq(1, api.nvim_get_var('listener_cursor_line')) end) it('has valid cursor position while deleting lines', function() - meths.buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3', 'line_4' }) - meths.win_set_cursor(0, { 2, 0 }) - eq(2, meths.win_get_cursor(0)[1]) - meths.buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3' }) - eq(2, meths.win_get_cursor(0)[1]) + api.nvim_buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3', 'line_4' }) + api.nvim_win_set_cursor(0, { 2, 0 }) + eq(2, api.nvim_win_get_cursor(0)[1]) + api.nvim_buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3' }) + eq(2, api.nvim_win_get_cursor(0)[1]) end) it('does not SEGFAULT when accessing window buffer info in on_detach #14998', function() @@ -299,7 +299,7 @@ describe('lua buffer event callbacks: on_lines', function() end) it('#12718 lnume', function() - meths.buf_set_lines(0, 0, -1, true, { '1', '2', '3' }) + api.nvim_buf_set_lines(0, 0, -1, true, { '1', '2', '3' }) exec_lua([[ vim.api.nvim_buf_attach(0, false, { on_lines = function(...) @@ -312,15 +312,15 @@ describe('lua buffer event callbacks: on_lines', function() feed('G0') feed('p') -- Is the last arg old_byte_size correct? Doesn't matter for this PR - eq(meths.get_var('linesev'), { 'lines', 1, 4, 2, 3, 5, 4 }) + eq(api.nvim_get_var('linesev'), { 'lines', 1, 4, 2, 3, 5, 4 }) feed('2G0') feed('p') - eq(meths.get_var('linesev'), { 'lines', 1, 5, 1, 4, 4, 8 }) + eq(api.nvim_get_var('linesev'), { 'lines', 1, 5, 1, 4, 4, 8 }) feed('1G0') feed('P') - eq(meths.get_var('linesev'), { 'lines', 1, 6, 0, 3, 3, 9 }) + eq(api.nvim_get_var('linesev'), { 'lines', 1, 6, 0, 3, 3, 9 }) end) it( @@ -334,7 +334,7 @@ describe('lua buffer event callbacks: on_lines', function() }) ]]) feed('itest123<Esc><C-A>') - eq('test124', meths.get_current_line()) + eq('test124', api.nvim_get_current_line()) end ) end) @@ -346,19 +346,19 @@ describe('lua: nvim_buf_attach on_bytes', function() -- test both ways. local function setup_eventcheck(verify, start_txt) if start_txt then - meths.buf_set_lines(0, 0, -1, true, start_txt) + api.nvim_buf_set_lines(0, 0, -1, true, start_txt) else - start_txt = meths.buf_get_lines(0, 0, -1, true) + start_txt = api.nvim_buf_get_lines(0, 0, -1, true) end local shadowbytes = table.concat(start_txt, '\n') .. '\n' -- TODO: while we are brewing the real strong coffee, -- verify should check buf_get_offset after every check_events if verify then - local len = meths.buf_get_offset(0, meths.buf_line_count(0)) + local len = api.nvim_buf_get_offset(0, api.nvim_buf_line_count(0)) eq(len == -1 and 1 or len, string.len(shadowbytes)) end exec_lua('return test_register(...)', 0, 'on_bytes', 'test1', false, false, true) - meths.buf_get_changedtick(0) + api.nvim_buf_get_changedtick(0) local verify_name = 'test1' local function check_events(expected) @@ -385,11 +385,11 @@ describe('lua: nvim_buf_attach on_bytes', function() local after = string.sub(shadowbytes, start_byte + old_byte + 1) shadowbytes = before .. unknown .. after elseif event[1] == verify_name and event[2] == 'reload' then - shadowbytes = table.concat(meths.buf_get_lines(0, 0, -1, true), '\n') .. '\n' + shadowbytes = table.concat(api.nvim_buf_get_lines(0, 0, -1, true), '\n') .. '\n' end end - local text = meths.buf_get_lines(0, 0, -1, true) + local text = api.nvim_buf_get_lines(0, 0, -1, true) local bytes = table.concat(text, '\n') .. '\n' eq( @@ -426,7 +426,7 @@ describe('lua: nvim_buf_attach on_bytes', function() it('opening lines', function() local check_events = setup_eventcheck(verify, origlines) - -- meths.set_option_value('autoindent', true, {}) + -- api.nvim_set_option_value('autoindent', true, {}) feed 'Go' check_events { { 'test1', 'bytes', 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 1 }, @@ -439,7 +439,7 @@ describe('lua: nvim_buf_attach on_bytes', function() it('opening lines with autoindent', function() local check_events = setup_eventcheck(verify, origlines) - meths.set_option_value('autoindent', true, {}) + api.nvim_set_option_value('autoindent', true, {}) feed 'Go' check_events { { 'test1', 'bytes', 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 5 }, @@ -453,19 +453,19 @@ describe('lua: nvim_buf_attach on_bytes', function() it('setline(num, line)', function() local check_events = setup_eventcheck(verify, origlines) - funcs.setline(2, 'babla') + fn.setline(2, 'babla') check_events { { 'test1', 'bytes', 1, 3, 1, 0, 16, 0, 15, 15, 0, 5, 5 }, } - funcs.setline(2, { 'foo', 'bar' }) + fn.setline(2, { 'foo', 'bar' }) check_events { { 'test1', 'bytes', 1, 4, 1, 0, 16, 0, 5, 5, 0, 3, 3 }, { 'test1', 'bytes', 1, 5, 2, 0, 20, 0, 15, 15, 0, 3, 3 }, } - local buf_len = meths.buf_line_count(0) - funcs.setline(buf_len + 1, 'baz') + local buf_len = api.nvim_buf_line_count(0) + fn.setline(buf_len + 1, 'baz') check_events { { 'test1', 'bytes', 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 }, } @@ -473,8 +473,8 @@ describe('lua: nvim_buf_attach on_bytes', function() it('continuing comments with fo=or', function() local check_events = setup_eventcheck(verify, { '// Comment' }) - meths.set_option_value('formatoptions', 'ro', {}) - meths.set_option_value('filetype', 'c', {}) + api.nvim_set_option_value('formatoptions', 'ro', {}) + api.nvim_set_option_value('filetype', 'c', {}) feed 'A<CR>' check_events { { 'test1', 'bytes', 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 }, @@ -555,7 +555,7 @@ describe('lua: nvim_buf_attach on_bytes', function() it('visual charwise paste', function() local check_events = setup_eventcheck(verify, { '1234567890' }) - funcs.setreg('a', '___') + fn.setreg('a', '___') feed '1G1|vll' check_events {} @@ -612,7 +612,7 @@ describe('lua: nvim_buf_attach on_bytes', function() it('inccomand=nosplit and substitute', function() local check_events = setup_eventcheck(verify, { 'abcde', '12345' }) - meths.set_option_value('inccommand', 'nosplit', {}) + api.nvim_set_option_value('inccommand', 'nosplit', {}) -- linewise substitute feed(':%s/bcd/') @@ -697,41 +697,41 @@ describe('lua: nvim_buf_attach on_bytes', function() it('nvim_buf_set_text insert', function() local check_events = setup_eventcheck(verify, { 'bastext' }) - meths.buf_set_text(0, 0, 3, 0, 3, { 'fiol', 'kontra' }) + api.nvim_buf_set_text(0, 0, 3, 0, 3, { 'fiol', 'kontra' }) check_events { { 'test1', 'bytes', 1, 3, 0, 3, 3, 0, 0, 0, 1, 6, 11 }, } - meths.buf_set_text(0, 1, 6, 1, 6, { 'punkt', 'syntgitarr', 'övnings' }) + api.nvim_buf_set_text(0, 1, 6, 1, 6, { 'punkt', 'syntgitarr', 'övnings' }) check_events { { 'test1', 'bytes', 1, 4, 1, 6, 14, 0, 0, 0, 2, 8, 25 }, } eq( { 'basfiol', 'kontrapunkt', 'syntgitarr', 'övningstext' }, - meths.buf_get_lines(0, 0, -1, true) + api.nvim_buf_get_lines(0, 0, -1, true) ) end) it('nvim_buf_set_text replace', function() local check_events = setup_eventcheck(verify, origlines) - meths.buf_set_text(0, 2, 3, 2, 8, { 'very text' }) + api.nvim_buf_set_text(0, 2, 3, 2, 8, { 'very text' }) check_events { { 'test1', 'bytes', 1, 3, 2, 3, 35, 0, 5, 5, 0, 9, 9 }, } - meths.buf_set_text(0, 3, 5, 3, 7, { ' splitty', 'line ' }) + api.nvim_buf_set_text(0, 3, 5, 3, 7, { ' splitty', 'line ' }) check_events { { 'test1', 'bytes', 1, 4, 3, 5, 57, 0, 2, 2, 1, 5, 14 }, } - meths.buf_set_text(0, 0, 8, 1, 2, { 'JOINY' }) + api.nvim_buf_set_text(0, 0, 8, 1, 2, { 'JOINY' }) check_events { { 'test1', 'bytes', 1, 5, 0, 8, 8, 1, 2, 10, 0, 5, 5 }, } - meths.buf_set_text(0, 4, 0, 6, 0, { 'was 5,6', '' }) + api.nvim_buf_set_text(0, 4, 0, 6, 0, { 'was 5,6', '' }) check_events { { 'test1', 'bytes', 1, 6, 4, 0, 75, 2, 0, 32, 1, 0, 8 }, } @@ -743,20 +743,20 @@ describe('lua: nvim_buf_attach on_bytes', function() 'line l line 4', 'was 5,6', ' indented line', - }, meths.buf_get_lines(0, 0, -1, true)) + }, api.nvim_buf_get_lines(0, 0, -1, true)) end) it('nvim_buf_set_text delete', function() local check_events = setup_eventcheck(verify, origlines) -- really {""} but accepts {} as a shorthand - meths.buf_set_text(0, 0, 0, 1, 0, {}) + api.nvim_buf_set_text(0, 0, 0, 1, 0, {}) check_events { { 'test1', 'bytes', 1, 3, 0, 0, 0, 1, 0, 16, 0, 0, 0 }, } -- TODO(bfredl): this works but is not as convenient as set_lines - meths.buf_set_text(0, 4, 15, 5, 17, { '' }) + api.nvim_buf_set_text(0, 4, 15, 5, 17, { '' }) check_events { { 'test1', 'bytes', 1, 4, 4, 15, 79, 1, 17, 18, 0, 0, 0 }, } @@ -766,7 +766,7 @@ describe('lua: nvim_buf_attach on_bytes', function() 'original line 4', 'original line 5', 'original line 6', - }, meths.buf_get_lines(0, 0, -1, true)) + }, api.nvim_buf_get_lines(0, 0, -1, true)) end) it('checktime autoread', function() @@ -777,7 +777,7 @@ describe('lua: nvim_buf_attach on_bytes', function() old line 2]] ) local atime = os.time() - 10 - luv.fs_utime('Xtest-reload', atime, atime) + vim.uv.fs_utime('Xtest-reload', atime, atime) command 'e Xtest-reload' command 'set autoread' @@ -801,7 +801,7 @@ describe('lua: nvim_buf_attach on_bytes', function() { 'test1', 'bytes', 1, 5, 0, 10, 10, 1, 0, 1, 0, 1, 1 }, } - eq({ 'new line 1 new line 2', 'new line 3' }, meths.buf_get_lines(0, 0, -1, true)) + eq({ 'new line 1 new line 2', 'new line 3' }, api.nvim_buf_get_lines(0, 0, -1, true)) -- check we can undo and redo a reload event. feed 'u' @@ -925,19 +925,19 @@ describe('lua: nvim_buf_attach on_bytes', function() command('set undodir=. | set undofile') local ns = helpers.request('nvim_create_namespace', 'ns1') - meths.buf_set_extmark(0, ns, 0, 0, {}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {}) - eq({ '12345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true)) + eq({ '12345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true)) -- splice feed('gg0d2l') - eq({ '345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true)) + eq({ '345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true)) -- move command('.m+1') - eq({ 'hello world', '345' }, meths.buf_get_lines(0, 0, -1, true)) + eq({ 'hello world', '345' }, api.nvim_buf_get_lines(0, 0, -1, true)) -- reload undofile and undo changes command('w') @@ -950,7 +950,7 @@ describe('lua: nvim_buf_attach on_bytes', function() local check_events = setup_eventcheck(verify, nil) feed('u') - eq({ '345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true)) + eq({ '345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true)) check_events { { 'test1', 'bytes', 2, 6, 1, 0, 12, 1, 0, 4, 0, 0, 0 }, @@ -958,7 +958,7 @@ describe('lua: nvim_buf_attach on_bytes', function() } feed('u') - eq({ '12345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true)) + eq({ '12345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true)) check_events { { 'test1', 'bytes', 2, 8, 0, 0, 0, 0, 0, 0, 0, 2, 2 }, @@ -969,7 +969,7 @@ describe('lua: nvim_buf_attach on_bytes', function() it('blockwise paste with uneven line lengths', function() local check_events = setup_eventcheck(verify, { 'aaaa', 'aaa', 'aaa' }) - -- eq({}, meths.buf_get_lines(0, 0, -1, true)) + -- eq({}, api.nvim_buf_get_lines(0, 0, -1, true)) feed('gg0<c-v>jj$d') check_events { @@ -1023,7 +1023,7 @@ describe('lua: nvim_buf_attach on_bytes', function() it('virtual edit', function() local check_events = setup_eventcheck(verify, { '', ' ' }) - meths.set_option_value('virtualedit', 'all', {}) + api.nvim_set_option_value('virtualedit', 'all', {}) feed [[<Right><Right>iab<ESC>]] @@ -1042,7 +1042,7 @@ describe('lua: nvim_buf_attach on_bytes', function() it('block visual paste', function() local check_events = setup_eventcheck(verify, { 'AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF' }) - funcs.setreg('a', '___') + fn.setreg('a', '___') feed([[gg0l<c-v>3jl"ap]]) check_events { @@ -1086,20 +1086,20 @@ describe('lua: nvim_buf_attach on_bytes', function() local check_events = setup_eventcheck(verify, { 'AAA', 'BBB' }) -- delete - meths.buf_set_lines(0, 0, 1, true, {}) + api.nvim_buf_set_lines(0, 0, 1, true, {}) check_events { { 'test1', 'bytes', 1, 3, 0, 0, 0, 1, 0, 4, 0, 0, 0 }, } -- add - meths.buf_set_lines(0, 0, 0, true, { 'asdf' }) + api.nvim_buf_set_lines(0, 0, 0, true, { 'asdf' }) check_events { { 'test1', 'bytes', 1, 4, 0, 0, 0, 0, 0, 0, 1, 0, 5 }, } -- replace - meths.buf_set_lines(0, 0, 1, true, { 'asdf', 'fdsa' }) + api.nvim_buf_set_lines(0, 0, 1, true, { 'asdf', 'fdsa' }) check_events { { 'test1', 'bytes', 1, 5, 0, 0, 0, 1, 0, 5, 2, 0, 10 }, } @@ -1211,13 +1211,13 @@ describe('lua: nvim_buf_attach on_bytes', function() command('diffthis') command('new') command('diffthis') - meths.buf_set_lines(0, 0, -1, true, { 'AAA', 'BBB' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'AAA', 'BBB' }) feed('G') command('diffput') check_events { { 'test1', 'bytes', 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 4 }, } - meths.buf_set_lines(0, 0, -1, true, { 'AAA', 'CCC' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'AAA', 'CCC' }) feed('<C-w>pG') command('diffget') check_events { @@ -1259,7 +1259,7 @@ describe('lua: nvim_buf_attach on_bytes', function() { 'test1', 'bytes', 1, 5, 3, 0, 10, 1, 0, 1, 0, 0, 0 }, } - eq('CCC|BBBB|', table.concat(meths.buf_get_lines(0, 0, -1, true), '|')) + eq('CCC|BBBB|', table.concat(api.nvim_buf_get_lines(0, 0, -1, true), '|')) end) end diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index b7bf2b2eae..28a99a86f8 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -3,22 +3,21 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq -local NIL = helpers.NIL +local NIL = vim.NIL local eval = helpers.eval local feed = helpers.feed local clear = helpers.clear local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local exec_lua = helpers.exec_lua local exec_capture = helpers.exec_capture -local funcs = helpers.funcs +local fn = helpers.fn local source = helpers.source local dedent = helpers.dedent local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err local write_file = helpers.write_file -local curbufmeths = helpers.curbufmeths local remove_trace = helpers.remove_trace before_each(clear) @@ -26,23 +25,23 @@ before_each(clear) describe(':lua command', function() it('works', function() eq('', exec_capture('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})')) - eq({ '', 'TEST' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'TEST' }, api.nvim_buf_get_lines(0, 0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"}) EOF]]) - eq({ '', 'TSET' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'TSET' }, api.nvim_buf_get_lines(0, 0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]]) - eq({ '', 'SETT' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'SETT' }, api.nvim_buf_get_lines(0, 0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) EOF]]) - eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'ETTS', 'TTSE', 'STTE' }, api.nvim_buf_get_lines(0, 0, 100, false)) matches( '.*Vim%(lua%):E15: Invalid expression: .*', pcall_err( @@ -68,7 +67,7 @@ describe(':lua command', function() [[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]], remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})')) ) - eq({ '' }, curbufmeths.get_lines(0, 100, false)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, 100, false)) end) it('works with NULL errors', function() eq([=[Vim(lua):E5108: Error executing lua [NULL]]=], exc_exec('lua error(nil)')) @@ -76,19 +75,19 @@ describe(':lua command', function() it('accepts embedded NLs without heredoc', function() -- Such code is usually used for `:execute 'lua' {generated_string}`: -- heredocs do not work in this case. - meths.command([[ + command([[ lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) ]]) - eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'ETTS', 'TTSE', 'STTE' }, api.nvim_buf_get_lines(0, 0, 100, false)) end) it('preserves global and not preserves local variables', function() eq('', exec_capture('lua gvar = 42')) eq('', exec_capture('lua local lvar = 100500')) - eq(NIL, funcs.luaeval('lvar')) - eq(42, funcs.luaeval('gvar')) + eq(NIL, fn.luaeval('lvar')) + eq(42, fn.luaeval('gvar')) end) it('works with long strings', function() local s = ('x'):rep(100500) @@ -97,10 +96,10 @@ describe(':lua command', function() 'Vim(lua):E5107: Error loading lua [string ":lua"]:0: unfinished string near \'<eof>\'', pcall_err(command, ('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s)) ) - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false)) eq('', exec_capture(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s))) - eq({ '', s }, curbufmeths.get_lines(0, -1, false)) + eq({ '', s }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('can show multiline error messages', function() @@ -197,31 +196,31 @@ end) describe(':luado command', function() it('works', function() - curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + api.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' }) eq('', exec_capture('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}')) - eq({ 'ABC', 'def', 'gHi' }, curbufmeths.get_lines(0, -1, false)) - eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, funcs.luaeval('lines')) + eq({ 'ABC', 'def', 'gHi' }, api.nvim_buf_get_lines(0, 0, -1, false)) + eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, fn.luaeval('lines')) -- Automatic transformation of numbers eq('', exec_capture('luado return linenr')) - eq({ '1', '2', '3' }, curbufmeths.get_lines(0, -1, false)) + eq({ '1', '2', '3' }, api.nvim_buf_get_lines(0, 0, -1, false)) eq('', exec_capture('luado return ("<%02x>"):format(line:byte())')) - eq({ '<31>', '<32>', '<33>' }, curbufmeths.get_lines(0, -1, false)) + eq({ '<31>', '<32>', '<33>' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('stops processing lines when suddenly out of lines', function() - curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + api.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' }) eq('', exec_capture('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")')) - eq({ '' }, curbufmeths.get_lines(0, -1, false)) - eq(1, funcs.luaeval('runs')) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false)) + eq(1, fn.luaeval('runs')) end) it('works correctly when changing lines out of range', function() - curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + api.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' }) eq( 'Vim(luado):E322: Line number out of range: 1 past the end', pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr') ) - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('fails on errors', function() eq( @@ -237,12 +236,12 @@ describe(':luado command', function() eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=], exc_exec('luado error(nil)')) end) it('fails in sandbox when needed', function() - curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + api.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' }) eq( 'Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1', pcall_err(command, 'sandbox luado runs = (runs or 0) + 1') ) - eq(NIL, funcs.luaeval('runs')) + eq(NIL, fn.luaeval('runs')) end) it('works with long strings', function() local s = ('x'):rep(100500) @@ -251,10 +250,10 @@ describe(':luado command', function() 'Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'', pcall_err(command, ('luado return "%s'):format(s)) ) - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false)) eq('', exec_capture(('luado return "%s"'):format(s))) - eq({ s }, curbufmeths.get_lines(0, -1, false)) + eq({ s }, api.nvim_buf_get_lines(0, 0, -1, false)) end) end) @@ -275,7 +274,7 @@ describe(':luafile', function() ]] ) eq('', exec_capture('luafile ' .. fname)) - eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'ETTS', 'TTSE', 'STTE' }, api.nvim_buf_get_lines(0, 0, 100, false)) end) it('correctly errors out', function() diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 22ef66bc60..5802925339 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1,12 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) -local NIL = helpers.NIL +local NIL = vim.NIL local command = helpers.command local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq -local nvim = helpers.nvim local matches = helpers.matches +local api = helpers.api local pcall_err = helpers.pcall_err describe('vim.diagnostic', function() @@ -1563,8 +1563,8 @@ describe('vim.diagnostic', function() it('can perform updates after insert_leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1577,15 +1577,15 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) eq( 1, @@ -1596,8 +1596,8 @@ describe('vim.diagnostic', function() it('does not perform updates when not needed', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1619,7 +1619,7 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] @@ -1627,8 +1627,8 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) eq( 1, @@ -1638,11 +1638,11 @@ describe('vim.diagnostic', function() eq(1, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) -- Should not have set the virtual text again. eq(1, exec_lua [[return DisplayCount]]) @@ -1650,8 +1650,8 @@ describe('vim.diagnostic', function() it('never sets virtual text, in combination with insert leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1674,7 +1674,7 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] @@ -1682,8 +1682,8 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) eq( 1, @@ -1693,11 +1693,11 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) -- Should not have set the virtual text still. eq(0, exec_lua [[return DisplayCount]]) @@ -1705,8 +1705,8 @@ describe('vim.diagnostic', function() it('can perform updates while in insert mode, if desired', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1720,15 +1720,15 @@ describe('vim.diagnostic', function() ]] -- Diagnostics are displayed, because the user wanted them that way! - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim('input', '<esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + api.nvim_input('<esc>') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) eq( 1, @@ -1825,7 +1825,7 @@ describe('vim.diagnostic', function() it('respects legacy signs placed with :sign define or sign_define #26618', function() -- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12 - eq(0, helpers.funcs.has('nvim-0.12')) + eq(0, helpers.fn.has('nvim-0.12')) helpers.command( 'sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg' diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua index 50db613dde..8b0e0a8beb 100644 --- a/test/functional/lua/filetype_spec.lua +++ b/test/functional/lua/filetype_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local exec_lua = helpers.exec_lua local eq = helpers.eq -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local pathroot = helpers.pathroot local command = helpers.command @@ -165,6 +165,6 @@ describe('filetype.lua', function() clear({ args = { '--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md' }, }) - eq('notmarkdown', meths.get_option_value('filetype', {})) + eq('notmarkdown', api.nvim_get_option_value('filetype', {})) end) end) diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index c212f4ad9a..66ba0f71f2 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local uv = require('luv') local clear = helpers.clear local exec_lua = helpers.exec_lua @@ -293,7 +292,7 @@ describe('vim.fs', function() eq('/', vim.fs.normalize('/')) end) it('works with ~', function() - eq(vim.fs.normalize(uv.os_homedir()) .. '/src/foo', vim.fs.normalize('~/src/foo')) + eq(vim.fs.normalize(vim.uv.os_homedir()) .. '/src/foo', vim.fs.normalize('~/src/foo')) end) it('works with environment variables', function() local xdg_config_home = test_build_dir .. '/.config' diff --git a/test/functional/lua/highlight_spec.lua b/test/functional/lua/highlight_spec.lua index 8e499f1e79..f304bec411 100644 --- a/test/functional/lua/highlight_spec.lua +++ b/test/functional/lua/highlight_spec.lua @@ -16,7 +16,7 @@ describe('vim.highlight.on_yank', function() vim.highlight.on_yank({timeout = 10, on_macro = true, event = {operator = "y", regtype = "v"}}) vim.cmd('bwipeout!') ]]) - helpers.sleep(10) + vim.uv.sleep(10) helpers.feed('<cr>') -- avoid hang if error message exists eq('', eval('v:errmsg')) end) diff --git a/test/functional/lua/loader_spec.lua b/test/functional/lua/loader_spec.lua index 92dd2296cb..cdb561330a 100644 --- a/test/functional/lua/loader_spec.lua +++ b/test/functional/lua/loader_spec.lua @@ -30,7 +30,7 @@ describe('vim.loader', function() ) -- fs latency - helpers.sleep(10) + vim.uv.sleep(10) eq( 2, diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index e46dbe7455..71eaf29009 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -1,10 +1,10 @@ -- Test suite for testing interactions with API bindings local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local clear = helpers.clear -local sleep = helpers.sleep +local sleep = vim.uv.sleep local feed = helpers.feed local eq = helpers.eq local eval = helpers.eval @@ -16,21 +16,19 @@ before_each(clear) describe('vim.uv', function() it('version', function() - assert(funcs.luaeval('vim.uv.version()') >= 72961, 'libuv version too old') - matches('(%d+)%.(%d+)%.(%d+)', funcs.luaeval('vim.uv.version_string()')) + assert(fn.luaeval('vim.uv.version()') >= 72961, 'libuv version too old') + matches('(%d+)%.(%d+)%.(%d+)', fn.luaeval('vim.uv.version_string()')) end) it('timer', function() exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {}) local code = [[ - local uv = vim.uv - local touch = 0 local function wait(ms) local this = coroutine.running() assert(this) - local timer = uv.new_timer() + local timer = vim.uv.new_timer() timer:start(ms, 0, vim.schedule_wrap(function () timer:close() touch = touch + 1 @@ -50,13 +48,13 @@ describe('vim.uv', function() end)() ]] - eq(0, meths.get_var('coroutine_cnt')) + eq(0, api.nvim_get_var('coroutine_cnt')) exec_lua(code) retry(2, nil, function() sleep(50) - eq(2, meths.get_var('coroutine_cnt')) + eq(2, api.nvim_get_var('coroutine_cnt')) end) - eq(3, meths.get_var('coroutine_cnt_1')) + eq(3, api.nvim_get_var('coroutine_cnt_1')) end) it('is API safe', function() diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 45a7258884..6ed7af6b6e 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -7,12 +7,12 @@ local exc_exec = helpers.exc_exec local remove_trace = helpers.remove_trace local exec_lua = helpers.exec_lua local command = helpers.command -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local clear = helpers.clear local eval = helpers.eval local feed = helpers.feed -local NIL = helpers.NIL +local NIL = vim.NIL local eq = helpers.eq before_each(clear) @@ -39,7 +39,7 @@ describe('luaeval()', function() describe('second argument', function() it('is successfully received', function() local t = {t=true, f=false, --[[n=NIL,]] d={l={'string', 42, 0.42}}} - eq(t, funcs.luaeval("_A", t)) + eq(t, fn.luaeval("_A", t)) -- Not tested: nil, funcrefs, returned object identity: behaviour will -- most likely change. end) @@ -47,37 +47,37 @@ describe('luaeval()', function() describe('lua values', function() it('are successfully transformed', function() eq({n=1, f=1.5, s='string', l={4, 2}}, - funcs.luaeval('{n=1, f=1.5, s="string", l={4, 2}}')) + fn.luaeval('{n=1, f=1.5, s="string", l={4, 2}}')) -- Not tested: nil inside containers: behaviour will most likely change. - eq(NIL, funcs.luaeval('nil')) - eq({['']=1}, funcs.luaeval('{[""]=1}')) + eq(NIL, fn.luaeval('nil')) + eq({['']=1}, fn.luaeval('{[""]=1}')) end) end) describe('recursive lua values', function() it('are successfully transformed', function() command('lua rawset(_G, "d", {})') command('lua rawset(d, "d", d)') - eq('\n{\'d\': {...@0}}', funcs.execute('echo luaeval("d")')) + eq('\n{\'d\': {...@0}}', fn.execute('echo luaeval("d")')) command('lua rawset(_G, "l", {})') command('lua table.insert(l, l)') - eq('\n[[...@0]]', funcs.execute('echo luaeval("l")')) + eq('\n[[...@0]]', fn.execute('echo luaeval("l")')) end) end) describe('strings with NULs', function() it('are successfully converted to blobs', function() command([[let s = luaeval('"\0"')]]) - eq('\000', meths.get_var('s')) + eq('\000', api.nvim_get_var('s')) end) it('are successfully converted to special dictionaries in table keys', function() command([[let d = luaeval('{["\0"]=1}')]]) - eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n'}}, 1}}}, meths.get_var('d')) - eq(1, funcs.eval('d._TYPE is v:msgpack_types.map')) - eq(1, funcs.eval('d._VAL[0][0]._TYPE is v:msgpack_types.string')) + eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n'}}, 1}}}, api.nvim_get_var('d')) + eq(1, fn.eval('d._TYPE is v:msgpack_types.map')) + eq(1, fn.eval('d._VAL[0][0]._TYPE is v:msgpack_types.string')) end) it('are successfully converted to blobs from a list', function() command([[let l = luaeval('{"abc", "a\0b", "c\0d", "def"}')]]) - eq({'abc', 'a\000b', 'c\000d', 'def'}, meths.get_var('l')) + eq({'abc', 'a\000b', 'c\000d', 'def'}, api.nvim_get_var('l')) end) end) @@ -86,68 +86,68 @@ describe('luaeval()', function() it('correctly evaluates scalars', function() -- Also test method call (->) syntax - eq(1, funcs.luaeval('1')) + eq(1, fn.luaeval('1')) eq(0, eval('"1"->luaeval()->type()')) - eq(1.5, funcs.luaeval('1.5')) + eq(1.5, fn.luaeval('1.5')) eq(5, eval('"1.5"->luaeval()->type()')) - eq("test", funcs.luaeval('"test"')) + eq("test", fn.luaeval('"test"')) eq(1, eval('"\'test\'"->luaeval()->type()')) - eq('', funcs.luaeval('""')) - eq('\000', funcs.luaeval([['\0']])) - eq('\000\n\000', funcs.luaeval([['\0\n\0']])) + eq('', fn.luaeval('""')) + eq('\000', fn.luaeval([['\0']])) + eq('\000\n\000', fn.luaeval([['\0\n\0']])) eq(10, eval([[type(luaeval("'\\0\\n\\0'"))]])) - eq(true, funcs.luaeval('true')) - eq(false, funcs.luaeval('false')) - eq(NIL, funcs.luaeval('nil')) + eq(true, fn.luaeval('true')) + eq(false, fn.luaeval('false')) + eq(NIL, fn.luaeval('nil')) end) it('correctly evaluates containers', function() - eq({}, funcs.luaeval('{}')) + eq({}, fn.luaeval('{}')) eq(3, eval('type(luaeval("{}"))')) - eq({test=1, foo=2}, funcs.luaeval('{test=1, foo=2}')) + eq({test=1, foo=2}, fn.luaeval('{test=1, foo=2}')) eq(4, eval('type(luaeval("{test=1, foo=2}"))')) - eq({4, 2}, funcs.luaeval('{4, 2}')) + eq({4, 2}, fn.luaeval('{4, 2}')) eq(3, eval('type(luaeval("{4, 2}"))')) - eq({NIL, 20}, funcs.luaeval('{[2] = 20}')) + eq({NIL, 20}, fn.luaeval('{[2] = 20}')) eq(3, eval('type(luaeval("{[2] = 20}"))')) - eq({10, NIL, 30}, funcs.luaeval('{[1] = 10, [3] = 30}')) + eq({10, NIL, 30}, fn.luaeval('{[1] = 10, [3] = 30}')) eq(3, eval('type(luaeval("{[1] = 10, [3] = 30}"))')) local level = 30 - eq(nested_by_level[level].o, funcs.luaeval(nested_by_level[level].s)) + eq(nested_by_level[level].o, fn.luaeval(nested_by_level[level].s)) eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, '\000\n\000\000'}}}, - funcs.luaeval([[{['\0\n\0']='\0\n\0\0'}]])) + fn.luaeval([[{['\0\n\0']='\0\n\0\0'}]])) eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._TYPE is v:msgpack_types.map]])) eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][0]._TYPE is v:msgpack_types.string]])) eq({nested={{_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, '\000\n\000\000'}}}}}, - funcs.luaeval([[{nested={{['\0\n\0']='\0\n\0\0'}}}]])) + fn.luaeval([[{nested={{['\0\n\0']='\0\n\0\0'}}}]])) end) it('correctly passes scalars as argument', function() - eq(1, funcs.luaeval('_A', 1)) - eq(1.5, funcs.luaeval('_A', 1.5)) - eq('', funcs.luaeval('_A', '')) - eq('test', funcs.luaeval('_A', 'test')) - eq(NIL, funcs.luaeval('_A', NIL)) - eq(true, funcs.luaeval('_A', true)) - eq(false, funcs.luaeval('_A', false)) + eq(1, fn.luaeval('_A', 1)) + eq(1.5, fn.luaeval('_A', 1.5)) + eq('', fn.luaeval('_A', '')) + eq('test', fn.luaeval('_A', 'test')) + eq(NIL, fn.luaeval('_A', NIL)) + eq(true, fn.luaeval('_A', true)) + eq(false, fn.luaeval('_A', false)) end) it('correctly passes containers as argument', function() - eq({}, funcs.luaeval('_A', {})) - eq({test=1}, funcs.luaeval('_A', {test=1})) - eq({4, 2}, funcs.luaeval('_A', {4, 2})) + eq({}, fn.luaeval('_A', {})) + eq({test=1}, fn.luaeval('_A', {test=1})) + eq({4, 2}, fn.luaeval('_A', {4, 2})) local level = 28 - eq(nested_by_level[level].o, funcs.luaeval('_A', nested_by_level[level].o)) + eq(nested_by_level[level].o, fn.luaeval('_A', nested_by_level[level].o)) end) local function sp(typ, val) @@ -399,26 +399,26 @@ describe('luaeval()', function() eq(4, eval([[type(luaeval('{[vim.type_idx]=vim.types.dictionary}'))]])) eq(3, eval([[type(luaeval('{[vim.type_idx]=vim.types.array}'))]])) - eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.array}')) + eq({}, fn.luaeval('{[vim.type_idx]=vim.types.array}')) -- Presence of type_idx makes Vim ignore some keys - eq({42}, funcs.luaeval('{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) - eq({foo=2}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) - eq(10, funcs.luaeval('{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + eq({42}, fn.luaeval('{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + eq({foo=2}, fn.luaeval('{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + eq(10, fn.luaeval('{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) -- The following should not crash - eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary}')) + eq({}, fn.luaeval('{[vim.type_idx]=vim.types.dictionary}')) end) it('correctly converts self-containing containers', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') eq(true, eval('luaeval("_A == _A[1]", l)')) eq(true, eval('luaeval("_A[1] == _A[1][1]", [l])')) eq(true, eval('luaeval("_A.d == _A.d[1]", {"d": l})')) eq(true, eval('luaeval("_A ~= _A[1]", [l])')) - meths.set_var('d', {foo=42}) + api.nvim_set_var('d', {foo=42}) eval('extend(d, {"d": d})') eq(true, eval('luaeval("_A == _A.d", d)')) eq(true, eval('luaeval("_A[1] == _A[1].d", [d])')) @@ -441,7 +441,7 @@ describe('luaeval()', function() local s = ('x'):rep(65536) eq('Vim(call):E5107: Error loading lua [string "luaeval()"]:1: unexpected symbol near \')\'', exc_exec([[call luaeval("(']] .. s ..[[' + )")]])) - eq(s, funcs.luaeval('"' .. s .. '"')) + eq(s, fn.luaeval('"' .. s .. '"')) end) end) @@ -478,7 +478,7 @@ describe('v:lua', function() eq(7, eval('v:lua.foo(3,4,v:null)')) eq(true, exec_lua([[return _G.val == vim.NIL]])) eq(NIL, eval('v:lua.mymod.noisy("eval")')) - eq("hey eval", meths.get_current_line()) + eq("hey eval", api.nvim_get_current_line()) eq("string: abc", eval('v:lua.mymod.whatis(0z616263)')) eq("string: ", eval('v:lua.mymod.whatis(v:_null_blob)')) @@ -494,7 +494,7 @@ describe('v:lua', function() eq("boop", exec_lua([[return _G.val]])) eq(NIL, eval('"there"->v:lua.mymod.noisy()')) - eq("hey there", meths.get_current_line()) + eq("hey there", api.nvim_get_current_line()) eq({5, 10, 15, 20}, eval('[[1], [2, 3], [4]]->v:lua.vim.tbl_flatten()->map({_, v -> v * 5})')) eq("Vim:E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)", @@ -503,7 +503,7 @@ describe('v:lua', function() it('works in :call', function() command(":call v:lua.mymod.noisy('command')") - eq("hey command", meths.get_current_line()) + eq("hey command", api.nvim_get_current_line()) eq("Vim(call):E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)", pcall_err(command, 'call v:lua.mymod.crashy()')) end) @@ -518,7 +518,7 @@ describe('v:lua', function() [5] = {bold = true, foreground = Screen.colors.SeaGreen4}, }) screen:attach() - meths.set_option_value('omnifunc', 'v:lua.mymod.omni', {}) + api.nvim_set_option_value('omnifunc', 'v:lua.mymod.omni', {}) feed('isome st<c-x><c-o>') screen:expect{grid=[[ some stuff^ | @@ -528,9 +528,9 @@ describe('v:lua', function() {1:~ }|*3 {4:-- Omni completion (^O^N^P) }{5:match 1 of 3} | ]]} - meths.set_option_value('operatorfunc', 'v:lua.mymod.noisy', {}) + api.nvim_set_option_value('operatorfunc', 'v:lua.mymod.noisy', {}) feed('<Esc>g@g@') - eq("hey line", meths.get_current_line()) + eq("hey line", api.nvim_get_current_line()) end) it('supports packages', function() diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 0f1c7d8a51..ecbdde3bfd 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -3,11 +3,11 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq -local NIL = helpers.NIL +local NIL = vim.NIL local feed = helpers.feed local clear = helpers.clear -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local command = helpers.command local write_file = helpers.write_file local exec_capture = helpers.exec_capture @@ -25,15 +25,15 @@ end) describe('print', function() it('returns nothing', function() - eq(NIL, funcs.luaeval('print("abc")')) - eq(0, funcs.luaeval('select("#", print("abc"))')) + eq(NIL, fn.luaeval('print("abc")')) + eq(0, fn.luaeval('select("#", print("abc"))')) end) it('allows catching printed text with :execute', function() - eq('\nabc', funcs.execute('lua print("abc")')) - eq('\nabc', funcs.execute('luado print("abc")')) - eq('\nabc', funcs.execute('call luaeval("print(\'abc\')")')) + eq('\nabc', fn.execute('lua print("abc")')) + eq('\nabc', fn.execute('luado print("abc")')) + eq('\nabc', fn.execute('call luaeval("print(\'abc\')")')) write_file(fname, 'print("abc")') - eq('\nabc', funcs.execute('luafile ' .. fname)) + eq('\nabc', fn.execute('luafile ' .. fname)) eq('abc', exec_capture('lua print("abc")')) eq('abc', exec_capture('luado print("abc")')) @@ -113,7 +113,7 @@ describe('print', function() eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua bad_custom_error()')) end) it('prints strings with NULs and NLs correctly', function() - meths.set_option_value('more', true, {}) + api.nvim_set_option_value('more', true, {}) eq( 'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]]) @@ -332,17 +332,17 @@ end) describe('os.getenv', function() it('returns nothing for undefined env var', function() - eq(NIL, funcs.luaeval('os.getenv("XTEST_1")')) + eq(NIL, fn.luaeval('os.getenv("XTEST_1")')) end) it('returns env var set by the parent process', function() local value = 'foo' clear({ env = { ['XTEST_1'] = value } }) - eq(value, funcs.luaeval('os.getenv("XTEST_1")')) + eq(value, fn.luaeval('os.getenv("XTEST_1")')) end) it('returns env var set by let', function() local value = 'foo' - meths.command('let $XTEST_1 = "' .. value .. '"') - eq(value, funcs.luaeval('os.getenv("XTEST_1")')) + command('let $XTEST_1 = "' .. value .. '"') + eq(value, fn.luaeval('os.getenv("XTEST_1")')) end) end) diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index 84948490ae..6f36ccfb9e 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval local exec = helpers.exec -local funcs = helpers.funcs +local fn = helpers.fn local mkdir_p = helpers.mkdir_p local rmdir = helpers.rmdir local write_file = helpers.write_file @@ -48,8 +48,8 @@ describe('runtime:', function() local colorscheme_file = table.concat({ colorscheme_folder, 'new_colorscheme.lua' }, sep) write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]]) - eq({ 'new_colorscheme' }, funcs.getcompletion('new_c', 'color')) - eq({ 'colors/new_colorscheme.lua' }, funcs.getcompletion('colors/new_c', 'runtime')) + eq({ 'new_colorscheme' }, fn.getcompletion('new_c', 'color')) + eq({ 'colors/new_colorscheme.lua' }, fn.getcompletion('colors/new_c', 'runtime')) exec('colorscheme new_colorscheme') @@ -126,8 +126,8 @@ describe('runtime:', function() local compiler_file = compiler_folder .. sep .. 'new_compiler.lua' write_file(compiler_file, [[vim.b.lua_compiler = 1]]) - eq({ 'new_compiler' }, funcs.getcompletion('new_c', 'compiler')) - eq({ 'compiler/new_compiler.lua' }, funcs.getcompletion('compiler/new_c', 'runtime')) + eq({ 'new_compiler' }, fn.getcompletion('new_c', 'compiler')) + eq({ 'compiler/new_compiler.lua' }, fn.getcompletion('compiler/new_c', 'runtime')) exec('compiler new_compiler') @@ -168,8 +168,8 @@ describe('runtime:', function() local ftplugin_file = table.concat({ ftplugin_folder, 'new-ft.lua' }, sep) write_file(ftplugin_file, [[vim.b.lua_ftplugin = 1]]) - eq({ 'new-ft' }, funcs.getcompletion('new-f', 'filetype')) - eq({ 'ftplugin/new-ft.lua' }, funcs.getcompletion('ftplugin/new-f', 'runtime')) + eq({ 'new-ft' }, fn.getcompletion('new-f', 'filetype')) + eq({ 'ftplugin/new-ft.lua' }, fn.getcompletion('ftplugin/new-f', 'runtime')) exec [[set filetype=new-ft]] eq(1, eval('b:lua_ftplugin')) @@ -281,8 +281,8 @@ describe('runtime:', function() local indent_file = table.concat({ indent_folder, 'new-ft.lua' }, sep) write_file(indent_file, [[vim.b.lua_indent = 1]]) - eq({ 'new-ft' }, funcs.getcompletion('new-f', 'filetype')) - eq({ 'indent/new-ft.lua' }, funcs.getcompletion('indent/new-f', 'runtime')) + eq({ 'new-ft' }, fn.getcompletion('new-f', 'filetype')) + eq({ 'indent/new-ft.lua' }, fn.getcompletion('indent/new-f', 'runtime')) exec [[set filetype=new-ft]] eq(1, eval('b:lua_indent')) @@ -338,9 +338,9 @@ describe('runtime:', function() end) it('lua syntaxes are included in cmdline completion', function() - eq({ 'my-lang' }, funcs.getcompletion('my-l', 'filetype')) - eq({ 'my-lang' }, funcs.getcompletion('my-l', 'syntax')) - eq({ 'syntax/my-lang.lua' }, funcs.getcompletion('syntax/my-l', 'runtime')) + eq({ 'my-lang' }, fn.getcompletion('my-l', 'filetype')) + eq({ 'my-lang' }, fn.getcompletion('my-l', 'syntax')) + eq({ 'syntax/my-lang.lua' }, fn.getcompletion('syntax/my-l', 'runtime')) end) it("'rtp' order is respected", function() diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua index 52770867a8..7aed711b23 100644 --- a/test/functional/lua/secure_spec.lua +++ b/test/functional/lua/secure_spec.lua @@ -6,11 +6,11 @@ local clear = helpers.clear local command = helpers.command local pathsep = helpers.get_pathsep() local is_os = helpers.is_os -local meths = helpers.meths +local api = helpers.api local exec_lua = helpers.exec_lua local feed_command = helpers.feed_command local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn local pcall_err = helpers.pcall_err local matches = helpers.matches @@ -45,7 +45,7 @@ describe('vim.secure', function() }) --- XXX: screen:expect() may fail if this path is too long. - local cwd = funcs.getcwd() + local cwd = fn.getcwd() -- Need to use feed_command instead of exec_lua because of the confirmation prompt feed_command([[lua vim.secure.read('Xfile')]]) @@ -71,11 +71,11 @@ describe('vim.secure', function() ]], } - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'Xfile'), vim.trim(trust)) - eq(helpers.NIL, exec_lua([[return vim.secure.read('Xfile')]])) + eq(vim.NIL, exec_lua([[return vim.secure.read('Xfile')]])) - os.remove(funcs.stdpath('state') .. pathsep .. 'trust') + os.remove(fn.stdpath('state') .. pathsep .. 'trust') feed_command([[lua vim.secure.read('Xfile')]]) screen:expect { @@ -100,12 +100,12 @@ describe('vim.secure', function() ]], } - local hash = funcs.sha256(helpers.read_file('Xfile')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local hash = fn.sha256(helpers.read_file('Xfile')) + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'Xfile'), vim.trim(trust)) - eq(helpers.NIL, exec_lua([[vim.secure.read('Xfile')]])) + eq(vim.NIL, exec_lua([[vim.secure.read('Xfile')]])) - os.remove(funcs.stdpath('state') .. pathsep .. 'trust') + os.remove(fn.stdpath('state') .. pathsep .. 'trust') feed_command([[lua vim.secure.read('Xfile')]]) screen:expect { @@ -131,7 +131,7 @@ describe('vim.secure', function() } -- Trust database is not updated - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(nil, trust) feed_command([[lua vim.secure.read('Xfile')]]) @@ -154,7 +154,7 @@ describe('vim.secure', function() ^let g:foobar = 42 | {1:~ }|*2 {2:]] - .. funcs.fnamemodify(cwd, ':~') + .. fn.fnamemodify(cwd, ':~') .. pathsep .. [[Xfile [RO]{MATCH:%s+}}| | @@ -165,12 +165,12 @@ describe('vim.secure', function() } -- Trust database is not updated - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(nil, trust) -- Cannot write file pcall_err(command, 'write') - eq(true, meths.get_option_value('readonly', {})) + eq(true, api.nvim_get_option_value('readonly', {})) end) end) @@ -209,71 +209,71 @@ describe('vim.secure', function() end) it('trust then deny then remove a file using bufnr', function() - local cwd = funcs.getcwd() - local hash = funcs.sha256(helpers.read_file('test_file')) + local cwd = fn.getcwd() + local hash = fn.sha256(helpers.read_file('test_file')) local full_path = cwd .. pathsep .. 'test_file' command('edit test_file') eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, full_path), vim.trim(trust)) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', full_path), vim.trim(trust)) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]])) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq('', vim.trim(trust)) end) it('deny then trust then remove a file using bufnr', function() - local cwd = funcs.getcwd() - local hash = funcs.sha256(helpers.read_file('test_file')) + local cwd = fn.getcwd() + local hash = fn.sha256(helpers.read_file('test_file')) local full_path = cwd .. pathsep .. 'test_file' command('edit test_file') eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', full_path), vim.trim(trust)) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, full_path), vim.trim(trust)) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]])) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq('', vim.trim(trust)) end) it('trust using bufnr then deny then remove a file using path', function() - local cwd = funcs.getcwd() - local hash = funcs.sha256(helpers.read_file('test_file')) + local cwd = fn.getcwd() + local hash = fn.sha256(helpers.read_file('test_file')) local full_path = cwd .. pathsep .. 'test_file' command('edit test_file') eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, full_path), vim.trim(trust)) eq( { true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]]) ) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', full_path), vim.trim(trust)) eq( { true, full_path }, exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]]) ) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq('', vim.trim(trust)) end) it('deny then trust then remove a file using bufnr', function() - local cwd = funcs.getcwd() - local hash = funcs.sha256(helpers.read_file('test_file')) + local cwd = fn.getcwd() + local hash = fn.sha256(helpers.read_file('test_file')) local full_path = cwd .. pathsep .. 'test_file' command('edit test_file') @@ -281,18 +281,18 @@ describe('vim.secure', function() { true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]]) ) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', full_path), vim.trim(trust)) eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, full_path), vim.trim(trust)) eq( { true, full_path }, exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]]) ) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq('', vim.trim(trust)) end) diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua index defd13429e..bf73e6c6fd 100644 --- a/test/functional/lua/snippet_spec.lua +++ b/test/functional/lua/snippet_spec.lua @@ -7,7 +7,7 @@ local exec_lua = helpers.exec_lua local feed = helpers.feed local matches = helpers.matches local pcall_err = helpers.pcall_err -local sleep = helpers.sleep +local sleep = vim.uv.sleep describe('vim.snippet', function() before_each(function() diff --git a/test/functional/lua/thread_spec.lua b/test/functional/lua/thread_spec.lua index 0a7a7f0448..c1981e19d4 100644 --- a/test/functional/lua/thread_spec.lua +++ b/test/functional/lua/thread_spec.lua @@ -6,7 +6,7 @@ local feed = helpers.feed local eq = helpers.eq local exec_lua = helpers.exec_lua local next_msg = helpers.next_msg -local NIL = helpers.NIL +local NIL = vim.NIL local pcall_err = helpers.pcall_err describe('thread', function() diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index c0a0b3e762..3e46018682 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -4,8 +4,7 @@ local eq = helpers.eq local exec_lua = helpers.exec_lua local clear = helpers.clear local feed = helpers.feed -local funcs = helpers.funcs -local inspect = require 'vim.inspect' +local fn = helpers.fn describe('vim.ui_attach', function() local screen @@ -38,7 +37,7 @@ describe('vim.ui_attach', function() local function expect_events(expected) local evs = exec_lua 'return get_events(...)' - eq(expected, evs, inspect(evs)) + eq(expected, evs, vim.inspect(evs)) end it('can receive popupmenu events', function() @@ -52,7 +51,7 @@ describe('vim.ui_attach', function() ]], } - funcs.complete(1, { 'food', 'foobar', 'foo' }) + fn.complete(1, { 'food', 'foobar', 'foo' }) screen:expect { grid = [[ food^ | @@ -108,7 +107,7 @@ describe('vim.ui_attach', function() end) it('does not crash on exit', function() - funcs.system({ + fn.system({ helpers.nvim_prog, '-u', 'NONE', @@ -148,6 +147,6 @@ describe('vim.ui_attach', function() { 'echomsg', { { 0, 'message3' } } }, }, }, - }, actual, inspect(actual)) + }, actual, vim.inspect(actual)) end) end) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 4ebba827ef..73fb4c1917 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -3,22 +3,22 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local nvim_prog = helpers.nvim_prog -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local command = helpers.command local dedent = helpers.dedent local insert = helpers.insert local clear = helpers.clear local eq = helpers.eq local ok = helpers.ok -local pesc = helpers.pesc +local pesc = vim.pesc local eval = helpers.eval local feed = helpers.feed local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua local matches = helpers.matches local exec = helpers.exec -local NIL = helpers.NIL +local NIL = vim.NIL local retry = helpers.retry local next_msg = helpers.next_msg local remove_trace = helpers.remove_trace @@ -39,93 +39,93 @@ describe('lua stdlib', function() -- Note: Built-in Nvim comparison (on systems lacking `strcasecmp`) works -- only on ASCII characters. it('vim.stricmp', function() - eq(0, funcs.luaeval('vim.stricmp("a", "A")')) - eq(0, funcs.luaeval('vim.stricmp("A", "a")')) - eq(0, funcs.luaeval('vim.stricmp("a", "a")')) - eq(0, funcs.luaeval('vim.stricmp("A", "A")')) - - eq(0, funcs.luaeval('vim.stricmp("", "")')) - eq(0, funcs.luaeval('vim.stricmp("\\0", "\\0")')) - eq(0, funcs.luaeval('vim.stricmp("\\0\\0", "\\0\\0")')) - eq(0, funcs.luaeval('vim.stricmp("\\0\\0\\0", "\\0\\0\\0")')) - eq(0, funcs.luaeval('vim.stricmp("\\0\\0\\0A", "\\0\\0\\0a")')) - eq(0, funcs.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0A")')) - eq(0, funcs.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0a")')) - - eq(0, funcs.luaeval('vim.stricmp("a\\0", "A\\0")')) - eq(0, funcs.luaeval('vim.stricmp("A\\0", "a\\0")')) - eq(0, funcs.luaeval('vim.stricmp("a\\0", "a\\0")')) - eq(0, funcs.luaeval('vim.stricmp("A\\0", "A\\0")')) - - eq(0, funcs.luaeval('vim.stricmp("\\0a", "\\0A")')) - eq(0, funcs.luaeval('vim.stricmp("\\0A", "\\0a")')) - eq(0, funcs.luaeval('vim.stricmp("\\0a", "\\0a")')) - eq(0, funcs.luaeval('vim.stricmp("\\0A", "\\0A")')) - - eq(0, funcs.luaeval('vim.stricmp("\\0a\\0", "\\0A\\0")')) - eq(0, funcs.luaeval('vim.stricmp("\\0A\\0", "\\0a\\0")')) - eq(0, funcs.luaeval('vim.stricmp("\\0a\\0", "\\0a\\0")')) - eq(0, funcs.luaeval('vim.stricmp("\\0A\\0", "\\0A\\0")')) - - eq(-1, funcs.luaeval('vim.stricmp("a", "B")')) - eq(-1, funcs.luaeval('vim.stricmp("A", "b")')) - eq(-1, funcs.luaeval('vim.stricmp("a", "b")')) - eq(-1, funcs.luaeval('vim.stricmp("A", "B")')) - - eq(-1, funcs.luaeval('vim.stricmp("", "\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0", "\\0\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0\\0", "\\0\\0\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0\\0\\0A", "\\0\\0\\0b")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0B")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0b")')) - - eq(-1, funcs.luaeval('vim.stricmp("a\\0", "B\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("A\\0", "b\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("a\\0", "b\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("A\\0", "B\\0")')) - - eq(-1, funcs.luaeval('vim.stricmp("\\0a", "\\0B")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0A", "\\0b")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0a", "\\0b")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0A", "\\0B")')) - - eq(-1, funcs.luaeval('vim.stricmp("\\0a\\0", "\\0B\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0A\\0", "\\0b\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0a\\0", "\\0b\\0")')) - eq(-1, funcs.luaeval('vim.stricmp("\\0A\\0", "\\0B\\0")')) - - eq(1, funcs.luaeval('vim.stricmp("c", "B")')) - eq(1, funcs.luaeval('vim.stricmp("C", "b")')) - eq(1, funcs.luaeval('vim.stricmp("c", "b")')) - eq(1, funcs.luaeval('vim.stricmp("C", "B")')) - - eq(1, funcs.luaeval('vim.stricmp("\\0", "")')) - eq(1, funcs.luaeval('vim.stricmp("\\0\\0", "\\0")')) - eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0", "\\0\\0")')) - eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0\\0", "\\0\\0\\0")')) - eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0C", "\\0\\0\\0b")')) - eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0c", "\\0\\0\\0B")')) - eq(1, funcs.luaeval('vim.stricmp("\\0\\0\\0c", "\\0\\0\\0b")')) - - eq(1, funcs.luaeval('vim.stricmp("c\\0", "B\\0")')) - eq(1, funcs.luaeval('vim.stricmp("C\\0", "b\\0")')) - eq(1, funcs.luaeval('vim.stricmp("c\\0", "b\\0")')) - eq(1, funcs.luaeval('vim.stricmp("C\\0", "B\\0")')) - - eq(1, funcs.luaeval('vim.stricmp("c\\0", "B")')) - eq(1, funcs.luaeval('vim.stricmp("C\\0", "b")')) - eq(1, funcs.luaeval('vim.stricmp("c\\0", "b")')) - eq(1, funcs.luaeval('vim.stricmp("C\\0", "B")')) - - eq(1, funcs.luaeval('vim.stricmp("\\0c", "\\0B")')) - eq(1, funcs.luaeval('vim.stricmp("\\0C", "\\0b")')) - eq(1, funcs.luaeval('vim.stricmp("\\0c", "\\0b")')) - eq(1, funcs.luaeval('vim.stricmp("\\0C", "\\0B")')) - - eq(1, funcs.luaeval('vim.stricmp("\\0c\\0", "\\0B\\0")')) - eq(1, funcs.luaeval('vim.stricmp("\\0C\\0", "\\0b\\0")')) - eq(1, funcs.luaeval('vim.stricmp("\\0c\\0", "\\0b\\0")')) - eq(1, funcs.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")')) + eq(0, fn.luaeval('vim.stricmp("a", "A")')) + eq(0, fn.luaeval('vim.stricmp("A", "a")')) + eq(0, fn.luaeval('vim.stricmp("a", "a")')) + eq(0, fn.luaeval('vim.stricmp("A", "A")')) + + eq(0, fn.luaeval('vim.stricmp("", "")')) + eq(0, fn.luaeval('vim.stricmp("\\0", "\\0")')) + eq(0, fn.luaeval('vim.stricmp("\\0\\0", "\\0\\0")')) + eq(0, fn.luaeval('vim.stricmp("\\0\\0\\0", "\\0\\0\\0")')) + eq(0, fn.luaeval('vim.stricmp("\\0\\0\\0A", "\\0\\0\\0a")')) + eq(0, fn.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0A")')) + eq(0, fn.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0a")')) + + eq(0, fn.luaeval('vim.stricmp("a\\0", "A\\0")')) + eq(0, fn.luaeval('vim.stricmp("A\\0", "a\\0")')) + eq(0, fn.luaeval('vim.stricmp("a\\0", "a\\0")')) + eq(0, fn.luaeval('vim.stricmp("A\\0", "A\\0")')) + + eq(0, fn.luaeval('vim.stricmp("\\0a", "\\0A")')) + eq(0, fn.luaeval('vim.stricmp("\\0A", "\\0a")')) + eq(0, fn.luaeval('vim.stricmp("\\0a", "\\0a")')) + eq(0, fn.luaeval('vim.stricmp("\\0A", "\\0A")')) + + eq(0, fn.luaeval('vim.stricmp("\\0a\\0", "\\0A\\0")')) + eq(0, fn.luaeval('vim.stricmp("\\0A\\0", "\\0a\\0")')) + eq(0, fn.luaeval('vim.stricmp("\\0a\\0", "\\0a\\0")')) + eq(0, fn.luaeval('vim.stricmp("\\0A\\0", "\\0A\\0")')) + + eq(-1, fn.luaeval('vim.stricmp("a", "B")')) + eq(-1, fn.luaeval('vim.stricmp("A", "b")')) + eq(-1, fn.luaeval('vim.stricmp("a", "b")')) + eq(-1, fn.luaeval('vim.stricmp("A", "B")')) + + eq(-1, fn.luaeval('vim.stricmp("", "\\0")')) + eq(-1, fn.luaeval('vim.stricmp("\\0", "\\0\\0")')) + eq(-1, fn.luaeval('vim.stricmp("\\0\\0", "\\0\\0\\0")')) + eq(-1, fn.luaeval('vim.stricmp("\\0\\0\\0A", "\\0\\0\\0b")')) + eq(-1, fn.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0B")')) + eq(-1, fn.luaeval('vim.stricmp("\\0\\0\\0a", "\\0\\0\\0b")')) + + eq(-1, fn.luaeval('vim.stricmp("a\\0", "B\\0")')) + eq(-1, fn.luaeval('vim.stricmp("A\\0", "b\\0")')) + eq(-1, fn.luaeval('vim.stricmp("a\\0", "b\\0")')) + eq(-1, fn.luaeval('vim.stricmp("A\\0", "B\\0")')) + + eq(-1, fn.luaeval('vim.stricmp("\\0a", "\\0B")')) + eq(-1, fn.luaeval('vim.stricmp("\\0A", "\\0b")')) + eq(-1, fn.luaeval('vim.stricmp("\\0a", "\\0b")')) + eq(-1, fn.luaeval('vim.stricmp("\\0A", "\\0B")')) + + eq(-1, fn.luaeval('vim.stricmp("\\0a\\0", "\\0B\\0")')) + eq(-1, fn.luaeval('vim.stricmp("\\0A\\0", "\\0b\\0")')) + eq(-1, fn.luaeval('vim.stricmp("\\0a\\0", "\\0b\\0")')) + eq(-1, fn.luaeval('vim.stricmp("\\0A\\0", "\\0B\\0")')) + + eq(1, fn.luaeval('vim.stricmp("c", "B")')) + eq(1, fn.luaeval('vim.stricmp("C", "b")')) + eq(1, fn.luaeval('vim.stricmp("c", "b")')) + eq(1, fn.luaeval('vim.stricmp("C", "B")')) + + eq(1, fn.luaeval('vim.stricmp("\\0", "")')) + eq(1, fn.luaeval('vim.stricmp("\\0\\0", "\\0")')) + eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0", "\\0\\0")')) + eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0\\0", "\\0\\0\\0")')) + eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0C", "\\0\\0\\0b")')) + eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0c", "\\0\\0\\0B")')) + eq(1, fn.luaeval('vim.stricmp("\\0\\0\\0c", "\\0\\0\\0b")')) + + eq(1, fn.luaeval('vim.stricmp("c\\0", "B\\0")')) + eq(1, fn.luaeval('vim.stricmp("C\\0", "b\\0")')) + eq(1, fn.luaeval('vim.stricmp("c\\0", "b\\0")')) + eq(1, fn.luaeval('vim.stricmp("C\\0", "B\\0")')) + + eq(1, fn.luaeval('vim.stricmp("c\\0", "B")')) + eq(1, fn.luaeval('vim.stricmp("C\\0", "b")')) + eq(1, fn.luaeval('vim.stricmp("c\\0", "b")')) + eq(1, fn.luaeval('vim.stricmp("C\\0", "B")')) + + eq(1, fn.luaeval('vim.stricmp("\\0c", "\\0B")')) + eq(1, fn.luaeval('vim.stricmp("\\0C", "\\0b")')) + eq(1, fn.luaeval('vim.stricmp("\\0c", "\\0b")')) + eq(1, fn.luaeval('vim.stricmp("\\0C", "\\0B")')) + + eq(1, fn.luaeval('vim.stricmp("\\0c\\0", "\\0B\\0")')) + eq(1, fn.luaeval('vim.stricmp("\\0C\\0", "\\0b\\0")')) + eq(1, fn.luaeval('vim.stricmp("\\0c\\0", "\\0b\\0")')) + eq(1, fn.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")')) end) it('vim.deprecate', function() @@ -157,14 +157,14 @@ describe('lua stdlib', function() end) it('vim.startswith', function() - eq(true, funcs.luaeval('vim.startswith("123", "1")')) - eq(true, funcs.luaeval('vim.startswith("123", "")')) - eq(true, funcs.luaeval('vim.startswith("123", "123")')) - eq(true, funcs.luaeval('vim.startswith("", "")')) + eq(true, fn.luaeval('vim.startswith("123", "1")')) + eq(true, fn.luaeval('vim.startswith("123", "")')) + eq(true, fn.luaeval('vim.startswith("123", "123")')) + eq(true, fn.luaeval('vim.startswith("", "")')) - eq(false, funcs.luaeval('vim.startswith("123", " ")')) - eq(false, funcs.luaeval('vim.startswith("123", "2")')) - eq(false, funcs.luaeval('vim.startswith("123", "1234")')) + eq(false, fn.luaeval('vim.startswith("123", " ")')) + eq(false, fn.luaeval('vim.startswith("123", "2")')) + eq(false, fn.luaeval('vim.startswith("123", "1234")')) matches( 'prefix: expected string, got nil', @@ -174,14 +174,14 @@ describe('lua stdlib', function() end) it('vim.endswith', function() - eq(true, funcs.luaeval('vim.endswith("123", "3")')) - eq(true, funcs.luaeval('vim.endswith("123", "")')) - eq(true, funcs.luaeval('vim.endswith("123", "123")')) - eq(true, funcs.luaeval('vim.endswith("", "")')) + eq(true, fn.luaeval('vim.endswith("123", "3")')) + eq(true, fn.luaeval('vim.endswith("123", "")')) + eq(true, fn.luaeval('vim.endswith("123", "123")')) + eq(true, fn.luaeval('vim.endswith("", "")')) - eq(false, funcs.luaeval('vim.endswith("123", " ")')) - eq(false, funcs.luaeval('vim.endswith("123", "2")')) - eq(false, funcs.luaeval('vim.endswith("123", "1234")')) + eq(false, fn.luaeval('vim.endswith("123", " ")')) + eq(false, fn.luaeval('vim.endswith("123", "2")')) + eq(false, fn.luaeval('vim.endswith("123", "1234")')) matches( 'suffix: expected string, got nil', @@ -1196,7 +1196,7 @@ describe('lua stdlib', function() end) ]]) - helpers.poke_eventloop() + poke_eventloop() eq('hello', exec_lua [[return vim.g.fnres]]) end) @@ -1205,7 +1205,7 @@ describe('lua stdlib', function() chan = vim.fn.jobstart({'cat'}, {rpc=true}) vim.rpcrequest(chan, 'nvim_set_current_line', 'meow') ]]) - eq('meow', meths.get_current_line()) + eq('meow', api.nvim_get_current_line()) command("let x = [3, 'aa', v:true, v:null]") eq( true, @@ -1250,7 +1250,7 @@ describe('lua stdlib', function() ]]) ) retry(10, nil, function() - eq('foo', meths.get_current_line()) + eq('foo', api.nvim_get_current_line()) end) local screen = Screen.new(50, 7) @@ -1282,7 +1282,7 @@ describe('lua stdlib', function() ]], } feed('<cr>') - eq({ 3, NIL }, meths.get_var('yy')) + eq({ 3, NIL }, api.nvim_get_var('yy')) exec_lua([[timer:close()]]) end) @@ -1426,11 +1426,11 @@ describe('lua stdlib', function() vim.api.nvim_set_var("to_delete", {hello="world"}) ]] - eq('hi', funcs.luaeval 'vim.g.testing') - eq(123, funcs.luaeval 'vim.g.other') - eq(5120.1, funcs.luaeval 'vim.g.floaty') - eq(NIL, funcs.luaeval 'vim.g.nonexistent') - eq(NIL, funcs.luaeval 'vim.g.nullvar') + eq('hi', fn.luaeval 'vim.g.testing') + eq(123, fn.luaeval 'vim.g.other') + eq(5120.1, fn.luaeval 'vim.g.floaty') + eq(NIL, fn.luaeval 'vim.g.nonexistent') + eq(NIL, fn.luaeval 'vim.g.nullvar') -- lost over RPC, so test locally: eq( { false, true }, @@ -1439,11 +1439,11 @@ describe('lua stdlib', function() ]] ) - eq({ hello = 'world' }, funcs.luaeval 'vim.g.to_delete') + eq({ hello = 'world' }, fn.luaeval 'vim.g.to_delete') exec_lua [[ vim.g.to_delete = nil ]] - eq(NIL, funcs.luaeval 'vim.g.to_delete') + eq(NIL, fn.luaeval 'vim.g.to_delete') matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.g[0].testing')) @@ -1453,7 +1453,7 @@ describe('lua stdlib', function() local function get_counter() return counter end vim.g.AddCounter = add_counter vim.g.GetCounter = get_counter - vim.g.funcs = {add = add_counter, get = get_counter} + vim.g.fn = {add = add_counter, get = get_counter} vim.g.AddParens = function(s) return '(' .. s .. ')' end ]] @@ -1466,10 +1466,10 @@ describe('lua stdlib', function() eq(3, exec_lua([[return vim.g.GetCounter()]])) exec_lua([[vim.api.nvim_get_var('AddCounter')()]]) eq(4, exec_lua([[return vim.api.nvim_get_var('GetCounter')()]])) - exec_lua([[vim.g.funcs.add()]]) - eq(5, exec_lua([[return vim.g.funcs.get()]])) - exec_lua([[vim.api.nvim_get_var('funcs').add()]]) - eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]])) + exec_lua([[vim.g.fn.add()]]) + eq(5, exec_lua([[return vim.g.fn.get()]])) + exec_lua([[vim.api.nvim_get_var('fn').add()]]) + eq(6, exec_lua([[return vim.api.nvim_get_var('fn').get()]])) eq('((foo))', eval([['foo'->AddParens()->AddParens()]])) exec_lua [[ @@ -1478,7 +1478,7 @@ describe('lua stdlib', function() local function get_counter() return counter end vim.api.nvim_set_var('AddCounter', add_counter) vim.api.nvim_set_var('GetCounter', get_counter) - vim.api.nvim_set_var('funcs', {add = add_counter, get = get_counter}) + vim.api.nvim_set_var('fn', {add = add_counter, get = get_counter}) vim.api.nvim_set_var('AddParens', function(s) return '(' .. s .. ')' end) ]] @@ -1491,10 +1491,10 @@ describe('lua stdlib', function() eq(3, exec_lua([[return vim.g.GetCounter()]])) exec_lua([[vim.api.nvim_get_var('AddCounter')()]]) eq(4, exec_lua([[return vim.api.nvim_get_var('GetCounter')()]])) - exec_lua([[vim.g.funcs.add()]]) - eq(5, exec_lua([[return vim.g.funcs.get()]])) - exec_lua([[vim.api.nvim_get_var('funcs').add()]]) - eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]])) + exec_lua([[vim.g.fn.add()]]) + eq(5, exec_lua([[return vim.g.fn.get()]])) + exec_lua([[vim.api.nvim_get_var('fn').add()]]) + eq(6, exec_lua([[return vim.api.nvim_get_var('fn').get()]])) eq('((foo))', eval([['foo'->AddParens()->AddParens()]])) exec([[ @@ -1534,13 +1534,13 @@ describe('lua stdlib', function() vim.api.nvim_buf_set_var(BUF, "testing", "bye") ]] - eq('hi', funcs.luaeval 'vim.b.testing') - eq('bye', funcs.luaeval 'vim.b[BUF].testing') - eq(123, funcs.luaeval 'vim.b.other') - eq(5120.1, funcs.luaeval 'vim.b.floaty') - eq(NIL, funcs.luaeval 'vim.b.nonexistent') - eq(NIL, funcs.luaeval 'vim.b[BUF].nonexistent') - eq(NIL, funcs.luaeval 'vim.b.nullvar') + eq('hi', fn.luaeval 'vim.b.testing') + eq('bye', fn.luaeval 'vim.b[BUF].testing') + eq(123, fn.luaeval 'vim.b.other') + eq(5120.1, fn.luaeval 'vim.b.floaty') + eq(NIL, fn.luaeval 'vim.b.nonexistent') + eq(NIL, fn.luaeval 'vim.b[BUF].nonexistent') + eq(NIL, fn.luaeval 'vim.b.nullvar') -- lost over RPC, so test locally: eq( { false, true }, @@ -1551,11 +1551,11 @@ describe('lua stdlib', function() matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.b[BUF][0].testing')) - eq({ hello = 'world' }, funcs.luaeval 'vim.b.to_delete') + eq({ hello = 'world' }, fn.luaeval 'vim.b.to_delete') exec_lua [[ vim.b.to_delete = nil ]] - eq(NIL, funcs.luaeval 'vim.b.to_delete') + eq(NIL, fn.luaeval 'vim.b.to_delete') exec_lua [[ local counter = 0 @@ -1563,7 +1563,7 @@ describe('lua stdlib', function() local function get_counter() return counter end vim.b.AddCounter = add_counter vim.b.GetCounter = get_counter - vim.b.funcs = {add = add_counter, get = get_counter} + vim.b.fn = {add = add_counter, get = get_counter} vim.b.AddParens = function(s) return '(' .. s .. ')' end ]] @@ -1576,10 +1576,10 @@ describe('lua stdlib', function() eq(3, exec_lua([[return vim.b.GetCounter()]])) exec_lua([[vim.api.nvim_buf_get_var(0, 'AddCounter')()]]) eq(4, exec_lua([[return vim.api.nvim_buf_get_var(0, 'GetCounter')()]])) - exec_lua([[vim.b.funcs.add()]]) - eq(5, exec_lua([[return vim.b.funcs.get()]])) - exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]]) - eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]])) + exec_lua([[vim.b.fn.add()]]) + eq(5, exec_lua([[return vim.b.fn.get()]])) + exec_lua([[vim.api.nvim_buf_get_var(0, 'fn').add()]]) + eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'fn').get()]])) eq('((foo))', eval([['foo'->b:AddParens()->b:AddParens()]])) exec_lua [[ @@ -1588,7 +1588,7 @@ describe('lua stdlib', function() local function get_counter() return counter end vim.api.nvim_buf_set_var(0, 'AddCounter', add_counter) vim.api.nvim_buf_set_var(0, 'GetCounter', get_counter) - vim.api.nvim_buf_set_var(0, 'funcs', {add = add_counter, get = get_counter}) + vim.api.nvim_buf_set_var(0, 'fn', {add = add_counter, get = get_counter}) vim.api.nvim_buf_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end) ]] @@ -1601,10 +1601,10 @@ describe('lua stdlib', function() eq(3, exec_lua([[return vim.b.GetCounter()]])) exec_lua([[vim.api.nvim_buf_get_var(0, 'AddCounter')()]]) eq(4, exec_lua([[return vim.api.nvim_buf_get_var(0, 'GetCounter')()]])) - exec_lua([[vim.b.funcs.add()]]) - eq(5, exec_lua([[return vim.b.funcs.get()]])) - exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]]) - eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]])) + exec_lua([[vim.b.fn.add()]]) + eq(5, exec_lua([[return vim.b.fn.get()]])) + exec_lua([[vim.api.nvim_buf_get_var(0, 'fn').add()]]) + eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'fn').get()]])) eq('((foo))', eval([['foo'->b:AddParens()->b:AddParens()]])) exec([[ @@ -1622,9 +1622,9 @@ describe('lua stdlib', function() vim.cmd "vnew" ]] - eq(NIL, funcs.luaeval 'vim.b.testing') - eq(NIL, funcs.luaeval 'vim.b.other') - eq(NIL, funcs.luaeval 'vim.b.nonexistent') + eq(NIL, fn.luaeval 'vim.b.testing') + eq(NIL, fn.luaeval 'vim.b.other') + eq(NIL, fn.luaeval 'vim.b.nonexistent') end) it('vim.w', function() @@ -1640,19 +1640,19 @@ describe('lua stdlib', function() vim.api.nvim_win_set_var(WIN, "testing", "bye") ]] - eq('hi', funcs.luaeval 'vim.w.testing') - eq('bye', funcs.luaeval 'vim.w[WIN].testing') - eq(123, funcs.luaeval 'vim.w.other') - eq(NIL, funcs.luaeval 'vim.w.nonexistent') - eq(NIL, funcs.luaeval 'vim.w[WIN].nonexistent') + eq('hi', fn.luaeval 'vim.w.testing') + eq('bye', fn.luaeval 'vim.w[WIN].testing') + eq(123, fn.luaeval 'vim.w.other') + eq(NIL, fn.luaeval 'vim.w.nonexistent') + eq(NIL, fn.luaeval 'vim.w[WIN].nonexistent') matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.w[WIN][0].testing')) - eq({ hello = 'world' }, funcs.luaeval 'vim.w.to_delete') + eq({ hello = 'world' }, fn.luaeval 'vim.w.to_delete') exec_lua [[ vim.w.to_delete = nil ]] - eq(NIL, funcs.luaeval 'vim.w.to_delete') + eq(NIL, fn.luaeval 'vim.w.to_delete') exec_lua [[ local counter = 0 @@ -1660,7 +1660,7 @@ describe('lua stdlib', function() local function get_counter() return counter end vim.w.AddCounter = add_counter vim.w.GetCounter = get_counter - vim.w.funcs = {add = add_counter, get = get_counter} + vim.w.fn = {add = add_counter, get = get_counter} vim.w.AddParens = function(s) return '(' .. s .. ')' end ]] @@ -1673,10 +1673,10 @@ describe('lua stdlib', function() eq(3, exec_lua([[return vim.w.GetCounter()]])) exec_lua([[vim.api.nvim_win_get_var(0, 'AddCounter')()]]) eq(4, exec_lua([[return vim.api.nvim_win_get_var(0, 'GetCounter')()]])) - exec_lua([[vim.w.funcs.add()]]) - eq(5, exec_lua([[return vim.w.funcs.get()]])) - exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]]) - eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]])) + exec_lua([[vim.w.fn.add()]]) + eq(5, exec_lua([[return vim.w.fn.get()]])) + exec_lua([[vim.api.nvim_win_get_var(0, 'fn').add()]]) + eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'fn').get()]])) eq('((foo))', eval([['foo'->w:AddParens()->w:AddParens()]])) exec_lua [[ @@ -1685,7 +1685,7 @@ describe('lua stdlib', function() local function get_counter() return counter end vim.api.nvim_win_set_var(0, 'AddCounter', add_counter) vim.api.nvim_win_set_var(0, 'GetCounter', get_counter) - vim.api.nvim_win_set_var(0, 'funcs', {add = add_counter, get = get_counter}) + vim.api.nvim_win_set_var(0, 'fn', {add = add_counter, get = get_counter}) vim.api.nvim_win_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end) ]] @@ -1698,10 +1698,10 @@ describe('lua stdlib', function() eq(3, exec_lua([[return vim.w.GetCounter()]])) exec_lua([[vim.api.nvim_win_get_var(0, 'AddCounter')()]]) eq(4, exec_lua([[return vim.api.nvim_win_get_var(0, 'GetCounter')()]])) - exec_lua([[vim.w.funcs.add()]]) - eq(5, exec_lua([[return vim.w.funcs.get()]])) - exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]]) - eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]])) + exec_lua([[vim.w.fn.add()]]) + eq(5, exec_lua([[return vim.w.fn.get()]])) + exec_lua([[vim.api.nvim_win_get_var(0, 'fn').add()]]) + eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'fn').get()]])) eq('((foo))', eval([['foo'->w:AddParens()->w:AddParens()]])) exec([[ @@ -1719,9 +1719,9 @@ describe('lua stdlib', function() vim.cmd "vnew" ]] - eq(NIL, funcs.luaeval 'vim.w.testing') - eq(NIL, funcs.luaeval 'vim.w.other') - eq(NIL, funcs.luaeval 'vim.w.nonexistent') + eq(NIL, fn.luaeval 'vim.w.testing') + eq(NIL, fn.luaeval 'vim.w.other') + eq(NIL, fn.luaeval 'vim.w.nonexistent') end) it('vim.t', function() @@ -1731,20 +1731,20 @@ describe('lua stdlib', function() vim.api.nvim_tabpage_set_var(0, "to_delete", {hello="world"}) ]] - eq('hi', funcs.luaeval 'vim.t.testing') - eq(123, funcs.luaeval 'vim.t.other') - eq(NIL, funcs.luaeval 'vim.t.nonexistent') - eq('hi', funcs.luaeval 'vim.t[0].testing') - eq(123, funcs.luaeval 'vim.t[0].other') - eq(NIL, funcs.luaeval 'vim.t[0].nonexistent') + eq('hi', fn.luaeval 'vim.t.testing') + eq(123, fn.luaeval 'vim.t.other') + eq(NIL, fn.luaeval 'vim.t.nonexistent') + eq('hi', fn.luaeval 'vim.t[0].testing') + eq(123, fn.luaeval 'vim.t[0].other') + eq(NIL, fn.luaeval 'vim.t[0].nonexistent') matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.t[0][0].testing')) - eq({ hello = 'world' }, funcs.luaeval 'vim.t.to_delete') + eq({ hello = 'world' }, fn.luaeval 'vim.t.to_delete') exec_lua [[ vim.t.to_delete = nil ]] - eq(NIL, funcs.luaeval 'vim.t.to_delete') + eq(NIL, fn.luaeval 'vim.t.to_delete') exec_lua [[ local counter = 0 @@ -1752,7 +1752,7 @@ describe('lua stdlib', function() local function get_counter() return counter end vim.t.AddCounter = add_counter vim.t.GetCounter = get_counter - vim.t.funcs = {add = add_counter, get = get_counter} + vim.t.fn = {add = add_counter, get = get_counter} vim.t.AddParens = function(s) return '(' .. s .. ')' end ]] @@ -1765,10 +1765,10 @@ describe('lua stdlib', function() eq(3, exec_lua([[return vim.t.GetCounter()]])) exec_lua([[vim.api.nvim_tabpage_get_var(0, 'AddCounter')()]]) eq(4, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'GetCounter')()]])) - exec_lua([[vim.t.funcs.add()]]) - eq(5, exec_lua([[return vim.t.funcs.get()]])) - exec_lua([[vim.api.nvim_tabpage_get_var(0, 'funcs').add()]]) - eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'funcs').get()]])) + exec_lua([[vim.t.fn.add()]]) + eq(5, exec_lua([[return vim.t.fn.get()]])) + exec_lua([[vim.api.nvim_tabpage_get_var(0, 'fn').add()]]) + eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'fn').get()]])) eq('((foo))', eval([['foo'->t:AddParens()->t:AddParens()]])) exec_lua [[ @@ -1777,7 +1777,7 @@ describe('lua stdlib', function() local function get_counter() return counter end vim.api.nvim_tabpage_set_var(0, 'AddCounter', add_counter) vim.api.nvim_tabpage_set_var(0, 'GetCounter', get_counter) - vim.api.nvim_tabpage_set_var(0, 'funcs', {add = add_counter, get = get_counter}) + vim.api.nvim_tabpage_set_var(0, 'fn', {add = add_counter, get = get_counter}) vim.api.nvim_tabpage_set_var(0, 'AddParens', function(s) return '(' .. s .. ')' end) ]] @@ -1790,45 +1790,45 @@ describe('lua stdlib', function() eq(3, exec_lua([[return vim.t.GetCounter()]])) exec_lua([[vim.api.nvim_tabpage_get_var(0, 'AddCounter')()]]) eq(4, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'GetCounter')()]])) - exec_lua([[vim.t.funcs.add()]]) - eq(5, exec_lua([[return vim.t.funcs.get()]])) - exec_lua([[vim.api.nvim_tabpage_get_var(0, 'funcs').add()]]) - eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'funcs').get()]])) + exec_lua([[vim.t.fn.add()]]) + eq(5, exec_lua([[return vim.t.fn.get()]])) + exec_lua([[vim.api.nvim_tabpage_get_var(0, 'fn').add()]]) + eq(6, exec_lua([[return vim.api.nvim_tabpage_get_var(0, 'fn').get()]])) eq('((foo))', eval([['foo'->t:AddParens()->t:AddParens()]])) exec_lua [[ vim.cmd "tabnew" ]] - eq(NIL, funcs.luaeval 'vim.t.testing') - eq(NIL, funcs.luaeval 'vim.t.other') - eq(NIL, funcs.luaeval 'vim.t.nonexistent') + eq(NIL, fn.luaeval 'vim.t.testing') + eq(NIL, fn.luaeval 'vim.t.other') + eq(NIL, fn.luaeval 'vim.t.nonexistent') end) it('vim.env', function() exec_lua([[vim.fn.setenv('A', 123)]]) - eq('123', funcs.luaeval('vim.env.A')) + eq('123', fn.luaeval('vim.env.A')) exec_lua([[vim.env.A = 456]]) - eq('456', funcs.luaeval('vim.env.A')) + eq('456', fn.luaeval('vim.env.A')) exec_lua([[vim.env.A = nil]]) - eq(NIL, funcs.luaeval('vim.env.A')) + eq(NIL, fn.luaeval('vim.env.A')) - eq(true, funcs.luaeval('vim.env.B == nil')) + eq(true, fn.luaeval('vim.env.B == nil')) command([[let $HOME = 'foo']]) - eq('foo', funcs.expand('~')) - eq('foo', funcs.luaeval('vim.env.HOME')) + eq('foo', fn.expand('~')) + eq('foo', fn.luaeval('vim.env.HOME')) exec_lua([[vim.env.HOME = nil]]) - eq('foo', funcs.expand('~')) + eq('foo', fn.expand('~')) exec_lua([[vim.env.HOME = 'bar']]) - eq('bar', funcs.expand('~')) - eq('bar', funcs.luaeval('vim.env.HOME')) + eq('bar', fn.expand('~')) + eq('bar', fn.luaeval('vim.env.HOME')) end) it('vim.v', function() - eq(funcs.luaeval "vim.api.nvim_get_vvar('progpath')", funcs.luaeval 'vim.v.progpath') - eq(false, funcs.luaeval "vim.v['false']") - eq(NIL, funcs.luaeval 'vim.v.null') + eq(fn.luaeval "vim.api.nvim_get_vvar('progpath')", fn.luaeval 'vim.v.progpath') + eq(false, fn.luaeval "vim.v['false']") + eq(NIL, fn.luaeval 'vim.v.null') matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.v[0].progpath')) eq('Key is read-only: count', pcall_err(exec_lua, [[vim.v.count = 42]])) eq('Dictionary is locked', pcall_err(exec_lua, [[vim.v.nosuchvar = 42]])) @@ -1845,18 +1845,18 @@ describe('lua stdlib', function() eq({}, eval('v:oldfiles')) feed('i foo foo foo<Esc>0/foo<CR>') - eq({ 1, 1 }, meths.win_get_cursor(0)) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) eq(1, eval('v:searchforward')) feed('n') - eq({ 1, 5 }, meths.win_get_cursor(0)) + eq({ 1, 5 }, api.nvim_win_get_cursor(0)) exec_lua([[vim.v.searchforward = 0]]) eq(0, eval('v:searchforward')) feed('n') - eq({ 1, 1 }, meths.win_get_cursor(0)) + eq({ 1, 1 }, api.nvim_win_get_cursor(0)) exec_lua([[vim.v.searchforward = 1]]) eq(1, eval('v:searchforward')) feed('n') - eq({ 1, 5 }, meths.win_get_cursor(0)) + eq({ 1, 5 }, api.nvim_win_get_cursor(0)) local screen = Screen.new(60, 3) screen:set_default_attr_ids({ @@ -1893,21 +1893,21 @@ describe('lua stdlib', function() end) it('vim.bo', function() - eq('', funcs.luaeval 'vim.bo.filetype') + eq('', fn.luaeval 'vim.bo.filetype') exec_lua [[ vim.api.nvim_set_option_value("filetype", "markdown", {}) BUF = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_option_value("modifiable", false, {buf = BUF}) ]] - eq(false, funcs.luaeval 'vim.bo.modified') - eq('markdown', funcs.luaeval 'vim.bo.filetype') - eq(false, funcs.luaeval 'vim.bo[BUF].modifiable') + eq(false, fn.luaeval 'vim.bo.modified') + eq('markdown', fn.luaeval 'vim.bo.filetype') + eq(false, fn.luaeval 'vim.bo[BUF].modifiable') exec_lua [[ vim.bo.filetype = '' vim.bo[BUF].modifiable = true ]] - eq('', funcs.luaeval 'vim.bo.filetype') - eq(true, funcs.luaeval 'vim.bo[BUF].modifiable') + eq('', fn.luaeval 'vim.bo.filetype') + eq(true, fn.luaeval 'vim.bo[BUF].modifiable') matches("Unknown option 'nosuchopt'$", pcall_err(exec_lua, 'return vim.bo.nosuchopt')) matches('Expected Lua string$', pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) matches('Invalid buffer id: %-1$', pcall_err(exec_lua, 'return vim.bo[-1].filetype')) @@ -1919,32 +1919,32 @@ describe('lua stdlib', function() vim.cmd "split" vim.api.nvim_set_option_value("cole", 2, {}) ]] - eq(2, funcs.luaeval 'vim.wo.cole') + eq(2, fn.luaeval 'vim.wo.cole') exec_lua [[ vim.wo.conceallevel = 0 ]] - eq(0, funcs.luaeval 'vim.wo.cole') - eq(0, funcs.luaeval 'vim.wo[0].cole') - eq(0, funcs.luaeval 'vim.wo[1001].cole') + eq(0, fn.luaeval 'vim.wo.cole') + eq(0, fn.luaeval 'vim.wo[0].cole') + eq(0, fn.luaeval 'vim.wo[1001].cole') matches("Unknown option 'notanopt'$", pcall_err(exec_lua, 'return vim.wo.notanopt')) matches('Invalid window id: %-1$', pcall_err(exec_lua, 'return vim.wo[-1].list')) - eq(2, funcs.luaeval 'vim.wo[1000].cole') + eq(2, fn.luaeval 'vim.wo[1000].cole') exec_lua [[ vim.wo[1000].cole = 0 ]] - eq(0, funcs.luaeval 'vim.wo[1000].cole') + eq(0, fn.luaeval 'vim.wo[1000].cole') -- Can handle global-local values exec_lua [[vim.o.scrolloff = 100]] exec_lua [[vim.wo.scrolloff = 200]] - eq(200, funcs.luaeval 'vim.wo.scrolloff') + eq(200, fn.luaeval 'vim.wo.scrolloff') exec_lua [[vim.wo.scrolloff = -1]] - eq(100, funcs.luaeval 'vim.wo.scrolloff') + eq(100, fn.luaeval 'vim.wo.scrolloff') exec_lua [[ vim.wo[0][0].scrolloff = 200 vim.cmd "enew" ]] - eq(100, funcs.luaeval 'vim.wo.scrolloff') + eq(100, fn.luaeval 'vim.wo.scrolloff') end) describe('vim.opt', function() @@ -2866,15 +2866,15 @@ describe('lua stdlib', function() vim.cmd "autocmd BufNew * ++once lua BUF = vim.fn.expand('<abuf>')" vim.cmd "new" ]] - eq('2', funcs.luaeval 'BUF') - eq(2, funcs.luaeval '#vim.api.nvim_list_bufs()') + eq('2', fn.luaeval 'BUF') + eq(2, fn.luaeval '#vim.api.nvim_list_bufs()') -- vim.cmd can be indexed with a command name exec_lua [[ vim.cmd.let 'g:var = 2' ]] - eq(2, funcs.luaeval 'vim.g.var') + eq(2, fn.luaeval 'vim.g.var') end) it('vim.regex', function() @@ -2886,7 +2886,7 @@ describe('lua stdlib', function() eq({}, exec_lua [[return {re1:match_str("x ac")}]]) eq({ 3, 7 }, exec_lua [[return {re1:match_str("ac abbc")}]]) - meths.buf_set_lines(0, 0, -1, true, { 'yy', 'abc abbc' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'yy', 'abc abbc' }) eq({}, exec_lua [[return {re1:match_line(0, 0)}]]) eq({ 0, 3 }, exec_lua [[return {re1:match_line(0, 1)}]]) eq({ 3, 7 }, exec_lua [[return {re1:match_line(0, 1, 1)}]]) @@ -2970,10 +2970,10 @@ describe('lua stdlib', function() it('allows removing on_key listeners', function() -- Create some unused namespaces - meths.create_namespace('unused1') - meths.create_namespace('unused2') - meths.create_namespace('unused3') - meths.create_namespace('unused4') + api.nvim_create_namespace('unused1') + api.nvim_create_namespace('unused2') + api.nvim_create_namespace('unused3') + api.nvim_create_namespace('unused4') insert([[hello world]]) @@ -3303,8 +3303,8 @@ describe('lua stdlib', function() describe('returns -2 when interrupted', function() before_each(function() - local channel = meths.get_api_info()[1] - meths.set_var('channel', channel) + local channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) end) it('without callback', function() @@ -3408,14 +3408,14 @@ describe('lua stdlib', function() describe('vim.api.nvim_buf_call', function() it('can access buf options', function() - local buf1 = meths.get_current_buf().id + local buf1 = api.nvim_get_current_buf().id local buf2 = exec_lua [[ buf2 = vim.api.nvim_create_buf(false, true) return buf2 ]] - eq(false, meths.get_option_value('autoindent', { buf = buf1 })) - eq(false, meths.get_option_value('autoindent', { buf = buf2 })) + eq(false, api.nvim_get_option_value('autoindent', { buf = buf1 })) + eq(false, api.nvim_get_option_value('autoindent', { buf = buf2 })) local val = exec_lua [[ return vim.api.nvim_buf_call(buf2, function() @@ -3424,9 +3424,9 @@ describe('lua stdlib', function() end) ]] - eq(false, meths.get_option_value('autoindent', { buf = buf1 })) - eq(true, meths.get_option_value('autoindent', { buf = buf2 })) - eq(buf1, meths.get_current_buf().id) + eq(false, api.nvim_get_option_value('autoindent', { buf = buf1 })) + eq(true, api.nvim_get_option_value('autoindent', { buf = buf2 })) + eq(buf1, api.nvim_get_current_buf().id) eq(buf2, val) end) @@ -3488,7 +3488,7 @@ describe('lua stdlib', function() describe('vim.api.nvim_win_call', function() it('can access window options', function() command('vsplit') - local win1 = meths.get_current_win().id + local win1 = api.nvim_get_current_win().id command('wincmd w') local win2 = exec_lua [[ win2 = vim.api.nvim_get_current_win() @@ -3496,8 +3496,8 @@ describe('lua stdlib', function() ]] command('wincmd p') - eq('', meths.get_option_value('winhighlight', { win = win1 })) - eq('', meths.get_option_value('winhighlight', { win = win2 })) + eq('', api.nvim_get_option_value('winhighlight', { win = win1 })) + eq('', api.nvim_get_option_value('winhighlight', { win = win2 })) local val = exec_lua [[ return vim.api.nvim_win_call(win2, function() @@ -3506,9 +3506,9 @@ describe('lua stdlib', function() end) ]] - eq('', meths.get_option_value('winhighlight', { win = win1 })) - eq('Normal:Normal', meths.get_option_value('winhighlight', { win = win2 })) - eq(win1, meths.get_current_win().id) + eq('', api.nvim_get_option_value('winhighlight', { win = win1 })) + eq('Normal:Normal', api.nvim_get_option_value('winhighlight', { win = win2 })) + eq(win1, api.nvim_get_current_win().id) eq(win2, val) end) @@ -3819,15 +3819,13 @@ describe('lua: builtin modules', function() clear() command("let $VIMRUNTIME='fixtures/a'") -- Use system([nvim,…]) instead of clear() to avoid stderr noise. #21844 - local out = funcs - .system({ - nvim_prog, - '--clean', - '--luamod-dev', - [[+call nvim_exec_lua('return vim.tbl_count {x=1,y=2}')]], - '+qa!', - }) - :gsub('\r\n', '\n') + local out = fn.system({ + nvim_prog, + '--clean', + '--luamod-dev', + [[+call nvim_exec_lua('return vim.tbl_count {x=1,y=2}')]], + '+qa!', + }):gsub('\r\n', '\n') eq(1, eval('v:shell_error')) matches("'vim%.shared' not found", out) end) @@ -3882,7 +3880,7 @@ describe('vim.keymap', function() feed('aa') - eq({ 'π<M-π>foo<' }, meths.buf_get_lines(0, 0, -1, false)) + eq({ 'π<M-π>foo<' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) it('can overwrite a mapping', function() @@ -4001,14 +3999,14 @@ describe('Vimscript function exists()', function() ]] ) - eq(1, funcs.exists('v:lua.require("mpack").decode')) - eq(1, funcs.exists("v:lua.require('mpack').decode")) - eq(1, funcs.exists('v:lua.require"mpack".decode')) - eq(1, funcs.exists("v:lua.require'mpack'.decode")) - eq(1, funcs.exists("v:lua.require('vim.lsp').start")) - eq(1, funcs.exists('v:lua.require"vim.lsp".start')) - eq(1, funcs.exists("v:lua.require'vim.lsp'.start")) - eq(0, funcs.exists("v:lua.require'vim.lsp'.unknown")) - eq(0, funcs.exists('v:lua.?')) + eq(1, fn.exists('v:lua.require("mpack").decode')) + eq(1, fn.exists("v:lua.require('mpack').decode")) + eq(1, fn.exists('v:lua.require"mpack".decode')) + eq(1, fn.exists("v:lua.require'mpack'.decode")) + eq(1, fn.exists("v:lua.require('vim.lsp').start")) + eq(1, fn.exists('v:lua.require"vim.lsp".start')) + eq(1, fn.exists("v:lua.require'vim.lsp'.start")) + eq(0, fn.exists("v:lua.require'vim.lsp'.unknown")) + eq(0, fn.exists('v:lua.?')) end) end) diff --git a/test/functional/options/autochdir_spec.lua b/test/functional/options/autochdir_spec.lua index 392c02b07e..11f71912a9 100644 --- a/test/functional/options/autochdir_spec.lua +++ b/test/functional/options/autochdir_spec.lua @@ -1,8 +1,7 @@ -local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command local mkdir = helpers.mkdir @@ -12,16 +11,16 @@ describe("'autochdir'", function() -- By default 'autochdir' is off, thus getcwd() returns the repo root. clear(targetdir .. '/tty-test.c') - local rootdir = funcs.getcwd() + local rootdir = fn.getcwd() local expected = rootdir .. '/' .. targetdir -- With 'autochdir' on, we should get the directory of tty-test.c. clear('--cmd', 'set autochdir', targetdir .. '/tty-test.c') - eq(helpers.is_os('win') and expected:gsub('/', '\\') or expected, funcs.getcwd()) + eq(helpers.is_os('win') and expected:gsub('/', '\\') or expected, fn.getcwd()) end) it('is not overwritten by getwinvar() call #17609', function() - local curdir = string.gsub(luv.cwd(), '\\', '/') + local curdir = vim.uv.cwd():gsub('\\', '/') local dir_a = curdir .. '/Xtest-functional-options-autochdir.dir_a' local dir_b = curdir .. '/Xtest-functional-options-autochdir.dir_b' mkdir(dir_a) @@ -30,15 +29,15 @@ describe("'autochdir'", function() command('set shellslash') command('set autochdir') command('edit ' .. dir_a .. '/file1') - eq(dir_a, funcs.getcwd()) + eq(dir_a, fn.getcwd()) command('lcd ' .. dir_b) - eq(dir_b, funcs.getcwd()) + eq(dir_b, fn.getcwd()) command('botright vnew ../file2') - eq(curdir, funcs.getcwd()) + eq(curdir, fn.getcwd()) command('wincmd w') - eq(dir_a, funcs.getcwd()) - funcs.getwinvar(2, 'foo') - eq(dir_a, funcs.getcwd()) + eq(dir_a, fn.getcwd()) + fn.getwinvar(2, 'foo') + eq(dir_a, fn.getcwd()) helpers.rmdir(dir_a) helpers.rmdir(dir_b) end) diff --git a/test/functional/options/chars_spec.lua b/test/functional/options/chars_spec.lua index d23dc2ed88..64de25112a 100644 --- a/test/functional/options/chars_spec.lua +++ b/test/functional/options/chars_spec.lua @@ -6,7 +6,7 @@ local eq = helpers.eq local exc_exec = helpers.exc_exec local insert = helpers.insert local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api describe("'fillchars'", function() local screen @@ -203,7 +203,7 @@ describe("'listchars'", function() | ]]) - meths._invalidate_glyph_cache() + api.nvim__invalidate_glyph_cache() screen:_reset() screen:expect([[ {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} | diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 1d5f657542..10a0baa30b 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -4,7 +4,7 @@ local Screen = require('test.functional.ui.screen') local assert_alive = helpers.assert_alive local assert_log = helpers.assert_log -local meths = helpers.meths +local api = helpers.api local command = helpers.command local clear = helpers.clear local exc_exec = helpers.exc_exec @@ -12,13 +12,13 @@ local exec_lua = helpers.exec_lua local eval = helpers.eval local eq = helpers.eq local ok = helpers.ok -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert local neq = helpers.neq local mkdir = helpers.mkdir local rmdir = helpers.rmdir local alter_slashes = helpers.alter_slashes -local tbl_contains = helpers.tbl_contains +local tbl_contains = vim.tbl_contains local expect_exit = helpers.expect_exit local is_os = helpers.is_os @@ -149,7 +149,7 @@ describe('startup defaults', function() ]]) -- change "vert" character to single-cell - funcs.setcellwidths({ { 0x2502, 0x2502, 1 } }) + fn.setcellwidths({ { 0x2502, 0x2502, 1 } }) screen:expect([[ 1 │1 | ^+-- 2 lines: 2----------│+-- 2 lines: 2---------| @@ -159,7 +159,7 @@ describe('startup defaults', function() ]]) -- change "vert" character to double-cell - funcs.setcellwidths({ { 0x2502, 0x2502, 2 } }) + fn.setcellwidths({ { 0x2502, 0x2502, 2 } }) screen:expect([[ 1 |1 | ^+-- 2 lines: 2----------|+-- 2 lines: 2---------| @@ -195,8 +195,8 @@ describe('startup defaults', function() clear { args = {}, args_rm = { '-i' }, env = env } -- Default 'shadafile' is empty. -- This means use the default location. :help shada-file-name - eq('', meths.get_option_value('shadafile', {})) - eq('', meths.get_option_value('viminfofile', {})) + eq('', api.nvim_get_option_value('shadafile', {})) + eq('', api.nvim_get_option_value('viminfofile', {})) -- Handles viminfo/viminfofile as alias for shada/shadafile. eq('\n shadafile=', eval('execute("set shadafile?")')) eq('\n shadafile=', eval('execute("set viminfofile?")')) @@ -218,13 +218,13 @@ describe('startup defaults', function() args_rm = { 'runtimepath' }, } -- Defaults to &runtimepath. - eq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {})) + eq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {})) -- Does not follow modifications to runtimepath. - meths.command('set runtimepath+=foo') - neq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {})) - meths.command('set packpath+=foo') - eq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {})) + command('set runtimepath+=foo') + neq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {})) + command('set packpath+=foo') + eq(api.nvim_get_option_value('runtimepath', {}), api.nvim_get_option_value('packpath', {})) end) it('v:progpath is set to the absolute path', function() @@ -316,11 +316,11 @@ describe('XDG defaults', function() }, }) - eq('.', meths.get_option_value('backupdir', {})) - eq('.', meths.get_option_value('viewdir', {})) - eq('.', meths.get_option_value('directory', {})) - eq('.', meths.get_option_value('undodir', {})) - ok((funcs.tempname()):len() > 4) + eq('.', api.nvim_get_option_value('backupdir', {})) + eq('.', api.nvim_get_option_value('viewdir', {})) + eq('.', api.nvim_get_option_value('directory', {})) + eq('.', api.nvim_get_option_value('undodir', {})) + ok((fn.tempname()):len() > 4) end) end) @@ -328,7 +328,7 @@ describe('XDG defaults', function() local vimruntime = eval('$VIMRUNTIME') -- libdir is hard to calculate reliably across various ci platforms -- local libdir = string.gsub(vimruntime, "share/nvim/runtime$", "lib/nvim") - local libdir = meths._get_lib_dir() + local libdir = api.nvim__get_lib_dir() return vimruntime, libdir end @@ -428,13 +428,13 @@ describe('XDG defaults', function() .. '/nvim/after' ):gsub('\\', '/') ), - (meths.get_option_value('runtimepath', {})):gsub('\\', '/') + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') ) - meths.command('set runtimepath&') - meths.command('set backupdir&') - meths.command('set directory&') - meths.command('set undodir&') - meths.command('set viewdir&') + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') eq( ( ( @@ -499,23 +499,23 @@ describe('XDG defaults', function() .. '/nvim/after' ):gsub('\\', '/') ), - (meths.get_option_value('runtimepath', {})):gsub('\\', '/') + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') ) eq( '.,' .. root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/backup//', - (meths.get_option_value('backupdir', {}):gsub('\\', '/')) + (api.nvim_get_option_value('backupdir', {}):gsub('\\', '/')) ) eq( root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/swap//', - (meths.get_option_value('directory', {})):gsub('\\', '/') + (api.nvim_get_option_value('directory', {})):gsub('\\', '/') ) eq( root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/undo//', - (meths.get_option_value('undodir', {})):gsub('\\', '/') + (api.nvim_get_option_value('undodir', {})):gsub('\\', '/') ) eq( root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/view//', - (meths.get_option_value('viewdir', {})):gsub('\\', '/') + (api.nvim_get_option_value('viewdir', {})):gsub('\\', '/') ) end) end) @@ -571,13 +571,13 @@ describe('XDG defaults', function() .. ',$XDG_DATA_HOME/nvim/after' ):gsub('\\', '/') ), - (meths.get_option_value('runtimepath', {})):gsub('\\', '/') + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') ) - meths.command('set runtimepath&') - meths.command('set backupdir&') - meths.command('set directory&') - meths.command('set undodir&') - meths.command('set viewdir&') + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') eq( ( ( @@ -599,25 +599,25 @@ describe('XDG defaults', function() .. ',$XDG_DATA_HOME/nvim/after' ):gsub('\\', '/') ), - (meths.get_option_value('runtimepath', {})):gsub('\\', '/') + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') ) eq( ('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'), - meths.get_option_value('backupdir', {}):gsub('\\', '/') + api.nvim_get_option_value('backupdir', {}):gsub('\\', '/') ) eq( ('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'), - meths.get_option_value('directory', {}):gsub('\\', '/') + api.nvim_get_option_value('directory', {}):gsub('\\', '/') ) eq( ('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'), - meths.get_option_value('undodir', {}):gsub('\\', '/') + api.nvim_get_option_value('undodir', {}):gsub('\\', '/') ) eq( ('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), - meths.get_option_value('viewdir', {}):gsub('\\', '/') + api.nvim_get_option_value('viewdir', {}):gsub('\\', '/') ) - meths.command('set all&') + command('set all&') eq( ( '$XDG_DATA_HOME/nvim' @@ -637,25 +637,25 @@ describe('XDG defaults', function() .. ',$XDG_DATA_DIRS/nvim/after' .. ',$XDG_DATA_HOME/nvim/after' ):gsub('\\', '/'), - (meths.get_option_value('runtimepath', {})):gsub('\\', '/') + (api.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') ) eq( ('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'), - meths.get_option_value('backupdir', {}):gsub('\\', '/') + api.nvim_get_option_value('backupdir', {}):gsub('\\', '/') ) eq( ('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'), - meths.get_option_value('directory', {}):gsub('\\', '/') + api.nvim_get_option_value('directory', {}):gsub('\\', '/') ) eq( ('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'), - meths.get_option_value('undodir', {}):gsub('\\', '/') + api.nvim_get_option_value('undodir', {}):gsub('\\', '/') ) eq( ('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), - meths.get_option_value('viewdir', {}):gsub('\\', '/') + api.nvim_get_option_value('viewdir', {}):gsub('\\', '/') ) - eq(nil, (funcs.tempname()):match('XDG_RUNTIME_DIR')) + eq(nil, (fn.tempname()):match('XDG_RUNTIME_DIR')) end) end) @@ -743,13 +743,13 @@ describe('XDG defaults', function() .. path_sep .. 'after' ), - meths.get_option_value('runtimepath', {}) + api.nvim_get_option_value('runtimepath', {}) ) - meths.command('set runtimepath&') - meths.command('set backupdir&') - meths.command('set directory&') - meths.command('set undodir&') - meths.command('set viewdir&') + command('set runtimepath&') + command('set backupdir&') + command('set directory&') + command('set undodir&') + command('set viewdir&') eq( ( '\\, \\, \\,' @@ -821,11 +821,11 @@ describe('XDG defaults', function() .. path_sep .. 'after' ), - meths.get_option_value('runtimepath', {}) + api.nvim_get_option_value('runtimepath', {}) ) eq( '.,\\,=\\,=\\,' .. path_sep .. state_dir .. '' .. path_sep .. 'backup' .. (path_sep):rep(2), - meths.get_option_value('backupdir', {}) + api.nvim_get_option_value('backupdir', {}) ) eq( '\\,=\\,=\\,' @@ -836,7 +836,7 @@ describe('XDG defaults', function() .. path_sep .. 'swap' .. (path_sep):rep(2), - meths.get_option_value('directory', {}) + api.nvim_get_option_value('directory', {}) ) eq( '\\,=\\,=\\,' @@ -847,7 +847,7 @@ describe('XDG defaults', function() .. path_sep .. 'undo' .. (path_sep):rep(2), - meths.get_option_value('undodir', {}) + api.nvim_get_option_value('undodir', {}) ) eq( '\\,=\\,=\\,' @@ -858,7 +858,7 @@ describe('XDG defaults', function() .. path_sep .. 'view' .. (path_sep):rep(2), - meths.get_option_value('viewdir', {}) + api.nvim_get_option_value('viewdir', {}) ) end) end) @@ -878,29 +878,29 @@ describe('stdpath()', function() it('acceptance', function() clear() -- Do not explicitly set any env vars. - eq('nvim', funcs.fnamemodify(funcs.stdpath('cache'), ':t')) - eq('nvim', funcs.fnamemodify(funcs.stdpath('config'), ':t')) - eq(datadir, funcs.fnamemodify(funcs.stdpath('data'), ':t')) - eq(statedir, funcs.fnamemodify(funcs.stdpath('state'), ':t')) - eq('table', type(funcs.stdpath('config_dirs'))) - eq('table', type(funcs.stdpath('data_dirs'))) - eq('string', type(funcs.stdpath('run'))) + eq('nvim', fn.fnamemodify(fn.stdpath('cache'), ':t')) + eq('nvim', fn.fnamemodify(fn.stdpath('config'), ':t')) + eq(datadir, fn.fnamemodify(fn.stdpath('data'), ':t')) + eq(statedir, fn.fnamemodify(fn.stdpath('state'), ':t')) + eq('table', type(fn.stdpath('config_dirs'))) + eq('table', type(fn.stdpath('data_dirs'))) + eq('string', type(fn.stdpath('run'))) assert_alive() -- Check for crash. #8393 end) it('reacts to $NVIM_APPNAME', function() local appname = 'NVIM_APPNAME_TEST' .. ('_'):rep(106) clear({ env = { NVIM_APPNAME = appname } }) - eq(appname, funcs.fnamemodify(funcs.stdpath('config'), ':t')) - eq(appname, funcs.fnamemodify(funcs.stdpath('cache'), ':t')) - eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('log'), ':t')) - eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('data'), ':t')) - eq(maybe_data(appname), funcs.fnamemodify(funcs.stdpath('state'), ':t')) + eq(appname, fn.fnamemodify(fn.stdpath('config'), ':t')) + eq(appname, fn.fnamemodify(fn.stdpath('cache'), ':t')) + eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('log'), ':t')) + eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('data'), ':t')) + eq(maybe_data(appname), fn.fnamemodify(fn.stdpath('state'), ':t')) -- config_dirs and data_dirs are empty on windows, so don't check them on -- that platform if not is_os('win') then - eq(appname, funcs.fnamemodify(funcs.stdpath('config_dirs')[1], ':t')) - eq(appname, funcs.fnamemodify(funcs.stdpath('data_dirs')[1], ':t')) + eq(appname, fn.fnamemodify(fn.stdpath('config_dirs')[1], ':t')) + eq(appname, fn.fnamemodify(fn.stdpath('data_dirs')[1], ':t')) end assert_alive() -- Check for crash. #8393 @@ -938,16 +938,16 @@ describe('stdpath()', function() XDG_CONFIG_HOME = alter_slashes('/home/docwhat/.config'), }, }) - eq(alter_slashes('/home/docwhat/.config/nvim'), funcs.stdpath('config')) + eq(alter_slashes('/home/docwhat/.config/nvim'), fn.stdpath('config')) end) it('handles changes during runtime', function() clear({ env = { XDG_CONFIG_HOME = alter_slashes('/home/original'), } }) - eq(alter_slashes('/home/original/nvim'), funcs.stdpath('config')) + eq(alter_slashes('/home/original/nvim'), fn.stdpath('config')) command("let $XDG_CONFIG_HOME='" .. alter_slashes('/home/new') .. "'") - eq(alter_slashes('/home/new/nvim'), funcs.stdpath('config')) + eq(alter_slashes('/home/new/nvim'), fn.stdpath('config')) end) it("doesn't expand $VARIABLES", function() @@ -957,14 +957,14 @@ describe('stdpath()', function() VARIABLES = 'this-should-not-happen', }, }) - eq(alter_slashes('$VARIABLES/nvim'), funcs.stdpath('config')) + eq(alter_slashes('$VARIABLES/nvim'), fn.stdpath('config')) end) it("doesn't expand ~/", function() clear({ env = { XDG_CONFIG_HOME = alter_slashes('~/frobnitz'), } }) - eq(alter_slashes('~/frobnitz/nvim'), funcs.stdpath('config')) + eq(alter_slashes('~/frobnitz/nvim'), fn.stdpath('config')) end) end) @@ -973,16 +973,16 @@ describe('stdpath()', function() clear({ env = { XDG_DATA_HOME = alter_slashes('/home/docwhat/.local'), } }) - eq(alter_slashes('/home/docwhat/.local/' .. datadir), funcs.stdpath('data')) + eq(alter_slashes('/home/docwhat/.local/' .. datadir), fn.stdpath('data')) end) it('handles changes during runtime', function() clear({ env = { XDG_DATA_HOME = alter_slashes('/home/original'), } }) - eq(alter_slashes('/home/original/' .. datadir), funcs.stdpath('data')) + eq(alter_slashes('/home/original/' .. datadir), fn.stdpath('data')) command("let $XDG_DATA_HOME='" .. alter_slashes('/home/new') .. "'") - eq(alter_slashes('/home/new/' .. datadir), funcs.stdpath('data')) + eq(alter_slashes('/home/new/' .. datadir), fn.stdpath('data')) end) it("doesn't expand $VARIABLES", function() @@ -992,14 +992,14 @@ describe('stdpath()', function() VARIABLES = 'this-should-not-happen', }, }) - eq(alter_slashes('$VARIABLES/' .. datadir), funcs.stdpath('data')) + eq(alter_slashes('$VARIABLES/' .. datadir), fn.stdpath('data')) end) it("doesn't expand ~/", function() clear({ env = { XDG_DATA_HOME = alter_slashes('~/frobnitz'), } }) - eq(alter_slashes('~/frobnitz/' .. datadir), funcs.stdpath('data')) + eq(alter_slashes('~/frobnitz/' .. datadir), fn.stdpath('data')) end) end) @@ -1010,16 +1010,16 @@ describe('stdpath()', function() XDG_STATE_HOME = alter_slashes('/home/docwhat/.local'), }, }) - eq(alter_slashes('/home/docwhat/.local/' .. statedir), funcs.stdpath('state')) + eq(alter_slashes('/home/docwhat/.local/' .. statedir), fn.stdpath('state')) end) it('handles changes during runtime', function() clear({ env = { XDG_STATE_HOME = alter_slashes('/home/original'), } }) - eq(alter_slashes('/home/original/' .. statedir), funcs.stdpath('state')) + eq(alter_slashes('/home/original/' .. statedir), fn.stdpath('state')) command("let $XDG_STATE_HOME='" .. alter_slashes('/home/new') .. "'") - eq(alter_slashes('/home/new/' .. statedir), funcs.stdpath('state')) + eq(alter_slashes('/home/new/' .. statedir), fn.stdpath('state')) end) it("doesn't expand $VARIABLES", function() @@ -1029,14 +1029,14 @@ describe('stdpath()', function() VARIABLES = 'this-should-not-happen', }, }) - eq(alter_slashes('$VARIABLES/' .. statedir), funcs.stdpath('state')) + eq(alter_slashes('$VARIABLES/' .. statedir), fn.stdpath('state')) end) it("doesn't expand ~/", function() clear({ env = { XDG_STATE_HOME = alter_slashes('~/frobnitz'), } }) - eq(alter_slashes('~/frobnitz/' .. statedir), funcs.stdpath('state')) + eq(alter_slashes('~/frobnitz/' .. statedir), fn.stdpath('state')) end) end) @@ -1047,16 +1047,16 @@ describe('stdpath()', function() XDG_CACHE_HOME = alter_slashes('/home/docwhat/.cache'), }, }) - eq(alter_slashes('/home/docwhat/.cache/nvim'), funcs.stdpath('cache')) + eq(alter_slashes('/home/docwhat/.cache/nvim'), fn.stdpath('cache')) end) it('handles changes during runtime', function() clear({ env = { XDG_CACHE_HOME = alter_slashes('/home/original'), } }) - eq(alter_slashes('/home/original/nvim'), funcs.stdpath('cache')) + eq(alter_slashes('/home/original/nvim'), fn.stdpath('cache')) command("let $XDG_CACHE_HOME='" .. alter_slashes('/home/new') .. "'") - eq(alter_slashes('/home/new/nvim'), funcs.stdpath('cache')) + eq(alter_slashes('/home/new/nvim'), fn.stdpath('cache')) end) it("doesn't expand $VARIABLES", function() @@ -1066,14 +1066,14 @@ describe('stdpath()', function() VARIABLES = 'this-should-not-happen', }, }) - eq(alter_slashes('$VARIABLES/nvim'), funcs.stdpath('cache')) + eq(alter_slashes('$VARIABLES/nvim'), fn.stdpath('cache')) end) it("doesn't expand ~/", function() clear({ env = { XDG_CACHE_HOME = alter_slashes('~/frobnitz'), } }) - eq(alter_slashes('~/frobnitz/nvim'), funcs.stdpath('cache')) + eq(alter_slashes('~/frobnitz/nvim'), fn.stdpath('cache')) end) end) end) @@ -1112,7 +1112,7 @@ describe('stdpath()', function() local function set_paths_at_runtime(var_name, paths) clear({ env = base_env() }) - meths.set_var('env_val', table.concat(paths, env_sep)) + api.nvim_set_var('env_val', table.concat(paths, env_sep)) command(('let $%s=g:env_val'):format(var_name)) end @@ -1120,12 +1120,12 @@ describe('stdpath()', function() describe(msg, function() it('set via system', function() set_paths_via_system(env_var_name, paths) - eq(expected_paths, funcs.stdpath(stdpath_arg)) + eq(expected_paths, fn.stdpath(stdpath_arg)) end) it('set at runtime', function() set_paths_at_runtime(env_var_name, paths) - eq(expected_paths, funcs.stdpath(stdpath_arg)) + eq(expected_paths, fn.stdpath(stdpath_arg)) end) end) end diff --git a/test/functional/options/num_options_spec.lua b/test/functional/options/num_options_spec.lua index d81b95ab41..0614bcf814 100644 --- a/test/functional/options/num_options_spec.lua +++ b/test/functional/options/num_options_spec.lua @@ -1,8 +1,8 @@ -- Tests for :setlocal and :setglobal local helpers = require('test.functional.helpers')(after_each) -local clear, feed_command, eval, eq, meths = - helpers.clear, helpers.feed_command, helpers.eval, helpers.eq, helpers.meths +local clear, feed_command, eval, eq, api = + helpers.clear, helpers.feed_command, helpers.eval, helpers.eq, helpers.api local function should_fail(opt, value, errmsg) feed_command('setglobal ' .. opt .. '=' .. value) @@ -11,7 +11,7 @@ local function should_fail(opt, value, errmsg) feed_command('setlocal ' .. opt .. '=' .. value) eq(errmsg, eval('v:errmsg'):match('E%d*')) feed_command('let v:errmsg = ""') - local status, err = pcall(meths.set_option_value, opt, value, {}) + local status, err = pcall(api.nvim_set_option_value, opt, value, {}) eq(status, false) eq(errmsg, err:match('E%d*')) eq('', eval('v:errmsg')) @@ -20,8 +20,8 @@ end local function should_succeed(opt, value) feed_command('setglobal ' .. opt .. '=' .. value) feed_command('setlocal ' .. opt .. '=' .. value) - meths.set_option_value(opt, value, {}) - eq(value, meths.get_option_value(opt, {})) + api.nvim_set_option_value(opt, value, {}) + eq(value, api.nvim_get_option_value(opt, {})) eq('', eval('v:errmsg')) end @@ -29,12 +29,12 @@ describe(':setlocal', function() before_each(clear) it('setlocal sets only local value', function() - eq(0, meths.get_option_value('iminsert', { scope = 'global' })) + eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' })) feed_command('setlocal iminsert=1') - eq(0, meths.get_option_value('iminsert', { scope = 'global' })) - eq(-1, meths.get_option_value('imsearch', { scope = 'global' })) + eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' })) + eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' })) feed_command('setlocal imsearch=1') - eq(-1, meths.get_option_value('imsearch', { scope = 'global' })) + eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' })) end) end) @@ -77,8 +77,8 @@ describe(':set validation', function() -- If smaller than 1 this one is set to 'lines'-1 feed_command('setglobal window=-10') - meths.set_option_value('window', -10, {}) - eq(23, meths.get_option_value('window', {})) + api.nvim_set_option_value('window', -10, {}) + eq(23, api.nvim_get_option_value('window', {})) eq('', eval('v:errmsg')) -- 'scrolloff' and 'sidescrolloff' can have a -1 value when @@ -112,8 +112,8 @@ describe(':set validation', function() local function setto(value) feed_command('setglobal maxcombine=' .. value) feed_command('setlocal maxcombine=' .. value) - meths.set_option_value('maxcombine', value, {}) - eq(6, meths.get_option_value('maxcombine', {})) + api.nvim_set_option_value('maxcombine', value, {}) + eq(6, api.nvim_get_option_value('maxcombine', {})) eq('', eval('v:errmsg')) end setto(0) diff --git a/test/functional/plugin/cfilter_spec.lua b/test/functional/plugin/cfilter_spec.lua index 8b1e75b495..37261d59df 100644 --- a/test/functional/plugin/cfilter_spec.lua +++ b/test/functional/plugin/cfilter_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn describe('cfilter.lua', function() before_each(function() @@ -13,16 +13,16 @@ describe('cfilter.lua', function() for _, list in ipairs({ { name = 'Cfilter', - get = funcs.getqflist, - set = funcs.setqflist, + get = fn.getqflist, + set = fn.setqflist, }, { name = 'Lfilter', get = function() - return funcs.getloclist(0) + return fn.getloclist(0) end, set = function(items) - return funcs.setloclist(0, items) + return fn.setloclist(0, items) end, }, }) do @@ -39,7 +39,7 @@ describe('cfilter.lua', function() describe((':%s'):format(list.name), function() it('does not error on empty list', function() filter('nothing') - eq({}, funcs.getqflist()) + eq({}, fn.getqflist()) end) it('requires an argument', function() @@ -66,7 +66,7 @@ describe('cfilter.lua', function() end local toname = function(qflist) - return funcs.map(qflist, 'v:val.text') + return fn.map(qflist, 'v:val.text') end test('filters with no matches', 'does not match', {}) @@ -83,7 +83,7 @@ describe('cfilter.lua', function() { filename = 'foo', lnum = 3, text = 'zed' }, }) - funcs.setreg('/', 'ba') + fn.setreg('/', 'ba') filter('/') eq({ 'bar', 'baz' }, toname(list.get())) @@ -96,7 +96,7 @@ describe('cfilter.lua', function() { filename = 'foo', lnum = 3, text = 'zed' }, }) - funcs.setreg('/', 'ba') + fn.setreg('/', 'ba') filter('/', true) eq({ 'zed' }, toname(list.get())) diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index 2c9ce7ae1a..115c28fbf6 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -3,8 +3,8 @@ local clear = helpers.clear local command = helpers.command local eq = helpers.eq local pathsep = helpers.get_pathsep() -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local exec_lua = helpers.exec_lua local testdir = 'Xtest-editorconfig' @@ -13,7 +13,7 @@ local function test_case(name, expected) local filename = testdir .. pathsep .. name command('edit ' .. filename) for opt, val in pairs(expected) do - eq(val, meths.get_option_value(opt, { buf = 0 }), name) + eq(val, api.nvim_get_option_value(opt, { buf = 0 }), name) end end @@ -195,15 +195,15 @@ But not this one end) it('can be disabled globally', function() - meths.set_var('editorconfig', false) - meths.set_option_value('shiftwidth', 42, {}) + api.nvim_set_var('editorconfig', false) + api.nvim_set_option_value('shiftwidth', 42, {}) test_case('3_space.txt', { shiftwidth = 42 }) end) it('can be disabled per-buffer', function() - meths.set_option_value('shiftwidth', 42, {}) - local bufnr = funcs.bufadd(testdir .. pathsep .. '3_space.txt') - meths.buf_set_var(bufnr, 'editorconfig', false) + api.nvim_set_option_value('shiftwidth', 42, {}) + local bufnr = fn.bufadd(testdir .. pathsep .. '3_space.txt') + api.nvim_buf_set_var(bufnr, 'editorconfig', false) test_case('3_space.txt', { shiftwidth = 42 }) test_case('4_space.py', { shiftwidth = 4 }) end) diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index f08f207d39..8564ec7c9b 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -5,7 +5,7 @@ local clear = helpers.clear local curbuf_contents = helpers.curbuf_contents local command = helpers.command local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches -local getcompletion = helpers.funcs.getcompletion +local getcompletion = helpers.fn.getcompletion local insert = helpers.insert local source = helpers.source local exec_lua = helpers.exec_lua diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index f641b42727..97fa108500 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local exec_lua = helpers.exec_lua local run = helpers.run local stop = helpers.stop -local NIL = helpers.NIL +local NIL = vim.NIL local M = {} diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index 9b33f4451e..bd1842ceb5 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -1,7 +1,7 @@ -- Test suite for testing interactions with the incremental sync algorithms powering the LSP client local helpers = require('test.functional.helpers')(after_each) -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local eq = helpers.eq local exec_lua = helpers.exec_lua @@ -62,7 +62,7 @@ local function test_edit( offset_encoding = offset_encoding or 'utf-16' line_ending = line_ending or '\n' - meths.buf_set_lines(0, 0, -1, true, prev_buffer) + api.nvim_buf_set_lines(0, 0, -1, true, prev_buffer) exec_lua('return test_register(...)', 0, 'test1', offset_encoding, line_ending) for _, edit in ipairs(edit_operations) do diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 86b9be79e0..252931eccb 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -11,19 +11,20 @@ local eq = helpers.eq local eval = helpers.eval local matches = helpers.matches local pcall_err = helpers.pcall_err -local pesc = helpers.pesc +local pesc = vim.pesc local insert = helpers.insert -local funcs = helpers.funcs +local fn = helpers.fn local retry = helpers.retry local stop = helpers.stop -local NIL = helpers.NIL +local NIL = vim.NIL local read_file = require('test.helpers').read_file local write_file = require('test.helpers').write_file local is_ci = helpers.is_ci -local meths = helpers.meths +local api = helpers.api local is_os = helpers.is_os local skip = helpers.skip local mkdir = helpers.mkdir +local tmpname = helpers.tmpname local clear_notrace = lsp_helpers.clear_notrace local create_server_definition = lsp_helpers.create_server_definition @@ -362,9 +363,9 @@ describe('LSP', function() end, on_handler = function(_, _, ctx) if ctx.method == 'finish' then - eq('basic_init', meths.get_var('lsp_attached')) + eq('basic_init', api.nvim_get_var('lsp_attached')) exec_lua('return lsp.buf_detach_client(BUFFER, TEST_RPC_CLIENT_ID)') - eq('basic_init', meths.get_var('lsp_detached')) + eq('basic_init', api.nvim_get_var('lsp_detached')) client.stop() end end, @@ -728,8 +729,8 @@ describe('LSP', function() on_handler = function(err, result, ctx) eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') if ctx.method == 'start' then - local tmpfile_old = helpers.tmpname() - local tmpfile_new = helpers.tmpname() + local tmpfile_old = tmpname() + local tmpfile_new = tmpname() os.remove(tmpfile_new) exec_lua( [=[ @@ -1876,7 +1877,7 @@ describe('LSP', function() describe('cursor position', function() it("don't fix the cursor if the range contains the cursor", function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 19, 'Second line of text'), } @@ -1888,11 +1889,11 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 6 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 6 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor to the valid col if the content was removed', function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), make_edit(1, 6, 1, 19, ''), @@ -1905,11 +1906,11 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 0 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 0 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor to the valid row if the content was removed', function() - funcs.nvim_win_set_cursor(0, { 2, 6 }) + fn.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), make_edit(0, 18, 5, 0, ''), @@ -1918,11 +1919,11 @@ describe('LSP', function() eq({ 'First line of text', }, buf_lines(1)) - eq({ 1, 17 }, funcs.nvim_win_get_cursor(0)) + eq({ 1, 17 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor row', function() - funcs.nvim_win_set_cursor(0, { 3, 0 }) + fn.nvim_win_set_cursor(0, { 3, 0 }) local edits = { make_edit(1, 0, 2, 0, ''), } @@ -1933,14 +1934,14 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 0 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 0 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor col', function() -- append empty last line. See #22636 exec_lua('vim.api.nvim_buf_set_lines(...)', 1, -1, -1, true, { '' }) - funcs.nvim_win_set_cursor(0, { 2, 11 }) + fn.nvim_win_set_cursor(0, { 2, 11 }) local edits = { make_edit(1, 7, 1, 11, ''), } @@ -1953,11 +1954,11 @@ describe('LSP', function() 'å å ɧ 汉语 ↥ 🤦 🦄', '', }, buf_lines(1)) - eq({ 2, 7 }, funcs.nvim_win_get_cursor(0)) + eq({ 2, 7 }, fn.nvim_win_get_cursor(0)) end) it('fix the cursor row and col', function() - funcs.nvim_win_set_cursor(0, { 2, 12 }) + fn.nvim_win_set_cursor(0, { 2, 12 }) local edits = { make_edit(0, 11, 1, 12, ''), } @@ -1968,7 +1969,7 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 1, 11 }, funcs.nvim_win_get_cursor(0)) + eq({ 1, 11 }, fn.nvim_win_get_cursor(0)) end) end) @@ -2278,7 +2279,7 @@ describe('LSP', function() ) end) it('Supports file creation with CreateFile payload', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) -- Should not exist, only interested in a tmpname local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2295,7 +2296,7 @@ describe('LSP', function() it( 'Supports file creation in folder that needs to be created with CreateFile payload', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) -- Should not exist, only interested in a tmpname tmpfile = tmpfile .. '/dummy/x/' local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) @@ -2312,7 +2313,7 @@ describe('LSP', function() end ) it('createFile does not touch file if it exists and ignoreIfExists is set', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Dummy content') local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2331,7 +2332,7 @@ describe('LSP', function() eq('Dummy content', read_file(tmpfile)) end) it('createFile overrides file if overwrite is set', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Dummy content') local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2351,7 +2352,7 @@ describe('LSP', function() eq('', read_file(tmpfile)) end) it('DeleteFile delete file and buffer', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() write_file(tmpfile, 'Be gone') local uri = exec_lua( [[ @@ -2375,7 +2376,7 @@ describe('LSP', function() eq(false, exec_lua('return vim.api.nvim_buf_is_loaded(vim.fn.bufadd(...))', tmpfile)) end) it('DeleteFile fails if file does not exist and ignoreIfNotExists is false', function() - local tmpfile = helpers.tmpname() + local tmpfile = tmpname() os.remove(tmpfile) local uri = exec_lua('return vim.uri_from_fname(...)', tmpfile) local edit = { @@ -2398,9 +2399,9 @@ describe('LSP', function() local pathsep = helpers.get_pathsep() it('Can rename an existing file', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Test content') - local new = helpers.tmpname() + local new = tmpname() os.remove(new) -- only reserve the name, file must not exist for the test scenario local lines = exec_lua( [[ @@ -2424,9 +2425,9 @@ describe('LSP', function() os.remove(new) end) it('Kills old buffer after renaming an existing file', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Test content') - local new = helpers.tmpname() + local new = tmpname() os.remove(new) -- only reserve the name, file must not exist for the test scenario local lines = exec_lua( [[ @@ -2444,8 +2445,8 @@ describe('LSP', function() end) it('Can rename a directory', function() -- only reserve the name, file must not exist for the test scenario - local old_dir = helpers.tmpname() - local new_dir = helpers.tmpname() + local old_dir = tmpname() + local new_dir = tmpname() os.remove(old_dir) os.remove(new_dir) @@ -2479,9 +2480,9 @@ describe('LSP', function() it( 'Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Old File') - local new = helpers.tmpname() + local new = tmpname() write_file(new, 'New file') exec_lua( @@ -2514,9 +2515,9 @@ describe('LSP', function() end ) it('Does override target if overwrite is true', function() - local old = helpers.tmpname() + local old = tmpname() write_file(old, 'Old file') - local new = helpers.tmpname() + local new = tmpname() write_file(new, 'New file') exec_lua( [[ @@ -2945,14 +2946,14 @@ describe('LSP', function() end) it('adds current position to jumplist before jumping', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + fn.nvim_win_set_buf(0, target_bufnr) + local mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_cursor(0, { 2, 3 }) jump(location(0, 9, 0, 9)) - mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 2, 3 }, mark) end) end) @@ -3046,101 +3047,101 @@ describe('LSP', function() end) it('does not add current position to jumplist if not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + fn.nvim_win_set_buf(0, target_bufnr) + local mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_cursor(0, { 2, 3 }) show_document(location(0, 9, 0, 9), false, true) show_document(location(0, 9, 0, 9, true), false, true) - mark = funcs.nvim_buf_get_mark(target_bufnr, "'") + mark = fn.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) end) it('does not change cursor position if not focus and not reuse_win', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local cursor = funcs.nvim_win_get_cursor(0) + fn.nvim_win_set_buf(0, target_bufnr) + local cursor = fn.nvim_win_get_cursor(0) show_document(location(0, 9, 0, 9), false, false) - eq(cursor, funcs.nvim_win_get_cursor(0)) + eq(cursor, fn.nvim_win_get_cursor(0)) end) it('does not change window if not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local win = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr) + local win = fn.nvim_get_current_win() -- same document/bufnr show_document(location(0, 9, 0, 9), false, true) - eq(win, funcs.nvim_get_current_win()) + eq(win, fn.nvim_get_current_win()) -- different document/bufnr, new window/split show_document(location(0, 9, 0, 9, true), false, true) - eq(2, #funcs.nvim_list_wins()) - eq(win, funcs.nvim_get_current_win()) + eq(2, #fn.nvim_list_wins()) + eq(win, fn.nvim_get_current_win()) end) it("respects 'reuse_win' parameter", function() - funcs.nvim_win_set_buf(0, target_bufnr) + fn.nvim_win_set_buf(0, target_bufnr) -- does not create a new window if the buffer is already open show_document(location(0, 9, 0, 9), false, true) - eq(1, #funcs.nvim_list_wins()) + eq(1, #fn.nvim_list_wins()) -- creates a new window even if the buffer is already open show_document(location(0, 9, 0, 9), false, false) - eq(2, #funcs.nvim_list_wins()) + eq(2, #fn.nvim_list_wins()) end) it('correctly sets the cursor of the split if range is given without focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) + fn.nvim_win_set_buf(0, target_bufnr) show_document(location(0, 9, 0, 9, true), false, true) - local wins = funcs.nvim_list_wins() + local wins = fn.nvim_list_wins() eq(2, #wins) table.sort(wins) - eq({ 1, 0 }, funcs.nvim_win_get_cursor(wins[1])) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(wins[2])) + eq({ 1, 0 }, fn.nvim_win_get_cursor(wins[1])) + eq({ 1, 9 }, fn.nvim_win_get_cursor(wins[2])) end) it('does not change cursor of the split if not range and not focus', function() - funcs.nvim_win_set_buf(0, target_bufnr) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_buf(0, target_bufnr) + fn.nvim_win_set_cursor(0, { 2, 3 }) exec_lua([[vim.cmd.new()]]) - funcs.nvim_win_set_buf(0, target_bufnr2) - funcs.nvim_win_set_cursor(0, { 2, 3 }) + fn.nvim_win_set_buf(0, target_bufnr2) + fn.nvim_win_set_cursor(0, { 2, 3 }) show_document({ uri = 'file:///fake/uri2' }, false, true) - local wins = funcs.nvim_list_wins() + local wins = fn.nvim_list_wins() eq(2, #wins) - eq({ 2, 3 }, funcs.nvim_win_get_cursor(wins[1])) - eq({ 2, 3 }, funcs.nvim_win_get_cursor(wins[2])) + eq({ 2, 3 }, fn.nvim_win_get_cursor(wins[1])) + eq({ 2, 3 }, fn.nvim_win_get_cursor(wins[2])) end) it('respects existing buffers', function() - funcs.nvim_win_set_buf(0, target_bufnr) - local win = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr) + local win = fn.nvim_get_current_win() exec_lua([[vim.cmd.new()]]) - funcs.nvim_win_set_buf(0, target_bufnr2) - funcs.nvim_win_set_cursor(0, { 2, 3 }) - local split = funcs.nvim_get_current_win() + fn.nvim_win_set_buf(0, target_bufnr2) + fn.nvim_win_set_cursor(0, { 2, 3 }) + local split = fn.nvim_get_current_win() -- reuse win for open document/bufnr if called from split show_document(location(0, 9, 0, 9, true), false, true) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(split)) - eq(2, #funcs.nvim_list_wins()) + eq({ 1, 9 }, fn.nvim_win_get_cursor(split)) + eq(2, #fn.nvim_list_wins()) - funcs.nvim_set_current_win(win) + fn.nvim_set_current_win(win) -- reuse win for open document/bufnr if called outside the split show_document(location(0, 9, 0, 9, true), false, true) - eq({ 1, 9 }, funcs.nvim_win_get_cursor(split)) - eq(2, #funcs.nvim_list_wins()) + eq({ 1, 9 }, fn.nvim_win_get_cursor(split)) + eq(2, #fn.nvim_list_wins()) end) end) @@ -4043,7 +4044,7 @@ describe('LSP', function() if is_os('win') then tmpfile = '\\\\.\\\\pipe\\pipe.test' else - tmpfile = helpers.tmpname() + tmpfile = tmpname() os.remove(tmpfile) end local result = exec_lua( @@ -4150,7 +4151,7 @@ describe('LSP', function() describe('#dynamic vim.lsp._dynamic', function() it('supports dynamic registration', function() ---@type string - local root_dir = helpers.tmpname() + local root_dir = tmpname() os.remove(root_dir) mkdir(root_dir) local tmpfile = root_dir .. '/dynamic.foo' @@ -4261,7 +4262,7 @@ describe('LSP', function() describe('vim.lsp._watchfiles', function() it('sends notifications when files change', function() skip(is_os('bsd'), 'bsd only reports rename on folders if file inside change') - local root_dir = helpers.tmpname() + local root_dir = tmpname() os.remove(root_dir) mkdir(root_dir) diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index ed9f21edf3..5bfa566729 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -3,13 +3,13 @@ local Screen = require('test.functional.ui.screen') local command, rawfeed = helpers.command, helpers.rawfeed local clear = helpers.clear local exec_lua = helpers.exec_lua -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local matches = helpers.matches local write_file = helpers.write_file local tmpname = helpers.tmpname local eq = helpers.eq -local pesc = helpers.pesc +local pesc = vim.pesc local skip = helpers.skip local is_ci = helpers.is_ci @@ -33,7 +33,7 @@ local function get_search_history(name) end clear() -if funcs.executable('man') == 0 then +if fn.executable('man') == 0 then pending('missing "man" command', function() end) return end @@ -192,7 +192,7 @@ describe(':Man', function() '+Man!', '+call nvim_input("q")', } - matches('quit works!!', funcs.system(args, { 'manpage contents' })) + matches('quit works!!', fn.system(args, { 'manpage contents' })) end) it('reports non-existent man pages for absolute paths', function() @@ -206,7 +206,7 @@ describe(':Man', function() ('Error detected while processing command line:\r\n' .. 'man.lua: "no manual entry for %s"'):format( pesc(actual_file) ), - funcs.system(args, { '' }) + fn.system(args, { '' }) ) os.remove(actual_file) end) diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 1c4e11d30b..530afd16e4 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command -local meths = helpers.meths +local api = helpers.api local feed = helpers.feed local eq = helpers.eq @@ -22,7 +22,7 @@ describe('matchparen', function() it('uses correct column after i_<Up>. Vim patch 7.4.1296', function() command('set noautoindent nosmartindent nocindent laststatus=0') - eq(1, meths.get_var('loaded_matchparen')) + eq(1, api.nvim_get_var('loaded_matchparen')) feed('ivoid f_test()<cr>') feed('{<cr>') feed('}') diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 01dd253384..8511e6c703 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -1,10 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear -local meths = helpers.meths -local eq, nvim_eval, nvim_command, exc_exec = - helpers.eq, helpers.eval, helpers.command, helpers.exc_exec +local api = helpers.api +local eq = helpers.eq +local nvim_eval = helpers.eval +local nvim_command = helpers.command +local exc_exec = helpers.exc_exec local ok = helpers.ok -local NIL = helpers.NIL +local NIL = vim.NIL describe('autoload/msgpack.vim', function() before_each(function() @@ -524,17 +526,17 @@ describe('autoload/msgpack.vim', function() end) it('works for special v: values like v:true', function() - meths.set_var('true', true) - meths.set_var('false', false) - meths.set_var('nil', NIL) + api.nvim_set_var('true', true) + api.nvim_set_var('false', false) + api.nvim_set_var('nil', NIL) nvim_command('let true2 = msgpack#deepcopy(true)') nvim_command('let false2 = msgpack#deepcopy(false)') nvim_command('let nil2 = msgpack#deepcopy(nil)') - eq(true, meths.get_var('true')) - eq(false, meths.get_var('false')) - eq(NIL, meths.get_var('nil')) + eq(true, api.nvim_get_var('true')) + eq(false, api.nvim_get_var('false')) + eq(NIL, api.nvim_get_var('nil')) end) end) diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index ef3fef1897..1c20548321 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,21 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear -local eq, meths, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf = - helpers.eq, - helpers.meths, - helpers.eval, - helpers.command, - helpers.nvim, - helpers.exc_exec, - helpers.funcs, - helpers.feed, - helpers.curbuf +local eq, api, nvim_eval, nvim_command, exc_exec, fn, nvim_feed = + helpers.eq, helpers.api, helpers.eval, helpers.command, helpers.exc_exec, helpers.fn, helpers.feed local neq = helpers.neq local read_file = helpers.read_file -local mpack = require('mpack') - local shada_helpers = require('test.functional.shada.helpers') local get_shada_rw = shada_helpers.get_shada_rw @@ -26,7 +16,7 @@ end local mpack_eq = function(expected, mpack_result) local mpack_keys = { 'type', 'timestamp', 'length', 'value' } - local unpack = mpack.Unpacker() + local unpack = vim.mpack.Unpacker() local actual = {} local cur, val local i = 0 @@ -126,7 +116,7 @@ describe('autoload/shada.vim', function() describe('function shada#sd_to_strings', function() local sd2strings_eq = function(expected, arg) if type(arg) == 'table' then - eq(expected, funcs['shada#sd_to_strings'](arg)) + eq(expected, fn['shada#sd_to_strings'](arg)) else eq(expected, nvim_eval(('shada#sd_to_strings(%s)'):format(arg))) end @@ -1583,7 +1573,7 @@ describe('autoload/shada.vim', function() describe('function shada#strings_to_sd', function() local strings2sd_eq = function(expected, input) - nvim('set_var', '__input', input) + api.nvim_set_var('__input', input) nvim_command( 'let g:__actual = map(shada#strings_to_sd(g:__input), ' .. '"filter(v:val, \\"v:key[0] isnot# \'_\' ' @@ -1591,7 +1581,7 @@ describe('autoload/shada.vim', function() ) -- print() if type(expected) == 'table' then - nvim('set_var', '__expected', expected) + api.nvim_set_var('__expected', expected) nvim_command('let g:__expected = ModifyVal(g:__expected)') expected = 'g:__expected' -- print(nvim_eval('msgpack#string(g:__expected)')) @@ -2527,7 +2517,7 @@ describe('autoload/shada.vim', function() describe('function shada#get_binstrings', function() local getbstrings_eq = function(expected, input) - local result = funcs['shada#get_binstrings'](input) + local result = fn['shada#get_binstrings'](input) for i, s in ipairs(result) do result[i] = s:gsub('\n', '\0') end @@ -2536,7 +2526,7 @@ describe('autoload/shada.vim', function() end it('works', function() - local version = nvim('get_vvar', 'version') + local version = api.nvim_get_vvar('version') getbstrings_eq({ { timestamp = 'current', @@ -2562,7 +2552,7 @@ describe('autoload/shada.vim', function() ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#add_own_header', 1) + api.nvim_set_var('shada#add_own_header', 1) getbstrings_eq({ { timestamp = 'current', @@ -2588,14 +2578,14 @@ describe('autoload/shada.vim', function() ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#add_own_header', 0) + api.nvim_set_var('shada#add_own_header', 0) getbstrings_eq({}, {}) getbstrings_eq({ { timestamp = 0, type = 1, value = { generator = 'test' } } }, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', ' + generator "test"', }) - nvim('set_var', 'shada#keep_old_header', 0) + api.nvim_set_var('shada#keep_old_header', 0) getbstrings_eq({}, { 'Header with timestamp ' .. epoch .. ':', ' % Key______ Value', @@ -2646,7 +2636,8 @@ describe('plugin/shada.vim', function() wshada('\004\000\009\147\000\196\002ab\196\001a') wshada_tmp('\004\000\009\147\000\196\002ab\196\001b') - local bufread_commands = meths.get_autocmds({ group = 'ShaDaCommands', event = 'BufReadCmd' }) + local bufread_commands = + api.nvim_get_autocmds({ group = 'ShaDaCommands', event = 'BufReadCmd' }) eq(2, #bufread_commands--[[, vim.inspect(bufread_commands) ]]) -- Need to set nohidden so that the buffer containing 'fname' is not unloaded @@ -2662,8 +2653,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - eq(false, nvim('get_option_value', 'modified', {})) - eq('shada', nvim('get_option_value', 'filetype', {})) + eq(false, api.nvim_get_option_value('modified', {})) + eq('shada', api.nvim_get_option_value('filetype', {})) nvim_command('edit ' .. fname_tmp) eq({ 'History entry with timestamp ' .. epoch .. ':', @@ -2672,8 +2663,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - eq(false, nvim('get_option_value', 'modified', {})) - eq('shada', nvim('get_option_value', 'filetype', {})) + eq(false, api.nvim_get_option_value('modified', {})) + eq('shada', api.nvim_get_option_value('filetype', {})) eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname)) neq({ 'History entry with timestamp ' .. epoch .. ':', @@ -2682,7 +2673,7 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - neq(true, nvim('get_option_value', 'modified', {})) + neq(true, api.nvim_get_option_value('modified', {})) end) it('event FileReadCmd', function() @@ -2698,8 +2689,8 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "a"', }, nvim_eval('getline(1, "$")')) - eq(true, nvim('get_option_value', 'modified', {})) - neq('shada', nvim('get_option_value', 'filetype', {})) + eq(true, api.nvim_get_option_value('modified', {})) + neq('shada', api.nvim_get_option_value('filetype', {})) nvim_command('1,$read ' .. fname_tmp) eq({ '', @@ -2714,9 +2705,9 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - eq(true, nvim('get_option_value', 'modified', {})) - neq('shada', nvim('get_option_value', 'filetype', {})) - nvim('set_option_value', 'modified', false, {}) + eq(true, api.nvim_get_option_value('modified', {})) + neq('shada', api.nvim_get_option_value('filetype', {})) + api.nvim_set_option_value('modified', false, {}) eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname)) eq({ '', @@ -2731,13 +2722,13 @@ describe('plugin/shada.vim', function() ' - contents "ab"', ' - "b"', }, nvim_eval('getline(1, "$")')) - neq(true, nvim('get_option_value', 'modified', {})) + neq(true, api.nvim_get_option_value('modified', {})) end) it('event BufWriteCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + api.nvim_set_var('shada#add_own_header', 0) + api.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2797,8 +2788,8 @@ describe('plugin/shada.vim', function() it('event FileWriteCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + api.nvim_set_var('shada#add_own_header', 0) + api.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2841,8 +2832,8 @@ describe('plugin/shada.vim', function() it('event FileAppendCmd', function() reset() - nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_lines', 0, 1, true, { + api.nvim_set_var('shada#add_own_header', 0) + api.nvim_buf_set_lines(0, 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', " + n name 'A'", @@ -2856,9 +2847,9 @@ describe('plugin/shada.vim', function() ' + l line number 2', ' + c column -200', }) - funcs.writefile({ '' }, fname .. '.tst', 'b') - funcs.writefile({ '' }, fname, 'b') - funcs.writefile({ '' }, fname_tmp, 'b') + fn.writefile({ '' }, fname .. '.tst', 'b') + fn.writefile({ '' }, fname, 'b') + fn.writefile({ '' }, fname_tmp, 'b') nvim_command('1,3w >> ' .. fname .. '.tst') nvim_command('1,3w >> ' .. fname) nvim_command('1,3w >> ' .. fname_tmp) @@ -2928,8 +2919,8 @@ describe('plugin/shada.vim', function() wshada_tmp('\004\001\006\146\000\196\002bc') eq(0, exc_exec('source ' .. fname)) eq(0, exc_exec('source ' .. fname_tmp)) - eq('bc', funcs.histget(':', -1)) - eq('ab', funcs.histget(':', -2)) + eq('bc', fn.histget(':', -1)) + eq('ab', fn.histget(':', -2)) end) end) @@ -2940,7 +2931,7 @@ describe('ftplugin/shada.vim', function() it('sets indentexpr correctly', function() nvim_command('filetype plugin indent on') nvim_command('setlocal filetype=shada') - funcs.setline(1, { + fn.setline(1, { 'Jump with timestamp ' .. epoch .. ':', '% Key________ Description Value', "+ n name 'A'", @@ -3012,34 +3003,34 @@ describe('ftplugin/shada.vim', function() ' + f file name 20', ' + l line number 1', ' + c column 0', - }, funcs.getline(1, funcs.line('$'))) + }, fn.getline(1, fn.line('$'))) end) it('sets options correctly', function() nvim_command('filetype plugin indent on') nvim_command('setlocal filetype=shada') - eq(true, nvim('get_option_value', 'expandtab', {})) - eq(2, nvim('get_option_value', 'tabstop', {})) - eq(2, nvim('get_option_value', 'softtabstop', {})) - eq(2, nvim('get_option_value', 'shiftwidth', {})) + eq(true, api.nvim_get_option_value('expandtab', {})) + eq(2, api.nvim_get_option_value('tabstop', {})) + eq(2, api.nvim_get_option_value('softtabstop', {})) + eq(2, api.nvim_get_option_value('shiftwidth', {})) end) it('sets indentkeys correctly', function() nvim_command('filetype plugin indent on') nvim_command('setlocal filetype=shada') - funcs.setline(1, ' Replacement with timestamp ' .. epoch) + fn.setline(1, ' Replacement with timestamp ' .. epoch) nvim_feed('ggA:\027') - eq('Replacement with timestamp ' .. epoch .. ':', curbuf('get_lines', 0, 1, true)[1]) + eq('Replacement with timestamp ' .. epoch .. ':', api.nvim_buf_get_lines(0, 0, 1, true)[1]) nvim_feed('o-\027') - eq({ ' -' }, curbuf('get_lines', 1, 2, true)) + eq({ ' -' }, api.nvim_buf_get_lines(0, 1, 2, true)) nvim_feed('ggO+\027') - eq({ '+' }, curbuf('get_lines', 0, 1, true)) + eq({ '+' }, api.nvim_buf_get_lines(0, 0, 1, true)) nvim_feed('GO*\027') - eq({ ' *' }, curbuf('get_lines', 2, 3, true)) + eq({ ' *' }, api.nvim_buf_get_lines(0, 2, 3, true)) nvim_feed('ggO /\027') - eq({ ' /' }, curbuf('get_lines', 0, 1, true)) + eq({ ' /' }, api.nvim_buf_get_lines(0, 0, 1, true)) nvim_feed('ggOx\027') - eq({ 'x' }, curbuf('get_lines', 0, 1, true)) + eq({ 'x' }, api.nvim_buf_get_lines(0, 0, 1, true)) end) end) @@ -3064,7 +3055,7 @@ describe('syntax/shada.vim', function() } screen:attach() - curbuf('set_lines', 0, 1, true, { + api.nvim_buf_set_lines(0, 0, 1, true, { 'Header with timestamp ' .. epoch .. ':', ' % Key Value', ' + t "test"', @@ -3211,7 +3202,7 @@ describe('syntax/shada.vim', function() s, } end - local act = funcs.GetSyntax() + local act = fn.GetSyntax() local ms = function(syn) return { { 'ShaDaEntryMap' .. syn, 'ShaDaEntryMap' .. syn .. 'EntryStart' }, diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua index a48404164f..0c4fd7aaa0 100644 --- a/test/functional/provider/clipboard_spec.lua +++ b/test/functional/provider/clipboard_spec.lua @@ -6,7 +6,7 @@ local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local feed_command, expect, eq, eval, source = helpers.feed_command, helpers.expect, helpers.eq, helpers.eval, helpers.source local command = helpers.command -local meths = helpers.meths +local api = helpers.api local function basic_register_test(noblock) insert('some words') @@ -188,7 +188,7 @@ describe('clipboard', function() it('valid g:clipboard', function() -- provider#clipboard#Executable() only checks the structure. - meths.set_var('clipboard', { + api.nvim_set_var('clipboard', { ['name'] = 'clippy!', ['copy'] = { ['+'] = 'any command', ['*'] = 'some other' }, ['paste'] = { ['+'] = 'any command', ['*'] = 'some other' }, @@ -545,7 +545,7 @@ describe('clipboard (with fake clipboard.vim)', function() eq({ { 'text', '' }, 'V' }, eval("g:test_clip['*']")) command("let g:test_clip['*'] = [['star'], 'c']") feed('p') - eq('textstar', meths.get_current_line()) + eq('textstar', api.nvim_get_current_line()) end) it('Block paste works correctly', function() diff --git a/test/functional/provider/define_spec.lua b/test/functional/provider/define_spec.lua index 59422d8224..a1109935d2 100644 --- a/test/functional/provider/define_spec.lua +++ b/test/functional/provider/define_spec.lua @@ -1,7 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) -local eval, command, nvim = helpers.eval, helpers.command, helpers.nvim +local eval, command = helpers.eval, helpers.command local eq, run, stop = helpers.eq, helpers.run, helpers.stop local clear = helpers.clear +local api = helpers.api local function get_prefix(sync) if sync then @@ -361,7 +362,7 @@ local function function_specs_for(fn, sync, first_arg_factory, init) end local function channel() - return nvim('get_api_info')[1] + return api.nvim_get_api_info()[1] end local function host() diff --git a/test/functional/provider/perl_spec.lua b/test/functional/provider/perl_spec.lua index ae110cb3b0..e9a031eb07 100644 --- a/test/functional/provider/perl_spec.lua +++ b/test/functional/provider/perl_spec.lua @@ -5,7 +5,7 @@ local command = helpers.command local write_file = helpers.write_file local eval = helpers.eval local retry = helpers.retry -local meths = helpers.meths +local api = helpers.api local insert = helpers.insert local expect = helpers.expect local feed = helpers.feed @@ -48,7 +48,7 @@ describe('legacy perl provider', function() -- :perldo 1; doesn't change $_, -- the buffer should not be changed command('normal :perldo 1;') - eq(false, meths.get_option_value('modified', {})) + eq(false, api.nvim_get_option_value('modified', {})) -- insert some text insert('abc\ndef\nghi') expect([[ diff --git a/test/functional/provider/python3_spec.lua b/test/functional/provider/python3_spec.lua index 8d81b86c9c..1419d7f651 100644 --- a/test/functional/provider/python3_spec.lua +++ b/test/functional/provider/python3_spec.lua @@ -8,7 +8,7 @@ local source = helpers.source local missing_provider = helpers.missing_provider local matches = helpers.matches local pcall_err = helpers.pcall_err -local funcs = helpers.funcs +local fn = helpers.fn local dedent = helpers.dedent do @@ -113,7 +113,7 @@ describe('python3 provider', function() describe('py3eval()', function() it('works', function() - eq({ 1, 2, { ['key'] = 'val' } }, funcs.py3eval('[1, 2, {"key": "val"}]')) + eq({ 1, 2, { ['key'] = 'val' } }, fn.py3eval('[1, 2, {"key": "val"}]')) end) it('errors out when given non-string', function() @@ -166,11 +166,11 @@ end) describe('python2 feature test', function() -- python2 is not supported, so correct behaviour is to return 0 it('works', function() - eq(0, funcs.has('python2')) - eq(0, funcs.has('python')) - eq(0, funcs.has('python_compiled')) - eq(0, funcs.has('python_dynamic')) - eq(0, funcs.has('python_dynamic_')) - eq(0, funcs.has('python_')) + eq(0, fn.has('python2')) + eq(0, fn.has('python')) + eq(0, fn.has('python_compiled')) + eq(0, fn.has('python_dynamic')) + eq(0, fn.has('python_dynamic_')) + eq(0, fn.has('python_')) end) end) diff --git a/test/functional/provider/ruby_spec.lua b/test/functional/provider/ruby_spec.lua index 56919d401c..9b2531a23c 100644 --- a/test/functional/provider/ruby_spec.lua +++ b/test/functional/provider/ruby_spec.lua @@ -8,9 +8,9 @@ local exc_exec = helpers.exc_exec local expect = helpers.expect local feed = helpers.feed local feed_command = helpers.feed_command -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert -local meths = helpers.meths +local api = helpers.api local missing_provider = helpers.missing_provider local matches = helpers.matches local write_file = helpers.write_file @@ -36,19 +36,19 @@ end) describe('ruby feature test', function() it('works', function() - eq(1, funcs.has('ruby')) + eq(1, fn.has('ruby')) end) end) describe(':ruby command', function() it('evaluates ruby', function() command('ruby VIM.command("let g:set_by_ruby = [100, 0]")') - eq({ 100, 0 }, meths.get_var('set_by_ruby')) + eq({ 100, 0 }, api.nvim_get_var('set_by_ruby')) end) it('supports nesting', function() command([[ruby VIM.command('ruby VIM.command("let set_by_nested_ruby = 555")')]]) - eq(555, meths.get_var('set_by_nested_ruby')) + eq(555, api.nvim_get_var('set_by_nested_ruby')) end) end) @@ -57,7 +57,7 @@ describe(':rubyfile command', function() local fname = 'rubyfile.rb' write_file(fname, 'VIM.command("let set_by_rubyfile = 123")') command('rubyfile rubyfile.rb') - eq(123, meths.get_var('set_by_rubyfile')) + eq(123, api.nvim_get_var('set_by_rubyfile')) os.remove(fname) end) end) @@ -97,7 +97,7 @@ describe(':rubydo command', function() it('does not modify the buffer if no changes are made', function() command('normal :rubydo 42') - eq(false, meths.get_option_value('modified', {})) + eq(false, api.nvim_get_option_value('modified', {})) end) end) @@ -112,11 +112,11 @@ end) describe('rubyeval()', function() it('evaluates ruby objects', function() - eq({ 1, 2, { ['key'] = 'val' } }, funcs.rubyeval('[1, 2, {key: "val"}]')) + eq({ 1, 2, { ['key'] = 'val' } }, fn.rubyeval('[1, 2, {key: "val"}]')) end) it('returns nil for empty strings', function() - eq(helpers.NIL, funcs.rubyeval('')) + eq(vim.NIL, fn.rubyeval('')) end) it('errors out when given non-string', function() diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua index b16fa975b6..9fead98fed 100644 --- a/test/functional/shada/buffers_spec.lua +++ b/test/functional/shada/buffers_spec.lua @@ -1,7 +1,6 @@ -- shada buffer list saving/reading support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, eq, curbufmeths, meths = - helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths, helpers.meths +local nvim_command, fn, eq, api = helpers.command, helpers.fn, helpers.eq, helpers.api local expect_exit = helpers.expect_exit local shada_helpers = require('test.functional.shada.helpers') @@ -18,10 +17,10 @@ describe('shada support code', function() nvim_command('edit ' .. testfilename_2) expect_exit(nvim_command, 'qall') reset('set shada+=%') - eq(3, funcs.bufnr('$')) - eq('', funcs.bufname(1)) - eq(testfilename, funcs.bufname(2)) - eq(testfilename_2, funcs.bufname(3)) + eq(3, fn.bufnr('$')) + eq('', fn.bufname(1)) + eq(testfilename, fn.bufname(2)) + eq(testfilename_2, fn.bufname(3)) end) it('does not restore buffer list without % in &shada', function() @@ -30,8 +29,8 @@ describe('shada support code', function() nvim_command('edit ' .. testfilename_2) expect_exit(nvim_command, 'qall') reset() - eq(1, funcs.bufnr('$')) - eq('', funcs.bufname(1)) + eq(1, fn.bufnr('$')) + eq('', fn.bufname(1)) end) it('does not dump buffer list without % in &shada', function() @@ -40,44 +39,44 @@ describe('shada support code', function() nvim_command('edit ' .. testfilename_2) expect_exit(nvim_command, 'qall') reset('set shada+=%') - eq(1, funcs.bufnr('$')) - eq('', funcs.bufname(1)) + eq(1, fn.bufnr('$')) + eq('', fn.bufname(1)) end) it('does not dump unlisted buffer', function() reset('set shada+=%') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - meths.set_option_value('buflisted', false, {}) + api.nvim_set_option_value('buflisted', false, {}) expect_exit(nvim_command, 'qall') reset('set shada+=%') - eq(2, funcs.bufnr('$')) - eq('', funcs.bufname(1)) - eq(testfilename, funcs.bufname(2)) + eq(2, fn.bufnr('$')) + eq('', fn.bufname(1)) + eq(testfilename, fn.bufname(2)) end) it('does not dump quickfix buffer', function() reset('set shada+=%') nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename_2) - meths.set_option_value('buftype', 'quickfix', {}) + api.nvim_set_option_value('buftype', 'quickfix', {}) expect_exit(nvim_command, 'qall') reset('set shada+=%') - eq(2, funcs.bufnr('$')) - eq('', funcs.bufname(1)) - eq(testfilename, funcs.bufname(2)) + eq(2, fn.bufnr('$')) + eq('', fn.bufname(1)) + eq(testfilename, fn.bufname(2)) end) it('does not dump unnamed buffers', function() reset('set shada+=% hidden') - curbufmeths.set_lines(0, 1, true, { 'foo' }) + api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' }) nvim_command('enew') - curbufmeths.set_lines(0, 1, true, { 'bar' }) - eq(2, funcs.bufnr('$')) + api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' }) + eq(2, fn.bufnr('$')) expect_exit(nvim_command, 'qall!') reset('set shada+=% hidden') - eq(1, funcs.bufnr('$')) - eq('', funcs.bufname(1)) + eq(1, fn.bufnr('$')) + eq('', fn.bufname(1)) end) it('restores 1 buffer with %1 in &shada, #5759', function() @@ -86,8 +85,8 @@ describe('shada support code', function() nvim_command('edit ' .. testfilename_2) expect_exit(nvim_command, 'qall') reset('set shada+=%1') - eq(2, funcs.bufnr('$')) - eq('', funcs.bufname(1)) - eq(testfilename, funcs.bufname(2)) + eq(2, fn.bufnr('$')) + eq('', fn.bufname(1)) + eq(testfilename, fn.bufname(2)) end) end) diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index 13797590f7..bc4e9675c6 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -1,6 +1,6 @@ -- ShaDa compatibility support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq +local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq local exc_exec = helpers.exc_exec local shada_helpers = require('test.functional.shada.helpers') @@ -49,11 +49,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada! ' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with s/search pattern item with BOOL unknown (sX) key value', function() @@ -81,11 +81,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with replacement item with BOOL additional value in list', function() @@ -114,11 +114,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) for _, v in ipairs({ @@ -138,8 +138,8 @@ describe('ShaDa forward compatibility support code', function() }) do it('works with ' .. v.name .. ' item with BOOL unknown (mX) key value', function() nvim_command('silent noautocmd edit ' .. mock_file_path .. 'c') - eq('' .. mock_file_path .. 'c', funcs.bufname('%')) - funcs.setline('.', { '1', '2', '3' }) + eq('' .. mock_file_path .. 'c', fn.bufname('%')) + fn.setline('.', { '1', '2', '3' }) wshada(v.mpack) eq(0, exc_exec(sdrcmd(true))) os.remove(shada_fname) @@ -155,7 +155,7 @@ describe('ShaDa forward compatibility support code', function() eq(true, found) eq(0, exc_exec(sdrcmd())) nvim_command('bwipeout!') - funcs.setpos("'A", { 0, 1, 1, 0 }) + fn.setpos("'A", { 0, 1, 1, 0 }) os.remove(shada_fname) nvim_command('wshada ' .. shada_fname) found = false @@ -167,18 +167,18 @@ describe('ShaDa forward compatibility support code', function() end end eq(false, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) if v.name == 'global mark' or v.name == 'local mark' then it('works with ' .. v.name .. ' item with <C-a> name', function() nvim_command('silent noautocmd edit ' .. mock_file_path .. 'c') - eq('' .. mock_file_path .. 'c', funcs.bufname('%')) - funcs.setline('.', { '1', '2', '3' }) + eq('' .. mock_file_path .. 'c', fn.bufname('%')) + fn.setline('.', { '1', '2', '3' }) wshada( v.mpack:gsub('n.$', 'n\001') .. v.mpack:gsub('n.$', 'n\002') @@ -213,11 +213,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) end end @@ -245,11 +245,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(false, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with register item with <C-a> name', function() @@ -281,18 +281,18 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with register item with type 10', function() wshada('\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010') eq(0, exc_exec(sdrcmd(true))) - eq({}, funcs.getreg('a', 1, 1)) - eq('', funcs.getregtype('a')) + eq({}, fn.getreg('a', 1, 1)) + eq('', fn.getregtype('a')) nvim_command('wshada ' .. shada_fname) local found = 0 for i, v in ipairs(read_shada_file(shada_fname)) do @@ -319,19 +319,19 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with buffer list item with BOOL unknown (bX) key', function() nvim_command('set shada+=%') wshada('\009\000\016\145\130\161f\196\006' .. mock_file_path .. 'c\162bX\195') eq(0, exc_exec(sdrcmd())) - eq(2, funcs.bufnr('$')) - eq('' .. mock_file_path .. 'c', funcs.bufname(2)) + eq(2, fn.bufnr('$')) + eq('' .. mock_file_path .. 'c', fn.bufname(2)) os.remove(shada_fname) nvim_command('wshada ' .. shada_fname) local found = false @@ -354,11 +354,11 @@ describe('ShaDa forward compatibility support code', function() end eq(false, found) nvim_command('bwipeout!') - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with history item with BOOL additional value in list', function() @@ -377,8 +377,8 @@ describe('ShaDa forward compatibility support code', function() eq(true, found) eq(0, exc_exec(sdrcmd())) os.remove(shada_fname) - funcs.histadd(':', '--') - funcs.histadd(':', '-') + fn.histadd(':', '--') + fn.histadd(':', '-') nvim_command('wshada ' .. shada_fname) found = false for _, v in ipairs(read_shada_file(shada_fname)) do @@ -388,11 +388,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(true, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with history item with type 10', function() @@ -425,11 +425,11 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) it('works with item with 100 type', function() @@ -462,10 +462,10 @@ describe('ShaDa forward compatibility support code', function() end end eq(0, found) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) nvim_command('rshada!' .. shada_fname) - funcs.garbagecollect(1) - funcs.garbagecollect(1) + fn.garbagecollect(1) + fn.garbagecollect(1) end) end) diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index b8d0352862..baa27889f3 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -1,10 +1,8 @@ local helpers = require('test.functional.helpers')(nil) -local meths = helpers.meths +local api = helpers.api local write_file = helpers.write_file local concat_tables = helpers.concat_tables -local mpack = require('mpack') - local tmpname = helpers.tmpname() -- o={ @@ -30,7 +28,7 @@ local function reset(o) args_rm = args_rm, args = args, } - meths.set_var('tmpname', tmpname) + api.nvim_set_var('tmpname', tmpname) end local clear = function() @@ -64,7 +62,7 @@ local read_shada_file = function(fname) local fd = io.open(fname, 'r') local mstring = fd:read('*a') fd:close() - local unpack = mpack.Unpacker() + local unpack = vim.mpack.Unpacker() local ret = {} local cur, val local i = 0 diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 476036312d..c8a19bb082 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -1,7 +1,7 @@ -- ShaDa history saving/reading support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, meths, nvim_feed, eq = - helpers.command, helpers.funcs, helpers.meths, helpers.feed, helpers.eq +local nvim_command, fn, api, nvim_feed, eq = + helpers.command, helpers.fn, helpers.api, helpers.feed, helpers.eq local assert_alive = helpers.assert_alive local expect_exit = helpers.expect_exit @@ -19,7 +19,7 @@ describe('ShaDa support code', function() reset() nvim_command("set shada='0") nvim_command('rshada') - eq('" Test', funcs.histget(':', -1)) + eq('" Test', fn.histget(':', -1)) end) it('is able to dump and read back 2 items in command-line history', function() @@ -30,8 +30,8 @@ describe('ShaDa support code', function() reset() nvim_command("set shada='0 history=2") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('" Test', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('" Test', fn.histget(':', -2)) end) it('respects &history when dumping', function() @@ -42,8 +42,8 @@ describe('ShaDa support code', function() reset() nvim_command("set shada='0 history=2") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('', fn.histget(':', -2)) end) it('respects &history when loading', function() @@ -54,8 +54,8 @@ describe('ShaDa support code', function() reset() nvim_command("set shada='0 history=1") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('', fn.histget(':', -2)) end) it('dumps only requested amount of command-line history items', function() @@ -64,13 +64,13 @@ describe('ShaDa support code', function() nvim_feed(':" Test 2\n') nvim_command('wshada') -- Regression test: :wshada should not alter or free history. - eq('" Test 2', funcs.histget(':', -1)) - eq('" Test', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('" Test', fn.histget(':', -2)) reset() nvim_command("set shada='0") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('', fn.histget(':', -2)) end) it('does not respect number in &shada when loading history', function() @@ -81,8 +81,8 @@ describe('ShaDa support code', function() reset() nvim_command("set shada='0,:1") nvim_command('rshada') - eq('" Test 2', funcs.histget(':', -1)) - eq('" Test', funcs.histget(':', -2)) + eq('" Test 2', fn.histget(':', -1)) + eq('" Test', fn.histget(':', -2)) end) it('dumps and loads all kinds of histories', function() @@ -96,48 +96,48 @@ describe('ShaDa support code', function() nvim_command('wshada') reset() nvim_command('rshada') - eq('" Test', funcs.histget(':', -1)) - eq('Test', funcs.histget('/', -1)) - eq('"Test"', funcs.histget('=', -1)) - eq('Test 2', funcs.histget('@', -1)) - eq('c', funcs.histget('>', -1)) + eq('" Test', fn.histget(':', -1)) + eq('Test', fn.histget('/', -1)) + eq('"Test"', fn.histget('=', -1)) + eq('Test 2', fn.histget('@', -1)) + eq('c', fn.histget('>', -1)) end) it('dumps and loads last search pattern with offset', function() - meths.set_option_value('wrapscan', false, {}) - funcs.setline('.', { 'foo', 'bar--' }) + api.nvim_set_option_value('wrapscan', false, {}) + fn.setline('.', { 'foo', 'bar--' }) nvim_feed('gg0/a/e+1\n') - eq({ 0, 2, 3, 0 }, funcs.getpos('.')) + eq({ 0, 2, 3, 0 }, fn.getpos('.')) nvim_command('wshada') reset() - meths.set_option_value('wrapscan', false, {}) - funcs.setline('.', { 'foo', 'bar--' }) + api.nvim_set_option_value('wrapscan', false, {}) + fn.setline('.', { 'foo', 'bar--' }) nvim_feed('gg0n') - eq({ 0, 2, 3, 0 }, funcs.getpos('.')) - eq(1, meths.get_vvar('searchforward')) + eq({ 0, 2, 3, 0 }, fn.getpos('.')) + eq(1, api.nvim_get_vvar('searchforward')) end) it('dumps and loads last search pattern with offset and backward direction', function() - meths.set_option_value('wrapscan', false, {}) - funcs.setline('.', { 'foo', 'bar--' }) + api.nvim_set_option_value('wrapscan', false, {}) + fn.setline('.', { 'foo', 'bar--' }) nvim_feed('G$?a?e+1\n') - eq({ 0, 2, 3, 0 }, funcs.getpos('.')) + eq({ 0, 2, 3, 0 }, fn.getpos('.')) nvim_command('wshada') reset() - meths.set_option_value('wrapscan', false, {}) - funcs.setline('.', { 'foo', 'bar--' }) + api.nvim_set_option_value('wrapscan', false, {}) + fn.setline('.', { 'foo', 'bar--' }) nvim_feed('G$n') - eq({ 0, 2, 3, 0 }, funcs.getpos('.')) - eq(0, meths.get_vvar('searchforward')) + eq({ 0, 2, 3, 0 }, fn.getpos('.')) + eq(0, api.nvim_get_vvar('searchforward')) end) it('saves v:hlsearch=1', function() nvim_command('set hlsearch shada-=h') nvim_feed('/test\n') - eq(1, meths.get_vvar('hlsearch')) + eq(1, api.nvim_get_vvar('hlsearch')) expect_exit(nvim_command, 'qall') reset() - eq(1, meths.get_vvar('hlsearch')) + eq(1, api.nvim_get_vvar('hlsearch')) end) it('saves v:hlsearch=0 with :nohl', function() @@ -146,27 +146,27 @@ describe('ShaDa support code', function() nvim_command('nohlsearch') expect_exit(nvim_command, 'qall') reset() - eq(0, meths.get_vvar('hlsearch')) + eq(0, api.nvim_get_vvar('hlsearch')) end) it('saves v:hlsearch=0 with default &shada', function() nvim_command('set hlsearch') nvim_feed('/test\n') - eq(1, meths.get_vvar('hlsearch')) + eq(1, api.nvim_get_vvar('hlsearch')) expect_exit(nvim_command, 'qall') reset() - eq(0, meths.get_vvar('hlsearch')) + eq(0, api.nvim_get_vvar('hlsearch')) end) it('dumps and loads last substitute pattern and replacement string', function() - funcs.setline('.', { 'foo', 'bar' }) + fn.setline('.', { 'foo', 'bar' }) nvim_command('%s/f/g/g') - eq('goo', funcs.getline(1)) + eq('goo', fn.getline(1)) nvim_command('wshada') reset() - funcs.setline('.', { 'foo', 'bar' }) + fn.setline('.', { 'foo', 'bar' }) nvim_command('&') - eq('goo', funcs.getline(1)) + eq('goo', fn.getline(1)) end) it('dumps and loads history with UTF-8 characters', function() @@ -174,25 +174,25 @@ describe('ShaDa support code', function() nvim_feed(':echo "«"\n') expect_exit(nvim_command, 'qall') reset() - eq('echo "«"', funcs.histget(':', -1)) + eq('echo "«"', fn.histget(':', -1)) end) it('dumps and loads replacement with UTF-8 characters', function() nvim_command('substitute/./«/ge') expect_exit(nvim_command, 'qall!') reset() - funcs.setline('.', { '.' }) + fn.setline('.', { '.' }) nvim_command('&') - eq('«', funcs.getline('.')) + eq('«', fn.getline('.')) end) it('dumps and loads substitute pattern with UTF-8 characters', function() nvim_command('substitute/«/./ge') expect_exit(nvim_command, 'qall!') reset() - funcs.setline('.', { '«\171' }) + fn.setline('.', { '«\171' }) nvim_command('&') - eq('.\171', funcs.getline('.')) + eq('.\171', fn.getline('.')) end) it('dumps and loads search pattern with UTF-8 characters', function() @@ -200,10 +200,10 @@ describe('ShaDa support code', function() nvim_command('set shada+=/0') expect_exit(nvim_command, 'qall!') reset() - funcs.setline('.', { '\171«' }) + fn.setline('.', { '\171«' }) nvim_command('~&') - eq('\171', funcs.getline('.')) - eq('', funcs.histget('/', -1)) + eq('\171', fn.getline('.')) + eq('', fn.histget('/', -1)) end) it('dumps and loads search pattern with 8-bit single-byte', function() @@ -212,10 +212,10 @@ describe('ShaDa support code', function() nvim_command('set shada+=/0') expect_exit(nvim_command, 'qall!') reset() - funcs.setline('.', { '\171«' }) + fn.setline('.', { '\171«' }) nvim_command('~&') - eq('«', funcs.getline('.')) - eq('', funcs.histget('/', -1)) + eq('«', fn.getline('.')) + eq('', fn.histget('/', -1)) end) it('does not crash when dumping last search pattern (#10945)', function() diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index a1c851a9d5..3f29a02506 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -1,12 +1,6 @@ -- ShaDa marks saving/reading support local helpers = require('test.functional.helpers')(after_each) -local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq = - helpers.meths, - helpers.curwinmeths, - helpers.curbufmeths, - helpers.command, - helpers.funcs, - helpers.eq +local api, nvim_command, fn, eq = helpers.api, helpers.command, helpers.fn, helpers.eq local feed = helpers.feed local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture local expect_exit = helpers.expect_exit @@ -15,7 +9,7 @@ local shada_helpers = require('test.functional.shada.helpers') local reset, clear = shada_helpers.reset, shada_helpers.clear local nvim_current_line = function() - return curwinmeths.get_cursor()[1] + return api.nvim_win_get_cursor(0)[1] end describe('ShaDa support code', function() @@ -49,7 +43,7 @@ describe('ShaDa support code', function() reset() nvim_command('rshada') nvim_command('normal! `A') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) nvim_command('normal! `B') eq(2, nvim_current_line()) @@ -76,7 +70,7 @@ describe('ShaDa support code', function() reset("set shada='0,f0") nvim_command('language C') nvim_command('normal! `A') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) end) @@ -89,7 +83,7 @@ describe('ShaDa support code', function() reset() nvim_command('edit ' .. testfilename) nvim_command('normal! `a') - eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) nvim_command('normal! `b') eq(2, nvim_current_line()) @@ -119,12 +113,12 @@ describe('ShaDa support code', function() it('is able to populate v:oldfiles', function() nvim_command('edit ' .. testfilename) - local tf_full = curbufmeths.get_name() + local tf_full = api.nvim_buf_get_name(0) nvim_command('edit ' .. testfilename_2) - local tf_full_2 = curbufmeths.get_name() + local tf_full_2 = api.nvim_buf_get_name(0) expect_exit(nvim_command, 'qall') reset() - local oldfiles = meths.get_vvar('oldfiles') + local oldfiles = api.nvim_get_vvar('oldfiles') table.sort(oldfiles) eq(2, #oldfiles) eq(testfilename, oldfiles[1]:sub(-#testfilename)) @@ -132,7 +126,7 @@ describe('ShaDa support code', function() eq(tf_full, oldfiles[1]) eq(tf_full_2, oldfiles[2]) nvim_command('rshada!') - oldfiles = meths.get_vvar('oldfiles') + oldfiles = api.nvim_get_vvar('oldfiles') table.sort(oldfiles) eq(2, #oldfiles) eq(testfilename, oldfiles[1]:sub(-#testfilename)) @@ -165,8 +159,8 @@ describe('ShaDa support code', function() nvim_command('quit') nvim_command('rshada') nvim_command('normal! \15') -- <C-o> - eq(testfilename_2, funcs.bufname('%')) - eq({ 2, 0 }, curwinmeths.get_cursor()) + eq(testfilename_2, fn.bufname('%')) + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) end) it('is able to dump and restore jump list with different times (slow!)', function() @@ -185,19 +179,19 @@ describe('ShaDa support code', function() reset() nvim_command('redraw') nvim_command('edit ' .. testfilename) - eq(testfilename, funcs.bufname('%')) + eq(testfilename, fn.bufname('%')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\<C-o>"') - eq(testfilename, funcs.bufname('%')) + eq(testfilename, fn.bufname('%')) eq(2, nvim_current_line()) nvim_command('execute "normal! \\<C-o>"') - eq(testfilename_2, funcs.bufname('%')) + eq(testfilename_2, fn.bufname('%')) eq(1, nvim_current_line()) nvim_command('execute "normal! \\<C-o>"') - eq(testfilename_2, funcs.bufname('%')) + eq(testfilename_2, fn.bufname('%')) eq(2, nvim_current_line()) nvim_command('execute "normal! \\<C-o>"') - eq(testfilename_2, funcs.bufname('%')) + eq(testfilename_2, fn.bufname('%')) eq(2, nvim_current_line()) end) @@ -229,14 +223,14 @@ describe('ShaDa support code', function() }, args = { '-i', - meths.get_var('tmpname'), -- Use same shada file as parent. + api.nvim_get_var('tmpname'), -- Use same shada file as parent. '--cmd', 'silent edit ' .. non_existent_testfilename, '-c', 'qall', }, } - eq('', funcs.system(argv)) + eq('', fn.system(argv)) eq(0, exc_exec('rshada')) end) @@ -248,14 +242,14 @@ describe('ShaDa support code', function() }, args = { '-i', - meths.get_var('tmpname'), -- Use same shada file as parent. + api.nvim_get_var('tmpname'), -- Use same shada file as parent. '-c', 'silent edit ' .. non_existent_testfilename, '-c', 'autocmd VimEnter * qall', }, } - eq('', funcs.system(argv)) + eq('', fn.system(argv)) eq(0, exc_exec('rshada')) end) diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua index 7ca261eb11..94e0ee6e82 100644 --- a/test/functional/shada/merging_spec.lua +++ b/test/functional/shada/merging_spec.lua @@ -1,8 +1,8 @@ -- ShaDa merging data support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, curbufmeths, eq = - helpers.command, helpers.funcs, helpers.curbufmeths, helpers.eq +local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture +local api = helpers.api local shada_helpers = require('test.functional.shada.helpers') local reset, clear, get_shada_rw = @@ -138,7 +138,7 @@ describe('ShaDa history merging code', function() eq(0, exc_exec('wshada! ' .. shada_fname)) local items = { 'ad', 'ab', 'ac', 'af', 'ae' } for i, v in ipairs(items) do - eq(v, funcs.histget(':', i)) + eq(v, fn.histget(':', i)) end local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -239,7 +239,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) end) it('uses last search pattern with gt tstamp from file when reading with bang', function() @@ -247,7 +247,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', funcs.getreg('/')) + eq('?', fn.getreg('/')) end) it('uses last search pattern with eq timestamp from instance when reading', function() @@ -255,7 +255,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) end) it('uses last search pattern with gt timestamp from file when reading', function() @@ -263,14 +263,14 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162sX\194\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', funcs.getreg('/')) + eq('?', fn.getreg('/')) end) it('uses last search pattern with gt timestamp from instance when writing', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162sX\194\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -285,7 +285,7 @@ describe('ShaDa search pattern support code', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162sX\194\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -300,7 +300,7 @@ describe('ShaDa search pattern support code', function() wshada('\002\001\011\130\162sX\194\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162sX\194\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -316,7 +316,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) end) it('uses last s/ pattern with gt timestamp from file when reading with !', function() @@ -324,7 +324,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', funcs.getreg('/')) + eq('?', fn.getreg('/')) end) it('uses last s/ pattern with eq timestamp from instance when reading', function() @@ -332,7 +332,7 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) end) it('uses last s/ pattern with gt timestamp from file when reading', function() @@ -340,14 +340,14 @@ describe('ShaDa search pattern support code', function() eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162ss\195\162sp\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', funcs.getreg('/')) + eq('?', fn.getreg('/')) end) it('uses last s/ pattern with gt timestamp from instance when writing', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\000\011\130\162ss\195\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -362,7 +362,7 @@ describe('ShaDa search pattern support code', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\001\011\130\162ss\195\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -377,7 +377,7 @@ describe('ShaDa search pattern support code', function() wshada('\002\001\011\130\162ss\195\162sp\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\002\002\011\130\162ss\195\162sp\196\001?') - eq('-', funcs.getreg('/')) + eq('-', fn.getreg('/')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -402,7 +402,7 @@ describe('ShaDa replacement string support code', function() wshada('\003\000\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) nvim_command('bwipeout!') end) @@ -412,7 +412,7 @@ describe('ShaDa replacement string support code', function() wshada('\003\000\004\145\196\001?') eq(0, exc_exec(sdrcmd(true))) nvim_command('s/.*/~') - eq('?', funcs.getline('.')) + eq('?', fn.getline('.')) nvim_command('bwipeout!') end) @@ -422,7 +422,7 @@ describe('ShaDa replacement string support code', function() wshada('\003\001\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) nvim_command('bwipeout!') end) @@ -432,7 +432,7 @@ describe('ShaDa replacement string support code', function() wshada('\003\002\004\145\196\001?') eq(0, exc_exec(sdrcmd())) nvim_command('s/.*/~') - eq('?', funcs.getline('.')) + eq('?', fn.getline('.')) nvim_command('bwipeout!') end) @@ -492,14 +492,14 @@ describe('ShaDa marks support code', function() wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) it('can merge with file with mark 9 as the only numeric mark', function() wshada('\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `9oabc') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -632,7 +632,7 @@ describe('ShaDa marks support code', function() wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd(true))) nvim_command('normal! `A') - eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('?', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) it('uses last A mark with eq timestamp from instance when reading', function() @@ -641,7 +641,7 @@ describe('ShaDa marks support code', function() wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) it('uses last A mark with gt timestamp from file when reading', function() @@ -650,7 +650,7 @@ describe('ShaDa marks support code', function() wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `A') - eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('?', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) end) it('uses last A mark with gt timestamp from instance when writing', function() @@ -658,7 +658,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -675,7 +675,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -692,7 +692,7 @@ describe('ShaDa marks support code', function() eq(0, exc_exec(sdrcmd())) wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') nvim_command('normal! `A') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = {} for _, v in ipairs(read_shada_file(shada_fname)) do @@ -708,56 +708,56 @@ describe('ShaDa marks support code', function() it('uses last a mark with gt timestamp from instance when reading', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, { '-', '?' }) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) end) it('uses last a mark with gt timestamp from file when reading with !', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, { '-', '?' }) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd(true))) nvim_command('normal! `a') - eq('?', funcs.getline('.')) + eq('?', fn.getline('.')) end) it('uses last a mark with eq timestamp from instance when reading', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, { '-', '?' }) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) end) it('uses last a mark with gt timestamp from file when reading', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, { '-', '?' }) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) nvim_command('normal! `a') - eq('?', funcs.getline('.')) + eq('?', fn.getline('.')) end) it('uses last a mark with gt timestamp from instance when writing', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, { '-', '?' }) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\000\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') nvim_command('normal! `a') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -775,12 +775,12 @@ describe('ShaDa marks support code', function() it('uses last a mark with eq timestamp from instance when writing', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, { '-', '?' }) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\001\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') nvim_command('normal! `a') - eq('-', funcs.getline('.')) + eq('-', fn.getline('.')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -798,12 +798,12 @@ describe('ShaDa marks support code', function() it('uses last a mark with gt timestamp from file when writing', function() nvim_command('edit ' .. mock_file_path .. '-') - funcs.setline(1, { '-', '?' }) + fn.setline(1, { '-', '?' }) wshada('\010\001\017\131\161l\001\161f\196\006' .. mock_file_path .. '-\161na') eq(0, exc_exec(sdrcmd())) wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') nvim_command('normal! `a') - eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) + eq('-', fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -832,7 +832,7 @@ describe('ShaDa registers support code', function() eq(0, exc_exec(sdrcmd())) wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) end) it('uses last a register with gt timestamp from file when reading with !', function() @@ -840,7 +840,7 @@ describe('ShaDa registers support code', function() eq(0, exc_exec(sdrcmd())) wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd(true))) - eq('?', funcs.getreg('a')) + eq('?', fn.getreg('a')) end) it('uses last a register with eq timestamp from instance when reading', function() @@ -848,7 +848,7 @@ describe('ShaDa registers support code', function() eq(0, exc_exec(sdrcmd())) wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) end) it('uses last a register with gt timestamp from file when reading', function() @@ -856,14 +856,14 @@ describe('ShaDa registers support code', function() eq(0, exc_exec(sdrcmd())) wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?') eq(0, exc_exec(sdrcmd())) - eq('?', funcs.getreg('a')) + eq('?', fn.getreg('a')) end) it('uses last a register with gt timestamp from instance when writing', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\000\015\131\161na\162rX\194\162rc\145\196\001?') - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -879,7 +879,7 @@ describe('ShaDa registers support code', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001?') - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -895,7 +895,7 @@ describe('ShaDa registers support code', function() wshada('\005\001\015\131\161na\162rX\194\162rc\145\196\001-') eq(0, exc_exec(sdrcmd())) wshada('\005\002\015\131\161na\162rX\194\162rc\145\196\001?') - eq('-', funcs.getreg('a')) + eq('-', fn.getreg('a')) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -940,7 +940,7 @@ describe('ShaDa jumps support code', function() .. 'f\161l\002' ) eq(0, exc_exec(sdrcmd())) - eq('', curbufmeths.get_name()) + eq('', api.nvim_buf_get_name(0)) eq( ' jump line col file/text\n' .. ' 5 2 0 ' diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua index ceb3ddf2fe..ef15ab9a05 100644 --- a/test/functional/shada/registers_spec.lua +++ b/test/functional/shada/registers_spec.lua @@ -1,6 +1,6 @@ -- ShaDa registers saving/reading support local helpers = require('test.functional.helpers')(after_each) -local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq +local nvim_command, fn, eq = helpers.command, helpers.fn, helpers.eq local shada_helpers = require('test.functional.shada.helpers') local reset, clear = shada_helpers.reset, shada_helpers.clear @@ -10,13 +10,13 @@ local setreg = function(name, contents, typ) if type(contents) == 'string' then contents = { contents } end - funcs.setreg(name, contents, typ) + fn.setreg(name, contents, typ) end local getreg = function(name) return { - funcs.getreg(name, 1, 1), - funcs.getregtype(name), + fn.getreg(name, 1, 1), + fn.getregtype(name), } end diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 9e3d2f7a58..2942beab2f 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -1,16 +1,14 @@ -- Other ShaDa tests local helpers = require('test.functional.helpers')(after_each) -local meths, nvim_command, funcs, eq = helpers.meths, helpers.command, helpers.funcs, helpers.eq +local api, nvim_command, fn, eq = helpers.api, helpers.command, helpers.fn, helpers.eq local write_file, spawn, set_session, nvim_prog, exc_exec = helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.exc_exec local is_os = helpers.is_os local skip = helpers.skip -local luv = require('luv') +local uv = vim.uv local paths = require('test.cmakeconfig.paths') -local mpack = require('mpack') - local shada_helpers = require('test.functional.shada.helpers') local reset, clear, get_shada_rw = shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw @@ -26,7 +24,7 @@ describe('ShaDa support code', function() after_each(function() clear() clean() - luv.fs_rmdir(dirname) + uv.fs_rmdir(dirname) end) it('preserves `s` item size limit with unknown entries', function() @@ -59,8 +57,8 @@ describe('ShaDa support code', function() local hist1 = ('-'):rep(1024 - 5) local hist2 = ('-'):rep(1025 - 5) nvim_command('set shada-=s10 shada+=s1') - funcs.histadd(':', hist1) - funcs.histadd(':', hist2) + fn.histadd(':', hist1) + fn.histadd(':', hist2) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 for _, v in ipairs(read_shada_file(shada_fname)) do @@ -87,7 +85,7 @@ describe('ShaDa support code', function() wshada('Some text file') eq(0, exc_exec('wshada! ' .. shada_fname)) eq(1, read_shada_file(shada_fname)[1].type) - eq(nil, luv.fs_stat(shada_fname .. '.tmp.a')) + eq(nil, uv.fs_stat(shada_fname .. '.tmp.a')) end ) @@ -148,11 +146,11 @@ describe('ShaDa support code', function() wshada(s .. table.concat(msgpack, e .. s) .. e) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 - local typ = mpack.decode(s) + local typ = vim.mpack.decode(s) for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == typ then found = found + 1 - eq(mpack.decode(msgpack[found]), v.timestamp) + eq(vim.mpack.decode(msgpack[found]), v.timestamp) end end eq(#msgpack, found) @@ -177,7 +175,7 @@ describe('ShaDa support code', function() it('correctly uses shada-r option', function() nvim_command('set shellslash') - meths.set_var('__home', paths.test_source_path) + api.nvim_set_var('__home', paths.test_source_path) nvim_command('let $HOME = __home') nvim_command('unlet __home') nvim_command('edit ~/README.md') @@ -185,7 +183,7 @@ describe('ShaDa support code', function() nvim_command('undo') nvim_command('set shada+=%') nvim_command('wshada! ' .. shada_fname) - local readme_fname = funcs.resolve(paths.test_source_path) .. '/README.md' + local readme_fname = fn.resolve(paths.test_source_path) .. '/README.md' eq({ [7] = 2, [8] = 2, [9] = 1, [10] = 4, [11] = 1 }, find_file(readme_fname)) nvim_command('set shada+=r~') nvim_command('wshada! ' .. shada_fname) @@ -193,21 +191,19 @@ describe('ShaDa support code', function() nvim_command('set shada-=r~') nvim_command('wshada! ' .. shada_fname) eq({ [7] = 2, [8] = 2, [9] = 1, [10] = 4, [11] = 1 }, find_file(readme_fname)) - nvim_command( - 'set shada+=r' .. funcs.escape(funcs.escape(paths.test_source_path, '$~'), ' "\\,') - ) + nvim_command('set shada+=r' .. fn.escape(fn.escape(paths.test_source_path, '$~'), ' "\\,')) nvim_command('wshada! ' .. shada_fname) eq({}, find_file(readme_fname)) end) it('correctly ignores case with shada-r option', function() nvim_command('set shellslash') - local pwd = funcs.getcwd() + local pwd = fn.getcwd() local relfname = 'абв/test' local fname = pwd .. '/' .. relfname - meths.set_var('__fname', fname) + api.nvim_set_var('__fname', fname) nvim_command('silent! edit `=__fname`') - funcs.setline(1, { 'a', 'b', 'c', 'd' }) + fn.setline(1, { 'a', 'b', 'c', 'd' }) nvim_command('normal! GmAggmaAabc') nvim_command('undo') nvim_command('set shada+=%') @@ -219,30 +215,30 @@ describe('ShaDa support code', function() end) it('is able to set &shada after &viminfo', function() - meths.set_option_value('viminfo', "'10", {}) - eq("'10", meths.get_option_value('viminfo', {})) - eq("'10", meths.get_option_value('shada', {})) - meths.set_option_value('shada', '', {}) - eq('', meths.get_option_value('viminfo', {})) - eq('', meths.get_option_value('shada', {})) + api.nvim_set_option_value('viminfo', "'10", {}) + eq("'10", api.nvim_get_option_value('viminfo', {})) + eq("'10", api.nvim_get_option_value('shada', {})) + api.nvim_set_option_value('shada', '', {}) + eq('', api.nvim_get_option_value('viminfo', {})) + eq('', api.nvim_get_option_value('shada', {})) end) it('is able to set all& after setting &shada', function() - meths.set_option_value('shada', "'10", {}) - eq("'10", meths.get_option_value('viminfo', {})) - eq("'10", meths.get_option_value('shada', {})) + api.nvim_set_option_value('shada', "'10", {}) + eq("'10", api.nvim_get_option_value('viminfo', {})) + eq("'10", api.nvim_get_option_value('shada', {})) nvim_command('set all&') - eq("!,'100,<50,s10,h", meths.get_option_value('viminfo', {})) - eq("!,'100,<50,s10,h", meths.get_option_value('shada', {})) + eq("!,'100,<50,s10,h", api.nvim_get_option_value('viminfo', {})) + eq("!,'100,<50,s10,h", api.nvim_get_option_value('shada', {})) end) it('is able to set &shada after &viminfo using :set', function() nvim_command("set viminfo='10") - eq("'10", meths.get_option_value('viminfo', {})) - eq("'10", meths.get_option_value('shada', {})) + eq("'10", api.nvim_get_option_value('viminfo', {})) + eq("'10", api.nvim_get_option_value('shada', {})) nvim_command('set shada=') - eq('', meths.get_option_value('viminfo', {})) - eq('', meths.get_option_value('shada', {})) + eq('', api.nvim_get_option_value('viminfo', {})) + eq('', api.nvim_get_option_value('shada', {})) end) it('setting &shada gives proper error message on missing number', function() @@ -258,17 +254,17 @@ describe('ShaDa support code', function() it('does not crash when ShaDa file directory is not writable', function() skip(is_os('win')) - funcs.mkdir(dirname, '', 0) - eq(0, funcs.filewritable(dirname)) + fn.mkdir(dirname, '', 0) + eq(0, fn.filewritable(dirname)) reset { shadafile = dirshada, args = { '--cmd', 'set shada=' } } - meths.set_option_value('shada', "'10", {}) + api.nvim_set_option_value('shada', "'10", {}) eq( 'Vim(wshada):E886: System error while opening ShaDa file ' .. 'Xtest-functional-shada-shada.d/main.shada for reading to merge ' .. 'before writing it: permission denied', exc_exec('wshada') ) - meths.set_option_value('shada', '', {}) + api.nvim_set_option_value('shada', '', {}) end) end) @@ -279,15 +275,15 @@ describe('ShaDa support code', function() true ) session:close() - eq(nil, luv.fs_stat('NONE')) - eq(nil, luv.fs_stat('NONE.tmp.a')) + eq(nil, uv.fs_stat('NONE')) + eq(nil, uv.fs_stat('NONE.tmp.a')) end) it('does not read NONE file', function() write_file('NONE', '\005\001\015\131\161na\162rX\194\162rc\145\196\001-') local session = spawn({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', '--headless' }, true) set_session(session) - eq('', funcs.getreg('a')) + eq('', fn.getreg('a')) session:close() os.remove('NONE') end) diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua index 49dd5837a7..d70f5deded 100644 --- a/test/functional/shada/variables_spec.lua +++ b/test/functional/shada/variables_spec.lua @@ -1,7 +1,7 @@ -- ShaDa variables saving/reading support local helpers = require('test.functional.helpers')(after_each) -local meths, funcs, nvim_command, eq, eval = - helpers.meths, helpers.funcs, helpers.command, helpers.eq, helpers.eval +local api, fn, nvim_command, eq, eval = + helpers.api, helpers.fn, helpers.command, helpers.eq, helpers.eval local expect_exit = helpers.expect_exit local shada_helpers = require('test.functional.shada.helpers') @@ -12,13 +12,13 @@ describe('ShaDa support code', function() after_each(clear) it('is able to dump and read back string variable', function() - meths.set_var('STRVAR', 'foo') + api.nvim_set_var('STRVAR', 'foo') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq('foo', meths.get_var('STRVAR')) + eq('foo', api.nvim_get_var('STRVAR')) end) local autotest = function(tname, varname, varval, val_is_expr) @@ -26,9 +26,9 @@ describe('ShaDa support code', function() reset('set shada+=!') if val_is_expr then nvim_command('let g:' .. varname .. ' = ' .. varval) - varval = meths.get_var(varname) + varval = api.nvim_get_var(varname) else - meths.set_var(varname, varval) + api.nvim_set_var(varname, varval) end local vartype = eval('type(g:' .. varname .. ')') -- Exit during `reset` is not a regular exit: it does not write shada @@ -36,7 +36,7 @@ describe('ShaDa support code', function() expect_exit(nvim_command, 'qall') reset('set shada+=!') eq(vartype, eval('type(g:' .. varname .. ')')) - eq(varval, meths.get_var(varname)) + eq(varval, api.nvim_get_var(varname)) end) end @@ -53,110 +53,110 @@ describe('ShaDa support code', function() autotest('blob (with NULs)', 'BLOBVARNULS', '0z004e554c7300', true) it('does not read back variables without `!` in &shada', function() - meths.set_var('STRVAR', 'foo') + api.nvim_set_var('STRVAR', 'foo') nvim_command('set shada+=!') nvim_command('wshada') reset('set shada-=!') nvim_command('rshada') - eq(0, funcs.exists('g:STRVAR')) + eq(0, fn.exists('g:STRVAR')) end) it('does not dump variables without `!` in &shada', function() nvim_command('set shada-=!') - meths.set_var('STRVAR', 'foo') + api.nvim_set_var('STRVAR', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, funcs.exists('g:STRVAR')) + eq(0, fn.exists('g:STRVAR')) end) it('does not dump session variables', function() nvim_command('set shada+=!') - meths.set_var('StrVar', 'foo') + api.nvim_set_var('StrVar', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, funcs.exists('g:StrVar')) + eq(0, fn.exists('g:StrVar')) end) it('does not dump regular variables', function() nvim_command('set shada+=!') - meths.set_var('str_var', 'foo') + api.nvim_set_var('str_var', 'foo') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq(0, funcs.exists('g:str_var')) + eq(0, fn.exists('g:str_var')) end) it('dumps and loads variables correctly with utf-8 strings', function() reset() - meths.set_var('STRVAR', '«') - meths.set_var('LSTVAR', { '«' }) - meths.set_var('DCTVAR', { ['«'] = '«' }) - meths.set_var('NESTEDVAR', { ['«'] = { { '«' }, { ['«'] = '«' }, { a = 'Test' } } }) + api.nvim_set_var('STRVAR', '«') + api.nvim_set_var('LSTVAR', { '«' }) + api.nvim_set_var('DCTVAR', { ['«'] = '«' }) + api.nvim_set_var('NESTEDVAR', { ['«'] = { { '«' }, { ['«'] = '«' }, { a = 'Test' } } }) expect_exit(nvim_command, 'qall') reset() - eq('«', meths.get_var('STRVAR')) - eq({ '«' }, meths.get_var('LSTVAR')) - eq({ ['«'] = '«' }, meths.get_var('DCTVAR')) - eq({ ['«'] = { { '«' }, { ['«'] = '«' }, { a = 'Test' } } }, meths.get_var('NESTEDVAR')) + eq('«', api.nvim_get_var('STRVAR')) + eq({ '«' }, api.nvim_get_var('LSTVAR')) + eq({ ['«'] = '«' }, api.nvim_get_var('DCTVAR')) + eq({ ['«'] = { { '«' }, { ['«'] = '«' }, { a = 'Test' } } }, api.nvim_get_var('NESTEDVAR')) end) it('dumps and loads variables correctly with 8-bit strings', function() reset() -- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1 -- This is invalid unicode, but we should still dump and restore it. - meths.set_var('STRVAR', '\171') - meths.set_var('LSTVAR', { '\171' }) - meths.set_var('DCTVAR', { ['«\171'] = '«\171' }) - meths.set_var( + api.nvim_set_var('STRVAR', '\171') + api.nvim_set_var('LSTVAR', { '\171' }) + api.nvim_set_var('DCTVAR', { ['«\171'] = '«\171' }) + api.nvim_set_var( 'NESTEDVAR', { ['\171'] = { { '\171«' }, { ['\171'] = '\171' }, { a = 'Test' } } } ) expect_exit(nvim_command, 'qall') reset() - eq('\171', meths.get_var('STRVAR')) - eq({ '\171' }, meths.get_var('LSTVAR')) - eq({ ['«\171'] = '«\171' }, meths.get_var('DCTVAR')) + eq('\171', api.nvim_get_var('STRVAR')) + eq({ '\171' }, api.nvim_get_var('LSTVAR')) + eq({ ['«\171'] = '«\171' }, api.nvim_get_var('DCTVAR')) eq( { ['\171'] = { { '\171«' }, { ['\171'] = '\171' }, { a = 'Test' } } }, - meths.get_var('NESTEDVAR') + api.nvim_get_var('NESTEDVAR') ) end) it('ignore when a funcref is stored in a variable', function() nvim_command('let F = function("tr")') - meths.set_var('U', '10') + api.nvim_set_var('U', '10') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq('10', meths.get_var('U')) + eq('10', api.nvim_get_var('U')) end) it('ignore when a partial is stored in a variable', function() nvim_command('let P = { -> 1 }') - meths.set_var('U', '10') + api.nvim_set_var('U', '10') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('set shada+=!') nvim_command('rshada') - eq('10', meths.get_var('U')) + eq('10', api.nvim_get_var('U')) end) it('ignore when a self-referencing list is stored in a variable', function() - meths.set_var('L', {}) + api.nvim_set_var('L', {}) nvim_command('call add(L, L)') - meths.set_var('U', '10') + api.nvim_set_var('U', '10') nvim_command('set shada+=!') nvim_command('wshada') reset() nvim_command('rshada') - eq('10', meths.get_var('U')) + eq('10', api.nvim_get_var('U')) end) end) diff --git a/test/functional/terminal/altscreen_spec.lua b/test/functional/terminal/altscreen_spec.lua index f626a463c5..c3be9ec6ca 100644 --- a/test/functional/terminal/altscreen_spec.lua +++ b/test/functional/terminal/altscreen_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf +local clear, eq, api = helpers.clear, helpers.eq, helpers.api local feed = helpers.feed local feed_data = thelpers.feed_data local enter_altscreen = thelpers.enter_altscreen @@ -42,7 +42,7 @@ describe(':terminal altscreen', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(10, curbuf('line_count')) + eq(10, api.nvim_buf_line_count(0)) end) it('wont clear lines already in the scrollback', function() @@ -107,7 +107,7 @@ describe(':terminal altscreen', function() end) it('wont modify line count', function() - eq(10, curbuf('line_count')) + eq(10, api.nvim_buf_line_count(0)) end) it('wont modify lines in the scrollback', function() @@ -144,7 +144,7 @@ describe(':terminal altscreen', function() rows: 4, cols: 50 | | ]]) - eq(9, curbuf('line_count')) + eq(9, api.nvim_buf_line_count(0)) end) describe('and after exit', function() diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 497d7668e8..b6eb8ebdfd 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -2,21 +2,21 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') local assert_alive = helpers.assert_alive -local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim +local feed, clear = helpers.feed, helpers.clear local poke_eventloop = helpers.poke_eventloop local nvim_prog = helpers.nvim_prog local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source local pcall_err = helpers.pcall_err local eq, neq = helpers.eq, helpers.neq -local meths = helpers.meths +local api = helpers.api local retry = helpers.retry local write_file = helpers.write_file local command = helpers.command local exc_exec = helpers.exc_exec local matches = helpers.matches local exec_lua = helpers.exec_lua -local sleep = helpers.sleep -local funcs = helpers.funcs +local sleep = vim.uv.sleep +local fn = helpers.fn local is_os = helpers.is_os local skip = helpers.skip @@ -92,12 +92,12 @@ describe(':terminal buffer', function() end) it('does not create swap files', function() - local swapfile = nvim('exec', 'swapname', true):gsub('\n', '') + local swapfile = api.nvim_exec('swapname', true):gsub('\n', '') eq(nil, io.open(swapfile)) end) it('does not create undofiles files', function() - local undofile = nvim('eval', 'undofile(bufname("%"))') + local undofile = api.nvim_eval('undofile(bufname("%"))') eq(nil, io.open(undofile)) end) end) @@ -172,7 +172,7 @@ describe(':terminal buffer', function() it('handles loss of focus gracefully', function() -- Change the statusline to avoid printing the file name, which varies. - nvim('set_option_value', 'statusline', '==========', {}) + api.nvim_set_option_value('statusline', '==========', {}) -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') @@ -277,7 +277,7 @@ describe(':terminal buffer', function() end) it([[can use temporary normal mode <c-\><c-o>]], function() - eq('t', funcs.mode(1)) + eq('t', fn.mode(1)) feed [[<c-\><c-o>]] screen:expect { grid = [[ @@ -287,7 +287,7 @@ describe(':terminal buffer', function() {3:-- (terminal) --} | ]], } - eq('ntT', funcs.mode(1)) + eq('ntT', fn.mode(1)) feed [[:let g:x = 17]] screen:expect { @@ -308,7 +308,7 @@ describe(':terminal buffer', function() {3:-- TERMINAL --} | ]], } - eq('t', funcs.mode(1)) + eq('t', fn.mode(1)) end) it('writing to an existing file with :w fails #13549', function() @@ -321,18 +321,18 @@ describe(':terminal buffer', function() it('emits TermRequest events #26972', function() command('split') command('enew') - local term = meths.open_term(0, {}) - local termbuf = meths.get_current_buf().id + local term = api.nvim_open_term(0, {}) + local termbuf = api.nvim_get_current_buf().id -- Test that autocommand buffer is associated with the terminal buffer, not the current buffer command('au TermRequest * let g:termbuf = +expand("<abuf>")') command('wincmd p') -- cwd will be inserted in a file URI, which cannot contain backs - local cwd = funcs.getcwd():gsub('\\', '/') + local cwd = fn.getcwd():gsub('\\', '/') local parent = cwd:match('^(.+/)') local expected = '\027]7;file://host' .. parent - meths.chan_send(term, string.format('%s\027\\', expected)) + api.nvim_chan_send(term, string.format('%s\027\\', expected)) eq(expected, eval('v:termrequest')) eq(termbuf, eval('g:termbuf')) end) @@ -405,11 +405,11 @@ end) it('terminal truncates number of composing characters to 5', function() clear() - local chan = meths.open_term(0, {}) + local chan = api.nvim_open_term(0, {}) local composing = ('a̳'):sub(2) - meths.chan_send(chan, 'a' .. composing:rep(8)) + api.nvim_chan_send(chan, 'a' .. composing:rep(8)) retry(nil, nil, function() - eq('a' .. composing:rep(5), meths.get_current_line()) + eq('a' .. composing:rep(5), api.nvim_get_current_line()) end) end) @@ -512,7 +512,7 @@ describe('terminal input', function() }) do feed('<CR><C-V>' .. key) retry(nil, nil, function() - eq(key, meths.get_current_line()) + eq(key, api.nvim_get_current_line()) end) end end) @@ -599,7 +599,7 @@ describe('termopen()', function() feed('q:') eq( 'Vim:E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(funcs.termopen, 'bar') + pcall_err(fn.termopen, 'bar') ) end) @@ -610,13 +610,13 @@ describe('termopen()', function() before_each(function() -- Outer value should never be propagated to :terminal - funcs.setenv('COLORTERM', 'wrongvalue') + fn.setenv('COLORTERM', 'wrongvalue') end) local function test_term_colorterm(expected, opts) local screen = Screen.new(50, 4) screen:attach() - funcs.termopen({ + fn.termopen({ nvim_prog, '-u', 'NONE', diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua index b2553bf2e0..2b39c93f14 100644 --- a/test/functional/terminal/channel_spec.lua +++ b/test/functional/terminal/channel_spec.lua @@ -8,7 +8,7 @@ local pcall_err = helpers.pcall_err local feed = helpers.feed local poke_eventloop = helpers.poke_eventloop local is_os = helpers.is_os -local meths = helpers.meths +local api = helpers.api local async_meths = helpers.async_meths local testprg = helpers.testprg local assert_alive = helpers.assert_alive @@ -140,7 +140,7 @@ describe('no crash when TermOpen autocommand', function() before_each(function() clear() - meths.set_option_value('shell', testprg('shell-test'), {}) + api.nvim_set_option_value('shell', testprg('shell-test'), {}) command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') screen = Screen.new(60, 4) screen:set_default_attr_ids({ @@ -232,11 +232,11 @@ describe('nvim_open_term', function() end) it('with force_crlf=true converts newlines', function() - local win = meths.get_current_win() - local buf = meths.create_buf(false, true) - local term = meths.open_term(buf, { force_crlf = true }) - meths.win_set_buf(win, buf) - meths.chan_send(term, 'here\nthere\nfoo\r\nbar\n\ntest') + local win = api.nvim_get_current_win() + local buf = api.nvim_create_buf(false, true) + local term = api.nvim_open_term(buf, { force_crlf = true }) + api.nvim_win_set_buf(win, buf) + api.nvim_chan_send(term, 'here\nthere\nfoo\r\nbar\n\ntest') screen:expect { grid = [[ ^here | @@ -248,7 +248,7 @@ describe('nvim_open_term', function() |*4 ]], } - meths.chan_send(term, '\nfirst') + api.nvim_chan_send(term, '\nfirst') screen:expect { grid = [[ ^here | @@ -264,11 +264,11 @@ describe('nvim_open_term', function() end) it('with force_crlf=false does not convert newlines', function() - local win = meths.get_current_win() - local buf = meths.create_buf(false, true) - local term = meths.open_term(buf, { force_crlf = false }) - meths.win_set_buf(win, buf) - meths.chan_send(term, 'here\nthere') + local win = api.nvim_get_current_win() + local buf = api.nvim_create_buf(false, true) + local term = api.nvim_open_term(buf, { force_crlf = false }) + api.nvim_win_set_buf(win, buf) + api.nvim_chan_send(term, 'here\nthere') screen:expect { grid = [[ ^here | there | diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index a818f8139c..73fd97203e 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') -local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim +local feed, clear = helpers.feed, helpers.clear local testprg, command = helpers.testprg, helpers.command local eq, eval = helpers.eq, helpers.eval local matches = helpers.matches @@ -118,8 +118,8 @@ describe('cursor with customized highlighting', function() before_each(function() clear() - nvim('command', 'highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE') - nvim('command', 'highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE') + command('highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE') + command('highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE') screen = Screen.new(50, 7) screen:set_default_attr_ids({ [1] = { foreground = 45, background = 46 }, diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index e9062bc9b5..f7ceb0a68b 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -1,16 +1,14 @@ local helpers = require('test.functional.helpers')(after_each) local screen = require('test.functional.ui.screen') -local curbufmeths = helpers.curbufmeths -local curwinmeths = helpers.curwinmeths local testprg = helpers.testprg local command = helpers.command -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local clear = helpers.clear local eq = helpers.eq local matches = helpers.matches -local pesc = helpers.pesc +local pesc = vim.pesc describe(':edit term://*', function() local get_screen = function(columns, lines) @@ -21,17 +19,17 @@ describe(':edit term://*', function() before_each(function() clear() - meths.set_option_value('shell', testprg('shell-test'), {}) - meths.set_option_value('shellcmdflag', 'EXE', {}) + api.nvim_set_option_value('shell', testprg('shell-test'), {}) + api.nvim_set_option_value('shellcmdflag', 'EXE', {}) end) it('runs TermOpen event', function() - meths.set_var('termopen_runs', {}) + api.nvim_set_var('termopen_runs', {}) command('autocmd TermOpen * :call add(g:termopen_runs, expand("<amatch>"))') command('edit term://') - local termopen_runs = meths.get_var('termopen_runs') + local termopen_runs = api.nvim_get_var('termopen_runs') eq(1, #termopen_runs) - local cwd = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') + local cwd = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') matches('^term://' .. pesc(cwd) .. '//%d+:$', termopen_runs[1]) end) @@ -39,7 +37,7 @@ describe(':edit term://*', function() local columns, lines = 20, 4 local scr = get_screen(columns, lines) local rep = 97 - meths.set_option_value('shellcmdflag', 'REP ' .. rep, {}) + api.nvim_set_option_value('shellcmdflag', 'REP ' .. rep, {}) command('set shellxquote=') -- win: avoid extra quotes local sb = 10 command( @@ -48,7 +46,7 @@ describe(':edit term://*', function() command('edit term://foobar') local bufcontents = {} - local winheight = curwinmeths.get_height() + local winheight = api.nvim_win_get_height(0) local buf_cont_start = rep - sb - winheight + 2 for i = buf_cont_start, (rep - 1) do bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i) @@ -65,6 +63,6 @@ describe(':edit term://*', function() exp_screen = exp_screen .. (' '):rep(columns) .. '|\n' scr:expect(exp_screen) - eq(bufcontents, curbufmeths.get_lines(0, -1, true)) + eq(bufcontents, api.nvim_buf_get_lines(0, 0, -1, true)) end) end) diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 68d206c177..55ddfbab7b 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -1,11 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local assert_alive = helpers.assert_alive -local clear, poke_eventloop, nvim = helpers.clear, helpers.poke_eventloop, helpers.nvim +local clear, poke_eventloop = helpers.clear, helpers.poke_eventloop local testprg, source, eq = helpers.testprg, helpers.source, helpers.eq local feed = helpers.feed local feed_command, eval = helpers.feed_command, helpers.eval -local funcs = helpers.funcs +local fn = helpers.fn +local api = helpers.api local retry = helpers.retry local ok = helpers.ok local command = helpers.command @@ -35,7 +36,7 @@ describe(':terminal', function() poke_eventloop() -- Wait for some terminal activity. retry(nil, 4000, function() - ok(funcs.line('$') > 6) + ok(fn.line('$') > 6) end) feed_command('messages') screen:expect([[ @@ -79,7 +80,7 @@ describe(':terminal', function() it('Enter/Leave does not increment jumplist #3723', function() feed_command('terminal') local function enter_and_leave() - local lines_before = funcs.line('$') + local lines_before = fn.line('$') -- Create a new line (in the shell). For a normal buffer this -- increments the jumplist; for a terminal-buffer it should not. #3723 feed('i') @@ -90,44 +91,44 @@ describe(':terminal', function() poke_eventloop() -- Wait for >=1 lines to be created. retry(nil, 4000, function() - ok(funcs.line('$') > lines_before) + ok(fn.line('$') > lines_before) end) end enter_and_leave() enter_and_leave() enter_and_leave() - ok(funcs.line('$') > 6) -- Verify assumption. - local jumps = funcs.split(funcs.execute('jumps'), '\n') + ok(fn.line('$') > 6) -- Verify assumption. + local jumps = fn.split(fn.execute('jumps'), '\n') eq(' jump line col file/text', jumps[1]) eq(3, #jumps) end) it('nvim_get_mode() in :terminal', function() command('terminal') - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, api.nvim_get_mode()) feed('i') - eq({ blocking = false, mode = 't' }, nvim('get_mode')) + eq({ blocking = false, mode = 't' }, api.nvim_get_mode()) feed([[<C-\><C-N>]]) - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, api.nvim_get_mode()) end) it(':stopinsert RPC request exits terminal-mode #7807', function() command('terminal') feed('i[tui] insert-mode') - eq({ blocking = false, mode = 't' }, nvim('get_mode')) + eq({ blocking = false, mode = 't' }, api.nvim_get_mode()) command('stopinsert') feed('<Ignore>') -- Add input to separate two RPC requests - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, api.nvim_get_mode()) end) it(":stopinsert in normal mode doesn't break insert mode #9889", function() command('terminal') - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, api.nvim_get_mode()) command('stopinsert') feed('<Ignore>') -- Add input to separate two RPC requests - eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) + eq({ blocking = false, mode = 'nt' }, api.nvim_get_mode()) feed('a') - eq({ blocking = false, mode = 't' }, nvim('get_mode')) + eq({ blocking = false, mode = 't' }, api.nvim_get_mode()) end) it('switching to terminal buffer in Insert mode goes to Terminal mode #7164', function() @@ -138,9 +139,9 @@ describe(':terminal', function() command('autocmd InsertLeave * let g:events += ["InsertLeave"]') command('autocmd TermEnter * let g:events += ["TermEnter"]') command('inoremap <F2> <Cmd>wincmd p<CR>') - eq({ blocking = false, mode = 'i' }, nvim('get_mode')) + eq({ blocking = false, mode = 'i' }, api.nvim_get_mode()) feed('<F2>') - eq({ blocking = false, mode = 't' }, nvim('get_mode')) + eq({ blocking = false, mode = 't' }, api.nvim_get_mode()) eq({ 'InsertLeave', 'TermEnter' }, eval('g:events')) end) end) @@ -158,9 +159,9 @@ local function test_terminal_with_fake_shell(backslash) clear() screen = Screen.new(50, 4) screen:attach({ rgb = false }) - nvim('set_option_value', 'shell', shell_path, {}) - nvim('set_option_value', 'shellcmdflag', 'EXE', {}) - nvim('set_option_value', 'shellxquote', '', {}) + api.nvim_set_option_value('shell', shell_path, {}) + api.nvim_set_option_value('shellcmdflag', 'EXE', {}) + api.nvim_set_option_value('shellxquote', '', {}) end) it('with no argument, acts like termopen()', function() @@ -177,7 +178,7 @@ local function test_terminal_with_fake_shell(backslash) end) it("with no argument, and 'shell' is set to empty string", function() - nvim('set_option_value', 'shell', '', {}) + api.nvim_set_option_value('shell', '', {}) feed_command('terminal') screen:expect([[ ^ | @@ -187,7 +188,7 @@ local function test_terminal_with_fake_shell(backslash) end) it("with no argument, but 'shell' has arguments, acts like termopen()", function() - nvim('set_option_value', 'shell', shell_path .. ' INTERACT', {}) + api.nvim_set_option_value('shell', shell_path .. ' INTERACT', {}) feed_command('terminal') screen:expect([[ ^interact $ | @@ -208,7 +209,7 @@ local function test_terminal_with_fake_shell(backslash) end) it("executes a given command through the shell, when 'shell' has arguments", function() - nvim('set_option_value', 'shell', shell_path .. ' -t jeff', {}) + api.nvim_set_option_value('shell', shell_path .. ' -t jeff', {}) command('set shellxquote=') -- win: avoid extra quotes feed_command('terminal echo hi') screen:expect([[ diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index babc2337fa..b878b9eb43 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(nil) local Screen = require('test.functional.ui.screen') local testprg = helpers.testprg local exec_lua = helpers.exec_lua -local nvim = helpers.nvim +local api = helpers.api local nvim_prog = helpers.nvim_prog local function feed_data(data) @@ -89,8 +89,8 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts) command = command and command or default_command cols = cols and cols or 50 - nvim('command', 'highlight TermCursor cterm=reverse') - nvim('command', 'highlight TermCursorNC ctermbg=11') + api.nvim_command('highlight TermCursor cterm=reverse') + api.nvim_command('highlight TermCursorNC ctermbg=11') local screen = Screen.new(cols, 7 + extra_rows) screen:set_default_attr_ids({ @@ -113,17 +113,17 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts) screen:attach(screen_opts or { rgb = false }) - nvim('command', 'enew') - nvim('call_function', 'termopen', { command, env and { env = env } or nil }) - nvim('input', '<CR>') - local vim_errmsg = nvim('eval', 'v:errmsg') + api.nvim_command('enew') + api.nvim_call_function('termopen', { command, env and { env = env } or nil }) + api.nvim_input('<CR>') + local vim_errmsg = api.nvim_eval('v:errmsg') if vim_errmsg and '' ~= vim_errmsg then error(vim_errmsg) end - nvim('command', 'setlocal scrollback=10') - nvim('command', 'startinsert') - nvim('input', '<Ignore>') -- Add input to separate two RPC requests + api.nvim_command('setlocal scrollback=10') + api.nvim_command('startinsert') + api.nvim_input('<Ignore>') -- Add input to separate two RPC requests -- tty-test puts the terminal into raw mode and echoes input. Tests work by -- feeding termcodes to control the display and asserting by screen:expect. @@ -147,7 +147,7 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts) screen:expect(table.concat(expected, '|\n') .. '|') else -- This eval also acts as a poke_eventloop(). - if 0 == nvim('eval', "exists('b:terminal_job_id')") then + if 0 == api.nvim_eval("exists('b:terminal_job_id')") then error('terminal job failed to start') end end diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index 951a0f6c65..ec057c6766 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -1,11 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') -local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim +local feed, clear = helpers.feed, helpers.clear +local api = helpers.api local testprg, command = helpers.testprg, helpers.command local nvim_prog_abs = helpers.nvim_prog_abs local eq, eval = helpers.eq, helpers.eval -local funcs = helpers.funcs +local fn = helpers.fn local nvim_set = helpers.nvim_set local is_os = helpers.is_os local skip = helpers.skip @@ -150,7 +151,7 @@ it(':terminal highlight has lower precedence than editor #9964', function() }) screen:attach({ rgb = true }) -- Child nvim process in :terminal (with cterm colors). - funcs.termopen({ + fn.termopen({ nvim_prog_abs(), '-n', '-u', @@ -250,7 +251,7 @@ describe(':terminal highlight with custom palette', function() [9] = { bold = true }, }) screen:attach({ rgb = true }) - nvim('set_var', 'terminal_color_3', '#123456') + api.nvim_set_var('terminal_color_3', '#123456') command(("enew | call termopen(['%s'])"):format(testprg('tty-test'))) feed('i') screen:expect([[ diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 65d0c8f854..0395d5ee16 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval -local feed, nvim, command = helpers.feed, helpers.nvim, helpers.command +local feed, api, command = helpers.feed, helpers.api, helpers.command local feed_data = thelpers.feed_data local is_os = helpers.is_os local skip = helpers.skip @@ -11,7 +11,7 @@ describe(':terminal mouse', function() before_each(function() clear() - nvim('set_option_value', 'statusline', '==========', {}) + api.nvim_set_option_value('statusline', '==========', {}) command('highlight StatusLine cterm=NONE') command('highlight StatusLineNC cterm=NONE') command('highlight VertSplit cterm=NONE') @@ -514,7 +514,7 @@ describe(':terminal mouse', function() end) it('handles terminal size when switching buffers', function() - nvim('set_option_value', 'hidden', true, {}) + api.nvim_set_option_value('hidden', true, {}) feed('<c-\\><c-n><c-w><c-w>') screen:expect([[ {7: 27 }line │line30 | diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index f5c9887cdd..858e23984d 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -1,14 +1,13 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf +local clear, eq = helpers.clear, helpers.eq local feed, testprg = helpers.feed, helpers.testprg local eval = helpers.eval local command = helpers.command local poke_eventloop = helpers.poke_eventloop local retry = helpers.retry -local meths = helpers.meths -local nvim = helpers.nvim +local api = helpers.api local feed_data = thelpers.feed_data local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua @@ -86,7 +85,7 @@ describe(':terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(7, curbuf('line_count')) + eq(7, api.nvim_buf_line_count(0)) end) describe('and then 3 more lines are printed', function() @@ -170,7 +169,7 @@ describe(':terminal scrollback', function() {2:^ } | | ]]) - eq(8, curbuf('line_count')) + eq(8, api.nvim_buf_line_count(0)) feed([[3k]]) screen:expect([[ ^line4 | @@ -204,7 +203,7 @@ describe(':terminal scrollback', function() | {3:-- TERMINAL --} | ]]) - eq(4, curbuf('line_count')) + eq(4, api.nvim_buf_line_count(0)) end it('will delete the last two empty lines', will_delete_last_two_lines) @@ -222,7 +221,7 @@ describe(':terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(4, curbuf('line_count')) + eq(4, api.nvim_buf_line_count(0)) feed('<c-\\><c-n>gg') screen:expect([[ ^tty ready | @@ -261,7 +260,7 @@ describe(':terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(7, curbuf('line_count')) + eq(7, api.nvim_buf_line_count(0)) end) describe('and the height is increased by 1', function() @@ -287,7 +286,7 @@ describe(':terminal scrollback', function() describe('and then by 3', function() before_each(function() pop_then_push() - eq(8, curbuf('line_count')) + eq(8, api.nvim_buf_line_count(0)) screen:try_resize(screen._width, screen._height + 3) end) @@ -302,7 +301,7 @@ describe(':terminal scrollback', function() {1: } | {3:-- TERMINAL --} | ]]) - eq(9, curbuf('line_count')) + eq(9, api.nvim_buf_line_count(0)) feed('<c-\\><c-n>gg') screen:expect([[ ^tty ready | @@ -342,7 +341,7 @@ describe(':terminal scrollback', function() ]]) -- since there's an empty line after the cursor, the buffer line -- count equals the terminal screen height - eq(11, curbuf('line_count')) + eq(11, api.nvim_buf_line_count(0)) end) end) end) @@ -381,7 +380,7 @@ describe("'scrollback' option", function() end) local function set_fake_shell() - nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) + api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) end local function expect_lines(expected, epsilon) @@ -400,7 +399,7 @@ describe("'scrollback' option", function() screen = thelpers.screen_setup(nil, { 'sh' }, 30) end - meths.set_option_value('scrollback', 0, {}) + api.nvim_set_option_value('scrollback', 0, {}) feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n')) screen:expect { any = '30: line ' } retry(nil, nil, function() @@ -418,7 +417,7 @@ describe("'scrollback' option", function() screen = thelpers.screen_setup(nil, { 'sh' }, 30) end - meths.set_option_value('scrollback', 200, {}) + api.nvim_set_option_value('scrollback', 200, {}) -- Wait for prompt. screen:expect { any = '%$' } @@ -429,12 +428,12 @@ describe("'scrollback' option", function() retry(nil, nil, function() expect_lines(33, 2) end) - meths.set_option_value('scrollback', 10, {}) + api.nvim_set_option_value('scrollback', 10, {}) poke_eventloop() retry(nil, nil, function() expect_lines(16) end) - meths.set_option_value('scrollback', 10000, {}) + api.nvim_set_option_value('scrollback', 10000, {}) retry(nil, nil, function() expect_lines(16) end) @@ -495,18 +494,18 @@ describe("'scrollback' option", function() ]]) local term_height = 6 -- Actual terminal screen height, not the scrollback -- Initial - local scrollback = meths.get_option_value('scrollback', {}) + local scrollback = api.nvim_get_option_value('scrollback', {}) eq(scrollback + term_height, eval('line("$")')) -- Reduction scrollback = scrollback - 2 - meths.set_option_value('scrollback', scrollback, {}) + api.nvim_set_option_value('scrollback', scrollback, {}) eq(scrollback + term_height, eval('line("$")')) end) it('defaults to 10000 in :terminal buffers', function() set_fake_shell() command('terminal') - eq(10000, meths.get_option_value('scrollback', {})) + eq(10000, api.nvim_get_option_value('scrollback', {})) end) it('error if set to invalid value', function() @@ -519,7 +518,7 @@ describe("'scrollback' option", function() it('defaults to -1 on normal buffers', function() command('new') - eq(-1, meths.get_option_value('scrollback', {})) + eq(-1, api.nvim_get_option_value('scrollback', {})) end) it(':setlocal in a :terminal buffer', function() @@ -528,45 +527,45 @@ describe("'scrollback' option", function() -- _Global_ scrollback=-1 defaults :terminal to 10_000. command('setglobal scrollback=-1') command('terminal') - eq(10000, meths.get_option_value('scrollback', {})) + eq(10000, api.nvim_get_option_value('scrollback', {})) -- _Local_ scrollback=-1 in :terminal forces the _maximum_. command('setlocal scrollback=-1') retry(nil, nil, function() -- Fixup happens on refresh, not immediately. - eq(100000, meths.get_option_value('scrollback', {})) + eq(100000, api.nvim_get_option_value('scrollback', {})) end) -- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605 command('setglobal scrollback=-1') command('autocmd TermOpen * setlocal scrollback=-1') command('terminal') - eq(100000, meths.get_option_value('scrollback', {})) + eq(100000, api.nvim_get_option_value('scrollback', {})) end) it(':setlocal in a normal buffer', function() command('new') -- :setlocal to -1. command('setlocal scrollback=-1') - eq(-1, meths.get_option_value('scrollback', {})) + eq(-1, api.nvim_get_option_value('scrollback', {})) -- :setlocal to anything except -1. Currently, this just has no effect. command('setlocal scrollback=42') - eq(42, meths.get_option_value('scrollback', {})) + eq(42, api.nvim_get_option_value('scrollback', {})) end) it(':set updates local value and global default', function() set_fake_shell() command('set scrollback=42') -- set global value - eq(42, meths.get_option_value('scrollback', {})) + eq(42, api.nvim_get_option_value('scrollback', {})) command('terminal') - eq(42, meths.get_option_value('scrollback', {})) -- inherits global default + eq(42, api.nvim_get_option_value('scrollback', {})) -- inherits global default command('setlocal scrollback=99') - eq(99, meths.get_option_value('scrollback', {})) + eq(99, api.nvim_get_option_value('scrollback', {})) command('set scrollback<') -- reset to global default - eq(42, meths.get_option_value('scrollback', {})) + eq(42, api.nvim_get_option_value('scrollback', {})) command('setglobal scrollback=734') -- new global default - eq(42, meths.get_option_value('scrollback', {})) -- local value did not change + eq(42, api.nvim_get_option_value('scrollback', {})) -- local value did not change command('terminal') - eq(734, meths.get_option_value('scrollback', {})) + eq(734, api.nvim_get_option_value('scrollback', {})) end) end) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index e65e57bc7f..54fbfd191a 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -20,8 +20,8 @@ local nvim_prog = helpers.nvim_prog local nvim_set = helpers.nvim_set local ok = helpers.ok local read_file = helpers.read_file -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local is_ci = helpers.is_ci local is_os = helpers.is_os local new_pipename = helpers.new_pipename @@ -375,7 +375,7 @@ describe('TUI', function() if esc then feed_data('\027[<65;8;1M') else - meths.input_mouse('wheel', 'down', '', 0, 0, 7) + api.nvim_input_mouse('wheel', 'down', '', 0, 0, 7) end screen:expect([[ {11: 2 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----| @@ -390,7 +390,7 @@ describe('TUI', function() if esc then feed_data('\027[<65;48;1M') else - meths.input_mouse('wheel', 'down', '', 0, 0, 47) + api.nvim_input_mouse('wheel', 'down', '', 0, 0, 47) end screen:expect([[ {11: 2 }{1:0}----1----2----3----4│{11: 2 }0----1----2----3----| @@ -405,7 +405,7 @@ describe('TUI', function() if esc then feed_data('\027[<67;8;1M') else - meths.input_mouse('wheel', 'right', '', 0, 0, 7) + api.nvim_input_mouse('wheel', 'right', '', 0, 0, 7) end screen:expect([[ {11: 2 }{1:-}---1----2----3----4-│{11: 2 }0----1----2----3----| @@ -420,7 +420,7 @@ describe('TUI', function() if esc then feed_data('\027[<67;48;1M') else - meths.input_mouse('wheel', 'right', '', 0, 0, 47) + api.nvim_input_mouse('wheel', 'right', '', 0, 0, 47) end screen:expect([[ {11: 2 }{1:-}---1----2----3----4-│{11: 2 }----1----2----3----4| @@ -435,7 +435,7 @@ describe('TUI', function() if esc then feed_data('\027[<69;8;1M') else - meths.input_mouse('wheel', 'down', 'S', 0, 0, 7) + api.nvim_input_mouse('wheel', 'down', 'S', 0, 0, 7) end screen:expect([[ {11: 5 }{1:-}---1----2----3----4-│{11: 2 }----1----2----3----4| @@ -450,7 +450,7 @@ describe('TUI', function() if esc then feed_data('\027[<69;48;1M') else - meths.input_mouse('wheel', 'down', 'S', 0, 0, 47) + api.nvim_input_mouse('wheel', 'down', 'S', 0, 0, 47) end screen:expect([[ {11: 5 }{1:-}---1----2----3----4-│{11: 5 }----1----2----3----4| @@ -465,7 +465,7 @@ describe('TUI', function() if esc then feed_data('\027[<71;8;1M') else - meths.input_mouse('wheel', 'right', 'S', 0, 0, 7) + api.nvim_input_mouse('wheel', 'right', 'S', 0, 0, 7) end screen:expect([[ {11: 5 }{1:-}---6----7----8----9 │{11: 5 }----1----2----3----4| @@ -480,7 +480,7 @@ describe('TUI', function() if esc then feed_data('\027[<71;48;1M') else - meths.input_mouse('wheel', 'right', 'S', 0, 0, 47) + api.nvim_input_mouse('wheel', 'right', 'S', 0, 0, 47) end screen:expect([[ {11: 5 }{1:-}---6----7----8----9 │{11: 5 }5----6----7----8----| @@ -495,7 +495,7 @@ describe('TUI', function() if esc then feed_data('\027[<64;8;1M') else - meths.input_mouse('wheel', 'up', '', 0, 0, 7) + api.nvim_input_mouse('wheel', 'up', '', 0, 0, 7) end screen:expect([[ {11: 4 }----6----7----8----9 │{11: 5 }5----6----7----8----| @@ -510,7 +510,7 @@ describe('TUI', function() if esc then feed_data('\027[<64;48;1M') else - meths.input_mouse('wheel', 'up', '', 0, 0, 47) + api.nvim_input_mouse('wheel', 'up', '', 0, 0, 47) end screen:expect([[ {11: 4 }----6----7----8----9 │{11: 4 }5----6----7----8----| @@ -525,7 +525,7 @@ describe('TUI', function() if esc then feed_data('\027[<66;8;1M') else - meths.input_mouse('wheel', 'left', '', 0, 0, 7) + api.nvim_input_mouse('wheel', 'left', '', 0, 0, 7) end screen:expect([[ {11: 4 }5----6----7----8----9│{11: 4 }5----6----7----8----| @@ -540,7 +540,7 @@ describe('TUI', function() if esc then feed_data('\027[<66;48;1M') else - meths.input_mouse('wheel', 'left', '', 0, 0, 47) + api.nvim_input_mouse('wheel', 'left', '', 0, 0, 47) end screen:expect([[ {11: 4 }5----6----7----8----9│{11: 4 }-5----6----7----8---| @@ -555,7 +555,7 @@ describe('TUI', function() if esc then feed_data('\027[<68;8;1M') else - meths.input_mouse('wheel', 'up', 'S', 0, 0, 7) + api.nvim_input_mouse('wheel', 'up', 'S', 0, 0, 7) end screen:expect([[ {11: 1 }5----6----7----8----9│{11: 4 }-5----6----7----8---| @@ -570,7 +570,7 @@ describe('TUI', function() if esc then feed_data('\027[<68;48;1M') else - meths.input_mouse('wheel', 'up', 'S', 0, 0, 47) + api.nvim_input_mouse('wheel', 'up', 'S', 0, 0, 47) end screen:expect([[ {11: 1 }5----6----7----8----9│{11: 1 }-5----6----7----8---| @@ -585,7 +585,7 @@ describe('TUI', function() if esc then feed_data('\027[<70;8;1M') else - meths.input_mouse('wheel', 'left', 'S', 0, 0, 7) + api.nvim_input_mouse('wheel', 'left', 'S', 0, 0, 7) end screen:expect([[ {11: 1 }0----1----2----3----4│{11: 1 }-5----6----7----8---| @@ -600,7 +600,7 @@ describe('TUI', function() if esc then feed_data('\027[<70;48;1M') else - meths.input_mouse('wheel', 'left', 'S', 0, 0, 47) + api.nvim_input_mouse('wheel', 'left', 'S', 0, 0, 47) end screen:expect([[ {11: 1 }0----1----2----3----4│{11: 1 }0----1----2----3----| @@ -642,7 +642,7 @@ describe('TUI', function() if esc then feed_data('\027[<2;5;1M') else - meths.input_mouse('right', 'press', '', 0, 0, 4) + api.nvim_input_mouse('right', 'press', '', 0, 0, 4) end screen:expect([[ {1:p}opup menu test | @@ -656,13 +656,13 @@ describe('TUI', function() if esc then feed_data('\027[<2;5;1m') else - meths.input_mouse('right', 'release', '', 0, 0, 4) + api.nvim_input_mouse('right', 'release', '', 0, 0, 4) end screen:expect_unchanged() if esc then feed_data('\027[<35;7;4M') else - meths.input_mouse('move', '', '', 0, 3, 6) + api.nvim_input_mouse('move', '', '', 0, 3, 6) end screen:expect([[ {1:p}opup menu test | @@ -676,7 +676,7 @@ describe('TUI', function() if esc then feed_data('\027[<0;7;3M') else - meths.input_mouse('left', 'press', '', 0, 2, 6) + api.nvim_input_mouse('left', 'press', '', 0, 2, 6) end screen:expect([[ {1:p}opup menu test | @@ -688,13 +688,13 @@ describe('TUI', function() if esc then feed_data('\027[<0;7;3m') else - meths.input_mouse('left', 'release', '', 0, 2, 6) + api.nvim_input_mouse('left', 'release', '', 0, 2, 6) end screen:expect_unchanged() if esc then feed_data('\027[<2;45;3M') else - meths.input_mouse('right', 'press', '', 0, 2, 44) + api.nvim_input_mouse('right', 'press', '', 0, 2, 44) end screen:expect([[ {1:p}opup menu test | @@ -707,7 +707,7 @@ describe('TUI', function() if esc then feed_data('\027[<34;48;6M') else - meths.input_mouse('right', 'drag', '', 0, 5, 47) + api.nvim_input_mouse('right', 'drag', '', 0, 5, 47) end screen:expect([[ {1:p}opup menu test | @@ -720,7 +720,7 @@ describe('TUI', function() if esc then feed_data('\027[<2;48;6m') else - meths.input_mouse('right', 'release', '', 0, 5, 47) + api.nvim_input_mouse('right', 'release', '', 0, 5, 47) end screen:expect([[ {1:p}opup menu test | @@ -743,23 +743,23 @@ describe('TUI', function() it('accepts keypad keys from kitty keyboard protocol #19180', function() feed_data('i') - feed_data(funcs.nr2char(57399)) -- KP_0 - feed_data(funcs.nr2char(57400)) -- KP_1 - feed_data(funcs.nr2char(57401)) -- KP_2 - feed_data(funcs.nr2char(57402)) -- KP_3 - feed_data(funcs.nr2char(57403)) -- KP_4 - feed_data(funcs.nr2char(57404)) -- KP_5 - feed_data(funcs.nr2char(57405)) -- KP_6 - feed_data(funcs.nr2char(57406)) -- KP_7 - feed_data(funcs.nr2char(57407)) -- KP_8 - feed_data(funcs.nr2char(57408)) -- KP_9 - feed_data(funcs.nr2char(57409)) -- KP_DECIMAL - feed_data(funcs.nr2char(57410)) -- KP_DIVIDE - feed_data(funcs.nr2char(57411)) -- KP_MULTIPLY - feed_data(funcs.nr2char(57412)) -- KP_SUBTRACT - feed_data(funcs.nr2char(57413)) -- KP_ADD - feed_data(funcs.nr2char(57414)) -- KP_ENTER - feed_data(funcs.nr2char(57415)) -- KP_EQUAL + feed_data(fn.nr2char(57399)) -- KP_0 + feed_data(fn.nr2char(57400)) -- KP_1 + feed_data(fn.nr2char(57401)) -- KP_2 + feed_data(fn.nr2char(57402)) -- KP_3 + feed_data(fn.nr2char(57403)) -- KP_4 + feed_data(fn.nr2char(57404)) -- KP_5 + feed_data(fn.nr2char(57405)) -- KP_6 + feed_data(fn.nr2char(57406)) -- KP_7 + feed_data(fn.nr2char(57407)) -- KP_8 + feed_data(fn.nr2char(57408)) -- KP_9 + feed_data(fn.nr2char(57409)) -- KP_DECIMAL + feed_data(fn.nr2char(57410)) -- KP_DIVIDE + feed_data(fn.nr2char(57411)) -- KP_MULTIPLY + feed_data(fn.nr2char(57412)) -- KP_SUBTRACT + feed_data(fn.nr2char(57413)) -- KP_ADD + feed_data(fn.nr2char(57414)) -- KP_ENTER + feed_data(fn.nr2char(57415)) -- KP_EQUAL screen:expect([[ 0123456789./*-+ | ={1: } | @@ -768,7 +768,7 @@ describe('TUI', function() {3:-- INSERT --} | {3:-- TERMINAL --} | ]]) - feed_data(funcs.nr2char(57417)) -- KP_LEFT + feed_data(fn.nr2char(57417)) -- KP_LEFT screen:expect([[ 0123456789./*-+ | {1:=} | @@ -777,7 +777,7 @@ describe('TUI', function() {3:-- INSERT --} | {3:-- TERMINAL --} | ]]) - feed_data(funcs.nr2char(57418)) -- KP_RIGHT + feed_data(fn.nr2char(57418)) -- KP_RIGHT screen:expect([[ 0123456789./*-+ | ={1: } | @@ -786,7 +786,7 @@ describe('TUI', function() {3:-- INSERT --} | {3:-- TERMINAL --} | ]]) - feed_data(funcs.nr2char(57419)) -- KP_UP + feed_data(fn.nr2char(57419)) -- KP_UP screen:expect([[ 0{1:1}23456789./*-+ | = | @@ -795,7 +795,7 @@ describe('TUI', function() {3:-- INSERT --} | {3:-- TERMINAL --} | ]]) - feed_data(funcs.nr2char(57420)) -- KP_DOWN + feed_data(fn.nr2char(57420)) -- KP_DOWN screen:expect([[ 0123456789./*-+ | ={1: } | @@ -804,7 +804,7 @@ describe('TUI', function() {3:-- INSERT --} | {3:-- TERMINAL --} | ]]) - feed_data(funcs.nr2char(57425)) -- KP_INSERT + feed_data(fn.nr2char(57425)) -- KP_INSERT screen:expect([[ 0123456789./*-+ | ={1: } | @@ -840,7 +840,7 @@ describe('TUI', function() | {3:-- TERMINAL --} | ]]) - feed_data(funcs.nr2char(57426)) -- KP_DELETE + feed_data(fn.nr2char(57426)) -- KP_DELETE screen:expect([[ 0123456789{1:/}*-+ | = | @@ -849,7 +849,7 @@ describe('TUI', function() | {3:-- TERMINAL --} | ]]) - feed_data(funcs.nr2char(57423)) -- KP_HOME + feed_data(fn.nr2char(57423)) -- KP_HOME screen:expect([[ {1:0}123456789/*-+ | = | @@ -858,7 +858,7 @@ describe('TUI', function() | {3:-- TERMINAL --} | ]]) - feed_data(funcs.nr2char(57424)) -- KP_END + feed_data(fn.nr2char(57424)) -- KP_END screen:expect([[ 0123456789/*-{1:+} | = | @@ -1903,7 +1903,7 @@ describe('TUI', function() [5] = { bold = true, reverse = true }, }) screen:attach() - funcs.termopen({ + fn.termopen({ nvim_prog, '--clean', '--cmd', @@ -2989,7 +2989,7 @@ describe('TUI as a client', function() local client_super = spawn_argv(true) set_session(server) - local server_pipe = meths.get_vvar('servername') + local server_pipe = api.nvim_get_vvar('servername') server:request('nvim_input', 'iHalloj!<Esc>') server:request('nvim_command', 'set notermguicolors') @@ -3022,10 +3022,10 @@ describe('TUI as a client', function() ]], } - eq(0, meths.get_vvar('shell_error')) + eq(0, api.nvim_get_vvar('shell_error')) -- exits on input eof #22244 - funcs.system({ nvim_prog, '--server', server_pipe, '--remote-ui' }) - eq(1, meths.get_vvar('shell_error')) + fn.system({ nvim_prog, '--server', server_pipe, '--remote-ui' }) + eq(1, api.nvim_get_vvar('shell_error')) client_super:close() server:close() diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index 1fb759b571..17411e2724 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -7,8 +7,8 @@ local feed_command = helpers.feed_command local command = helpers.command local eq = helpers.eq local eval = helpers.eval -local meths = helpers.meths -local sleep = helpers.sleep +local api = helpers.api +local sleep = vim.uv.sleep local retry = helpers.retry local is_os = helpers.is_os @@ -19,7 +19,7 @@ describe(':terminal', function() clear() -- set the statusline to a constant value because of variables like pid -- and current directory and to improve visibility of splits - meths.set_option_value('statusline', '==========', {}) + api.nvim_set_option_value('statusline', '==========', {}) command('highlight StatusLine cterm=NONE') command('highlight StatusLineNC cterm=NONE') command('highlight VertSplit cterm=NONE') @@ -69,10 +69,10 @@ describe(':terminal', function() end) it('does not change size if updated when not visible in any window #19665', function() - local channel = meths.get_option_value('channel', {}) + local channel = api.nvim_get_option_value('channel', {}) command('enew') sleep(100) - meths.chan_send(channel, 'foo') + api.nvim_chan_send(channel, 'foo') sleep(100) command('bprevious') screen:expect([[ diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua index afcb3a8ef6..f4f7bc691c 100644 --- a/test/functional/treesitter/highlight_spec.lua +++ b/test/functional/treesitter/highlight_spec.lua @@ -6,7 +6,7 @@ local insert = helpers.insert local exec_lua = helpers.exec_lua local feed = helpers.feed local command = helpers.command -local meths = helpers.meths +local api = helpers.api local eq = helpers.eq before_each(clear) @@ -709,11 +709,11 @@ describe('treesitter highlighting (C)', function() it('@foo.bar groups has the correct fallback behavior', function() local get_hl = function(name) - return meths.get_hl_by_name(name, 1).foreground + return api.nvim_get_hl_by_name(name, 1).foreground end - meths.set_hl(0, '@foo', { fg = 1 }) - meths.set_hl(0, '@foo.bar', { fg = 2 }) - meths.set_hl(0, '@foo.bar.baz', { fg = 3 }) + api.nvim_set_hl(0, '@foo', { fg = 1 }) + api.nvim_set_hl(0, '@foo.bar', { fg = 2 }) + api.nvim_set_hl(0, '@foo.bar.baz', { fg = 3 }) eq(1, get_hl '@foo') eq(1, get_hl '@foo.a.b.c.d') @@ -725,7 +725,7 @@ describe('treesitter highlighting (C)', function() -- lookup is case insensitive eq(2, get_hl '@FOO.BAR.SPAM') - meths.set_hl(0, '@foo.missing.exists', { fg = 3 }) + api.nvim_set_hl(0, '@foo.missing.exists', { fg = 3 }) eq(1, get_hl '@foo.missing') eq(3, get_hl '@foo.missing.exists') eq(3, get_hl '@foo.missing.exists.bar') @@ -772,7 +772,7 @@ describe('treesitter highlighting (help)', function() ]], } - helpers.curbufmeths.set_text(0, 1, 0, 5, { 'lua' }) + helpers.api.nvim_buf_set_text(0, 0, 1, 0, 5, { 'lua' }) screen:expect { grid = [[ @@ -785,7 +785,7 @@ describe('treesitter highlighting (help)', function() ]], } - helpers.curbufmeths.set_text(0, 1, 0, 4, { 'ruby' }) + helpers.api.nvim_buf_set_text(0, 0, 1, 0, 4, { 'ruby' }) screen:expect { grid = [[ diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua index 220537f58a..417a19f92c 100644 --- a/test/functional/ui/bufhl_spec.lua +++ b/test/functional/ui/bufhl_spec.lua @@ -3,9 +3,10 @@ local Screen = require('test.functional.ui.screen') local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, neq = helpers.command, helpers.neq -local meths = helpers.meths -local curbufmeths, eq = helpers.curbufmeths, helpers.eq +local api = helpers.api +local eq = helpers.eq local pcall_err = helpers.pcall_err +local set_virtual_text = api.nvim_buf_set_virtual_text describe('Buffer highlighting', function() local screen @@ -39,8 +40,8 @@ describe('Buffer highlighting', function() }) end) - local add_highlight = curbufmeths.add_highlight - local clear_namespace = curbufmeths.clear_namespace + local add_highlight = api.nvim_buf_add_highlight + local clear_namespace = api.nvim_buf_clear_namespace it('works', function() insert([[ @@ -55,8 +56,8 @@ describe('Buffer highlighting', function() | ]]) - add_highlight(-1, 'String', 0, 10, 14) - add_highlight(-1, 'Statement', 1, 5, -1) + add_highlight(0, -1, 'String', 0, 10, 14) + add_highlight(0, -1, 'Statement', 1, 5, -1) screen:expect([[ these are {2:some} lines | @@ -74,7 +75,7 @@ describe('Buffer highlighting', function() | ]]) - clear_namespace(-1, 0, -1) + clear_namespace(0, -1, 0, -1) screen:expect([[ these are some lines | ^ | @@ -94,21 +95,21 @@ describe('Buffer highlighting', function() from different sources]]) command('hi ImportantWord gui=bold cterm=bold') - id1 = add_highlight(0, 'ImportantWord', 0, 2, 8) - add_highlight(id1, 'ImportantWord', 1, 12, -1) - add_highlight(id1, 'ImportantWord', 2, 0, 9) - add_highlight(id1, 'ImportantWord', 3, 5, 14) + id1 = add_highlight(0, 0, 'ImportantWord', 0, 2, 8) + add_highlight(0, id1, 'ImportantWord', 1, 12, -1) + add_highlight(0, id1, 'ImportantWord', 2, 0, 9) + add_highlight(0, id1, 'ImportantWord', 3, 5, 14) -- add_highlight can be called like this to get a new source -- without adding any highlight - id2 = add_highlight(0, '', 0, 0, 0) + id2 = add_highlight(0, 0, '', 0, 0, 0) neq(id1, id2) - add_highlight(id2, 'Special', 0, 2, 8) - add_highlight(id2, 'Identifier', 1, 3, 8) - add_highlight(id2, 'Special', 1, 14, 20) - add_highlight(id2, 'Underlined', 2, 6, 12) - add_highlight(id2, 'Underlined', 3, 0, 9) + add_highlight(0, id2, 'Special', 0, 2, 8) + add_highlight(0, id2, 'Identifier', 1, 3, 8) + add_highlight(0, id2, 'Special', 1, 14, 20) + add_highlight(0, id2, 'Underlined', 2, 6, 12) + add_highlight(0, id2, 'Underlined', 3, 0, 9) screen:expect([[ a {5:longer} example | @@ -121,7 +122,7 @@ describe('Buffer highlighting', function() end) it('and clearing the first added', function() - clear_namespace(id1, 0, -1) + clear_namespace(0, id1, 0, -1) screen:expect([[ a {4:longer} example | in {6:order} to de{4:monstr}ate | @@ -133,7 +134,7 @@ describe('Buffer highlighting', function() end) it('and clearing using deprecated name', function() - curbufmeths.clear_highlight(id1, 0, -1) + api.nvim_buf_clear_highlight(0, id1, 0, -1) screen:expect([[ a {4:longer} example | in {6:order} to de{4:monstr}ate | @@ -145,7 +146,7 @@ describe('Buffer highlighting', function() end) it('and clearing the second added', function() - clear_namespace(id2, 0, -1) + clear_namespace(0, id2, 0, -1) screen:expect([[ a {7:longer} example | in order to {7:demonstrate} | @@ -157,9 +158,9 @@ describe('Buffer highlighting', function() end) it('and clearing line ranges', function() - clear_namespace(-1, 0, 1) - clear_namespace(id1, 1, 2) - clear_namespace(id2, 2, -1) + clear_namespace(0, -1, 0, 1) + clear_namespace(0, id1, 1, 2) + clear_namespace(0, id2, 2, -1) screen:expect([[ a longer example | in {6:order} to de{4:monstr}ate | @@ -449,9 +450,9 @@ describe('Buffer highlighting', function() pending('prioritizes latest added highlight', function() insert([[ three overlapping colors]]) - add_highlight(0, 'Identifier', 0, 6, 17) - add_highlight(0, 'String', 0, 14, 23) - local id = add_highlight(0, 'Special', 0, 0, 9) + add_highlight(0, 0, 'Identifier', 0, 6, 17) + add_highlight(0, 0, 'String', 0, 14, 23) + local id = add_highlight(0, 0, 'Special', 0, 0, 9) screen:expect([[ {4:three ove}{6:rlapp}{2:ing color}^s | @@ -459,7 +460,7 @@ describe('Buffer highlighting', function() | ]]) - clear_namespace(id, 0, 1) + clear_namespace(0, id, 0, 1) screen:expect([[ three {6:overlapp}{2:ing color}^s | {1:~ }|*6 @@ -470,9 +471,9 @@ describe('Buffer highlighting', function() it('prioritizes earlier highlight groups (TEMP)', function() insert([[ three overlapping colors]]) - add_highlight(0, 'Identifier', 0, 6, 17) - add_highlight(0, 'String', 0, 14, 23) - local id = add_highlight(0, 'Special', 0, 0, 9) + add_highlight(0, 0, 'Identifier', 0, 6, 17) + add_highlight(0, 0, 'String', 0, 14, 23) + local id = add_highlight(0, 0, 'Special', 0, 0, 9) screen:expect { grid = [[ @@ -482,7 +483,7 @@ describe('Buffer highlighting', function() ]], } - clear_namespace(id, 0, 1) + clear_namespace(0, id, 0, 1) screen:expect { grid = [[ three {6:overlapp}{2:ing color}^s | @@ -493,17 +494,16 @@ describe('Buffer highlighting', function() end) it('respects priority', function() - local set_extmark = curbufmeths.set_extmark - local id = meths.create_namespace('') + local id = api.nvim_create_namespace('') insert [[foobar]] - set_extmark(id, 0, 0, { + api.nvim_buf_set_extmark(0, id, 0, 0, { end_line = 0, end_col = 5, hl_group = 'Statement', priority = 100, }) - set_extmark(id, 0, 0, { + api.nvim_buf_set_extmark(0, id, 0, 0, { end_line = 0, end_col = 6, hl_group = 'String', @@ -516,7 +516,7 @@ describe('Buffer highlighting', function() | ]] - clear_namespace(id, 0, -1) + clear_namespace(0, id, 0, -1) screen:expect { grid = [[ fooba^r | @@ -525,13 +525,13 @@ describe('Buffer highlighting', function() ]], } - set_extmark(id, 0, 0, { + api.nvim_buf_set_extmark(0, id, 0, 0, { end_line = 0, end_col = 6, hl_group = 'String', priority = 1, }) - set_extmark(id, 0, 0, { + api.nvim_buf_set_extmark(0, id, 0, 0, { end_line = 0, end_col = 5, hl_group = 'Statement', @@ -548,8 +548,8 @@ describe('Buffer highlighting', function() it('works with multibyte text', function() insert([[ Ta båten över sjön!]]) - add_highlight(-1, 'Identifier', 0, 3, 9) - add_highlight(-1, 'String', 0, 16, 21) + add_highlight(0, -1, 'Identifier', 0, 3, 9) + add_highlight(0, -1, 'String', 0, 16, 21) screen:expect([[ Ta {6:båten} över {2:sjön}^! | @@ -561,7 +561,7 @@ describe('Buffer highlighting', function() it('works with new syntax groups', function() insert([[ fancy code in a new fancy language]]) - add_highlight(-1, 'FancyLangItem', 0, 0, 5) + add_highlight(0, -1, 'FancyLangItem', 0, 0, 5) screen:expect([[ fancy code in a new fancy languag^e | {1:~ }|*6 @@ -577,7 +577,6 @@ describe('Buffer highlighting', function() end) describe('virtual text decorations', function() - local set_virtual_text = curbufmeths.set_virtual_text local id1, id2 before_each(function() insert([[ @@ -595,9 +594,9 @@ describe('Buffer highlighting', function() | ]]) - id1 = set_virtual_text(0, 0, { { '=', 'Statement' }, { ' 3', 'Number' } }, {}) - set_virtual_text(id1, 1, { { 'ERROR:', 'ErrorMsg' }, { ' invalid syntax' } }, {}) - id2 = set_virtual_text(0, 2, { + id1 = set_virtual_text(0, 0, 0, { { '=', 'Statement' }, { ' 3', 'Number' } }, {}) + set_virtual_text(0, id1, 1, { { 'ERROR:', 'ErrorMsg' }, { ' invalid syntax' } }, {}) + id2 = set_virtual_text(0, 0, 2, { { 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', }, @@ -616,7 +615,7 @@ describe('Buffer highlighting', function() | ]]) - clear_namespace(id1, 0, -1) + clear_namespace(0, id1, 0, -1) screen:expect([[ ^1 + 2 | 3 + | @@ -632,6 +631,7 @@ describe('Buffer highlighting', function() eq( -1, set_virtual_text( + 0, -1, 1, { { '暗x事zz速野谷質結育副住新覚丸活解終事', 'Comment' } }, @@ -687,22 +687,22 @@ describe('Buffer highlighting', function() -- this used to leak memory eq( "Invalid 'chunk': expected Array, got String", - pcall_err(set_virtual_text, id1, 0, { 'texty' }, {}) + pcall_err(set_virtual_text, 0, id1, 0, { 'texty' }, {}) ) eq( "Invalid 'chunk': expected Array, got String", - pcall_err(set_virtual_text, id1, 0, { { 'very' }, 'texty' }, {}) + pcall_err(set_virtual_text, 0, id1, 0, { { 'very' }, 'texty' }, {}) ) end) it('can be retrieved', function() - local get_extmarks = curbufmeths.get_extmarks - local line_count = curbufmeths.line_count + local get_extmarks = api.nvim_buf_get_extmarks + local line_count = api.nvim_buf_line_count local s1 = { { 'Köttbullar', 'Comment' }, { 'Kräuterbutter' } } local s2 = { { 'こんにちは', 'Comment' } } - set_virtual_text(id1, 0, s1, {}) + set_virtual_text(0, id1, 0, s1, {}) eq({ { 1, @@ -719,10 +719,10 @@ describe('Buffer highlighting', function() virt_text_hide = false, }, }, - }, get_extmarks(id1, { 0, 0 }, { 0, -1 }, { details = true })) + }, get_extmarks(0, id1, { 0, 0 }, { 0, -1 }, { details = true })) - local lastline = line_count() - set_virtual_text(id1, line_count(), s2, {}) + local lastline = line_count(0) + set_virtual_text(0, id1, line_count(0), s2, {}) eq({ { 3, @@ -739,9 +739,9 @@ describe('Buffer highlighting', function() virt_text_hide = false, }, }, - }, get_extmarks(id1, { lastline, 0 }, { lastline, -1 }, { details = true })) + }, get_extmarks(0, id1, { lastline, 0 }, { lastline, -1 }, { details = true })) - eq({}, get_extmarks(id1, { lastline + 9000, 0 }, { lastline + 9000, -1 }, {})) + eq({}, get_extmarks(0, id1, { lastline + 9000, 0 }, { lastline + 9000, -1 }, {})) end) it('is not highlighted by visual selection', function() @@ -814,7 +814,7 @@ describe('Buffer highlighting', function() | ]]) - clear_namespace(-1, 0, -1) + clear_namespace(0, -1, 0, -1) screen:expect([[ ^1 + 2{1:$} | 3 +{1:$} | @@ -869,7 +869,7 @@ describe('Buffer highlighting', function() end) it('works with color column', function() - eq(-1, set_virtual_text(-1, 3, { { '暗x事', 'Comment' } }, {})) + eq(-1, set_virtual_text(0, -1, 3, { { '暗x事', 'Comment' } }, {})) screen:expect { grid = [[ ^1 + 2 {3:=}{2: 3} | @@ -898,12 +898,11 @@ describe('Buffer highlighting', function() end) it('and virtual text use the same namespace counter', function() - local set_virtual_text = curbufmeths.set_virtual_text - eq(1, add_highlight(0, 'String', 0, 0, -1)) - eq(2, set_virtual_text(0, 0, { { '= text', 'Comment' } }, {})) - eq(3, meths.create_namespace('my-ns')) - eq(4, add_highlight(0, 'String', 0, 0, -1)) - eq(5, set_virtual_text(0, 0, { { '= text', 'Comment' } }, {})) - eq(6, meths.create_namespace('other-ns')) + eq(1, add_highlight(0, 0, 'String', 0, 0, -1)) + eq(2, set_virtual_text(0, 0, 0, { { '= text', 'Comment' } }, {})) + eq(3, api.nvim_create_namespace('my-ns')) + eq(4, add_highlight(0, 0, 'String', 0, 0, -1)) + eq(5, set_virtual_text(0, 0, 0, { { '= text', 'Comment' } }, {})) + eq(6, api.nvim_create_namespace('other-ns')) end) end) diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua index 4b3657f834..6c4000ba41 100644 --- a/test/functional/ui/cmdline_highlight_spec.lua +++ b/test/functional/ui/cmdline_highlight_spec.lua @@ -4,13 +4,12 @@ local Screen = require('test.functional.ui.screen') local eq = helpers.eq local feed = helpers.feed local clear = helpers.clear -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local source = helpers.source local exec_capture = helpers.exec_capture local dedent = helpers.dedent local command = helpers.command -local curbufmeths = helpers.curbufmeths local screen @@ -157,16 +156,16 @@ before_each(function() end) local function set_color_cb(funcname, callback_return, id) - meths.set_var('id', id or '') - if id and id ~= '' and funcs.exists('*' .. funcname .. 'N') then + api.nvim_set_var('id', id or '') + if id and id ~= '' and fn.exists('*' .. funcname .. 'N') then command(('let g:Nvim_color_input%s = {cmdline -> %sN(%s, cmdline)}'):format(id, funcname, id)) if callback_return then - meths.set_var('callback_return' .. id, callback_return) + api.nvim_set_var('callback_return' .. id, callback_return) end else - meths.set_var('Nvim_color_input', funcname) + api.nvim_set_var('Nvim_color_input', funcname) if callback_return then - meths.set_var('callback_return', callback_return) + api.nvim_set_var('callback_return', callback_return) end end end @@ -177,7 +176,7 @@ end describe('Command-line coloring', function() it('works', function() set_color_cb('RainBowParens') - meths.set_option_value('more', false, {}) + api.nvim_set_option_value('more', false, {}) start_prompt() screen:expect([[ | @@ -362,9 +361,9 @@ describe('Command-line coloring', function() | ]]) feed('\n') - eq('let x = "«»«»«»«»«»"', meths.get_var('out')) + eq('let x = "«»«»«»«»«»"', api.nvim_get_var('out')) local msg = '\nE5405: Chunk 0 start 10 splits multibyte character' - eq(msg:rep(1), funcs.execute('messages')) + eq(msg:rep(1), fn.execute('messages')) end) it('allows interrupting callback with <C-c>', function() set_color_cb('Halting') @@ -398,7 +397,7 @@ describe('Command-line coloring', function() :echo 42 | ]]) feed('\n') - eq('echo 42', meths.get_var('out')) + eq('echo 42', api.nvim_get_var('out')) feed('<C-c>') screen:expect([[ ^ | @@ -503,9 +502,9 @@ describe('Command-line coloring', function() ]])) eq( { '', ':', 'E888 detected for \\ze*', ':', 'E888 detected for \\zs*' }, - curbufmeths.get_lines(0, -1, false) + api.nvim_buf_get_lines(0, 0, -1, false) ) - eq('', funcs.execute('messages')) + eq('', fn.execute('messages')) end) it('allows nesting input()s', function() set_color_cb('ReturningGlobal', { { 0, 1, 'RBP1' } }, '') @@ -564,16 +563,16 @@ describe('Command-line coloring', function() {EOB:~ }|*6 | ]]) - eq('1234', meths.get_var('out')) - eq('234', meths.get_var('out1')) - eq('34', meths.get_var('out2')) - eq('4', meths.get_var('out3')) - eq(0, funcs.exists('g:out4')) + eq('1234', api.nvim_get_var('out')) + eq('234', api.nvim_get_var('out1')) + eq('34', api.nvim_get_var('out2')) + eq('4', api.nvim_get_var('out3')) + eq(0, fn.exists('g:out4')) end) it('runs callback with the same data only once', function() local function new_recording_calls(...) - eq({ ... }, meths.get_var('recording_calls')) - meths.set_var('recording_calls', {}) + eq({ ... }, api.nvim_get_var('recording_calls')) + api.nvim_set_var('recording_calls', {}) end set_color_cb('Recording') start_prompt('') @@ -594,7 +593,7 @@ describe('Command-line coloring', function() feed('<BS>') new_recording_calls() -- ('a') feed('<CR><CR>') - eq('', meths.get_var('out')) + eq('', api.nvim_get_var('out')) end) it('does not crash when callback has caught not-a-editor-command exception', function() source([[ @@ -609,12 +608,12 @@ describe('Command-line coloring', function() ]]) set_color_cb('CaughtExc') start_prompt('1') - eq(1, meths.eval('1')) + eq(1, api.nvim_eval('1')) end) end) describe('Ex commands coloring', function() it('works', function() - meths.set_var('Nvim_color_cmdline', 'RainBowParens') + api.nvim_set_var('Nvim_color_cmdline', 'RainBowParens') feed(':echo (((1)))') screen:expect([[ | @@ -623,11 +622,11 @@ describe('Ex commands coloring', function() ]]) end) it('still executes command-line even if errored out', function() - meths.set_var('Nvim_color_cmdline', 'SplitMultibyteStart') + api.nvim_set_var('Nvim_color_cmdline', 'SplitMultibyteStart') feed(':let x = "«"\n') - eq('«', meths.get_var('x')) + eq('«', api.nvim_get_var('x')) local msg = 'E5405: Chunk 0 start 10 splits multibyte character' - eq('\n' .. msg, funcs.execute('messages')) + eq('\n' .. msg, fn.execute('messages')) end) it('does not error out when called from a errorred out cycle', function() -- Apparently when there is a cycle in which one of the commands errors out @@ -646,9 +645,9 @@ describe('Ex commands coloring', function() ]])) eq( { '', 'E888 detected for \\ze*', 'E888 detected for \\zs*' }, - curbufmeths.get_lines(0, -1, false) + api.nvim_buf_get_lines(0, 0, -1, false) ) - eq('', funcs.execute('messages')) + eq('', fn.execute('messages')) end) it('does not crash when using `n` in debug mode', function() feed(':debug execute "echo 1"\n') @@ -709,7 +708,7 @@ describe('Ex commands coloring', function() ) end) it('errors out when failing to get callback', function() - meths.set_var('Nvim_color_cmdline', 42) + api.nvim_set_var('Nvim_color_cmdline', 42) feed(':#') screen:expect([[ | @@ -725,10 +724,10 @@ describe('Ex commands coloring', function() end) describe('Expressions coloring support', function() it('works', function() - meths.command('hi clear NvimNumber') - meths.command('hi clear NvimNestingParenthesis') - meths.command('hi NvimNumber guifg=Blue2') - meths.command('hi NvimNestingParenthesis guifg=Yellow') + command('hi clear NvimNumber') + command('hi clear NvimNestingParenthesis') + command('hi NvimNumber guifg=Blue2') + command('hi NvimNestingParenthesis guifg=Yellow') feed(':echo <C-r>=(((1)))') screen:expect([[ | @@ -737,10 +736,10 @@ describe('Expressions coloring support', function() ]]) end) it('does not use Nvim_color_expr', function() - meths.set_var('Nvim_color_expr', 42) + api.nvim_set_var('Nvim_color_expr', 42) -- Used to error out due to failing to get callback. - meths.command('hi clear NvimNumber') - meths.command('hi NvimNumber guifg=Blue2') + command('hi clear NvimNumber') + command('hi NvimNumber guifg=Blue2') feed(':<C-r>=1') screen:expect([[ | @@ -749,12 +748,12 @@ describe('Expressions coloring support', function() ]]) end) it('works correctly with non-ASCII and control characters', function() - meths.command('hi clear NvimStringBody') - meths.command('hi clear NvimStringQuote') - meths.command('hi clear NvimInvalid') - meths.command('hi NvimStringQuote guifg=Blue3') - meths.command('hi NvimStringBody guifg=Blue4') - meths.command('hi NvimInvalid guifg=Red guibg=Blue') + command('hi clear NvimStringBody') + command('hi clear NvimStringQuote') + command('hi clear NvimInvalid') + command('hi NvimStringQuote guifg=Blue3') + command('hi NvimStringBody guifg=Blue4') + command('hi NvimInvalid guifg=Red guibg=Blue') feed('i<C-r>="«»"«»') screen:expect([[ | @@ -787,7 +786,7 @@ describe('Expressions coloring support', function() {EOB:~ }|*6 :^ | ]]) - funcs.setreg('a', { '\192' }) + fn.setreg('a', { '\192' }) feed('<C-r>="<C-r><C-r>a"<C-r><C-r>a"foo"') screen:expect([[ | diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 82ff633fcb..40221269a8 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -9,7 +9,7 @@ local exec = helpers.exec local eval = helpers.eval local eq = helpers.eq local is_os = helpers.is_os -local meths = helpers.meths +local api = helpers.api local function new_screen(opt) local screen = Screen.new(25, 5) @@ -922,7 +922,7 @@ describe('cmdline redraw', function() it('with rightleftcmd', function() command('set rightleft rightleftcmd=search shortmess+=s') - meths.buf_set_lines(0, 0, -1, true, { "let's rock!" }) + api.nvim_buf_set_lines(0, 0, -1, true, { "let's rock!" }) screen:expect { grid = [[ !kcor s'te^l| @@ -1531,7 +1531,7 @@ describe('cmdheight=0', function() it('with multigrid', function() clear { args = { '--cmd', 'set cmdheight=0' } } screen:attach { ext_multigrid = true } - meths.buf_set_lines(0, 0, -1, true, { 'p' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'p' }) screen:expect { grid = [[ ## grid 1 @@ -1701,9 +1701,9 @@ describe('cmdheight=0', function() {1:~ }|*3 {3:[No Name] }| ]]) - meths.input_mouse('left', 'press', '', 0, 6, 10) + api.nvim_input_mouse('left', 'press', '', 0, 6, 10) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 5, 10) + api.nvim_input_mouse('left', 'drag', '', 0, 5, 10) screen:expect_unchanged() end) end) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 9b3de1e108..8d58c11302 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, meths = helpers.clear, helpers.meths +local clear, api = helpers.clear, helpers.api local eq = helpers.eq local command = helpers.command @@ -299,7 +299,7 @@ describe('ui/cursor', function() } -- Another cursor style. - meths.set_option_value( + api.nvim_set_option_value( 'guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173' .. ',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42', @@ -326,7 +326,7 @@ describe('ui/cursor', function() end) -- If there is no setting for guicursor, it becomes the default setting. - meths.set_option_value( + api.nvim_set_option_value( 'guicursor', 'n:ver35-blinkwait171-blinkoff172-blinkon173-Cursor/lCursor', {} @@ -346,7 +346,7 @@ describe('ui/cursor', function() end) it("empty 'guicursor' sets cursor_shape=block in all modes", function() - meths.set_option_value('guicursor', '', {}) + api.nvim_set_option_value('guicursor', '', {}) screen:expect(function() -- Empty 'guicursor' sets enabled=false. eq(false, screen._cursor_style_enabled) diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index d6a0205b7e..186bf19214 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -7,9 +7,8 @@ local insert = helpers.insert local exec_lua = helpers.exec_lua local exec = helpers.exec local expect_events = helpers.expect_events -local meths = helpers.meths -local funcs = helpers.funcs -local curbufmeths = helpers.curbufmeths +local api = helpers.api +local fn = helpers.fn local command = helpers.command local eq = helpers.eq local assert_alive = helpers.assert_alive @@ -243,8 +242,8 @@ describe('decorations providers', function() ]]} -- spell=false with higher priority does disable spell - local ns = meths.create_namespace "spell" - local id = curbufmeths.set_extmark(ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false }) + local ns = api.nvim_create_namespace "spell" + local id = api.nvim_buf_set_extmark(0, ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false }) screen:expect{grid=[[ I am well written text. | @@ -267,7 +266,7 @@ describe('decorations providers', function() command('echo ""') -- spell=false with lower priority doesn't disable spell - curbufmeths.set_extmark(ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false }) screen:expect{grid=[[ I am well written text. | @@ -306,7 +305,7 @@ describe('decorations providers', function() LineNr = {italic=true, bg="Magenta"}; Comment = {fg="#FF0000", bg = 80*256+40}; CursorLine = {link="ErrorMsg"}; - } do meths.set_hl(ns1, k, v) end + } do api.nvim_set_hl(ns1, k, v) end screen:expect{grid=[[ {3: 1 }{4:// just to see if there was an accid}| @@ -327,7 +326,7 @@ describe('decorations providers', function() | ]]} - meths.set_hl_ns(ns1) + api.nvim_set_hl_ns(ns1) screen:expect{grid=[[ {10: 1 }{11:// just to see if there was an accid}| {10: }{11:ent} | @@ -387,7 +386,7 @@ describe('decorations providers', function() highlight link LinkGroup OriginalGroup ]] - meths.buf_set_virtual_text(0, 0, 2, {{'- not red', 'LinkGroup'}}, {}) + api.nvim_buf_set_virtual_text(0, 0, 2, {{'- not red', 'LinkGroup'}}, {}) screen:expect{grid=[[ // just to see if there was an accident | // on Mulholland Drive | @@ -399,8 +398,8 @@ describe('decorations providers', function() | ]]} - meths.set_hl(ns1, 'LinkGroup', {fg = 'Blue'}) - meths.set_hl_ns(ns1) + api.nvim_set_hl(ns1, 'LinkGroup', {fg = 'Blue'}) + api.nvim_set_hl_ns(ns1) screen:expect{grid=[[ // just to see if there was an accident | @@ -423,7 +422,7 @@ describe('decorations providers', function() highlight link LinkGroup OriginalGroup ]] - meths.buf_set_virtual_text(0, 0, 2, {{'- not red', 'LinkGroup'}}, {}) + api.nvim_buf_set_virtual_text(0, 0, 2, {{'- not red', 'LinkGroup'}}, {}) screen:expect{grid=[[ // just to see if there was an accident | // on Mulholland Drive | @@ -435,8 +434,8 @@ describe('decorations providers', function() | ]]} - meths.set_hl(ns1, 'LinkGroup', {fg = 'Blue', default=true}) - meths.set_hl_ns(ns1) + api.nvim_set_hl(ns1, 'LinkGroup', {fg = 'Blue', default=true}) + api.nvim_set_hl_ns(ns1) feed 'k' screen:expect{grid=[[ @@ -626,7 +625,7 @@ describe('decorations providers', function() end ]]) command([[autocmd CursorMoved * call line('w$')]]) - meths.win_set_cursor(0, {100, 0}) + api.nvim_win_set_cursor(0, {100, 0}) screen:expect([[ {14: }hello97 | {14: }hello98 | @@ -637,7 +636,7 @@ describe('decorations providers', function() {14: }hello103 | | ]]) - meths.win_set_cursor(0, {1, 0}) + api.nvim_win_set_cursor(0, {1, 0}) screen:expect([[ ^hello1 | hello2 | @@ -766,7 +765,7 @@ describe('extmark decorations', function() [43] = {background = Screen.colors.Yellow, undercurl = true, special = Screen.colors.Red}; } - ns = meths.create_namespace 'test' + ns = api.nvim_create_namespace 'test' end) it('empty virtual text at eol should not break colorcolumn #17860', function() @@ -789,7 +788,7 @@ describe('extmark decorations', function() {1:~ }|*2 | ]]) - meths.buf_set_extmark(0, ns, 4, 0, { virt_text={{''}}, virt_text_pos='eol'}) + api.nvim_buf_set_extmark(0, ns, 4, 0, { virt_text={{''}}, virt_text_pos='eol'}) screen:expect_unchanged() end) @@ -798,19 +797,19 @@ describe('extmark decorations', function() feed 'gg' for i = 1,9 do - meths.buf_set_extmark(0, ns, i, 0, { virt_text={{'|', 'LineNr'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, i, 0, { virt_text={{'|', 'LineNr'}}, virt_text_pos='overlay'}) if i == 3 or (i >= 6 and i <= 9) then - meths.buf_set_extmark(0, ns, i, 4, { virt_text={{'|', 'NonText'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, i, 4, { virt_text={{'|', 'NonText'}}, virt_text_pos='overlay'}) end end - meths.buf_set_extmark(0, ns, 9, 10, { virt_text={{'foo'}, {'bar', 'MoreMsg'}, {'!!', 'ErrorMsg'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, 9, 10, { virt_text={{'foo'}, {'bar', 'MoreMsg'}, {'!!', 'ErrorMsg'}}, virt_text_pos='overlay'}) -- can "float" beyond end of line - meths.buf_set_extmark(0, ns, 5, 28, { virt_text={{'loopy', 'ErrorMsg'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, 5, 28, { virt_text={{'loopy', 'ErrorMsg'}}, virt_text_pos='overlay'}) -- bound check: right edge of window - meths.buf_set_extmark(0, ns, 2, 26, { virt_text={{'bork bork bork'}, {(' bork'):rep(10), 'ErrorMsg'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, 2, 26, { virt_text={{'bork bork bork'}, {(' bork'):rep(10), 'ErrorMsg'}}, virt_text_pos='overlay'}) -- empty virt_text should not change anything - meths.buf_set_extmark(0, ns, 6, 16, { virt_text={{''}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, 6, 16, { virt_text={{''}}, virt_text_pos='overlay'}) screen:expect{grid=[[ ^for _,item in ipairs(items) do | @@ -859,12 +858,12 @@ describe('extmark decorations', function() ]]} -- truncating in the middle of a char leaves a space - meths.buf_set_lines(0, 0, 1, true, {'for _,item in ipairs(items) do -- 古古古'}) - meths.buf_set_lines(0, 10, 12, true, {' end -- ??????????', 'end -- ?古古古古?古古'}) - meths.buf_set_extmark(0, ns, 0, 35, { virt_text={{'A', 'ErrorMsg'}, {'AA'}}, virt_text_pos='overlay'}) - meths.buf_set_extmark(0, ns, 10, 19, { virt_text={{'口口口', 'ErrorMsg'}}, virt_text_pos='overlay'}) - meths.buf_set_extmark(0, ns, 11, 21, { virt_text={{'口口口', 'ErrorMsg'}}, virt_text_pos='overlay'}) - meths.buf_set_extmark(0, ns, 11, 8, { virt_text={{'口口', 'ErrorMsg'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_lines(0, 0, 1, true, {'for _,item in ipairs(items) do -- 古古古'}) + api.nvim_buf_set_lines(0, 10, 12, true, {' end -- ??????????', 'end -- ?古古古古?古古'}) + api.nvim_buf_set_extmark(0, ns, 0, 35, { virt_text={{'A', 'ErrorMsg'}, {'AA'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, 10, 19, { virt_text={{'口口口', 'ErrorMsg'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, 11, 21, { virt_text={{'口口口', 'ErrorMsg'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, 11, 8, { virt_text={{'口口', 'ErrorMsg'}}, virt_text_pos='overlay'}) screen:expect{grid=[[ ^for _,item in ipairs(i| tems) do -- {4:A}AA 古 | @@ -909,7 +908,7 @@ describe('extmark decorations', function() | ]]} - meths.buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_clear_namespace(0, ns, 0, -1) screen:expect{grid=[[ ^for _,item in ipairs(items) do -- 古古古 | local text, hl_id_cell, count = unpack(item) | @@ -931,8 +930,8 @@ describe('extmark decorations', function() screen:try_resize(50, 6) insert(('ab'):rep(100)) for i = 0, 9 do - meths.buf_set_extmark(0, ns, 0, 42 + i, { virt_text={{tostring(i), 'ErrorMsg'}}, virt_text_pos='overlay'}) - meths.buf_set_extmark(0, ns, 0, 91 + i, { virt_text={{tostring(i), 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true}) + api.nvim_buf_set_extmark(0, ns, 0, 42 + i, { virt_text={{tostring(i), 'ErrorMsg'}}, virt_text_pos='overlay'}) + api.nvim_buf_set_extmark(0, ns, 0, 91 + i, { virt_text={{tostring(i), 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true}) end screen:expect{grid=[[ ababababababababababababababababababababab{4:01234567}| @@ -1028,9 +1027,9 @@ describe('extmark decorations', function() it('virt_text_hide hides overlay virtual text when extmark is off-screen', function() screen:try_resize(50, 3) command('set nowrap') - meths.buf_set_lines(0, 0, -1, true, {'-- ' .. ('…'):rep(57)}) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text={{'?????', 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true}) - meths.buf_set_extmark(0, ns, 0, 123, { virt_text={{'!!!!!', 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true}) + api.nvim_buf_set_lines(0, 0, -1, true, {'-- ' .. ('…'):rep(57)}) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text={{'?????', 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true}) + api.nvim_buf_set_extmark(0, ns, 0, 123, { virt_text={{'!!!!!', 'ErrorMsg'}}, virt_text_pos='overlay', virt_text_hide=true}) screen:expect{grid=[[ {4:^?????}……………………………………………………………………………………………………{4:!!!!!}……| {1:~ }| @@ -1083,10 +1082,10 @@ describe('extmark decorations', function() it('overlay virtual text works on and after a TAB #24022', function() screen:try_resize(40, 3) - meths.buf_set_lines(0, 0, -1, true, {'\t\tline 1'}) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 0, 1, { virt_text = {{'BB', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 0, 2, { virt_text = {{'CC', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' }) + api.nvim_buf_set_lines(0, 0, -1, true, {'\t\tline 1'}) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 0, 1, { virt_text = {{'BB', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 0, 2, { virt_text = {{'CC', 'Search'}}, virt_text_pos = 'overlay', hl_mode = 'combine' }) screen:expect{grid=[[ {34:AA} ^ {34:BB} {34:CC}ne 1 | {1:~ }| @@ -1125,13 +1124,13 @@ describe('extmark decorations', function() ]]} command 'hi Blendy guibg=Red blend=30' - meths.buf_set_extmark(0, ns, 1, 5, { virt_text={{'blendy text - here', 'Blendy'}}, virt_text_pos='overlay', hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 2, 5, { virt_text={{'combining color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='combine'}) - meths.buf_set_extmark(0, ns, 3, 5, { virt_text={{'replacing color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='replace'}) + api.nvim_buf_set_extmark(0, ns, 1, 5, { virt_text={{'blendy text - here', 'Blendy'}}, virt_text_pos='overlay', hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 2, 5, { virt_text={{'combining color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='combine'}) + api.nvim_buf_set_extmark(0, ns, 3, 5, { virt_text={{'replacing color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='replace'}) - meths.buf_set_extmark(0, ns, 4, 5, { virt_text={{'blendy text - here', 'Blendy'}}, virt_text_pos='overlay', hl_mode='blend', virt_text_hide=true}) - meths.buf_set_extmark(0, ns, 5, 5, { virt_text={{'combining color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='combine', virt_text_hide=true}) - meths.buf_set_extmark(0, ns, 6, 5, { virt_text={{'replacing color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='replace', virt_text_hide=true}) + api.nvim_buf_set_extmark(0, ns, 4, 5, { virt_text={{'blendy text - here', 'Blendy'}}, virt_text_pos='overlay', hl_mode='blend', virt_text_hide=true}) + api.nvim_buf_set_extmark(0, ns, 5, 5, { virt_text={{'combining color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='combine', virt_text_hide=true}) + api.nvim_buf_set_extmark(0, ns, 6, 5, { virt_text={{'replacing color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='replace', virt_text_hide=true}) screen:expect{grid=[[ {5:^for} _,item {5:in} {6:ipairs}(items) {5:do} | @@ -1190,17 +1189,17 @@ describe('extmark decorations', function() it('can have virtual text of right_align and fixed win_col position', function() insert(example_text) feed 'gg' - meths.buf_set_extmark(0, ns, 1, 0, { virt_text={{'Very', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 1, 0, { virt_text={{'VERY', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 2, 10, { virt_text={{'Much', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 2, 10, { virt_text={{'MUCH', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 3, 14, { virt_text={{'Error', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 3, 14, { virt_text={{'ERROR', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 7, 21, { virt_text={{'-', 'NonText'}}, virt_text_win_col=4, hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 7, 21, { virt_text={{'-', 'NonText'}}, virt_text_pos='right_align', hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 1, 0, { virt_text={{'Very', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 1, 0, { virt_text={{'VERY', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 2, 10, { virt_text={{'Much', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 2, 10, { virt_text={{'MUCH', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 3, 14, { virt_text={{'Error', 'ErrorMsg'}}, virt_text_win_col=31, hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 3, 14, { virt_text={{'ERROR', 'ErrorMsg'}}, virt_text_pos='right_align', hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 7, 21, { virt_text={{'-', 'NonText'}}, virt_text_win_col=4, hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 7, 21, { virt_text={{'-', 'NonText'}}, virt_text_pos='right_align', hl_mode='blend'}) -- empty virt_text should not change anything - meths.buf_set_extmark(0, ns, 8, 0, { virt_text={{''}}, virt_text_win_col=14, hl_mode='blend'}) - meths.buf_set_extmark(0, ns, 8, 0, { virt_text={{''}}, virt_text_pos='right_align', hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 8, 0, { virt_text={{''}}, virt_text_win_col=14, hl_mode='blend'}) + api.nvim_buf_set_extmark(0, ns, 8, 0, { virt_text={{''}}, virt_text_pos='right_align', hl_mode='blend'}) screen:expect{grid=[[ ^for _,item in ipairs(items) do | @@ -1294,7 +1293,7 @@ describe('extmark decorations', function() | ]]} - meths.buf_set_extmark(0, ns, 4, 50, { virt_text={{'EOL', 'NonText'}} }) + api.nvim_buf_set_extmark(0, ns, 4, 50, { virt_text={{'EOL', 'NonText'}} }) screen:expect{grid=[[ for _,item in ipairs(items) do | local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}| @@ -1450,7 +1449,7 @@ describe('extmark decorations', function() it('virtual text win_col out of window does not break display #25645', function() screen:try_resize(51, 6) command('vnew') - meths.buf_set_lines(0, 0, -1, false, { string.rep('a', 50) }) + api.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 50) }) screen:expect{grid=[[ ^aaaaaaaaaaaaaaaaaaaaaaaaa│ | aaaaaaaaaaaaaaaaaaaaaaaaa│{1:~ }| @@ -1459,7 +1458,7 @@ describe('extmark decorations', function() | ]]} local extmark_opts = { virt_text_win_col = 35, virt_text = { { ' ', 'Comment' } } } - meths.buf_set_extmark(0, ns, 0, 0, extmark_opts) + api.nvim_buf_set_extmark(0, ns, 0, 0, extmark_opts) screen:expect_unchanged() assert_alive() end) @@ -1475,9 +1474,9 @@ describe('extmark decorations', function() -- XXX: the behavior of overlay virtual text at non-zero column is strange: -- 1. With 'wrap' it is never shown. -- 2. With 'nowrap' it is shown only if the extmark is hidden before leftcol. - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Underlined'}}, hl_mode = 'combine', virt_text_pos = 'overlay' }) - meths.buf_set_extmark(0, ns, 0, 5, { virt_text = {{'BB', 'Underlined'}}, hl_mode = 'combine', virt_text_win_col = 10 }) - meths.buf_set_extmark(0, ns, 0, 2, { virt_text = {{'CC', 'Underlined'}}, hl_mode = 'combine', virt_text_pos = 'right_align' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Underlined'}}, hl_mode = 'combine', virt_text_pos = 'overlay' }) + api.nvim_buf_set_extmark(0, ns, 0, 5, { virt_text = {{'BB', 'Underlined'}}, hl_mode = 'combine', virt_text_win_col = 10 }) + api.nvim_buf_set_extmark(0, ns, 0, 2, { virt_text = {{'CC', 'Underlined'}}, hl_mode = 'combine', virt_text_pos = 'right_align' }) screen:expect{grid=[[ {29:AA}{33:- 2 lin}{29:BB}{33:: 11111·····························}{29:CC}| 3333^3 | @@ -1520,9 +1519,9 @@ describe('extmark decorations', function() ddddd eeeee]]) command('windo diffthis') - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Underlined'}}, virt_text_pos = 'overlay' }) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'BB', 'Underlined'}}, virt_text_win_col = 10 }) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'CC', 'Underlined'}}, virt_text_pos = 'right_align' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'AA', 'Underlined'}}, virt_text_pos = 'overlay' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'BB', 'Underlined'}}, virt_text_win_col = 10 }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'CC', 'Underlined'}}, virt_text_pos = 'right_align' }) screen:expect{grid=[[ {37: }{38:aaaaa }│{37: }{39:------------------------}| {37: }bbbbb │{37: }{28:AA}bbb {28:BB} {28:CC}| @@ -1565,10 +1564,10 @@ describe('extmark decorations', function() {'d', {'BgTwo', 'FgZwei'}}; {'X', {'BgTwo', 'FgZwei', 'VeryBold'}}; } - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'eol' }) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'right_align' }) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 0, { virt_lines = { vt, vt } }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'eol' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'right_align' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = vt, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_lines = { vt, vt } }) screen:expect{grid=[[ {2:a}{3:b}{4:c}{5:d}{6:X}#^# {2:a}{3:b}{4:c}{5:d}{6:X} {2:a}{3:b}{4:c}{5:d}{6:X}| {2:a}{3:b}{4:c}{5:d}{6:X} |*2 @@ -1603,7 +1602,7 @@ describe('extmark decorations', function() it('conceal with conceal char #19007', function() screen:try_resize(50, 5) insert('foo\n') - meths.buf_set_extmark(0, ns, 0, 0, {end_col=0, end_row=2, conceal='X'}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {end_col=0, end_row=2, conceal='X'}) command('set conceallevel=2') screen:expect([[ {26:X} | @@ -1614,13 +1613,13 @@ describe('extmark decorations', function() command('set conceallevel=1') screen:expect_unchanged() - eq("conceal char has to be printable", pcall_err(meths.buf_set_extmark, 0, ns, 0, 0, {end_col=0, end_row=2, conceal='\255'})) + eq("conceal char has to be printable", pcall_err(api.nvim_buf_set_extmark, 0, ns, 0, 0, {end_col=0, end_row=2, conceal='\255'})) end) it('conceal with composed conceal char', function() screen:try_resize(50, 5) insert('foo\n') - meths.buf_set_extmark(0, ns, 0, 0, {end_col=0, end_row=2, conceal='ẍ̲'}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {end_col=0, end_row=2, conceal='ẍ̲'}) command('set conceallevel=2') screen:expect([[ {26:ẍ̲} | @@ -1632,7 +1631,7 @@ describe('extmark decorations', function() screen:expect_unchanged() -- this is rare, but could happen. Save at least the first codepoint - meths._invalidate_glyph_cache() + api.nvim__invalidate_glyph_cache() screen:expect{grid=[[ {26:x} | ^ | @@ -1644,7 +1643,7 @@ describe('extmark decorations', function() it('conceal without conceal char #24782', function() screen:try_resize(50, 5) insert('foobar\n') - meths.buf_set_extmark(0, ns, 0, 0, {end_col=3, conceal=''}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {end_col=3, conceal=''}) command('set listchars=conceal:?') command('let &conceallevel=1') screen:expect([[ @@ -1664,8 +1663,8 @@ describe('extmark decorations', function() it('conceal works just before truncated double-width char #21486', function() screen:try_resize(40, 4) - meths.buf_set_lines(0, 0, -1, true, {'', ('a'):rep(37) .. '<>古'}) - meths.buf_set_extmark(0, ns, 1, 37, {end_col=39, conceal=''}) + api.nvim_buf_set_lines(0, 0, -1, true, {'', ('a'):rep(37) .. '<>古'}) + api.nvim_buf_set_extmark(0, ns, 1, 37, {end_col=39, conceal=''}) command('setlocal conceallevel=2') screen:expect{grid=[[ ^ | @@ -1706,7 +1705,7 @@ describe('extmark decorations', function() ]] for _ = 1, 3 do - helpers.sleep(10) + vim.uv.sleep(10) feed 'j' end @@ -1739,32 +1738,32 @@ describe('extmark decorations', function() [6] = {bold = true, undercurl = true, special = Screen.colors.Red}; }) - meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 20 }) - meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUC', priority = 30 }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 20 }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUC', priority = 30 }) screen:expect([[ {1:aaa}{4:bbb}{1:aa^a} | {0:~ }| | ]]) - meths.buf_clear_namespace(0, ns, 0, -1) - meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 20 }) - meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUL', priority = 30 }) + api.nvim_buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 20 }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUL', priority = 30 }) screen:expect([[ {2:aaa}{3:bbb}{2:aa^a} | {0:~ }| | ]]) - meths.buf_clear_namespace(0, ns, 0, -1) - meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 30 }) - meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUC', priority = 20 }) + api.nvim_buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 30 }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUC', priority = 20 }) screen:expect([[ {1:aaa}{3:bbb}{1:aa^a} | {0:~ }| | ]]) - meths.buf_clear_namespace(0, ns, 0, -1) - meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 30 }) - meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUL', priority = 20 }) + api.nvim_buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 30 }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestUL', priority = 20 }) screen:expect([[ {2:aaa}{4:bbb}{2:aa^a} | {0:~ }| @@ -1773,14 +1772,14 @@ describe('extmark decorations', function() -- When only one highlight group has an underline attribute, it should always take effect. for _, d in ipairs({-5, 5}) do - meths.buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_clear_namespace(0, ns, 0, -1) screen:expect([[ aaabbbaa^a | {0:~ }| | ]]) - meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 25 + d }) - meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestBold', priority = 25 - d }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUL', priority = 25 + d }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestBold', priority = 25 - d }) screen:expect([[ {1:aaa}{5:bbb}{1:aa^a} | {0:~ }| @@ -1788,14 +1787,14 @@ describe('extmark decorations', function() ]]) end for _, d in ipairs({-5, 5}) do - meths.buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_clear_namespace(0, ns, 0, -1) screen:expect([[ aaabbbaa^a | {0:~ }| | ]]) - meths.buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 25 + d }) - meths.buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestBold', priority = 25 - d }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 9, hl_group = 'TestUC', priority = 25 + d }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { end_col = 6, hl_group = 'TestBold', priority = 25 - d }) screen:expect([[ {2:aaa}{6:bbb}{2:aa^a} | {0:~ }| @@ -1812,10 +1811,10 @@ describe('extmark decorations', function() feed('gg') command('set ft=lua') command('syntax on') - meths.buf_set_extmark(0, ns, 0, 0, { end_col = 3, hl_mode = 'combine', hl_group = 'Visual' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 3, hl_mode = 'combine', hl_group = 'Visual' }) command('hi default MyLine gui=underline') command('sign define CurrentLine linehl=MyLine') - funcs.sign_place(6, 'Test', 'CurrentLine', '', { lnum = 1 }) + fn.sign_place(6, 'Test', 'CurrentLine', '', { lnum = 1 }) screen:expect{grid=[[ {30:^fun}{31:ction}{32: Func() }| {6:end} | @@ -1826,8 +1825,8 @@ describe('extmark decorations', function() it('highlight works after TAB with sidescroll #14201', function() screen:try_resize(50, 3) command('set nowrap') - meths.buf_set_lines(0, 0, -1, true, {'\tword word word word'}) - meths.buf_set_extmark(0, ns, 0, 1, { end_col = 3, hl_group = 'ErrorMsg' }) + api.nvim_buf_set_lines(0, 0, -1, true, {'\tword word word word'}) + api.nvim_buf_set_extmark(0, ns, 0, 1, { end_col = 3, hl_group = 'ErrorMsg' }) screen:expect{grid=[[ ^ {4:wo}rd word word word | {1:~ }| @@ -1855,16 +1854,16 @@ describe('extmark decorations', function() it('highlights the beginning of a TAB char correctly #23734', function() screen:try_resize(50, 3) - meths.buf_set_lines(0, 0, -1, true, {'this is the\ttab'}) - meths.buf_set_extmark(0, ns, 0, 11, { end_col = 15, hl_group = 'ErrorMsg' }) + api.nvim_buf_set_lines(0, 0, -1, true, {'this is the\ttab'}) + api.nvim_buf_set_extmark(0, ns, 0, 11, { end_col = 15, hl_group = 'ErrorMsg' }) screen:expect{grid=[[ ^this is the{4: tab} | {1:~ }| | ]]} - meths.buf_clear_namespace(0, ns, 0, -1) - meths.buf_set_extmark(0, ns, 0, 12, { end_col = 15, hl_group = 'ErrorMsg' }) + api.nvim_buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_set_extmark(0, ns, 0, 12, { end_col = 15, hl_group = 'ErrorMsg' }) screen:expect{grid=[[ ^this is the {4:tab} | {1:~ }| @@ -1874,10 +1873,10 @@ describe('extmark decorations', function() it('highlight applies to a full TAB on line with matches #20885', function() screen:try_resize(50, 3) - meths.buf_set_lines(0, 0, -1, true, {'\t-- match1', ' -- match2'}) - funcs.matchadd('Underlined', 'match') - meths.buf_set_extmark(0, ns, 0, 0, { end_row = 1, end_col = 0, hl_group = 'Visual' }) - meths.buf_set_extmark(0, ns, 1, 0, { end_row = 2, end_col = 0, hl_group = 'Visual' }) + api.nvim_buf_set_lines(0, 0, -1, true, {'\t-- match1', ' -- match2'}) + fn.matchadd('Underlined', 'match') + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_row = 1, end_col = 0, hl_group = 'Visual' }) + api.nvim_buf_set_extmark(0, ns, 1, 0, { end_row = 2, end_col = 0, hl_group = 'Visual' }) screen:expect{grid=[[ {18: ^ -- }{29:match}{18:1} | {18: -- }{29:match}{18:2} | @@ -1887,8 +1886,8 @@ describe('extmark decorations', function() pending('highlight applies to a full TAB in visual block mode', function() screen:try_resize(50, 8) - meths.buf_set_lines(0, 0, -1, true, {'asdf', '\tasdf', '\tasdf', '\tasdf', 'asdf'}) - meths.buf_set_extmark(0, ns, 0, 0, {end_row = 5, end_col = 0, hl_group = 'Underlined'}) + api.nvim_buf_set_lines(0, 0, -1, true, {'asdf', '\tasdf', '\tasdf', '\tasdf', 'asdf'}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {end_row = 5, end_col = 0, hl_group = 'Underlined'}) screen:expect([[ {28:^asdf} | {28: asdf} |*3 @@ -1909,7 +1908,7 @@ describe('extmark decorations', function() it('highlight works properly with multibyte text and spell #26771', function() insert('口口\n') screen:try_resize(50, 3) - meths.buf_set_extmark(0, ns, 0, 0, { end_col = 3, hl_group = 'Search' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 3, hl_group = 'Search' }) screen:expect([[ {34:口}口 | ^ | @@ -1928,7 +1927,7 @@ describe('extmark decorations', function() feed 'gg' for _,i in ipairs {1,2,3,5,6,7} do for _,j in ipairs {2,5,10,15} do - meths.buf_set_extmark(0, ns, i, j, { end_col=j+2, hl_group = 'NonText'}) + api.nvim_buf_set_extmark(0, ns, i, j, { end_col=j+2, hl_group = 'NonText'}) end end screen:expect{grid=[[ @@ -1960,7 +1959,7 @@ describe('extmark decorations', function() | ]]} - meths.buf_set_extmark(0, ns, 1, 0, { end_line=8, end_col=10, hl_group = 'ErrorMsg'}) + api.nvim_buf_set_extmark(0, ns, 1, 0, { end_line=8, end_col=10, hl_group = 'ErrorMsg'}) screen:expect{grid=[[ {4:^ }{36: }{4:f}{36:or}{4: _ }{36:= }{4:1, }{36:(c}{4:ount or 1) do} | {4: }{36: }{4: }{36: }{4: lo}{36:ca}{4:l c}{36:el}{4:l = line[colpos]} | @@ -1978,7 +1977,7 @@ describe('extmark decorations', function() screen:try_resize(50, 5) insert(example_text) feed'gg' - meths.buf_set_extmark(0, ns, 0, 6, { end_col=13, hl_group = 'NonText', undo_restore=val}) + api.nvim_buf_set_extmark(0, ns, 0, 6, { end_col=13, hl_group = 'NonText', undo_restore=val}) screen:expect{grid=[[ ^for _,{1:item in} ipairs(items) do | local text, hl_id_cell, count = unpack(item) | @@ -1987,7 +1986,7 @@ describe('extmark decorations', function() | ]]} - meths.buf_set_text(0, 0, 4, 0, 8, {''}) + api.nvim_buf_set_text(0, 0, 4, 0, 8, {''}) screen:expect{grid=[[ ^for {1:em in} ipairs(items) do | local text, hl_id_cell, count = unpack(item) | @@ -2025,7 +2024,7 @@ describe('extmark decorations', function() eq({ { 1, 0, 8, { end_col = 13, end_right_gravity = false, end_row = 0, hl_eol = false, hl_group = "NonText", undo_restore = false, ns_id = 1, priority = 4096, right_gravity = true } } }, - meths.buf_get_extmarks(0, ns, {0,0}, {0, -1}, {details=true})) + api.nvim_buf_get_extmarks(0, ns, {0,0}, {0, -1}, {details=true})) end) it('virtual text works with rightleft', function() @@ -2033,10 +2032,10 @@ describe('extmark decorations', function() insert('abcdefghijklmn') feed('0') command('set rightleft') - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'EOL', 'Underlined'}}}) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'right_align', 'Underlined'}}, virt_text_pos = 'right_align' }) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'win_col', 'Underlined'}}, virt_text_win_col = 20 }) - meths.buf_set_extmark(0, ns, 0, 2, { virt_text = {{'overlayed', 'Underlined'}}, virt_text_pos = 'overlay' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'EOL', 'Underlined'}}}) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'right_align', 'Underlined'}}, virt_text_pos = 'right_align' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'win_col', 'Underlined'}}, virt_text_win_col = 20 }) + api.nvim_buf_set_extmark(0, ns, 0, 2, { virt_text = {{'overlayed', 'Underlined'}}, virt_text_pos = 'overlay' }) screen:expect{grid=[[ {28:ngila_thgir} {28:loc_niw} {28:LOE} nml{28:deyalrevo}b^a| {1: ~}| @@ -2086,7 +2085,7 @@ describe('extmark decorations', function() screen:try_resize(50, 3) insert('abcdefghij口klmnopqrstu口vwx口yz') feed('0') - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'!!!!!', 'Underlined'}}, virt_text_win_col = 11 }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'!!!!!', 'Underlined'}}, virt_text_win_col = 11 }) screen:expect{grid=[[ ^abcdefghij {28:!!!!!}opqrstu口vwx口yz | {1:~ }| @@ -2117,7 +2116,7 @@ describe('extmark decorations', function() insert('abcdefghij口klmnopqrstu口vwx口yz') feed('0') command('hi Blendy guibg=Red blend=30') - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{' ! ! ', 'Blendy'}}, virt_text_win_col = 8, hl_mode = 'blend' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{' ! ! ', 'Blendy'}}, virt_text_win_col = 8, hl_mode = 'blend' }) screen:expect{grid=[[ ^abcdefgh{10:i}{7:!}{10:口}{7:!}{10:l}mnopqrstu口vwx口yz | {1:~ }| @@ -2159,10 +2158,10 @@ describe('extmark decorations', function() {1: ~}| | ]]} - meths.buf_set_extmark(0, ns, 0, 2, { virt_text = {{'overlayed', 'Underlined'}}, virt_text_pos = 'overlay' }) - meths.buf_set_extmark(0, ns, 0, 14, { virt_text = {{'古', 'Underlined'}}, virt_text_pos = 'overlay' }) - meths.buf_set_extmark(0, ns, 0, 20, { virt_text = {{'\t', 'Underlined'}}, virt_text_pos = 'overlay' }) - meths.buf_set_extmark(0, ns, 0, 29, { virt_text = {{'古', 'Underlined'}}, virt_text_pos = 'overlay' }) + api.nvim_buf_set_extmark(0, ns, 0, 2, { virt_text = {{'overlayed', 'Underlined'}}, virt_text_pos = 'overlay' }) + api.nvim_buf_set_extmark(0, ns, 0, 14, { virt_text = {{'古', 'Underlined'}}, virt_text_pos = 'overlay' }) + api.nvim_buf_set_extmark(0, ns, 0, 20, { virt_text = {{'\t', 'Underlined'}}, virt_text_pos = 'overlay' }) + api.nvim_buf_set_extmark(0, ns, 0, 29, { virt_text = {{'古', 'Underlined'}}, virt_text_pos = 'overlay' }) screen:expect{grid=[[ zy {28:古}wv {28: }qpon{28:古}k {28:deyalrevo}b^a| {1: ~}| @@ -2173,7 +2172,7 @@ describe('extmark decorations', function() it('works with both hl_group and sign_hl_group', function() screen:try_resize(screen._width, 3) insert('abcdefghijklmn') - meths.buf_set_extmark(0, ns, 0, 0, {sign_text='S', sign_hl_group='NonText', hl_group='Error', end_col=14}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {sign_text='S', sign_hl_group='NonText', hl_group='Error', end_col=14}) screen:expect{grid=[[ {1:S }{4:abcdefghijklm^n} | {1:~ }| @@ -2183,10 +2182,10 @@ describe('extmark decorations', function() it('virt_text_repeat_linebreak repeats virtual text on wrapped lines', function() screen:try_resize(40, 5) - meths.set_option_value('breakindent', true, {}) + api.nvim_set_option_value('breakindent', true, {}) insert(example_text) - meths.buf_set_extmark(0, ns, 1, 0, { virt_text = {{'│', 'NonText'}}, virt_text_pos = 'overlay', virt_text_repeat_linebreak = true }) - meths.buf_set_extmark(0, ns, 1, 3, { virt_text = {{'│', 'NonText'}}, virt_text_pos = 'overlay', virt_text_repeat_linebreak = true }) + api.nvim_buf_set_extmark(0, ns, 1, 0, { virt_text = {{'│', 'NonText'}}, virt_text_pos = 'overlay', virt_text_repeat_linebreak = true }) + api.nvim_buf_set_extmark(0, ns, 1, 3, { virt_text = {{'│', 'NonText'}}, virt_text_pos = 'overlay', virt_text_repeat_linebreak = true }) command('norm gg') screen:expect{grid=[[ ^for _,item in ipairs(items) do | @@ -2195,9 +2194,9 @@ describe('extmark decorations', function() if hl_id_cell ~= nil then | | ]]} - meths.buf_clear_namespace(0, ns, 0, -1) - meths.buf_set_extmark(0, ns, 1, 0, { virt_text = {{'│', 'NonText'}}, virt_text_repeat_linebreak = true, virt_text_win_col = 0 }) - meths.buf_set_extmark(0, ns, 1, 0, { virt_text = {{'│', 'NonText'}}, virt_text_repeat_linebreak = true, virt_text_win_col = 2 }) + api.nvim_buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_set_extmark(0, ns, 1, 0, { virt_text = {{'│', 'NonText'}}, virt_text_repeat_linebreak = true, virt_text_win_col = 0 }) + api.nvim_buf_set_extmark(0, ns, 1, 0, { virt_text = {{'│', 'NonText'}}, virt_text_repeat_linebreak = true, virt_text_win_col = 2 }) screen:expect{grid=[[ ^for _,item in ipairs(items) do | {1:│} {1:│} local text, hl_id_cell, count = unpa| @@ -2238,7 +2237,7 @@ describe('decorations: inline virtual text', function() [21] = {reverse = true, foreground = Screen.colors.SlateBlue} } - ns = meths.create_namespace 'test' + ns = api.nvim_create_namespace 'test' end) @@ -2259,7 +2258,7 @@ describe('decorations: inline virtual text', function() | ]]} - meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{': ', 'Special'}, {'string', 'Type'}}, virt_text_pos='inline'}) + api.nvim_buf_set_extmark(0, ns, 1, 14, {virt_text={{': ', 'Special'}, {'string', 'Type'}}, virt_text_pos='inline'}) screen:expect{grid=[[ ^for _,item in ipairs(items) do | local text{10:: }{3:string}, hl_id_cell, count = unpack| @@ -2319,9 +2318,9 @@ describe('decorations: inline virtual text', function() | ]]} - meths.buf_set_extmark(0, ns, 0, 5, {virt_text={{''}, {''}}, virt_text_pos='inline'}) - meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {': ', 'Special'}}, virt_text_pos='inline'}) - meths.buf_set_extmark(0, ns, 1, 48, {virt_text={{''}, {''}}, virt_text_pos='inline'}) + api.nvim_buf_set_extmark(0, ns, 0, 5, {virt_text={{''}, {''}}, virt_text_pos='inline'}) + api.nvim_buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {': ', 'Special'}}, virt_text_pos='inline'}) + api.nvim_buf_set_extmark(0, ns, 1, 48, {virt_text={{''}, {''}}, virt_text_pos='inline'}) screen:expect{grid=[[ ^for _,item in ipairs(items) do | local text{10:: }, hl_id_cell, count = unpack(item)| @@ -2335,7 +2334,7 @@ describe('decorations: inline virtual text', function() | ]]} - meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {'string', 'Type'}}, virt_text_pos='inline'}) + api.nvim_buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {'string', 'Type'}}, virt_text_pos='inline'}) feed('V') screen:expect{grid=[[ ^f{7:or _,item in ipairs(items) do} | @@ -2367,8 +2366,8 @@ describe('decorations: inline virtual text', function() it('Normal mode "gM" command works properly', function() command([[call setline(1, '123456789')]]) - meths.buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 7, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 7, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' }) feed('gM') screen:expect{grid=[[ 12{10:bbb}34^567{10:bbb}89 | @@ -2380,8 +2379,8 @@ describe('decorations: inline virtual text', function() local function test_normal_gj_gk() screen:try_resize(60, 6) command([[call setline(1, repeat([repeat('a', 55)], 2))]]) - meths.buf_set_extmark(0, ns, 0, 40, { virt_text = { { ('b'):rep(10), 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 1, 40, { virt_text = { { ('b'):rep(10), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 40, { virt_text = { { ('b'):rep(10), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 1, 40, { virt_text = { { ('b'):rep(10), 'Special' } }, virt_text_pos = 'inline' }) screen:expect{grid=[[ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{10:bbbbbbbbbb}aaaaaaaaaa| aaaaa | @@ -2459,8 +2458,8 @@ describe('decorations: inline virtual text', function() it('cursor positions are correct with multiple inline virtual text', function() insert('12345678') - meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' }) feed '^' feed '4l' screen:expect{grid=[[ @@ -2473,7 +2472,7 @@ describe('decorations: inline virtual text', function() it('adjusts cursor location correctly when inserting around inline virtual text', function() insert('12345678') feed '$' - meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 4, { virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' }) screen:expect{grid=[[ 1234{10: virtual text }567^8 | @@ -2484,7 +2483,7 @@ describe('decorations: inline virtual text', function() it('has correct highlighting with multi-byte characters', function() insert('12345678') - meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { 'múlti-byté chñröcters 修补', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 4, { virt_text = { { 'múlti-byté chñröcters 修补', 'Special' } }, virt_text_pos = 'inline' }) screen:expect{grid=[[ 1234{10:múlti-byté chñröcters 修补}567^8 | @@ -2495,7 +2494,7 @@ describe('decorations: inline virtual text', function() it('has correct cursor position when inserting around virtual text', function() insert('12345678') - meths.buf_set_extmark(0, ns, 0, 4, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 4, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) feed '^' feed '3l' feed 'a' @@ -2521,7 +2520,7 @@ describe('decorations: inline virtual text', function() end) it('has correct cursor position with virtual text on an empty line', function() - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) screen:expect{grid=[[ {10:^virtual text} | {1:~ }| @@ -2535,8 +2534,8 @@ describe('decorations: inline virtual text', function() call setline(1, ['', 'aaa', '', 'bbbbbb']) normal gg0 ]]) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('X', 60), 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 2, 0, { virt_text = { { string.rep('X', 61), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('X', 60), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 2, 0, { virt_text = { { string.rep('X', 61), 'Special' } }, virt_text_pos = 'inline' }) feed('$') screen:expect{grid=[[ {10:^XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}| @@ -2626,7 +2625,7 @@ describe('decorations: inline virtual text', function() feed('<TAB>') feed('test') feed('<ESC>') - meths.buf_set_extmark(0, ns, 0, 1, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 1, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) feed('0') screen:expect{grid=[[ ^ {10:virtual text} test | @@ -2667,7 +2666,7 @@ describe('decorations: inline virtual text', function() command('set linebreak') insert('one twoword') feed('0') - meths.buf_set_extmark(0, ns, 0, 3, { virt_text = { { ': virtual text', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { virt_text = { { ': virtual text', 'Special' } }, virt_text_pos = 'inline' }) screen:expect{grid=[[ ^one{10:: virtual text} twoword | {1:~ }| @@ -2678,10 +2677,10 @@ describe('decorations: inline virtual text', function() it('search highlight is correct', function() insert('foo foo foo bar\nfoo foo foo bar') feed('gg0') - meths.buf_set_extmark(0, ns, 0, 9, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 9, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 1, 9, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 1, 9, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) + api.nvim_buf_set_extmark(0, ns, 0, 9, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 9, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 9, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 9, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) screen:expect{grid=[[ ^foo foo f{10:AAABBB}oo bar | foo foo f{10:CCCDDD}oo bar | @@ -2695,7 +2694,7 @@ describe('decorations: inline virtual text', function() /foo^ | ]]} - meths.buf_set_extmark(0, ns, 0, 13, { virt_text = { { 'EEE', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 0, 13, { virt_text = { { 'EEE', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) feed('<C-G>') screen:expect{grid=[[ {12:foo} {12:foo} {13:f}{10:AAA}{21:BBB}{13:oo} b{10:EEE}ar | @@ -2707,10 +2706,10 @@ describe('decorations: inline virtual text', function() it('Visual select highlight is correct', function() insert('foo foo foo bar\nfoo foo foo bar') feed('gg0') - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) feed('8l') screen:expect{grid=[[ foo foo {10:AAABBB}^foo bar | @@ -2726,7 +2725,7 @@ describe('decorations: inline virtual text', function() {8:-- VISUAL BLOCK --} | ]]} - meths.buf_set_extmark(0, ns, 0, 10, { virt_text = { { 'EEE', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 0, 10, { virt_text = { { 'EEE', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) screen:expect{grid=[[ foo fo{7:o }{10:AAA}{20:BBB}{7:f}o{10:EEE}o bar | foo fo^o{7: }{20:CCC}{10:DDD}{7:f}oo bar | @@ -2736,12 +2735,12 @@ describe('decorations: inline virtual text', function() it('inside highlight range of another extmark', function() insert('foo foo foo bar\nfoo foo foo bar') - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) - meths.buf_set_extmark(0, ns, 0, 4, { end_col = 11, hl_group = 'Search' }) - meths.buf_set_extmark(0, ns, 1, 4, { end_col = 11, hl_group = 'Search' }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) + api.nvim_buf_set_extmark(0, ns, 0, 4, { end_col = 11, hl_group = 'Search' }) + api.nvim_buf_set_extmark(0, ns, 1, 4, { end_col = 11, hl_group = 'Search' }) screen:expect{grid=[[ foo {12:foo }{10:AAA}{19:BBB}{12:foo} bar | foo {12:foo }{19:CCC}{10:DDD}{12:foo} ba^r | @@ -2751,10 +2750,10 @@ describe('decorations: inline virtual text', function() it('inside highlight range of syntax', function() insert('foo foo foo bar\nfoo foo foo bar') - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) command([[syntax match Search 'foo \zsfoo foo\ze bar']]) screen:expect{grid=[[ foo {12:foo }{10:AAA}{19:BBB}{12:foo} bar | @@ -2766,7 +2765,7 @@ describe('decorations: inline virtual text', function() it('cursor position is correct when inserting around a virtual text with left gravity', function() screen:try_resize(27, 4) insert(('a'):rep(15)) - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { ('>'):rep(43), 'Special' } }, virt_text_pos = 'inline', right_gravity = false }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = { { ('>'):rep(43), 'Special' } }, virt_text_pos = 'inline', right_gravity = false }) command('setlocal showbreak=+ breakindent breakindentopt=shift:2') feed('08l') screen:expect{grid=[[ @@ -2837,8 +2836,8 @@ describe('decorations: inline virtual text', function() screen:try_resize(30, 4) command('setlocal showbreak=+ breakindent breakindentopt=shift:2') insert(('a'):rep(15)) - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = {{ ('>'):rep(32), 'Special' }}, virt_text_pos = 'inline', right_gravity = false }) - meths.buf_set_extmark(0, ns, 0, 8, { virt_text = {{ ('<'):rep(32), 'Special' }}, virt_text_pos = 'inline', right_gravity = true }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = {{ ('>'):rep(32), 'Special' }}, virt_text_pos = 'inline', right_gravity = false }) + api.nvim_buf_set_extmark(0, ns, 0, 8, { virt_text = {{ ('<'):rep(32), 'Special' }}, virt_text_pos = 'inline', right_gravity = true }) feed('08l') screen:expect{grid=[[ aaaaaaaa{10:>>>>>>>>>>>>>>>>>>>>>>}| @@ -2935,8 +2934,8 @@ describe('decorations: inline virtual text', function() it('draws correctly with no wrap multiple virtual text, where one is hidden', function() insert('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz') command("set nowrap") - meths.buf_set_extmark(0, ns, 0, 50, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 50, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) feed('$') screen:expect{grid=[[ opqrstuvwxyzabcdefghijklmnopqrstuvwx{10:virtual text}y^z| @@ -2948,7 +2947,7 @@ describe('decorations: inline virtual text', function() it('draws correctly with no wrap and a long virtual text', function() insert('abcdefghi') command("set nowrap") - meths.buf_set_extmark(0, ns, 0, 2, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 2, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' }) feed('$') screen:expect{grid=[[ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}cdefgh^i| @@ -2960,7 +2959,7 @@ describe('decorations: inline virtual text', function() it('tabs are the correct length with no wrap following virtual text', function() command('set nowrap') feed('itest<TAB>a<ESC>') - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('a', 55), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('a', 55), 'Special' } }, virt_text_pos = 'inline' }) feed('gg$') screen:expect{grid=[[ {10:aaaaaaaaaaaaaaaaaaaaaaaaa}test ^a | @@ -2972,7 +2971,7 @@ describe('decorations: inline virtual text', function() it('highlighting does not extend with no wrap and a long virtual text', function() insert('abcdef') command("set nowrap") - meths.buf_set_extmark(0, ns, 0, 3, { virt_text = { { string.rep('X', 50), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { virt_text = { { string.rep('X', 50), 'Special' } }, virt_text_pos = 'inline' }) feed('$') screen:expect{grid=[[ {10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}de^f| @@ -2984,7 +2983,7 @@ describe('decorations: inline virtual text', function() it('hidden virtual text does not interfere with Visual highlight', function() insert('abcdef') command('set nowrap') - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'XXX', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'XXX', 'Special' } }, virt_text_pos = 'inline' }) feed('V2zl') screen:expect{grid=[[ {10:X}{7:abcde}^f | @@ -3011,7 +3010,7 @@ describe('decorations: inline virtual text', function() test test]]) command('set number') - meths.buf_set_extmark(0, ns, 0, 1, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 1, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' }) feed('gg0') screen:expect{grid=[[ {2: 1 }^t{10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}| @@ -3024,7 +3023,7 @@ describe('decorations: inline virtual text', function() it('highlighting is correct when virtual text is proceeded with a match', function() insert([[test]]) - meths.buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 2, { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' }) feed('gg0') command('match ErrorMsg /e/') screen:expect{grid=[[ @@ -3042,7 +3041,7 @@ describe('decorations: inline virtual text', function() it('smoothscroll works correctly when virtual text wraps', function() insert('foobar') - meths.buf_set_extmark(0, ns, 0, 3, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' }) command('setlocal smoothscroll') screen:expect{grid=[[ foo{10:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}| @@ -3068,9 +3067,9 @@ describe('decorations: inline virtual text', function() ]]) insert('aaa\tbbb') command("set diff") - meths.buf_set_extmark(0, ns, 0, 1, { virt_text = { { 'test', 'Special' } }, virt_text_pos = 'inline', right_gravity = false }) - meths.buf_set_extmark(0, ns, 5, 0, { virt_text = { { '!', 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 5, 3, { virt_text = { { '' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 1, { virt_text = { { 'test', 'Special' } }, virt_text_pos = 'inline', right_gravity = false }) + api.nvim_buf_set_extmark(0, ns, 5, 0, { virt_text = { { '!', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 5, 3, { virt_text = { { '' } }, virt_text_pos = 'inline' }) command("vnew") insert([[ 000 @@ -3109,8 +3108,8 @@ describe('decorations: inline virtual text', function() it('correctly draws when there are multiple overlapping virtual texts on the same line with nowrap', function() command('set nowrap') insert('a') - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('a', 55), 'Special' } }, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('b', 55), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('a', 55), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { string.rep('b', 55), 'Special' } }, virt_text_pos = 'inline' }) feed('$') screen:expect{grid=[[ {10:bbbbbbbbbbbbbbbbbbbbbbbbb}^a | @@ -3122,7 +3121,7 @@ describe('decorations: inline virtual text', function() it('correctly draws when overflowing virtual text is followed by TAB with no wrap', function() command('set nowrap') feed('i<TAB>test<ESC>') - meths.buf_set_extmark( 0, ns, 0, 0, { virt_text = { { string.rep('a', 60), 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark( 0, ns, 0, 0, { virt_text = { { string.rep('a', 60), 'Special' } }, virt_text_pos = 'inline' }) feed('0') screen:expect({grid=[[ {10:aaaaaaaaaaaaaaaaaaaaaa} ^ test | @@ -3140,8 +3139,8 @@ describe('decorations: inline virtual text', function() bbbbb ccccc]]) - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = {{'foo'}}, virt_text_pos = 'inline' }) - meths.buf_set_extmark(0, ns, 2, 0, { virt_text = {{'bar'}}, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = {{'foo'}}, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 2, 0, { virt_text = {{'bar'}}, virt_text_pos = 'inline' }) screen:expect{grid=[[ fooaaaaa | bbbbb | @@ -3183,7 +3182,7 @@ describe('decorations: inline virtual text', function() it('does not crash at right edge of wide window #23848', function() screen:try_resize(82, 5) - meths.buf_set_extmark(0, ns, 0, 0, {virt_text = {{('a'):rep(82)}, {'b'}}, virt_text_pos = 'inline'}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {virt_text = {{('a'):rep(82)}, {'b'}}, virt_text_pos = 'inline'}) screen:expect{grid=[[ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| b | @@ -3217,7 +3216,7 @@ describe('decorations: inline virtual text', function() setlocal nowrap list listchars=extends:! call setline(1, repeat('a', 51)) ]]) - meths.buf_set_extmark(0, ns, 0, 50, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 50, { virt_text = { { 'bbb', 'Special' } }, virt_text_pos = 'inline' }) feed('20l') screen:expect{grid=[[ aaaaaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaa{1:!}| @@ -3254,7 +3253,7 @@ describe('decorations: inline virtual text', function() command('set nowrap') command('set list') command('set listchars+=extends:c') - meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'test', 'Special' } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'test', 'Special' } }, virt_text_pos = 'inline' }) insert(string.rep('a', 50)) feed('gg0') screen:expect{grid=[[ @@ -3267,8 +3266,8 @@ describe('decorations: inline virtual text', function() it('blockwise Visual highlight with double-width virtual text (replace)', function() screen:try_resize(60, 6) insert('123456789\n123456789\n123456789\n123456789') - meths.buf_set_extmark(0, ns, 1, 1, { virt_text = { { '-口-', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) - meths.buf_set_extmark(0, ns, 2, 2, { virt_text = { { '口', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) + api.nvim_buf_set_extmark(0, ns, 1, 1, { virt_text = { { '-口-', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) + api.nvim_buf_set_extmark(0, ns, 2, 2, { virt_text = { { '口', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' }) feed('gg0') screen:expect{grid=[[ ^123456789 | @@ -3337,8 +3336,8 @@ describe('decorations: inline virtual text', function() it('blockwise Visual highlight with double-width virtual text (combine)', function() screen:try_resize(60, 6) insert('123456789\n123456789\n123456789\n123456789') - meths.buf_set_extmark(0, ns, 1, 1, { virt_text = { { '-口-', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) - meths.buf_set_extmark(0, ns, 2, 2, { virt_text = { { '口', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 1, 1, { virt_text = { { '-口-', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) + api.nvim_buf_set_extmark(0, ns, 2, 2, { virt_text = { { '口', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' }) feed('gg0') screen:expect{grid=[[ ^123456789 | @@ -3413,7 +3412,7 @@ describe('decorations: inline virtual text', function() call setline(1, repeat('a', 28)) normal! $ ]]) - meths.buf_set_extmark(0, ns, 0, 27, { virt_text = { { ('123'):rep(23) } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 27, { virt_text = { { ('123'):rep(23) } }, virt_text_pos = 'inline' }) feed(':<CR>') -- Have a screen line that doesn't start with spaces screen:expect{grid=[[ 1 aaaaaaaaaaaaaaaaaaaaaaaaaa| @@ -3626,7 +3625,7 @@ describe('decorations: inline virtual text', function() call setline(1, repeat("\t", 4) .. 'a') normal! $ ]]) - meths.buf_set_extmark(0, ns, 0, 3, { virt_text = { { ('12'):rep(32) } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 3, { virt_text = { { ('12'):rep(32) } }, virt_text_pos = 'inline' }) screen:expect{grid=[[ {1:<------><------><------>}121212| 121212121212121212121212121212| @@ -3722,7 +3721,7 @@ describe('decorations: inline virtual text', function() call setline(1, repeat('a', 50) .. ' ' .. repeat('c', 45)) normal! $ ]]) - meths.buf_set_extmark(0, ns, 0, 50, { virt_text = { { ('b'):rep(10) } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 50, { virt_text = { { ('b'):rep(10) } }, virt_text_pos = 'inline' }) screen:expect{grid=[[ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {1:+}bbbbbbbbbb | @@ -3745,7 +3744,7 @@ describe('decorations: inline virtual text', function() call setline(1, repeat('a', 40) .. '口' .. '12345') normal! $ ]]) - meths.buf_set_extmark(0, ns, 0, 40, { virt_text = { { ('b'):rep(9) } }, virt_text_pos = 'inline' }) + api.nvim_buf_set_extmark(0, ns, 0, 40, { virt_text = { { ('b'):rep(9) } }, virt_text_pos = 'inline' }) screen:expect{grid=[[ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbb{1:>}| 口1234^5 | @@ -3772,7 +3771,7 @@ describe('decorations: virtual lines', function() [9] = {foreground = Screen.colors.Brown}; } - ns = meths.create_namespace 'test' + ns = api.nvim_create_namespace 'test' end) local example_text2 = [[ @@ -3788,7 +3787,7 @@ if (h->n_buckets < new_n_buckets) { // expand it('works with one line', function() insert(example_text2) feed 'gg' - meths.buf_set_extmark(0, ns, 1, 33, { + api.nvim_buf_set_extmark(0, ns, 1, 33, { virt_lines={ {{">> ", "NonText"}, {"krealloc", "Identifier"}, {": change the size of an allocation"}}}; virt_lines_above=true; }) @@ -3857,7 +3856,7 @@ if (h->n_buckets < new_n_buckets) { // expand | ]]} - meths.buf_set_extmark(0, ns, 5, 0, { + api.nvim_buf_set_extmark(0, ns, 5, 0, { virt_lines = { {{"^^ REVIEW:", "Todo"}, {" new_vals variable seems unnecessary?", "Comment"}} }; }) -- TODO: what about the cursor?? @@ -3876,7 +3875,7 @@ if (h->n_buckets < new_n_buckets) { // expand | ]]} - meths.buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_clear_namespace(0, ns, 0, -1) -- Cursor should be drawn on the correct line. #22704 screen:expect{grid=[[ if (h->n_buckets < new_n_buckets) { // expand | @@ -3913,7 +3912,7 @@ if (h->n_buckets < new_n_buckets) { // expand | ]]} - meths.buf_set_extmark(0, ns, 0, 0, { + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_lines={ {{"refactor(khash): ", "Special"}, {"take size of values as parameter"}}; {{"Author: Dev Devsson, "}, {"Tue Aug 31 10:13:37 2021", "Comment"}}; @@ -3974,7 +3973,7 @@ if (h->n_buckets < new_n_buckets) { // expand | ]]} - local id = meths.buf_set_extmark(0, ns, 7, 0, { + local id = api.nvim_buf_set_extmark(0, ns, 7, 0, { virt_lines={{{"Grugg"}}}; right_gravity=false; }) @@ -4057,7 +4056,7 @@ if (h->n_buckets < new_n_buckets) { // expand | ]]} - meths.buf_del_extmark(0, ns, id) + api.nvim_buf_del_extmark(0, ns, id) screen:expect{grid=[[ if (h->n_buckets < new_n_buckets) { // expand | khkey_t *new_keys = (khkey_t *)krealloc((void *)| @@ -4093,7 +4092,7 @@ if (h->n_buckets < new_n_buckets) { // expand | ]]} - local id = meths.buf_set_extmark(0, ns, 8, 0, { + local id = api.nvim_buf_set_extmark(0, ns, 8, 0, { virt_lines={{{"Grugg"}}}; virt_lines_above = true, }) @@ -4151,7 +4150,7 @@ if (h->n_buckets < new_n_buckets) { // expand --No lines in buffer-- | ]]} - meths.buf_del_extmark(0, ns, id) + api.nvim_buf_del_extmark(0, ns, id) screen:expect{grid=[[ ^ | {1:~ }|*10 @@ -4163,7 +4162,7 @@ if (h->n_buckets < new_n_buckets) { // expand command([[syntax region foo keepend start='^foo' end='^$']]) command('syntax sync minlines=100') insert('foo') - meths.buf_set_extmark(0, ns, 0, 0, {virt_lines = {{{'bar', 'Comment'}}}}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {virt_lines = {{{'bar', 'Comment'}}}}) screen:expect([[ fo^o | {6:bar} | @@ -4177,7 +4176,7 @@ if (h->n_buckets < new_n_buckets) { // expand insert("aa\nbb\ncc\ndd\nee\nff\ngg\nhh") feed 'gg' - meths.buf_set_extmark(0, ns, 6, 0, { + api.nvim_buf_set_extmark(0, ns, 6, 0, { virt_lines={ {{"they see me"}}; {{"scrolling", "Special"}}; @@ -4327,7 +4326,7 @@ if (h->n_buckets < new_n_buckets) { // expand | ]]} - local markid = meths.buf_set_extmark(0, ns, 2, 0, { + local markid = api.nvim_buf_set_extmark(0, ns, 2, 0, { virt_lines={ {{"Some special", "Special"}}; {{"remark about codes", "Comment"}}; @@ -4349,7 +4348,7 @@ if (h->n_buckets < new_n_buckets) { // expand | ]]} - meths.buf_set_extmark(0, ns, 2, 0, { + api.nvim_buf_set_extmark(0, ns, 2, 0, { virt_lines={ {{"Some special", "Special"}}; {{"remark about codes", "Comment"}}; @@ -4377,7 +4376,7 @@ if (h->n_buckets < new_n_buckets) { // expand it('works with hard TABs', function() insert(example_text2) feed 'gg' - meths.buf_set_extmark(0, ns, 1, 0, { + api.nvim_buf_set_extmark(0, ns, 1, 0, { virt_lines={ {{">>", "NonText"}, {"\tvery\ttabby", "Identifier"}, {"text\twith\ttabs"}}}; }) screen:expect{grid=[[ @@ -4451,8 +4450,8 @@ if (h->n_buckets < new_n_buckets) { // expand bbb ccc ddd]]) - meths.buf_set_extmark(0, ns, 0, 0, {end_row = 2, virt_lines = {{{'VIRT LINE 1', 'NonText'}}}}) - meths.buf_set_extmark(0, ns, 3, 0, {end_col = 2, virt_lines = {{{'VIRT LINE 2', 'NonText'}}}}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {end_row = 2, virt_lines = {{{'VIRT LINE 1', 'NonText'}}}}) + api.nvim_buf_set_extmark(0, ns, 3, 0, {end_col = 2, virt_lines = {{{'VIRT LINE 2', 'NonText'}}}}) screen:expect{grid=[[ aaa | {1:VIRT LINE 1} | @@ -4473,8 +4472,8 @@ if (h->n_buckets < new_n_buckets) { // expand ccc ddd]]) command('set number rightleft') - meths.buf_set_extmark(0, ns, 0, 0, {virt_lines = {{{'VIRT LINE 1', 'NonText'}}}, virt_lines_leftcol = true}) - meths.buf_set_extmark(0, ns, 3, 0, {virt_lines = {{{'VIRT LINE 2', 'NonText'}}}}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {virt_lines = {{{'VIRT LINE 1', 'NonText'}}}, virt_lines_leftcol = true}) + api.nvim_buf_set_extmark(0, ns, 3, 0, {virt_lines = {{{'VIRT LINE 2', 'NonText'}}}}) screen:expect{grid=[[ aaa{9: 1 }| {1:1 ENIL TRIV}| @@ -4494,7 +4493,7 @@ if (h->n_buckets < new_n_buckets) { // expand line3 line4 line5]]) - meths.buf_set_extmark(0, ns, 0, 0, {virt_lines={{{"foo"}}, {{"bar"}}, {{"baz"}}}}) + api.nvim_buf_set_extmark(0, ns, 0, 0, {virt_lines={{{"foo"}}, {{"bar"}}, {{"baz"}}}}) screen:expect{grid=[[ line1 | foo | @@ -4551,8 +4550,8 @@ describe('decorations: signs', function() [3] = {background = Screen.colors.Yellow1, foreground = Screen.colors.Blue1}; } - ns = meths.create_namespace 'test' - meths.set_option_value('signcolumn', 'auto:9', {}) + ns = api.nvim_create_namespace 'test' + api.nvim_set_option_value('signcolumn', 'auto:9', {}) end) local example_test3 = [[ @@ -4567,7 +4566,7 @@ l5 insert(example_test3) feed 'gg' - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S'}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S'}) screen:expect{grid=[[ {1: }^l1 | @@ -4585,7 +4584,7 @@ l5 insert(example_test3) feed 'gg' - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S', end_row=1}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S', end_row=1}) screen:expect{grid=[[ {1: }^l1 | @@ -4603,7 +4602,7 @@ l5 insert(example_test3) feed 'gg' - meths.buf_set_extmark(0, ns, 1, 0, {sign_text='S', hl_group='Todo', end_col=1}) + api.nvim_buf_set_extmark(0, ns, 1, 0, {sign_text='S', hl_group='Todo', end_col=1}) screen:expect{grid=[[ {1: }^l1 | S {3:l}2 | @@ -4615,14 +4614,14 @@ l5 | ]]} - meths.buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_clear_namespace(0, ns, 0, -1) end) it('can add multiple signs (single extmark)', function() insert(example_test3) feed 'gg' - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S', end_row = 2}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S', end_row = 2}) screen:expect{grid=[[ {1: }^l1 | @@ -4640,8 +4639,8 @@ l5 insert(example_test3) feed'gg' - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S1'}) - meths.buf_set_extmark(0, ns, 3, -1, {sign_text='S2', end_row = 4}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S1'}) + api.nvim_buf_set_extmark(0, ns, 3, -1, {sign_text='S2', end_row = 4}) screen:expect{grid=[[ {1: }^l1 | @@ -4659,8 +4658,8 @@ l5 insert(example_test3) feed 'gg' - meths.buf_set_extmark(0, ns, 3, -1, {sign_text='S1'}) - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row = 3}) + api.nvim_buf_set_extmark(0, ns, 3, -1, {sign_text='S1'}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row = 3}) screen:expect{grid=[[ {1: }^l1 | S2{1: }l2 | @@ -4678,8 +4677,8 @@ l5 insert(example_test3) feed 'gg' - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S1', end_row=2}) - meths.buf_set_extmark(0, ns, 2, -1, {sign_text='S2', end_row=3}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S1', end_row=2}) + api.nvim_buf_set_extmark(0, ns, 2, -1, {sign_text='S2', end_row=3}) screen:expect{grid=[[ {1: }^l1 | @@ -4697,8 +4696,8 @@ l5 insert(example_test3) feed 'gg' - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=0}) - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row=1}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=0}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row=1}) screen:expect{grid=[[ S1^l1 | @@ -4719,10 +4718,10 @@ l5 helpers.command('sign define Oldsign text=x') helpers.command([[exe 'sign place 42 line=2 name=Oldsign buffer=' . bufnr('')]]) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1'}) - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S2'}) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S4'}) - meths.buf_set_extmark(0, ns, 2, -1, {sign_text='S5'}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1'}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2'}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S4'}) + api.nvim_buf_set_extmark(0, ns, 2, -1, {sign_text='S5'}) screen:expect{grid=[[ S1S4^l1 | @@ -4743,11 +4742,11 @@ l5 helpers.command('sign define Oldsign text=x') helpers.command([[exe 'sign place 42 line=2 name=Oldsign buffer=' . bufnr('')]]) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1'}) - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S2'}) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S3', end_row = 4}) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S4'}) - meths.buf_set_extmark(0, ns, 2, -1, {sign_text='S5'}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1'}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2'}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S3', end_row = 4}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S4'}) + api.nvim_buf_set_extmark(0, ns, 2, -1, {sign_text='S5'}) screen:expect{grid=[[ S1S3S4^l1 | @@ -4767,7 +4766,7 @@ l5 feed 'gg' feed '2<C-e>' - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='X', end_row=3}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='X', end_row=3}) screen:expect{grid=[[ X {1: }^l3 | @@ -4784,18 +4783,18 @@ l5 command 'normal 10oa b c d e f g h' for i = 1, 10 do - meths.buf_set_extmark(0, ns, i, 0, { end_col = 1, hl_group='Todo' }) - meths.buf_set_extmark(0, ns, i, 2, { end_col = 3, hl_group='Todo' }) - meths.buf_set_extmark(0, ns, i, 4, { end_col = 5, hl_group='Todo' }) - meths.buf_set_extmark(0, ns, i, 6, { end_col = 7, hl_group='Todo' }) - meths.buf_set_extmark(0, ns, i, 8, { end_col = 9, hl_group='Todo' }) - meths.buf_set_extmark(0, ns, i, 10, { end_col = 11, hl_group='Todo' }) - meths.buf_set_extmark(0, ns, i, 12, { end_col = 13, hl_group='Todo' }) - meths.buf_set_extmark(0, ns, i, 14, { end_col = 15, hl_group='Todo' }) - meths.buf_set_extmark(0, ns, i, -1, { sign_text='W' }) - meths.buf_set_extmark(0, ns, i, -1, { sign_text='X' }) - meths.buf_set_extmark(0, ns, i, -1, { sign_text='Y' }) - meths.buf_set_extmark(0, ns, i, -1, { sign_text='Z' }) + api.nvim_buf_set_extmark(0, ns, i, 0, { end_col = 1, hl_group='Todo' }) + api.nvim_buf_set_extmark(0, ns, i, 2, { end_col = 3, hl_group='Todo' }) + api.nvim_buf_set_extmark(0, ns, i, 4, { end_col = 5, hl_group='Todo' }) + api.nvim_buf_set_extmark(0, ns, i, 6, { end_col = 7, hl_group='Todo' }) + api.nvim_buf_set_extmark(0, ns, i, 8, { end_col = 9, hl_group='Todo' }) + api.nvim_buf_set_extmark(0, ns, i, 10, { end_col = 11, hl_group='Todo' }) + api.nvim_buf_set_extmark(0, ns, i, 12, { end_col = 13, hl_group='Todo' }) + api.nvim_buf_set_extmark(0, ns, i, 14, { end_col = 15, hl_group='Todo' }) + api.nvim_buf_set_extmark(0, ns, i, -1, { sign_text='W' }) + api.nvim_buf_set_extmark(0, ns, i, -1, { sign_text='X' }) + api.nvim_buf_set_extmark(0, ns, i, -1, { sign_text='Y' }) + api.nvim_buf_set_extmark(0, ns, i, -1, { sign_text='Z' }) end screen:expect{grid=[[ @@ -4813,10 +4812,10 @@ l5 command('sign define Oldsign text=O3') command([[exe 'sign place 42 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]]) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S4', priority=100}) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S2', priority=5}) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S5', priority=200}) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1', priority=1}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S4', priority=100}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S2', priority=5}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S5', priority=200}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', priority=1}) screen:expect{grid=[[ S1S2O3S4S5^l1 | @@ -4825,7 +4824,7 @@ l5 ]]} -- Check truncation works too - meths.set_option_value('signcolumn', 'auto', {}) + api.nvim_set_option_value('signcolumn', 'auto', {}) screen:expect{grid=[[ S5^l1 | @@ -4854,10 +4853,10 @@ l5 | ]]} - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1', priority=1}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', priority=1}) screen:expect_unchanged() - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S5', priority=200}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S5', priority=200}) screen:expect{grid=[[ O3O3O3O3O3O3O3O3S5^ | {2:~ }| @@ -4869,10 +4868,10 @@ l5 it('does not set signcolumn for signs without text', function() screen:try_resize(20, 3) - meths.set_option_value('signcolumn', 'auto', {}) + api.nvim_set_option_value('signcolumn', 'auto', {}) insert(example_test3) feed 'gg' - meths.buf_set_extmark(0, ns, 0, -1, {number_hl_group='Error'}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {number_hl_group='Error'}) screen:expect{grid=[[ ^l1 | l2 | @@ -4883,9 +4882,9 @@ l5 it('correct width when removing multiple signs from sentinel line', function() screen:try_resize(20, 4) insert(example_test3) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=3}) - meths.buf_set_extmark(0, ns, 1, -1, {invalidate = true, sign_text='S2'}) - meths.buf_set_extmark(0, ns, 1, -1, {invalidate = true, sign_text='S3'}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=3}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {invalidate = true, sign_text='S2'}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {invalidate = true, sign_text='S3'}) feed('2Gdd') screen:expect{grid=[[ @@ -4899,8 +4898,8 @@ l5 it('correct width with multiple overlapping signs', function() screen:try_resize(20, 4) insert(example_test3) - meths.buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=2}) - meths.buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row=2}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=2}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row=2}) feed('gg') screen:expect{grid=[[ @@ -4935,9 +4934,9 @@ describe('decorations: virt_text', function() command 'normal 4ohello' command 'normal aVIRTUAL' - local ns = meths.create_namespace('test') + local ns = api.nvim_create_namespace('test') - meths.buf_set_extmark(0, ns, 2, 0, { + api.nvim_buf_set_extmark(0, ns, 2, 0, { virt_text = {{"hello", "String"}}, virt_text_win_col = 20, }) @@ -4977,9 +4976,9 @@ describe('decorations: virt_text', function() | ]]} - local ns = meths.create_namespace('ns') + local ns = api.nvim_create_namespace('ns') for row = 1, 5 do - meths.buf_set_extmark(0, ns, row, 0, { id = 1, virt_text = {{'world', 'Normal'}} }) + api.nvim_buf_set_extmark(0, ns, row, 0, { id = 1, virt_text = {{'world', 'Normal'}} }) end screen:expect{grid=[[ diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua index e208385e92..cbb6ee466b 100644 --- a/test/functional/ui/diff_spec.lua +++ b/test/functional/ui/diff_spec.lua @@ -9,7 +9,7 @@ local write_file = helpers.write_file local dedent = helpers.dedent local exec = helpers.exec local eq = helpers.eq -local meths = helpers.meths +local api = helpers.api before_each(clear) @@ -1053,7 +1053,7 @@ AAAB]] write_file(fname, 'aaa\nbbb\nccc\n\nxx', false) write_file(fname_2, 'aaa\nbbb\nccc\n\nyy', false) reread() - local buf = meths.get_current_buf() + local buf = api.nvim_get_current_buf() command('botright new') screen:expect { grid = [[ @@ -1071,7 +1071,7 @@ AAAB]] ]], } - meths.buf_set_lines(buf, 1, 2, true, { 'BBB' }) + api.nvim_buf_set_lines(buf, 1, 2, true, { 'BBB' }) screen:expect { grid = [[ {1: }aaa │{1: }aaa | @@ -1093,7 +1093,7 @@ AAAB]] write_file(fname, 'aaa\nbbb\nccc\n\nxx', false) write_file(fname_2, 'aaa\nbbb\nccc\n\nyy', false) reread() - local buf = meths.get_current_buf() + local buf = api.nvim_get_current_buf() command('botright split | diffoff') screen:expect { grid = [[ @@ -1115,7 +1115,7 @@ AAAB]] ]], } - meths.buf_set_lines(buf, 1, 2, true, { 'BBB' }) + api.nvim_buf_set_lines(buf, 1, 2, true, { 'BBB' }) screen:expect { grid = [[ {1: }aaa │{1: }aaa | @@ -1372,14 +1372,14 @@ it("diff mode doesn't restore invalid 'foldcolumn' value #21647", function() [0] = { foreground = Screen.colors.Blue, bold = true }, }) screen:attach() - eq('0', meths.get_option_value('foldcolumn', {})) + eq('0', api.nvim_get_option_value('foldcolumn', {})) command('diffsplit | bd') screen:expect([[ ^ | {0:~ }|*4 | ]]) - eq('0', meths.get_option_value('foldcolumn', {})) + eq('0', api.nvim_get_option_value('foldcolumn', {})) end) -- oldtest: Test_diff_binary() diff --git a/test/functional/ui/embed_spec.lua b/test/functional/ui/embed_spec.lua index 1ce465eaae..9e08f7748e 100644 --- a/test/functional/ui/embed_spec.lua +++ b/test/functional/ui/embed_spec.lua @@ -1,4 +1,4 @@ -local uv = require 'luv' +local uv = vim.uv local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') @@ -8,7 +8,7 @@ local eq = helpers.eq local neq = helpers.neq local clear = helpers.clear local ok = helpers.ok -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local retry = helpers.retry @@ -178,7 +178,7 @@ describe('--embed --listen UI', function() helpers.skip(helpers.is_os('win')) clear() local child_server = assert(helpers.new_pipename()) - funcs.jobstart({ + fn.jobstart({ nvim_prog, '--embed', '--listen', diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 5a78e2baa9..d08e346fc2 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1,6 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local global_helpers = require('test.helpers') local os = require('os') local clear, feed = helpers.clear, helpers.feed local assert_alive = helpers.assert_alive @@ -12,14 +11,15 @@ local expect = helpers.expect local exec = helpers.exec local exec_lua = helpers.exec_lua local insert = helpers.insert -local meths = helpers.meths -local curbufmeths = helpers.curbufmeths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local run = helpers.run local pcall_err = helpers.pcall_err -local tbl_contains = global_helpers.tbl_contains -local curbuf, curwin, curtab = helpers.curbuf, helpers.curwin, helpers.curtab -local NIL = helpers.NIL +local tbl_contains = vim.tbl_contains +local curbuf = helpers.api.nvim_get_current_buf +local curwin = helpers.api.nvim_get_current_win +local curtab = helpers.api.nvim_get_current_tabpage +local NIL = vim.NIL describe('float window', function() before_each(function() @@ -31,36 +31,36 @@ describe('float window', function() -- Create three windows and test that ":wincmd <direction>" changes to the -- first window, if the previous window is invalid. command('split') - meths.open_win(0, true, {width=10, height=10, relative='editor', row=0, col=0}) - eq(1002, funcs.win_getid()) - eq('editor', meths.win_get_config(1002).relative) + api.nvim_open_win(0, true, {width=10, height=10, relative='editor', row=0, col=0}) + eq(1002, fn.win_getid()) + eq('editor', api.nvim_win_get_config(1002).relative) command([[ call nvim_win_close(1001, v:false) wincmd j ]]) - eq(1000, funcs.win_getid()) + eq(1000, fn.win_getid()) end) it('win_execute() should work' , function() - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {'the floatwin', 'abc', 'def'}) - local win = meths.open_win(buf, false, {relative='win', width=16, height=1, row=0, col=10}) - local line = funcs.win_execute(win, 'echo getline(1)') + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'the floatwin', 'abc', 'def'}) + local win = api.nvim_open_win(buf, false, {relative='win', width=16, height=1, row=0, col=10}) + local line = fn.win_execute(win, 'echo getline(1)') eq('\nthe floatwin', line) - eq('\n1', funcs.win_execute(win, 'echo line(".",'..win.id..')')) - eq('\n3', funcs.win_execute(win, 'echo line("$",'..win.id..')')) - eq('\n0', funcs.win_execute(win, 'echo line("$", 123456)')) - funcs.win_execute(win, 'bwipe!') + eq('\n1', fn.win_execute(win, 'echo line(".",'..win.id..')')) + eq('\n3', fn.win_execute(win, 'echo line("$",'..win.id..')')) + eq('\n0', fn.win_execute(win, 'echo line("$", 123456)')) + fn.win_execute(win, 'bwipe!') end) it("win_execute() call commands that are not allowed when 'hidden' is not set" , function() command('set nohidden') - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {'the floatwin'}) - local win = meths.open_win(buf, true, {relative='win', width=16, height=1, row=0, col=10}) - eq('Vim(close):E37: No write since last change (add ! to override)', pcall_err(funcs.win_execute, win, 'close')) - eq('Vim(bdelete):E89: No write since last change for buffer 2 (add ! to override)', pcall_err(funcs.win_execute, win, 'bdelete')) - funcs.win_execute(win, 'bwipe!') + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'the floatwin'}) + local win = api.nvim_open_win(buf, true, {relative='win', width=16, height=1, row=0, col=10}) + eq('Vim(close):E37: No write since last change (add ! to override)', pcall_err(fn.win_execute, win, 'close')) + eq('Vim(bdelete):E89: No write since last change for buffer 2 (add ! to override)', pcall_err(fn.win_execute, win, 'bdelete')) + fn.win_execute(win, 'bwipe!') end) it('closed immediately by autocmd #11383', function() @@ -193,7 +193,7 @@ describe('float window', function() end) it('opened with correct position relative to the mouse', function() - meths.input_mouse('left', 'press', '', 0, 10, 10) + api.nvim_input_mouse('left', 'press', '', 0, 10, 10) local pos = exec_lua([[ local bufnr = vim.api.nvim_create_buf(false, true) @@ -480,67 +480,67 @@ describe('float window', function() it('no crash with bufpos and non-existent window', function() command('new') - local closed_win = meths.get_current_win().id + local closed_win = api.nvim_get_current_win().id command('close') - local buf = meths.create_buf(false,false) - meths.open_win(buf, true, {relative='win', win=closed_win, width=1, height=1, bufpos={0,0}}) + local buf = api.nvim_create_buf(false,false) + api.nvim_open_win(buf, true, {relative='win', win=closed_win, width=1, height=1, bufpos={0,0}}) assert_alive() end) it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function() local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1} - local float_win = meths.open_win(0, true, float_opts) - meths.set_option_value('fillchars', NIL, {win=float_win.id}) + local float_win = api.nvim_open_win(0, true, float_opts) + api.nvim_set_option_value('fillchars', NIL, {win=float_win.id}) float_opts.style = 'minimal' - meths.win_set_config(float_win, float_opts) + api.nvim_win_set_config(float_win, float_opts) assert_alive() end) it("should re-apply 'style' when present", function() local float_opts = {style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1} - local float_win = meths.open_win(0, true, float_opts) - meths.set_option_value('number', true, { win = float_win }) + local float_win = api.nvim_open_win(0, true, float_opts) + api.nvim_set_option_value('number', true, { win = float_win }) float_opts.row = 2 - meths.win_set_config(float_win, float_opts) - eq(false, meths.get_option_value('number', { win = float_win })) + api.nvim_win_set_config(float_win, float_opts) + eq(false, api.nvim_get_option_value('number', { win = float_win })) end) it("should not re-apply 'style' when missing", function() local float_opts = {style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1} - local float_win = meths.open_win(0, true, float_opts) - meths.set_option_value('number', true, { win = float_win }) + local float_win = api.nvim_open_win(0, true, float_opts) + api.nvim_set_option_value('number', true, { win = float_win }) float_opts.row = 2 float_opts.style = nil - meths.win_set_config(float_win, float_opts) - eq(true, meths.get_option_value('number', { win = float_win })) + api.nvim_win_set_config(float_win, float_opts) + eq(true, api.nvim_get_option_value('number', { win = float_win })) end) it("'scroll' is computed correctly when opening float with splitkeep=screen #20684", function() - meths.set_option_value('splitkeep', 'screen', {}) + api.nvim_set_option_value('splitkeep', 'screen', {}) local float_opts = {relative = 'editor', row = 1, col = 1, width = 10, height = 10} - local float_win = meths.open_win(0, true, float_opts) - eq(5, meths.get_option_value('scroll', {win=float_win.id})) + local float_win = api.nvim_open_win(0, true, float_opts) + eq(5, api.nvim_get_option_value('scroll', {win=float_win.id})) end) it(':unhide works when there are floating windows', function() local float_opts = {relative = 'editor', row = 1, col = 1, width = 5, height = 5} local w0 = curwin() - meths.open_win(0, false, float_opts) - meths.open_win(0, false, float_opts) - eq(3, #meths.list_wins()) + api.nvim_open_win(0, false, float_opts) + api.nvim_open_win(0, false, float_opts) + eq(3, #api.nvim_list_wins()) command('unhide') - eq({ w0 }, meths.list_wins()) + eq({ w0 }, api.nvim_list_wins()) end) it(':all works when there are floating windows', function() command('args Xa.txt') local float_opts = {relative = 'editor', row = 1, col = 1, width = 5, height = 5} local w0 = curwin() - meths.open_win(0, false, float_opts) - meths.open_win(0, false, float_opts) - eq(3, #meths.list_wins()) + api.nvim_open_win(0, false, float_opts) + api.nvim_open_win(0, false, float_opts) + eq(3, #api.nvim_list_wins()) command('all') - eq({ w0 }, meths.list_wins()) + eq({ w0 }, api.nvim_list_wins()) end) describe('with only one tabpage,', function() @@ -553,37 +553,37 @@ describe('float window', function() end) describe('closing the last non-floating window gives E444', function() before_each(function() - meths.open_win(old_buf, true, float_opts) + api.nvim_open_win(old_buf, true, float_opts) end) it('if called from non-floating window', function() - meths.set_current_win(old_win) + api.nvim_set_current_win(old_win) eq('Vim:E444: Cannot close last window', - pcall_err(meths.win_close, old_win, false)) + pcall_err(api.nvim_win_close, old_win, false)) end) it('if called from floating window', function() eq('Vim:E444: Cannot close last window', - pcall_err(meths.win_close, old_win, false)) + pcall_err(api.nvim_win_close, old_win, false)) end) end) describe("deleting the last non-floating window's buffer", function() describe('leaves one window with an empty buffer when there is only one buffer', function() local same_buf_float before_each(function() - same_buf_float = meths.open_win(old_buf, false, float_opts).id + same_buf_float = api.nvim_open_win(old_buf, false, float_opts).id end) after_each(function() eq(old_win, curwin().id) expect('') - eq(1, #meths.list_wins()) + eq(1, #api.nvim_list_wins()) end) it('if called from non-floating window', function() - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) end) it('if called from floating window', function() - meths.set_current_win(same_buf_float) + api.nvim_set_current_win(same_buf_float) command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()') command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()') - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(same_buf_float, eval('g:win_leave')) eq(old_win, eval('g:win_enter')) end) @@ -591,67 +591,67 @@ describe('float window', function() describe('closes other windows with that buffer when there are other buffers', function() local same_buf_float, other_buf, other_buf_float before_each(function() - same_buf_float = meths.open_win(old_buf, false, float_opts).id - other_buf = meths.create_buf(true, false).id - other_buf_float = meths.open_win(other_buf, true, float_opts).id + same_buf_float = api.nvim_open_win(old_buf, false, float_opts).id + other_buf = api.nvim_create_buf(true, false).id + other_buf_float = api.nvim_open_win(other_buf, true, float_opts).id insert('bar') - meths.set_current_win(old_win) + api.nvim_set_current_win(old_win) end) after_each(function() eq(other_buf, curbuf().id) expect('bar') - eq(2, #meths.list_wins()) + eq(2, #api.nvim_list_wins()) end) it('if called from non-floating window', function() - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(old_win, curwin().id) end) it('if called from floating window with the same buffer', function() - meths.set_current_win(same_buf_float) + api.nvim_set_current_win(same_buf_float) command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()') command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()') - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(same_buf_float, eval('g:win_leave')) eq(old_win, eval('g:win_enter')) eq(old_win, curwin().id) end) -- TODO: this case is too hard to deal with pending('if called from floating window with another buffer', function() - meths.set_current_win(other_buf_float) - meths.buf_delete(old_buf, {force = true}) + api.nvim_set_current_win(other_buf_float) + api.nvim_buf_delete(old_buf, {force = true}) end) end) describe('creates an empty buffer when there is only one listed buffer', function() local same_buf_float, unlisted_buf_float before_each(function() - same_buf_float = meths.open_win(old_buf, false, float_opts).id - local unlisted_buf = meths.create_buf(true, false).id - unlisted_buf_float = meths.open_win(unlisted_buf, true, float_opts).id + same_buf_float = api.nvim_open_win(old_buf, false, float_opts).id + local unlisted_buf = api.nvim_create_buf(true, false).id + unlisted_buf_float = api.nvim_open_win(unlisted_buf, true, float_opts).id insert('unlisted') command('set nobuflisted') - meths.set_current_win(old_win) + api.nvim_set_current_win(old_win) end) after_each(function() expect('') - eq(2, #meths.list_wins()) + eq(2, #api.nvim_list_wins()) end) it('if called from non-floating window', function() - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(old_win, curwin().id) end) it('if called from floating window with the same buffer', function() - meths.set_current_win(same_buf_float) + api.nvim_set_current_win(same_buf_float) command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()') command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()') - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(same_buf_float, eval('g:win_leave')) eq(old_win, eval('g:win_enter')) eq(old_win, curwin().id) end) -- TODO: this case is too hard to deal with pending('if called from floating window with an unlisted buffer', function() - meths.set_current_win(unlisted_buf_float) - meths.buf_delete(old_buf, {force = true}) + api.nvim_set_current_win(unlisted_buf_float) + api.nvim_buf_delete(old_buf, {force = true}) end) end) end) @@ -662,20 +662,20 @@ describe('float window', function() command('botright vnew') insert('unlisted') command('set nobuflisted') - meths.set_current_win(old_win) - same_buf_float = meths.open_win(old_buf, false, float_opts).id + api.nvim_set_current_win(old_win) + same_buf_float = api.nvim_open_win(old_buf, false, float_opts).id end) after_each(function() expect('') - eq(2, #meths.list_wins()) + eq(2, #api.nvim_list_wins()) end) it('if called from non-floating window with the deleted buffer', function() - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(old_win, curwin().id) end) it('if called from floating window with the deleted buffer', function() - meths.set_current_win(same_buf_float) - meths.buf_delete(old_buf, {force = true}) + api.nvim_set_current_win(same_buf_float) + api.nvim_buf_delete(old_buf, {force = true}) eq(same_buf_float, curwin().id) end) end) @@ -697,28 +697,28 @@ describe('float window', function() describe('without splits, deleting the last listed buffer creates an empty buffer', function() local same_buf_float before_each(function() - meths.set_current_win(old_win) - same_buf_float = meths.open_win(old_buf, false, float_opts).id + api.nvim_set_current_win(old_win) + same_buf_float = api.nvim_open_win(old_buf, false, float_opts).id end) after_each(function() expect('') - eq(2, #meths.list_wins()) - eq(2, #meths.list_tabpages()) + eq(2, #api.nvim_list_wins()) + eq(2, #api.nvim_list_tabpages()) end) it('if called from non-floating window', function() - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(old_win, curwin().id) end) it('if called from non-floating window in another tabpage', function() command('tab split') - eq(3, #meths.list_tabpages()) - meths.buf_delete(old_buf, {force = true}) + eq(3, #api.nvim_list_tabpages()) + api.nvim_buf_delete(old_buf, {force = true}) end) it('if called from floating window with the same buffer', function() - meths.set_current_win(same_buf_float) + api.nvim_set_current_win(same_buf_float) command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()') command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()') - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(same_buf_float, eval('g:win_leave')) eq(old_win, eval('g:win_enter')) eq(old_win, curwin().id) @@ -728,22 +728,22 @@ describe('float window', function() local same_buf_float before_each(function() command('botright vsplit') - meths.set_current_buf(unlisted_buf) - meths.set_current_win(old_win) - same_buf_float = meths.open_win(old_buf, false, float_opts).id + api.nvim_set_current_buf(unlisted_buf) + api.nvim_set_current_win(old_win) + same_buf_float = api.nvim_open_win(old_buf, false, float_opts).id end) after_each(function() expect('') - eq(3, #meths.list_wins()) - eq(2, #meths.list_tabpages()) + eq(3, #api.nvim_list_wins()) + eq(2, #api.nvim_list_tabpages()) end) it('if called from non-floating window with the deleted buffer', function() - meths.buf_delete(old_buf, {force = true}) + api.nvim_buf_delete(old_buf, {force = true}) eq(old_win, curwin().id) end) it('if called from floating window with the deleted buffer', function() - meths.set_current_win(same_buf_float) - meths.buf_delete(old_buf, {force = true}) + api.nvim_set_current_win(same_buf_float) + api.nvim_buf_delete(old_buf, {force = true}) eq(same_buf_float, curwin().id) end) end) @@ -763,38 +763,38 @@ describe('float window', function() describe('closes the tabpage when all floating windows are closeable', function() local same_buf_float before_each(function() - same_buf_float = meths.open_win(old_buf, false, float_opts).id + same_buf_float = api.nvim_open_win(old_buf, false, float_opts).id end) after_each(function() eq(old_tabpage, curtab().id) expect('oldtab') - eq(1, #meths.list_tabpages()) + eq(1, #api.nvim_list_tabpages()) end) it('if called from non-floating window', function() - meths.win_close(old_win, false) + api.nvim_win_close(old_win, false) end) it('if called from floating window', function() - meths.set_current_win(same_buf_float) - meths.win_close(old_win, false) + api.nvim_set_current_win(same_buf_float) + api.nvim_win_close(old_win, false) end) end) describe('gives E5601 when there are non-closeable floating windows', function() local other_buf_float before_each(function() command('set nohidden') - local other_buf = meths.create_buf(true, false).id - other_buf_float = meths.open_win(other_buf, true, float_opts).id + local other_buf = api.nvim_create_buf(true, false).id + other_buf_float = api.nvim_open_win(other_buf, true, float_opts).id insert('foo') - meths.set_current_win(old_win) + api.nvim_set_current_win(old_win) end) it('if called from non-floating window', function() eq('Vim:E5601: Cannot close window, only floating window would remain', - pcall_err(meths.win_close, old_win, false)) + pcall_err(api.nvim_win_close, old_win, false)) end) it('if called from floating window', function() - meths.set_current_win(other_buf_float) + api.nvim_set_current_win(other_buf_float) eq('Vim:E5601: Cannot close window, only floating window would remain', - pcall_err(meths.win_close, old_win, false)) + pcall_err(api.nvim_win_close, old_win, false)) end) end) end) @@ -802,27 +802,27 @@ describe('float window', function() describe('closes the tabpage when all floating windows are closeable', function() local same_buf_float, other_buf, other_buf_float before_each(function() - same_buf_float = meths.open_win(old_buf, false, float_opts).id - other_buf = meths.create_buf(true, false).id - other_buf_float = meths.open_win(other_buf, true, float_opts).id - meths.set_current_win(old_win) + same_buf_float = api.nvim_open_win(old_buf, false, float_opts).id + other_buf = api.nvim_create_buf(true, false).id + other_buf_float = api.nvim_open_win(other_buf, true, float_opts).id + api.nvim_set_current_win(old_win) end) after_each(function() eq(old_tabpage, curtab().id) expect('oldtab') - eq(1, #meths.list_tabpages()) + eq(1, #api.nvim_list_tabpages()) end) it('if called from non-floating window', function() - meths.buf_delete(old_buf, {force = false}) + api.nvim_buf_delete(old_buf, {force = false}) end) it('if called from floating window with the same buffer', function() - meths.set_current_win(same_buf_float) - meths.buf_delete(old_buf, {force = false}) + api.nvim_set_current_win(same_buf_float) + api.nvim_buf_delete(old_buf, {force = false}) end) -- TODO: this case is too hard to deal with pending('if called from floating window with another buffer', function() - meths.set_current_win(other_buf_float) - meths.buf_delete(old_buf, {force = false}) + api.nvim_set_current_win(other_buf_float) + api.nvim_buf_delete(old_buf, {force = false}) end) end) -- TODO: what to do when there are non-closeable floating windows? @@ -869,8 +869,8 @@ describe('float window', function() end) it('can be created and reconfigured', function() - local buf = meths.create_buf(false,false) - local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) + local buf = api.nvim_create_buf(false,false) + local win = api.nvim_open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) local expected_pos = { [4]={{id=1001}, 'NW', 1, 2, 5, true}, } @@ -901,7 +901,7 @@ describe('float window', function() end - meths.win_set_config(win, {relative='editor', row=0, col=10}) + api.nvim_win_set_config(win, {relative='editor', row=0, col=10}) expected_pos[4][4] = 0 expected_pos[4][5] = 10 if multigrid then @@ -927,7 +927,7 @@ describe('float window', function() ]]) end - meths.win_close(win, false) + api.nvim_win_close(win, false) if multigrid then screen:expect([[ ## grid 1 @@ -950,8 +950,8 @@ describe('float window', function() it('window position fixed', function() command('rightbelow 20vsplit') - local buf = meths.create_buf(false,false) - local win = meths.open_win(buf, false, { + local buf = api.nvim_create_buf(false,false) + local win = api.nvim_open_win(buf, false, { relative='win', width=15, height=2, row=2, col=10, anchor='NW', fixed=true}) if multigrid then @@ -986,7 +986,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {fixed=false}) + api.nvim_win_set_config(win, {fixed=false}) if multigrid then screen:expect_unchanged() @@ -1010,8 +1010,8 @@ describe('float window', function() -- or something. command("set redrawdebug=compositor") command("set wd=1") - local buf = meths.create_buf(false,false) - local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) + local buf = api.nvim_create_buf(false,false) + local win = api.nvim_open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) local expected_pos = { [4]={{id=1001}, 'NW', 1, 2, 5, true}, } @@ -1042,7 +1042,7 @@ describe('float window', function() end - meths.win_set_config(win, {relative='editor', row=0, col=10}) + api.nvim_win_set_config(win, {relative='editor', row=0, col=10}) expected_pos[4][4] = 0 expected_pos[4][5] = 10 if multigrid then @@ -1068,7 +1068,7 @@ describe('float window', function() ]]) end - meths.win_close(win, false) + api.nvim_win_close(win, false) if multigrid then screen:expect([[ ## grid 1 @@ -1090,16 +1090,16 @@ describe('float window', function() end) it('return their configuration', function() - local buf = meths.create_buf(false, false) - local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=3, col=5, zindex=60}) + local buf = api.nvim_create_buf(false, false) + local win = api.nvim_open_win(buf, false, {relative='editor', width=20, height=2, row=3, col=5, zindex=60}) local expected = {anchor='NW', col=5, external=false, focusable=true, height=2, relative='editor', row=3, width=20, zindex=60, hide=false} - eq(expected, meths.win_get_config(win)) + eq(expected, api.nvim_win_get_config(win)) - eq({relative='', external=false, focusable=true, hide=false}, meths.win_get_config(0)) + eq({relative='', external=false, focusable=true, hide=false}, api.nvim_win_get_config(0)) if multigrid then - meths.win_set_config(win, {external=true, width=10, height=1}) - eq({external=true,focusable=true,width=10,height=1,relative='',hide=false}, meths.win_get_config(win)) + api.nvim_win_set_config(win, {external=true, width=10, height=1}) + eq({external=true,focusable=true,width=10,height=1,relative='',hide=false}, api.nvim_win_get_config(win)) end end) @@ -1107,7 +1107,7 @@ describe('float window', function() command('set number') command('hi NormalFloat guibg=#333333 guifg=NONE') feed('ix<cr>y<cr><esc>gg') - local win = meths.open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10}) + local win = api.nvim_open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1138,8 +1138,8 @@ describe('float window', function() ]]) end - local buf = meths.create_buf(false, true) - meths.win_set_buf(win, buf) + local buf = api.nvim_create_buf(false, true) + api.nvim_win_set_buf(win, buf) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1175,7 +1175,7 @@ describe('float window', function() command('set foldcolumn=1') command('hi NormalFloat guibg=#333333 guifg=NONE') feed('ix<cr>y<cr><esc>gg') - local win = meths.open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10, style='minimal'}) + local win = api.nvim_open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10, style='minimal'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1239,8 +1239,8 @@ describe('float window', function() end command('sign unplace 1 buffer=1') - local buf = meths.create_buf(false, true) - meths.win_set_buf(win, buf) + local buf = api.nvim_create_buf(false, true) + api.nvim_win_set_buf(win, buf) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1275,7 +1275,7 @@ describe('float window', function() command('set foldcolumn=1') command('hi NormalFloat guibg=#333333 guifg=NONE') feed('ix<cr>y<cr><esc>gg') - local win = meths.open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10, style='minimal'}) + local win = api.nvim_open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10, style='minimal'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1339,8 +1339,8 @@ describe('float window', function() end command('sign unplace 1 buffer=1') - local buf = meths.create_buf(false, true) - meths.win_set_buf(win, buf) + local buf = api.nvim_create_buf(false, true) + api.nvim_win_set_buf(win, buf) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1376,7 +1376,7 @@ describe('float window', function() command('set statuscolumn=%l%s%C') command('hi NormalFloat guibg=#333333 guifg=NONE') feed('ix<cr>y<cr><esc>gg') - meths.open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10, style='minimal'}) + api.nvim_open_win(0, false, {relative='editor', width=20, height=4, row=4, col=10, style='minimal'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1407,10 +1407,10 @@ describe('float window', function() end) it('can have border', function() - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {' halloj! ', ' BORDAA '}) - local win = meths.open_win(buf, false, {relative='editor', width=9, height=2, row=2, col=5, border="double"}) + local win = api.nvim_open_win(buf, false, {relative='editor', width=9, height=2, row=2, col=5, border="double"}) if multigrid then screen:expect{grid=[[ @@ -1445,7 +1445,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {border="single"}) + api.nvim_win_set_config(win, {border="single"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1479,7 +1479,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {border="rounded"}) + api.nvim_win_set_config(win, {border="rounded"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1513,7 +1513,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {border="solid"}) + api.nvim_win_set_config(win, {border="solid"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1548,7 +1548,7 @@ describe('float window', function() end -- support: ascii char, UTF-8 char, composed char, highlight per char - meths.win_set_config(win, {border={"x", {"å", "ErrorMsg"}, {"\\"}, {"n̈̊", "Search"}}}) + api.nvim_win_set_config(win, {border={"x", {"å", "ErrorMsg"}, {"\\"}, {"n̈̊", "Search"}}}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1582,7 +1582,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {border="none"}) + api.nvim_win_set_config(win, {border="none"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1613,7 +1613,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {border={"", "", "", ">", "", "", "", "<"}}) + api.nvim_win_set_config(win, {border={"", "", "", ">", "", "", "", "<"}}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1644,7 +1644,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {border={"", "_", "", "", "", "-", "", ""}}) + api.nvim_win_set_config(win, {border={"", "_", "", "", "", "-", "", ""}}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1686,7 +1686,7 @@ describe('float window', function() of border shadow ]] - meths.win_set_config(win, {border="shadow"}) + api.nvim_win_set_config(win, {border="shadow"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1725,13 +1725,13 @@ describe('float window', function() end) it('validates title title_pos', function() - local buf = meths.create_buf(false,false) + local buf = api.nvim_create_buf(false,false) eq("title requires border to be set", - pcall_err(meths.open_win,buf, false, { + pcall_err(api.nvim_open_win,buf, false, { relative='editor', width=9, height=2, row=2, col=5, title='Title', })) eq("title_pos requires title to be set", - pcall_err(meths.open_win,buf, false, { + pcall_err(api.nvim_open_win,buf, false, { relative='editor', width=9, height=2, row=2, col=5, border='single', title_pos='left', })) @@ -1759,13 +1759,13 @@ describe('float window', function() end) it('validates footer footer_pos', function() - local buf = meths.create_buf(false,false) + local buf = api.nvim_create_buf(false,false) eq("footer requires border to be set", - pcall_err(meths.open_win,buf, false, { + pcall_err(api.nvim_open_win,buf, false, { relative='editor', width=9, height=2, row=2, col=5, footer='Footer', })) eq("footer_pos requires footer to be set", - pcall_err(meths.open_win,buf, false, { + pcall_err(api.nvim_open_win,buf, false, { relative='editor', width=9, height=2, row=2, col=5, border='single', footer_pos='left', })) @@ -1793,10 +1793,10 @@ describe('float window', function() end) it('center aligned title longer than window width #25746', function() - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {' halloj! ', ' BORDAA '}) - local win = meths.open_win(buf, false, { + local win = api.nvim_open_win(buf, false, { relative='editor', width=9, height=2, row=2, col=5, border="double", title = "abcdefghijklmnopqrstuvwxyz",title_pos = "center", }) @@ -1834,15 +1834,15 @@ describe('float window', function() ]]} end - meths.win_close(win, false) + api.nvim_win_close(win, false) assert_alive() end) it('border with title', function() - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {' halloj! ', ' BORDAA '}) - local win = meths.open_win(buf, false, { + local win = api.nvim_open_win(buf, false, { relative='editor', width=9, height=2, row=2, col=5, border="double", title = "Left",title_pos = "left", }) @@ -1880,7 +1880,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {title= "Center",title_pos="center"}) + api.nvim_win_set_config(win, {title= "Center",title_pos="center"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1914,7 +1914,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {title= "Right",title_pos="right"}) + api.nvim_win_set_config(win, {title= "Right",title_pos="right"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1948,7 +1948,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {title= { {"🦄"},{"BB"}},title_pos="right"}) + api.nvim_win_set_config(win, {title= { {"🦄"},{"BB"}},title_pos="right"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -1984,10 +1984,10 @@ describe('float window', function() end) it('border with footer', function() - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {' halloj! ', ' BORDAA '}) - local win = meths.open_win(buf, false, { + local win = api.nvim_open_win(buf, false, { relative='editor', width=9, height=2, row=2, col=5, border="double", footer = "Left",footer_pos = "left", }) @@ -2025,7 +2025,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {footer= "Center",footer_pos="center"}) + api.nvim_win_set_config(win, {footer= "Center",footer_pos="center"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2059,7 +2059,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {footer= "Right",footer_pos="right"}) + api.nvim_win_set_config(win, {footer= "Right",footer_pos="right"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2093,7 +2093,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {footer= { {"🦄"},{"BB"}},footer_pos="right"}) + api.nvim_win_set_config(win, {footer= { {"🦄"},{"BB"}},footer_pos="right"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2129,10 +2129,10 @@ describe('float window', function() end) it('border with title and footer', function() - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {' halloj! ', ' BORDAA '}) - local win = meths.open_win(buf, false, { + local win = api.nvim_open_win(buf, false, { relative='editor', width=9, height=2, row=2, col=5, border="double", title = "Left", title_pos = "left", footer = "Right", footer_pos = "right", }) @@ -2170,7 +2170,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {title= "Center",title_pos="center",footer= "Center",footer_pos="center"}) + api.nvim_win_set_config(win, {title= "Center",title_pos="center",footer= "Center",footer_pos="center"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2204,7 +2204,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {title= "Right",title_pos="right",footer= "Left",footer_pos="left"}) + api.nvim_win_set_config(win, {title= "Right",title_pos="right",footer= "Left",footer_pos="left"}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2240,7 +2240,7 @@ describe('float window', function() command('hi B0 guibg=Red guifg=Black') command('hi B1 guifg=White') - meths.win_set_config(win, { + api.nvim_win_set_config(win, { title = {{"🦄"}, {"BB", {"B0", "B1"}}}, title_pos = "right", footer= {{"🦄"}, {"BB", {"B0", "B1"}}}, footer_pos = "right", }) @@ -2279,8 +2279,8 @@ describe('float window', function() end) it('terminates border on edge of viewport when window extends past viewport', function() - local buf = meths.create_buf(false, false) - meths.open_win(buf, false, {relative='editor', width=40, height=7, row=0, col=0, border="single", zindex=201}) + local buf = api.nvim_create_buf(false, false) + api.nvim_open_win(buf, false, {relative='editor', width=40, height=7, row=0, col=0, border="single", zindex=201}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2314,10 +2314,10 @@ describe('float window', function() it('with border show popupmenu', function() screen:try_resize(40,10) - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {'aaa aab ', + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'aaa aab ', 'abb acc ', ''}) - meths.open_win(buf, true, {relative='editor', width=9, height=3, row=0, col=5, border="double"}) + api.nvim_open_win(buf, true, {relative='editor', width=9, height=3, row=0, col=5, border="double"}) feed 'G' if multigrid then @@ -2483,10 +2483,10 @@ describe('float window', function() it('show ruler of current floating window', function() command 'set ruler' - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {'aaa aab ', + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'aaa aab ', 'abb acc '}) - meths.open_win(buf, true, {relative='editor', width=9, height=3, row=0, col=5}) + api.nvim_open_win(buf, true, {relative='editor', width=9, height=3, row=0, col=5}) feed 'gg' if multigrid then @@ -2553,7 +2553,7 @@ describe('float window', function() it("correct ruler position in current float with 'rulerformat' set", function() command 'set ruler rulerformat=fish:<><' - meths.open_win(0, true, {relative='editor', width=9, height=3, row=0, col=5}) + api.nvim_open_win(0, true, {relative='editor', width=9, height=3, row=0, col=5}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2586,11 +2586,11 @@ describe('float window', function() it('does not show ruler of not-last current float during ins-completion', function() screen:try_resize(50,9) command 'set ruler showmode' - meths.open_win(0, false, {relative='editor', width=3, height=3, row=0, col=0}) - meths.open_win(0, false, {relative='editor', width=3, height=3, row=0, col=5}) + api.nvim_open_win(0, false, {relative='editor', width=3, height=3, row=0, col=0}) + api.nvim_open_win(0, false, {relative='editor', width=3, height=3, row=0, col=5}) feed '<c-w>w' - neq('', meths.win_get_config(0).relative) - neq(funcs.winnr '$', funcs.winnr()) + neq('', api.nvim_win_get_config(0).relative) + neq(fn.winnr '$', fn.winnr()) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2660,9 +2660,9 @@ describe('float window', function() it('can have minimum size', function() insert("the background text") - local buf = meths.create_buf(false, true) - meths.buf_set_lines(buf, 0, -1, true, {'x'}) - local win = meths.open_win(buf, false, {relative='win', width=1, height=1, row=0, col=4, focusable=false}) + local buf = api.nvim_create_buf(false, true) + api.nvim_buf_set_lines(buf, 0, -1, true, {'x'}) + local win = api.nvim_open_win(buf, false, {relative='win', width=1, height=1, row=0, col=4, focusable=false}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2686,7 +2686,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='win', row=0, col=15}) + api.nvim_win_set_config(win, {relative='win', row=0, col=15}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2710,7 +2710,7 @@ describe('float window', function() ]]) end - meths.win_close(win,false) + api.nvim_win_close(win,false) if multigrid then screen:expect([[ ## grid 1 @@ -2746,8 +2746,8 @@ describe('float window', function() command('sargument 6') local float_opts = { relative = 'editor', row = 6, col = 0, width = 40, height = 1 } - meths.win_set_config(w3, float_opts) - meths.win_set_config(w4, float_opts) + api.nvim_win_set_config(w3, float_opts) + api.nvim_win_set_config(w4, float_opts) command('wincmd =') if multigrid then screen:expect{grid=[[ @@ -2876,36 +2876,36 @@ describe('float window', function() end) it('API has proper error messages', function() - local buf = meths.create_buf(false,false) + local buf = api.nvim_create_buf(false,false) eq("Invalid key: 'bork'", - pcall_err(meths.open_win,buf, false, {width=20,height=2,bork=true})) + pcall_err(api.nvim_open_win,buf, false, {width=20,height=2,bork=true})) eq("'win' key is only valid with relative='win'", - pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,win=0})) + pcall_err(api.nvim_open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,win=0})) eq("Only one of 'relative' and 'external' must be used", - pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,external=true})) + pcall_err(api.nvim_open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,external=true})) eq("Invalid value of 'relative' key", - pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='shell',row=0,col=0})) + pcall_err(api.nvim_open_win,buf, false, {width=20,height=2,relative='shell',row=0,col=0})) eq("Invalid value of 'anchor' key", - pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,anchor='bottom'})) + pcall_err(api.nvim_open_win,buf, false, {width=20,height=2,relative='editor',row=0,col=0,anchor='bottom'})) eq("'relative' requires 'row'/'col' or 'bufpos'", - pcall_err(meths.open_win,buf, false, {width=20,height=2,relative='editor'})) + pcall_err(api.nvim_open_win,buf, false, {width=20,height=2,relative='editor'})) eq("'width' key must be a positive Integer", - pcall_err(meths.open_win,buf, false, {width=-1,height=2,relative='editor', row=0, col=0})) + pcall_err(api.nvim_open_win,buf, false, {width=-1,height=2,relative='editor', row=0, col=0})) eq("'height' key must be a positive Integer", - pcall_err(meths.open_win,buf, false, {width=20,height=-1,relative='editor', row=0, col=0})) + pcall_err(api.nvim_open_win,buf, false, {width=20,height=-1,relative='editor', row=0, col=0})) eq("'height' key must be a positive Integer", - pcall_err(meths.open_win,buf, false, {width=20,height=0,relative='editor', row=0, col=0})) + pcall_err(api.nvim_open_win,buf, false, {width=20,height=0,relative='editor', row=0, col=0})) eq("Must specify 'width'", - pcall_err(meths.open_win,buf, false, {relative='editor', row=0, col=0})) + pcall_err(api.nvim_open_win,buf, false, {relative='editor', row=0, col=0})) eq("Must specify 'height'", - pcall_err(meths.open_win,buf, false, {relative='editor', row=0, col=0, width=2})) + pcall_err(api.nvim_open_win,buf, false, {relative='editor', row=0, col=0, width=2})) end) it('can be placed relative window or cursor', function() screen:try_resize(40,9) - meths.buf_set_lines(0, 0, -1, true, {'just some', 'example text'}) + api.nvim_buf_set_lines(0, 0, -1, true, {'just some', 'example text'}) feed('gge') - local oldwin = meths.get_current_win() + local oldwin = api.nvim_get_current_win() command('below split') if multigrid then screen:expect([[ @@ -2940,9 +2940,9 @@ describe('float window', function() ]]) end - local buf = meths.create_buf(false,false) + local buf = api.nvim_create_buf(false,false) -- no 'win' arg, relative default window - local win = meths.open_win(buf, false, {relative='win', width=20, height=2, row=0, col=10}) + local win = api.nvim_open_win(buf, false, {relative='win', width=20, height=2, row=0, col=10}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -2981,7 +2981,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='cursor', row=1, col=-2}) + api.nvim_win_set_config(win, {relative='cursor', row=1, col=-2}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3020,7 +3020,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='cursor', row=0, col=0, anchor='SW'}) + api.nvim_win_set_config(win, {relative='cursor', row=0, col=0, anchor='SW'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3059,7 +3059,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='win', win=oldwin, row=1, col=10, anchor='NW'}) + api.nvim_win_set_config(win, {relative='win', win=oldwin, row=1, col=10, anchor='NW'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3098,7 +3098,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='win', win=oldwin, row=3, col=39, anchor='SE'}) + api.nvim_win_set_config(win, {relative='win', win=oldwin, row=3, col=39, anchor='SE'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3137,7 +3137,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='win', win=0, row=0, col=50, anchor='NE'}) + api.nvim_win_set_config(win, {relative='win', win=0, row=0, col=50, anchor='NE'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3207,7 +3207,7 @@ describe('float window', function() it('always anchor to corner including border', function() screen:try_resize(40,13) - meths.buf_set_lines(0, 0, -1, true, {'just some example text', 'some more example text'}) + api.nvim_buf_set_lines(0, 0, -1, true, {'just some example text', 'some more example text'}) feed('ggeee') command('below split') if multigrid then @@ -3243,10 +3243,10 @@ describe('float window', function() ]]) end - local buf = meths.create_buf(false, false) - meths.buf_set_lines(buf, 0, -1, true, {' halloj! ', + local buf = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(buf, 0, -1, true, {' halloj! ', ' BORDAA '}) - local win = meths.open_win(buf, false, {relative='cursor', width=9, height=2, row=1, col=-2, border="double"}) + local win = api.nvim_open_win(buf, false, {relative='cursor', width=9, height=2, row=1, col=-2, border="double"}) if multigrid then screen:expect{grid=[[ @@ -3290,7 +3290,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='cursor', row=0, col=-2, anchor='NE'}) + api.nvim_win_set_config(win, {relative='cursor', row=0, col=-2, anchor='NE'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3333,7 +3333,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='cursor', row=1, col=-2, anchor='SE'}) + api.nvim_win_set_config(win, {relative='cursor', row=1, col=-2, anchor='SE'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3376,7 +3376,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='cursor', row=0, col=-2, anchor='SW'}) + api.nvim_win_set_config(win, {relative='cursor', row=0, col=-2, anchor='SW'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3596,8 +3596,8 @@ describe('float window', function() it('can be placed relative text in a window', function() screen:try_resize(30,5) - local firstwin = meths.get_current_win().id - meths.buf_set_lines(0, 0, -1, true, {'just some', 'example text that is wider than the window', '', '', 'more text'}) + local firstwin = api.nvim_get_current_win().id + api.nvim_buf_set_lines(0, 0, -1, true, {'just some', 'example text that is wider than the window', '', '', 'more text'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3620,10 +3620,10 @@ describe('float window', function() ]]} end - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {'some info!'}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'some info!'}) - local win = meths.open_win(buf, false, {relative='win', width=12, height=1, bufpos={1,32}}) + local win = api.nvim_open_win(buf, false, {relative='win', width=12, height=1, bufpos={1,32}}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3651,7 +3651,7 @@ describe('float window', function() ]]} end eq({relative='win', width=12, height=1, bufpos={1,32}, anchor='NW', hide=false, - external=false, col=0, row=1, win=firstwin, focusable=true, zindex=50}, meths.win_get_config(win)) + external=false, col=0, row=1, win=firstwin, focusable=true, zindex=50}, api.nvim_win_get_config(win)) feed('<c-e>') if multigrid then @@ -3739,7 +3739,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {relative='win', bufpos={1,32}, anchor='SW'}) + api.nvim_win_set_config(win, {relative='win', bufpos={1,32}, anchor='SW'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3812,7 +3812,7 @@ describe('float window', function() end command('close') - meths.win_set_config(win, {relative='win', bufpos={1,32}, anchor='NW', col=-2}) + api.nvim_win_set_config(win, {relative='win', bufpos={1,32}, anchor='NW', col=-2}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3843,7 +3843,7 @@ describe('float window', function() ]]} end - meths.win_set_config(win, {relative='win', bufpos={1,32}, row=2}) + api.nvim_win_set_config(win, {relative='win', bufpos={1,32}, row=2}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3924,9 +3924,9 @@ describe('float window', function() ]]) end - local buf = meths.create_buf(false,true) - meths.buf_set_lines(buf, 0, -1, true, {'some floaty text'}) - meths.open_win(buf, false, {relative='editor', width=20, height=1, row=3, col=1}) + local buf = api.nvim_create_buf(false,true) + api.nvim_buf_set_lines(buf, 0, -1, true, {'some floaty text'}) + api.nvim_open_win(buf, false, {relative='editor', width=20, height=1, row=3, col=1}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -3959,8 +3959,8 @@ describe('float window', function() local screen2 = Screen.new(40,7) screen2:attach(nil, session2) screen2:set_default_attr_ids(attrs) - local buf = meths.create_buf(false,false) - meths.open_win(buf, true, {relative='editor', width=20, height=2, row=2, col=5}) + local buf = api.nvim_create_buf(false,false) + api.nvim_open_win(buf, true, {relative='editor', width=20, height=2, row=2, col=5}) local expected_pos = { [2]={{id=1001}, 'NW', 1, 2, 5} } @@ -3986,9 +3986,9 @@ describe('float window', function() it('handles resized screen', function() - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {'such', 'very', 'float'}) - local win = meths.open_win(buf, false, {relative='editor', width=15, height=4, row=2, col=10}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'such', 'very', 'float'}) + local win = api.nvim_open_win(buf, false, {relative='editor', width=15, height=4, row=2, col=10}) local expected_pos = { [4]={{id=1001}, 'NW', 1, 2, 10, true}, } @@ -4151,7 +4151,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {height=3}) + api.nvim_win_set_config(win, {height=3}) feed('gg') if multigrid then screen:expect{grid=[[ @@ -4436,8 +4436,8 @@ describe('float window', function() command("set inccommand=split") command("set laststatus=2") - local buf = meths.create_buf(false,false) - meths.open_win(buf, true, {relative='editor', width=30, height=3, row=2, col=0}) + local buf = api.nvim_create_buf(false,false) + api.nvim_open_win(buf, true, {relative='editor', width=30, height=3, row=2, col=0}) insert([[ foo @@ -4533,17 +4533,17 @@ describe('float window', function() end) it('does not crash when set cmdheight #9680', function() - local buf = meths.create_buf(false,false) - meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) + local buf = api.nvim_create_buf(false,false) + api.nvim_open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) command("set cmdheight=2") - eq(1, meths.eval('1')) + eq(1, api.nvim_eval('1')) end) describe('and completion', function() before_each(function() - local buf = meths.create_buf(false,false) - local win = meths.open_win(buf, true, {relative='editor', width=12, height=4, row=2, col=5}).id - meths.set_option_value('winhl', 'Normal:ErrorMsg', {win=win}) + local buf = api.nvim_create_buf(false,false) + local win = api.nvim_open_win(buf, true, {relative='editor', width=12, height=4, row=2, col=5}).id + api.nvim_set_option_value('winhl', 'Normal:ErrorMsg', {win=win}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -4573,7 +4573,7 @@ describe('float window', function() it('with builtin popupmenu', function() feed('ix ') - funcs.complete(3, {'aa', 'word', 'longtext'}) + fn.complete(3, {'aa', 'word', 'longtext'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -4636,7 +4636,7 @@ describe('float window', function() end feed('<c-w>wi') - funcs.complete(1, {'xx', 'yy', 'zz'}) + fn.complete(1, {'xx', 'yy', 'zz'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -4736,7 +4736,7 @@ describe('float window', function() it('with ext_popupmenu', function() screen:set_option('ext_popupmenu', true) feed('ix ') - funcs.complete(3, {'aa', 'word', 'longtext'}) + fn.complete(3, {'aa', 'word', 'longtext'}) local items = {{"aa", "", "", ""}, {"word", "", "", ""}, {"longtext", "", "", ""}} if multigrid then screen:expect{grid=[[ @@ -4796,7 +4796,7 @@ describe('float window', function() end feed('<c-w>wi') - funcs.complete(1, {'xx', 'yy', 'zz'}) + fn.complete(1, {'xx', 'yy', 'zz'}) items = {{"xx", "", "", ""}, {"yy", "", "", ""}, {"zz", "", "", ""}} if multigrid then screen:expect{grid=[[ @@ -4862,7 +4862,7 @@ describe('float window', function() before_each(function() command('hi NormalFloat guibg=#333333 guifg=NONE') feed('i') - funcs.complete(1, {'aa', 'word', 'longtext'}) + fn.complete(1, {'aa', 'word', 'longtext'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -4891,9 +4891,9 @@ describe('float window', function() ]]) end - local buf = meths.create_buf(false,true) - meths.buf_set_lines(buf,0,-1,true,{"some info", "about item"}) - win = meths.open_win(buf, false, {relative='cursor', width=12, height=2, row=1, col=10}) + local buf = api.nvim_create_buf(false,true) + api.nvim_buf_set_lines(buf,0,-1,true,{"some info", "about item"}) + win = api.nvim_open_win(buf, false, {relative='cursor', width=12, height=2, row=1, col=10}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -4955,7 +4955,7 @@ describe('float window', function() ]]) end - meths.win_close(win, false) + api.nvim_win_close(win, false) if multigrid then screen:expect([[ ## grid 1 @@ -4977,7 +4977,7 @@ describe('float window', function() end) it('and close float first', function() - meths.win_close(win, false) + api.nvim_win_close(win, false) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -5029,10 +5029,10 @@ describe('float window', function() end) it("can use Normal as background", function() - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf,0,-1,true,{"here", "float"}) - local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) - meths.set_option_value('winhl', 'Normal:Normal', {win=win}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf,0,-1,true,{"here", "float"}) + local win = api.nvim_open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) + api.nvim_set_option_value('winhl', 'Normal:Normal', {win=win}) if multigrid then screen:expect{grid=[[ @@ -5072,10 +5072,10 @@ describe('float window', function() -- the default, but be explicit: command("set laststatus=1") command("set hidden") - meths.buf_set_lines(0,0,-1,true,{"x"}) - local buf = meths.create_buf(false,false) - win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) - meths.buf_set_lines(buf,0,-1,true,{"y"}) + api.nvim_buf_set_lines(0,0,-1,true,{"x"}) + local buf = api.nvim_create_buf(false,false) + win = api.nvim_open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) + api.nvim_buf_set_lines(buf,0,-1,true,{"y"}) expected_pos = { [4]={{id=1001}, 'NW', 1, 2, 5, true} } @@ -5160,7 +5160,7 @@ describe('float window', function() end) it("w with focusable=false", function() - meths.win_set_config(win, {focusable=false}) + api.nvim_win_set_config(win, {focusable=false}) expected_pos[4][6] = false feed("<c-w>wi") -- i to provoke redraw if multigrid then @@ -5271,7 +5271,7 @@ describe('float window', function() it("focus by mouse", function() if multigrid then - meths.input_mouse('left', 'press', '', 4, 0, 0) + api.nvim_input_mouse('left', 'press', '', 4, 0, 0) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -5286,7 +5286,7 @@ describe('float window', function() {2:~ }| ]], float_pos=expected_pos} else - meths.input_mouse('left', 'press', '', 0, 2, 5) + api.nvim_input_mouse('left', 'press', '', 0, 2, 5) screen:expect([[ x | {0:~ }| @@ -5298,7 +5298,7 @@ describe('float window', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 0, 0) + api.nvim_input_mouse('left', 'press', '', 2, 0, 0) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -5313,7 +5313,7 @@ describe('float window', function() {2:~ }| ]], float_pos=expected_pos} else - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) screen:expect([[ ^x | {0:~ }| @@ -5326,11 +5326,11 @@ describe('float window', function() end) it("focus by mouse (focusable=false)", function() - meths.win_set_config(win, {focusable=false}) - meths.buf_set_lines(0, -1, -1, true, {"a"}) + api.nvim_win_set_config(win, {focusable=false}) + api.nvim_buf_set_lines(0, -1, -1, true, {"a"}) expected_pos[4][6] = false if multigrid then - meths.input_mouse('left', 'press', '', 4, 0, 0) + api.nvim_input_mouse('left', 'press', '', 4, 0, 0) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -5346,7 +5346,7 @@ describe('float window', function() {2:~ }| ]], float_pos=expected_pos} else - meths.input_mouse('left', 'press', '', 0, 2, 5) + api.nvim_input_mouse('left', 'press', '', 0, 2, 5) screen:expect([[ x | ^a | @@ -5358,7 +5358,7 @@ describe('float window', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 0, 0) + api.nvim_input_mouse('left', 'press', '', 2, 0, 0) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -5374,7 +5374,7 @@ describe('float window', function() {2:~ }| ]], float_pos=expected_pos, unchanged=true} else - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) screen:expect([[ ^x | a | @@ -6156,7 +6156,7 @@ describe('float window', function() -- enter first float feed('<c-w><c-w>') -- enter second float - meths.open_win(0, true, {relative='editor', width=20, height=2, row=4, col=8}) + api.nvim_open_win(0, true, {relative='editor', width=20, height=2, row=4, col=8}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -6476,7 +6476,7 @@ describe('float window', function() end if multigrid then - meths.win_set_config(0, {external=true, width=30, height=2}) + api.nvim_win_set_config(0, {external=true, width=30, height=2}) expected_pos = {[4]={external=true}} screen:expect{grid=[[ ## grid 1 @@ -6494,7 +6494,7 @@ describe('float window', function() ]], float_pos=expected_pos} else eq("UI doesn't support external windows", - pcall_err(meths.win_set_config, 0, {external=true, width=30, height=2})) + pcall_err(api.nvim_win_set_config, 0, {external=true, width=30, height=2})) return end @@ -6520,7 +6520,7 @@ describe('float window', function() end) it('J (float with border)', function() - meths.win_set_config(win, {relative='editor', width=20, height=2, row=2, col=5, border='single'}) + api.nvim_win_set_config(win, {relative='editor', width=20, height=2, row=2, col=5, border='single'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -6625,7 +6625,7 @@ describe('float window', function() for i = 1,5 do feed(i.."<c-w>w") feed_command("enew") - curbufmeths.set_lines(0,-1,true,{tostring(i)}) + api.nvim_buf_set_lines(0, 0,-1,true,{tostring(i)}) end if multigrid then @@ -6681,7 +6681,7 @@ describe('float window', function() for i = 1,5 do feed(i.."<c-w>w") feed('<c-w>'..k) - local nr = funcs.winnr() + local nr = fn.winnr() eq(v[i],nr, "when using <c-w>"..k.." from window "..i) end end @@ -6692,7 +6692,7 @@ describe('float window', function() if j ~= i then feed(j.."<c-w>w") feed('<c-w>p') - local nr = funcs.winnr() + local nr = fn.winnr() eq(i,nr, "when using <c-w>p to window "..i.." from window "..j) end end @@ -6792,7 +6792,7 @@ describe('float window', function() it(":tabnew and :tabnext (external)", function() if multigrid then -- also test external window wider than main screen - meths.win_set_config(win, {external=true, width=65, height=4}) + api.nvim_win_set_config(win, {external=true, width=65, height=4}) expected_pos = {[4]={external=true}} feed(":tabnew<cr>") screen:expect{grid=[[ @@ -6814,7 +6814,7 @@ describe('float window', function() ]], float_pos=expected_pos} else eq("UI doesn't support external windows", - pcall_err(meths.win_set_config, 0, {external=true, width=65, height=4})) + pcall_err(api.nvim_win_set_config, 0, {external=true, width=65, height=4})) end feed(":tabnext<cr>") @@ -6862,9 +6862,9 @@ describe('float window', function() end) it("left drag changes visual selection in float window", function() - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) - meths.open_win(buf, false, {relative='editor', width=20, height=3, row=2, col=5}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) + api.nvim_open_win(buf, false, {relative='editor', width=20, height=3, row=2, col=5}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -6886,7 +6886,7 @@ describe('float window', function() [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0}; }} - meths.input_mouse('left', 'press', '', 4, 0, 0) + api.nvim_input_mouse('left', 'press', '', 4, 0, 0) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -6907,7 +6907,7 @@ describe('float window', function() [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0}; }} - meths.input_mouse('left', 'drag', '', 4, 1, 2) + api.nvim_input_mouse('left', 'drag', '', 4, 1, 2) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -6938,7 +6938,7 @@ describe('float window', function() | ]]} - meths.input_mouse('left', 'press', '', 0, 2, 5) + api.nvim_input_mouse('left', 'press', '', 0, 2, 5) screen:expect{grid=[[ | {0:~ }| @@ -6949,7 +6949,7 @@ describe('float window', function() | ]]} - meths.input_mouse('left', 'drag', '', 0, 3, 7) + api.nvim_input_mouse('left', 'drag', '', 0, 3, 7) screen:expect{grid=[[ | {0:~ }| @@ -6963,9 +6963,9 @@ describe('float window', function() end) it("left drag changes visual selection in float window with border", function() - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) - meths.open_win(buf, false, {relative='editor', width=20, height=3, row=0, col=5, border='single'}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) + api.nvim_open_win(buf, false, {relative='editor', width=20, height=3, row=0, col=5, border='single'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -6989,7 +6989,7 @@ describe('float window', function() [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0}; }} - meths.input_mouse('left', 'press', '', 4, 1, 1) + api.nvim_input_mouse('left', 'press', '', 4, 1, 1) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -7012,7 +7012,7 @@ describe('float window', function() [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0}; }} - meths.input_mouse('left', 'drag', '', 4, 2, 3) + api.nvim_input_mouse('left', 'drag', '', 4, 2, 3) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -7045,7 +7045,7 @@ describe('float window', function() | ]]} - meths.input_mouse('left', 'press', '', 0, 1, 6) + api.nvim_input_mouse('left', 'press', '', 0, 1, 6) screen:expect{grid=[[ {5:┌────────────────────┐} | {0:~ }{5:│}{1:^foo }{5:│}{0: }| @@ -7056,7 +7056,7 @@ describe('float window', function() | ]]} - meths.input_mouse('left', 'drag', '', 0, 2, 8) + api.nvim_input_mouse('left', 'drag', '', 0, 2, 8) screen:expect{grid=[[ {5:┌────────────────────┐} | {0:~ }{5:│}{27:foo}{1: }{5:│}{0: }| @@ -7070,10 +7070,10 @@ describe('float window', function() end) it("left drag changes visual selection in float window with winbar", function() - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) - local float_win = meths.open_win(buf, false, {relative='editor', width=20, height=4, row=1, col=5}) - meths.set_option_value('winbar', 'floaty bar', {win=float_win.id}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) + local float_win = api.nvim_open_win(buf, false, {relative='editor', width=20, height=4, row=1, col=5}) + api.nvim_set_option_value('winbar', 'floaty bar', {win=float_win.id}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -7096,7 +7096,7 @@ describe('float window', function() [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0}; }} - meths.input_mouse('left', 'press', '', 4, 1, 0) + api.nvim_input_mouse('left', 'press', '', 4, 1, 0) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -7118,7 +7118,7 @@ describe('float window', function() [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0}; }} - meths.input_mouse('left', 'drag', '', 4, 2, 2) + api.nvim_input_mouse('left', 'drag', '', 4, 2, 2) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -7150,7 +7150,7 @@ describe('float window', function() | ]]} - meths.input_mouse('left', 'press', '', 0, 2, 5) + api.nvim_input_mouse('left', 'press', '', 0, 2, 5) screen:expect{grid=[[ | {0:~ }{3:floaty bar }{0: }| @@ -7161,7 +7161,7 @@ describe('float window', function() | ]]} - meths.input_mouse('left', 'drag', '', 0, 3, 7) + api.nvim_input_mouse('left', 'drag', '', 0, 3, 7) screen:expect{grid=[[ | {0:~ }{3:floaty bar }{0: }| @@ -7175,9 +7175,9 @@ describe('float window', function() end) it('left drag changes visual selection if float window is turned into a split', function() - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) - meths.open_win(buf, true, {relative='editor', width=20, height=3, row=2, col=5}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) + api.nvim_open_win(buf, true, {relative='editor', width=20, height=3, row=2, col=5}) command('wincmd L') if multigrid then screen:expect([[ @@ -7197,7 +7197,7 @@ describe('float window', function() {0:~ }|*2 ]]) - meths.input_mouse('left', 'press', '', 4, 2, 2) + api.nvim_input_mouse('left', 'press', '', 4, 2, 2) screen:expect([[ ## grid 1 [2:-------------------]{5:│}[4:--------------------]|*5 @@ -7215,7 +7215,7 @@ describe('float window', function() {0:~ }|*2 ]]) - meths.input_mouse('left', 'drag', '', 4, 1, 1) + api.nvim_input_mouse('left', 'drag', '', 4, 1, 1) screen:expect([[ ## grid 1 [2:-------------------]{5:│}[4:--------------------]|*5 @@ -7242,7 +7242,7 @@ describe('float window', function() | ]]) - meths.input_mouse('left', 'press', '', 0, 2, 22) + api.nvim_input_mouse('left', 'press', '', 0, 2, 22) screen:expect([[ {5:│}foo | {0:~ }{5:│}bar | @@ -7252,7 +7252,7 @@ describe('float window', function() | ]]) - meths.input_mouse('left', 'drag', '', 0, 1, 21) + api.nvim_input_mouse('left', 'drag', '', 0, 1, 21) screen:expect([[ {5:│}foo | {0:~ }{5:│}b^a{27:r} | @@ -7265,9 +7265,9 @@ describe('float window', function() end) it('left click sets correct curswant in float window with border', function() - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {'', '', ''}) - meths.open_win(buf, false, {relative='editor', width=20, height=3, row=0, col=5, border='single'}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'', '', ''}) + api.nvim_open_win(buf, false, {relative='editor', width=20, height=3, row=0, col=5, border='single'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -7299,25 +7299,25 @@ describe('float window', function() end if multigrid then - meths.input_mouse('left', 'press', '', 4, 3, 1) + api.nvim_input_mouse('left', 'press', '', 4, 3, 1) else - meths.input_mouse('left', 'press', '', 0, 3, 6) + api.nvim_input_mouse('left', 'press', '', 0, 3, 6) end - eq({0, 3, 1, 0, 1}, funcs.getcurpos()) + eq({0, 3, 1, 0, 1}, fn.getcurpos()) if multigrid then - meths.input_mouse('left', 'press', '', 4, 3, 2) + api.nvim_input_mouse('left', 'press', '', 4, 3, 2) else - meths.input_mouse('left', 'press', '', 0, 3, 7) + api.nvim_input_mouse('left', 'press', '', 0, 3, 7) end - eq({0, 3, 1, 0, 2}, funcs.getcurpos()) + eq({0, 3, 1, 0, 2}, fn.getcurpos()) if multigrid then - meths.input_mouse('left', 'press', '', 4, 3, 10) + api.nvim_input_mouse('left', 'press', '', 4, 3, 10) else - meths.input_mouse('left', 'press', '', 0, 3, 15) + api.nvim_input_mouse('left', 'press', '', 0, 3, 15) end - eq({0, 3, 1, 0, 10}, funcs.getcurpos()) + eq({0, 3, 1, 0, 10}, fn.getcurpos()) command('setlocal foldcolumn=1') feed('zfkgg') @@ -7356,7 +7356,7 @@ describe('float window', function() end if multigrid then - meths.input_mouse('left', 'press', '', 4, 2, 1) + api.nvim_input_mouse('left', 'press', '', 4, 2, 1) screen:expect{grid=[[ ## grid 1 [2:----------------------------------------]|*6 @@ -7379,7 +7379,7 @@ describe('float window', function() [4] = {win = {id = 1001}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0}; }} else - meths.input_mouse('left', 'press', '', 0, 2, 6) + api.nvim_input_mouse('left', 'press', '', 0, 2, 6) screen:expect{grid=[[ {5:┌────────────────────┐} | {0:~ }{5:│}{19: }{1:^ }{5:│}{0: }| @@ -7392,25 +7392,25 @@ describe('float window', function() end if multigrid then - meths.input_mouse('left', 'press', '', 4, 2, 2) + api.nvim_input_mouse('left', 'press', '', 4, 2, 2) else - meths.input_mouse('left', 'press', '', 0, 2, 7) + api.nvim_input_mouse('left', 'press', '', 0, 2, 7) end - eq({0, 2, 1, 0, 1}, funcs.getcurpos()) + eq({0, 2, 1, 0, 1}, fn.getcurpos()) if multigrid then - meths.input_mouse('left', 'press', '', 4, 2, 3) + api.nvim_input_mouse('left', 'press', '', 4, 2, 3) else - meths.input_mouse('left', 'press', '', 0, 2, 8) + api.nvim_input_mouse('left', 'press', '', 0, 2, 8) end - eq({0, 2, 1, 0, 2}, funcs.getcurpos()) + eq({0, 2, 1, 0, 2}, fn.getcurpos()) if multigrid then - meths.input_mouse('left', 'press', '', 4, 2, 11) + api.nvim_input_mouse('left', 'press', '', 4, 2, 11) else - meths.input_mouse('left', 'press', '', 0, 2, 16) + api.nvim_input_mouse('left', 'press', '', 0, 2, 16) end - eq({0, 2, 1, 0, 10}, funcs.getcurpos()) + eq({0, 2, 1, 0, 10}, fn.getcurpos()) end) it("'winblend' option", function() @@ -7454,9 +7454,9 @@ describe('float window', function() occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.]]) - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {"test", "", "popup text"}) - local win = meths.open_win(buf, false, {relative='editor', width=15, height=3, row=2, col=5}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {"test", "", "popup text"}) + local win = api.nvim_open_win(buf, false, {relative='editor', width=15, height=3, row=2, col=5}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -7492,7 +7492,7 @@ describe('float window', function() ]]) end - meths.set_option_value("winblend", 30, {win=win.id}) + api.nvim_set_option_value("winblend", 30, {win=win.id}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -7529,7 +7529,7 @@ describe('float window', function() end -- Check that 'winblend' works with NormalNC highlight - meths.set_option_value('winhighlight', 'NormalNC:Visual', {win = win}) + api.nvim_set_option_value('winhighlight', 'NormalNC:Visual', {win = win}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -7574,7 +7574,7 @@ describe('float window', function() command('hi clear NormalNC') command('hi SpecialRegion guifg=Red blend=0') - meths.buf_add_highlight(buf, -1, "SpecialRegion", 2, 0, -1) + api.nvim_buf_add_highlight(buf, -1, "SpecialRegion", 2, 0, -1) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -7648,7 +7648,7 @@ describe('float window', function() -- Test scrolling by mouse if multigrid then - meths.input_mouse('wheel', 'down', '', 4, 2, 2) + api.nvim_input_mouse('wheel', 'down', '', 4, 2, 2) screen:expect{grid=[[ ## grid 1 [2:--------------------------------------------------]|*8 @@ -7669,7 +7669,7 @@ describe('float window', function() {12:~ }|*2 ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}} else - meths.input_mouse('wheel', 'down', '', 0, 4, 7) + api.nvim_input_mouse('wheel', 'down', '', 0, 4, 7) screen:expect([[ Ut enim ad minim veniam, quis nostrud | exercitation ullamco laboris nisi ut aliquip ex | @@ -7684,9 +7684,9 @@ describe('float window', function() end -- Check that 'winblend' applies to border/title/footer - meths.win_set_config(win, {border='single', title='Title', footer='Footer'}) - meths.set_option_value('winblend', 100, {win=win.id}) - meths.set_option_value("cursorline", true, {win=0}) + api.nvim_win_set_config(win, {border='single', title='Title', footer='Footer'}) + api.nvim_set_option_value('winblend', 100, {win=win.id}) + api.nvim_set_option_value("cursorline", true, {win=0}) command('hi clear VertSplit') feed('k0') if multigrid then @@ -7730,9 +7730,9 @@ describe('float window', function() insert([[ # TODO: 测试字典信息的准确性 # FIXME: 测试字典信息的准确性]]) - local buf = meths.create_buf(false,false) - meths.buf_set_lines(buf, 0, -1, true, {'口', '口'}) - local win = meths.open_win(buf, false, {relative='editor', width=5, height=3, row=0, col=11, style='minimal'}) + local buf = api.nvim_create_buf(false,false) + api.nvim_buf_set_lines(buf, 0, -1, true, {'口', '口'}) + local win = api.nvim_open_win(buf, false, {relative='editor', width=5, height=3, row=0, col=11, style='minimal'}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -7758,7 +7758,7 @@ describe('float window', function() ]]) end - meths.win_close(win, false) + api.nvim_win_close(win, false) if multigrid then screen:expect([[ ## grid 1 @@ -7783,9 +7783,9 @@ describe('float window', function() -- The interaction between 'winblend' and doublewidth chars in the background -- does not look very good. But check no chars get incorrectly placed -- at least. Also check invisible EndOfBuffer region blends correctly. - meths.buf_set_lines(buf, 0, -1, true, {" x x x xx", " x x x x"}) - win = meths.open_win(buf, false, {relative='editor', width=12, height=3, row=0, col=11, style='minimal'}) - meths.set_option_value('winblend', 30, {win=win.id}) + api.nvim_buf_set_lines(buf, 0, -1, true, {" x x x xx", " x x x x"}) + win = api.nvim_open_win(buf, false, {relative='editor', width=12, height=3, row=0, col=11, style='minimal'}) + api.nvim_set_option_value('winblend', 30, {win=win.id}) screen:set_default_attr_ids({ [1] = {foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff')}, [2] = {foreground = Screen.colors.Grey0, background = tonumber('0xffcfff')}, @@ -7821,7 +7821,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {relative='editor', row=0, col=12}) + api.nvim_win_set_config(win, {relative='editor', row=0, col=12}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -7975,9 +7975,9 @@ describe('float window', function() end) it("correctly orders multiple opened floats (current last)", function() - local buf = meths.create_buf(false,false) - local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) - meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win.id}) + local buf = api.nvim_create_buf(false,false) + local win = api.nvim_open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) + api.nvim_set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win.id}) if multigrid then screen:expect{grid=[[ @@ -8061,9 +8061,9 @@ describe('float window', function() end) it("correctly orders multiple opened floats (non-current last)", function() - local buf = meths.create_buf(false,false) - local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) - meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win.id}) + local buf = api.nvim_create_buf(false,false) + local win = api.nvim_open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) + api.nvim_set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win.id}) if multigrid then screen:expect{grid=[[ @@ -8147,13 +8147,13 @@ describe('float window', function() end) it('can use z-index', function() - local buf = meths.create_buf(false,false) - local win1 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=1, col=5, zindex=30}) - meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win1.id}) - local win2 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=2, col=6, zindex=50}) - meths.set_option_value("winhl", "Normal:Search,EndOfBuffer:Search", {win=win2.id}) - local win3 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=3, col=7, zindex=40}) - meths.set_option_value("winhl", "Normal:Question,EndOfBuffer:Question", {win=win3.id}) + local buf = api.nvim_create_buf(false,false) + local win1 = api.nvim_open_win(buf, false, {relative='editor', width=20, height=3, row=1, col=5, zindex=30}) + api.nvim_set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win1.id}) + local win2 = api.nvim_open_win(buf, false, {relative='editor', width=20, height=3, row=2, col=6, zindex=50}) + api.nvim_set_option_value("winhl", "Normal:Search,EndOfBuffer:Search", {win=win2.id}) + local win3 = api.nvim_open_win(buf, false, {relative='editor', width=20, height=3, row=3, col=7, zindex=40}) + api.nvim_set_option_value("winhl", "Normal:Question,EndOfBuffer:Question", {win=win3.id}) if multigrid then screen:expect{grid=[[ @@ -8198,9 +8198,9 @@ describe('float window', function() end) it('can use winbar', function() - local buf = meths.create_buf(false,false) - local win1 = meths.open_win(buf, false, {relative='editor', width=15, height=3, row=1, col=5}) - meths.set_option_value('winbar', 'floaty bar', {win=win1.id}) + local buf = api.nvim_create_buf(false,false) + local win1 = api.nvim_open_win(buf, false, {relative='editor', width=15, height=3, row=1, col=5}) + api.nvim_set_option_value('winbar', 'floaty bar', {win=win1.id}) if multigrid then screen:expect{grid=[[ @@ -8234,7 +8234,7 @@ describe('float window', function() end -- resize and add a border - meths.win_set_config(win1, {relative='editor', width=15, height=4, row=0, col=4, border = 'single'}) + api.nvim_win_set_config(win1, {relative='editor', width=15, height=4, row=0, col=4, border = 'single'}) if multigrid then screen:expect{grid=[[ @@ -8273,8 +8273,8 @@ describe('float window', function() it('it can be resized with messages and cmdheight=0 #20106', function() screen:try_resize(40,9) command 'set cmdheight=0' - local buf = meths.create_buf(false,true) - local win = meths.open_win(buf, false, {relative='editor', width=40, height=4, anchor='SW', row=9, col=0, style='minimal', border="single", noautocmd=true}) + local buf = api.nvim_create_buf(false,true) + local win = api.nvim_open_win(buf, false, {relative='editor', width=40, height=4, anchor='SW', row=9, col=0, style='minimal', border="single", noautocmd=true}) if multigrid then screen:expect{grid=[[ @@ -8339,7 +8339,7 @@ describe('float window', function() end - meths.win_close(win, true) + api.nvim_win_close(win, true) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -8361,8 +8361,8 @@ describe('float window', function() it('it can be resized with messages and cmdheight=1', function() screen:try_resize(40,9) - local buf = meths.create_buf(false,true) - local win = meths.open_win(buf, false, {relative='editor', width=40, height=4, anchor='SW', row=8, col=0, style='minimal', border="single", noautocmd=true}) + local buf = api.nvim_create_buf(false,true) + local win = api.nvim_open_win(buf, false, {relative='editor', width=40, height=4, anchor='SW', row=8, col=0, style='minimal', border="single", noautocmd=true}) if multigrid then screen:expect{grid=[[ @@ -8469,7 +8469,7 @@ describe('float window', function() ]]} end - meths.win_close(win, true) + api.nvim_win_close(win, true) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -8495,7 +8495,7 @@ describe('float window', function() describe('no crash after moving and closing float window #21547', function() local function test_float_move_close(cmd) local float_opts = {relative = 'editor', row = 1, col = 1, width = 10, height = 10} - meths.open_win(meths.create_buf(false, false), true, float_opts) + api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts) if multigrid then screen:expect({float_pos = {[4] = {{id = 1001}, 'NW', 1, 1, 1, true}}}) end @@ -8522,7 +8522,7 @@ describe('float window', function() it(':sleep cursor placement #22639', function() local float_opts = {relative = 'editor', row = 1, col = 1, width = 4, height = 3} - local win = meths.open_win(meths.create_buf(false, false), true, float_opts) + local win = api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts) feed('iab<CR>cd<Esc>') feed(':sleep 100') if multigrid then @@ -8590,7 +8590,7 @@ describe('float window', function() feed('<C-C>') screen:expect_unchanged() - meths.win_set_config(win, {border = 'single'}) + api.nvim_win_set_config(win, {border = 'single'}) feed(':sleep 100') if multigrid then screen:expect{grid=[[ @@ -8739,7 +8739,7 @@ describe('float window', function() it('with rightleft and border #22640', function() local float_opts = {relative='editor', width=5, height=3, row=1, col=1, border='single'} - meths.open_win(meths.create_buf(false, false), true, float_opts) + api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts) command('setlocal rightleft') feed('iabc<CR>def<Esc>') if multigrid then @@ -8778,8 +8778,8 @@ describe('float window', function() end) it('float window with hide option', function() - local buf = meths.create_buf(false,false) - local win = meths.open_win(buf, false, {relative='editor', width=10, height=2, row=2, col=5, hide = true}) + local buf = api.nvim_create_buf(false,false) + local win = api.nvim_open_win(buf, false, {relative='editor', width=10, height=2, row=2, col=5, hide = true}) local expected_pos = { [4]={{id=1001}, 'NW', 1, 2, 5, true}, } @@ -8807,7 +8807,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {hide = false}) + api.nvim_win_set_config(win, {hide = false}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -8834,7 +8834,7 @@ describe('float window', function() ]]) end - meths.win_set_config(win, {hide=true}) + api.nvim_win_set_config(win, {hide=true}) if multigrid then screen:expect{grid=[[ ## grid 1 @@ -8860,18 +8860,18 @@ describe('float window', function() end) it(':fclose command #9663', function() - local buf_a = meths.create_buf(false,false) - local buf_b = meths.create_buf(false,false) - local buf_c = meths.create_buf(false,false) - local buf_d = meths.create_buf(false,false) + local buf_a = api.nvim_create_buf(false,false) + local buf_b = api.nvim_create_buf(false,false) + local buf_c = api.nvim_create_buf(false,false) + local buf_d = api.nvim_create_buf(false,false) local config_a = {relative='editor', width=11, height=11, row=5, col=5, border ='single', zindex=50} local config_b = {relative='editor', width=8, height=8, row=7, col=7, border ='single', zindex=70} local config_c = {relative='editor', width=4, height=4, row=9, col=9, border ='single',zindex=90} local config_d = {relative='editor', width=2, height=2, row=10, col=10, border ='single',zindex=100} - meths.open_win(buf_a, false, config_a) - meths.open_win(buf_b, false, config_b) - meths.open_win(buf_c, false, config_c) - meths.open_win(buf_d, false, config_d) + api.nvim_open_win(buf_a, false, config_a) + api.nvim_open_win(buf_b, false, config_b) + api.nvim_open_win(buf_c, false, config_c) + api.nvim_open_win(buf_d, false, config_d) local expected_pos = { [4]={{id=1001}, 'NW', 1, 5, 5, true, 50}, [5]={{id=1002}, 'NW', 1, 7, 7, true, 70}, diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index 6951d2eb9a..833e3833d5 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -4,8 +4,8 @@ local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq local command = helpers.command local feed_command = helpers.feed_command local insert = helpers.insert -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local exec = helpers.exec local assert_alive = helpers.assert_alive @@ -317,7 +317,7 @@ describe('folded lines', function() feed_command('set norightleft') if multigrid then - meths.input_mouse('left', 'press', '', 2, 0, 1) + api.nvim_input_mouse('left', 'press', '', 2, 0, 1) screen:expect([[ ## grid 1 [2:---------------------------------------------]|*7 @@ -330,7 +330,7 @@ describe('folded lines', function() :set norightleft | ]]) else - meths.input_mouse('left', 'press', '', 0, 0, 1) + api.nvim_input_mouse('left', 'press', '', 0, 0, 1) screen:expect([[ {7:▾▸}{5:^+--- 5 lines: aa··························}| {7:│ }ff | @@ -340,7 +340,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 0, 0) + api.nvim_input_mouse('left', 'press', '', 2, 0, 0) screen:expect([[ ## grid 1 [2:---------------------------------------------]|*7 @@ -352,7 +352,7 @@ describe('folded lines', function() :set norightleft | ]]) else - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) screen:expect([[ {7:▸ }{5:^+-- 6 lines: aa···························}| {1:~ }|*6 @@ -363,7 +363,7 @@ describe('folded lines', function() -- Add a winbar to avoid double-clicks command('setlocal winbar=!!!!!!') if multigrid then - meths.input_mouse('left', 'press', '', 2, 1, 0) + api.nvim_input_mouse('left', 'press', '', 2, 1, 0) screen:expect([[ ## grid 1 [2:---------------------------------------------]|*7 @@ -377,7 +377,7 @@ describe('folded lines', function() :set norightleft | ]]) else - meths.input_mouse('left', 'press', '', 0, 1, 0) + api.nvim_input_mouse('left', 'press', '', 0, 1, 0) screen:expect([[ {11:!!!!!! }| {7:▾▸}{5:^+--- 5 lines: aa··························}| @@ -388,7 +388,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 1, 1) + api.nvim_input_mouse('left', 'press', '', 2, 1, 1) screen:expect([[ ## grid 1 [2:---------------------------------------------]|*7 @@ -405,7 +405,7 @@ describe('folded lines', function() :set norightleft | ]]) else - meths.input_mouse('left', 'press', '', 0, 1, 1) + api.nvim_input_mouse('left', 'press', '', 0, 1, 1) screen:expect([[ {11:!!!!!! }| {7:▾▾}^aa | @@ -447,7 +447,7 @@ describe('folded lines', function() feed_command('1') feed('zf2j') if multigrid then - meths.input_mouse('left', 'press', '', 4, 0, 0) + api.nvim_input_mouse('left', 'press', '', 4, 0, 0) screen:expect([[ ## grid 1 [2:---------------------------------------------]|*2 @@ -466,7 +466,7 @@ describe('folded lines', function() {7:│}ff | ]]) else - meths.input_mouse('left', 'press', '', 0, 3, 0) + api.nvim_input_mouse('left', 'press', '', 0, 3, 0) screen:expect([[ {7:-}aa | {7:-}bb | @@ -480,7 +480,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 4, 1, 0) + api.nvim_input_mouse('left', 'press', '', 4, 1, 0) screen:expect([[ ## grid 1 [2:---------------------------------------------]|*2 @@ -499,7 +499,7 @@ describe('folded lines', function() {7:2}cc | ]]) else - meths.input_mouse('left', 'press', '', 0, 4, 0) + api.nvim_input_mouse('left', 'press', '', 0, 4, 0) screen:expect([[ {7:-}aa | {7:-}bb | @@ -513,7 +513,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 1, 0) + api.nvim_input_mouse('left', 'press', '', 2, 1, 0) screen:expect([[ ## grid 1 [2:---------------------------------------------]|*2 @@ -532,7 +532,7 @@ describe('folded lines', function() {7:2}cc | ]]) else - meths.input_mouse('left', 'press', '', 0, 1, 0) + api.nvim_input_mouse('left', 'press', '', 0, 1, 0) screen:expect([[ {7:-}aa | {7:+}{5:^+--- 4 lines: bb···························}| @@ -546,7 +546,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 0, 0) + api.nvim_input_mouse('left', 'press', '', 2, 0, 0) screen:expect([[ ## grid 1 [2:---------------------------------------------]|*2 @@ -565,7 +565,7 @@ describe('folded lines', function() {7:2}cc | ]]) else - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) screen:expect([[ {7:+}{5:^+-- 6 lines: aa····························}| {1:~ }| @@ -607,7 +607,7 @@ describe('folded lines', function() feed_command('1') feed('zf2j') if multigrid then - meths.input_mouse('left', 'press', '', 4, 0, 0) + api.nvim_input_mouse('left', 'press', '', 4, 0, 0) screen:expect([[ ## grid 1 [2:----------------------]{2:│}[4:----------------------]|*6 @@ -629,7 +629,7 @@ describe('folded lines', function() {1:~ }|*3 ]]) else - meths.input_mouse('left', 'press', '', 0, 0, 23) + api.nvim_input_mouse('left', 'press', '', 0, 0, 23) screen:expect([[ {7:-}aa {2:│}{7:-}^aa | {7:-}bb {2:│}{7:+}{5:+--- 4 lines: bb····}| @@ -643,7 +643,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 4, 1, 0) + api.nvim_input_mouse('left', 'press', '', 4, 1, 0) screen:expect([[ ## grid 1 [2:----------------------]{2:│}[4:----------------------]|*6 @@ -667,7 +667,7 @@ describe('folded lines', function() {7:│}ff | ]]) else - meths.input_mouse('left', 'press', '', 0, 1, 23) + api.nvim_input_mouse('left', 'press', '', 0, 1, 23) screen:expect([[ {7:-}aa {2:│}{7:-}^aa | {7:-}bb {2:│}{7:-}bb | @@ -681,7 +681,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 1, 0) + api.nvim_input_mouse('left', 'press', '', 2, 1, 0) screen:expect([[ ## grid 1 [2:----------------------]{2:│}[4:----------------------]|*6 @@ -703,7 +703,7 @@ describe('folded lines', function() {7:│}ff | ]]) else - meths.input_mouse('left', 'press', '', 0, 1, 0) + api.nvim_input_mouse('left', 'press', '', 0, 1, 0) screen:expect([[ {7:-}aa {2:│}{7:-}aa | {7:+}{5:^+--- 4 lines: bb····}{2:│}{7:-}bb | @@ -717,7 +717,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 0, 0) + api.nvim_input_mouse('left', 'press', '', 2, 0, 0) screen:expect([[ ## grid 1 [2:----------------------]{2:│}[4:----------------------]|*6 @@ -737,7 +737,7 @@ describe('folded lines', function() {7:│}ff | ]]) else - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) screen:expect([[ {7:+}{5:^+-- 6 lines: aa·····}{2:│}{7:-}aa | {1:~ }{2:│}{7:-}bb | @@ -767,7 +767,7 @@ describe('folded lines', function() feed('zO') feed_command('tab split') if multigrid then - meths.input_mouse('left', 'press', '', 4, 1, 1) + api.nvim_input_mouse('left', 'press', '', 4, 1, 1) screen:expect([[ ## grid 1 {10: + [No Name] }{11: + [No Name] }{2: }{10:X}| @@ -790,7 +790,7 @@ describe('folded lines', function() {1:~ }|*3 ]]) else - meths.input_mouse('left', 'press', '', 0, 2, 1) + api.nvim_input_mouse('left', 'press', '', 0, 2, 1) screen:expect([[ {10: + [No Name] }{11: + [No Name] }{2: }{10:X}| {7:- }^aa | @@ -802,7 +802,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 4, 0, 0) + api.nvim_input_mouse('left', 'press', '', 4, 0, 0) screen:expect([[ ## grid 1 {10: + [No Name] }{11: + [No Name] }{2: }{10:X}| @@ -823,7 +823,7 @@ describe('folded lines', function() {1:~ }|*5 ]]) else - meths.input_mouse('left', 'press', '', 0, 1, 0) + api.nvim_input_mouse('left', 'press', '', 0, 1, 0) screen:expect([[ {10: + [No Name] }{11: + [No Name] }{2: }{10:X}| {7:+ }{5:^+-- 6 lines: aa···························}| @@ -834,7 +834,7 @@ describe('folded lines', function() feed_command('tabnext') if multigrid then - meths.input_mouse('left', 'press', '', 2, 1, 1) + api.nvim_input_mouse('left', 'press', '', 2, 1, 1) screen:expect([[ ## grid 1 {11: + [No Name] }{10: + [No Name] }{2: }{10:X}| @@ -852,7 +852,7 @@ describe('folded lines', function() {1:~ }|*5 ]]) else - meths.input_mouse('left', 'press', '', 0, 2, 1) + api.nvim_input_mouse('left', 'press', '', 0, 2, 1) screen:expect([[ {11: + [No Name] }{10: + [No Name] }{2: }{10:X}| {7:- }^aa | @@ -864,7 +864,7 @@ describe('folded lines', function() end if multigrid then - meths.input_mouse('left', 'press', '', 2, 0, 0) + api.nvim_input_mouse('left', 'press', '', 2, 0, 0) screen:expect([[ ## grid 1 {11: + [No Name] }{10: + [No Name] }{2: }{10:X}| @@ -880,7 +880,7 @@ describe('folded lines', function() {1:~ }|*5 ]]) else - meths.input_mouse('left', 'press', '', 0, 1, 0) + api.nvim_input_mouse('left', 'press', '', 0, 1, 0) screen:expect([[ {11: + [No Name] }{10: + [No Name] }{2: }{10:X}| {7:+ }{5:^+-- 6 lines: aa···························}| @@ -891,7 +891,7 @@ describe('folded lines', function() end) it('works with multibyte text', function() - eq(true, meths.get_option_value('arabicshape', {})) + eq(true, api.nvim_get_option_value('arabicshape', {})) insert([[ å 语 x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢͟ العَرَبِيَّة möre text]]) @@ -1232,10 +1232,10 @@ describe('folded lines', function() end) it('work with autoresize', function() - funcs.setline(1, 'line 1') - funcs.setline(2, 'line 2') - funcs.setline(3, 'line 3') - funcs.setline(4, 'line 4') + fn.setline(1, 'line 1') + fn.setline(2, 'line 2') + fn.setline(3, 'line 3') + fn.setline(4, 'line 4') feed('zfj') command('set foldcolumn=0') @@ -1526,28 +1526,40 @@ describe('folded lines', function() end) it('fold attached virtual lines are drawn and scrolled correctly #21837', function() - funcs.setline(1, 'line 1') - funcs.setline(2, 'line 2') - funcs.setline(3, 'line 3') - funcs.setline(4, 'line 4') + fn.setline(1, 'line 1') + fn.setline(2, 'line 2') + fn.setline(3, 'line 3') + fn.setline(4, 'line 4') feed('zfj') - local ns = meths.create_namespace('ns') - meths.buf_set_extmark( + local ns = api.nvim_create_namespace('ns') + api.nvim_buf_set_extmark( 0, ns, 0, 0, { virt_lines_above = true, virt_lines = { { { 'virt_line above line 1', '' } } } } ) - meths.buf_set_extmark(0, ns, 1, 0, { virt_lines = { { { 'virt_line below line 2', '' } } } }) - meths.buf_set_extmark( + api.nvim_buf_set_extmark( + 0, + ns, + 1, + 0, + { virt_lines = { { { 'virt_line below line 2', '' } } } } + ) + api.nvim_buf_set_extmark( 0, ns, 2, 0, { virt_lines_above = true, virt_lines = { { { 'virt_line above line 3', '' } } } } ) - meths.buf_set_extmark(0, ns, 3, 0, { virt_lines = { { { 'virt_line below line 4', '' } } } }) + api.nvim_buf_set_extmark( + 0, + ns, + 3, + 0, + { virt_lines = { { { 'virt_line below line 4', '' } } } } + ) if multigrid then screen:expect { grid = [[ @@ -1624,7 +1636,7 @@ describe('folded lines', function() end feed('kzo<C-Y>') - funcs.setline(5, 'line 5') + fn.setline(5, 'line 5') if multigrid then screen:expect { grid = [[ @@ -1667,7 +1679,7 @@ describe('folded lines', function() ]]) end - meths.input_mouse('left', 'press', '', multigrid and 2 or 0, 4, 0) + api.nvim_input_mouse('left', 'press', '', multigrid and 2 or 0, 4, 0) eq({ screencol = 1, screenrow = 5, @@ -1677,9 +1689,9 @@ describe('folded lines', function() line = 3, column = 1, coladd = 0, - }, funcs.getmousepos()) + }, fn.getmousepos()) - meths.buf_set_extmark( + api.nvim_buf_set_extmark( 0, ns, 1, @@ -1953,7 +1965,7 @@ describe('folded lines', function() ]]) end - meths.input_mouse('left', 'press', '3', multigrid and 2 or 0, 3, 0) + api.nvim_input_mouse('left', 'press', '3', multigrid and 2 or 0, 3, 0) if multigrid then screen:expect { grid = [[ @@ -1992,7 +2004,7 @@ describe('folded lines', function() ]]) end - meths.input_mouse('left', 'drag', '3', multigrid and 2 or 0, 7, 0) + api.nvim_input_mouse('left', 'drag', '3', multigrid and 2 or 0, 7, 0) if multigrid then screen:expect { grid = [[ @@ -2029,7 +2041,7 @@ describe('folded lines', function() ]]) end - meths.input_mouse('left', 'drag', '3', multigrid and 2 or 0, 7, 5) + api.nvim_input_mouse('left', 'drag', '3', multigrid and 2 or 0, 7, 5) if multigrid then screen:expect { grid = [[ @@ -2388,7 +2400,7 @@ describe('folded lines', function() ]]) end feed('<Esc>') - funcs.matchadd('Search', 'line') + fn.matchadd('Search', 'line') if multigrid then screen:expect([[ ## grid 1 @@ -2419,9 +2431,9 @@ describe('folded lines', function() command('hi! CursorLine guibg=NONE guifg=Red gui=NONE') command('hi F0 guibg=Red guifg=Black') command('hi F1 guifg=White') - meths.set_option_value('cursorline', true, {}) - meths.set_option_value('foldcolumn', '4', {}) - meths.set_option_value( + api.nvim_set_option_value('cursorline', true, {}) + api.nvim_set_option_value('foldcolumn', '4', {}) + api.nvim_set_option_value( 'foldtext', '[' .. '["▶", ["F0", "F1"]], ' @@ -2454,7 +2466,7 @@ describe('folded lines', function() | ]]) end - eq('▶-\tvalid English', funcs.foldtextresult(2)) + eq('▶-\tvalid English', fn.foldtextresult(2)) feed('zo') if multigrid then @@ -2481,8 +2493,8 @@ describe('folded lines', function() | ]]) end - eq('▶--\tsentence composed by', funcs.foldtextresult(3)) - eq('▶--\tin his cave.', funcs.foldtextresult(5)) + eq('▶--\tsentence composed by', fn.foldtextresult(3)) + eq('▶--\tin his cave.', fn.foldtextresult(5)) command('hi! Visual guibg=Red') feed('V2k') @@ -2511,7 +2523,7 @@ describe('folded lines', function() ]]) end - meths.set_option_value('rightleft', true, {}) + api.nvim_set_option_value('rightleft', true, {}) if multigrid then screen:expect([[ ## grid 1 diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 54c14fb44a..fc692f47bb 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -5,9 +5,8 @@ local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, exec = helpers.command, helpers.exec local eval = helpers.eval local feed_command, eq = helpers.feed_command, helpers.eq -local curbufmeths = helpers.curbufmeths -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local exec_lua = helpers.exec_lua describe('colorscheme compatibility', function() @@ -16,8 +15,8 @@ describe('colorscheme compatibility', function() end) it('&t_Co exists and is set to 256 by default', function() - eq(1, funcs.exists('&t_Co')) - eq(1, funcs.exists('+t_Co')) + eq(1, fn.exists('&t_Co')) + eq(1, fn.exists('+t_Co')) eq('256', eval('&t_Co')) end) end) @@ -2088,7 +2087,7 @@ describe("'winhighlight' highlight", function() end) it('can override NonText, Conceal and EndOfBuffer', function() - curbufmeths.set_lines(0, -1, true, { 'raa\000' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'raa\000' }) command('call matchaddpos("Conceal", [[1,2]], 0, -1, {"conceal": "#"})') command('set cole=2 cocu=nvic') command('split') @@ -2403,13 +2402,13 @@ describe('highlight namespaces', function() [10] = { bold = true, foreground = Screen.colors.SeaGreen }, } - ns1 = meths.create_namespace 'grungy' - ns2 = meths.create_namespace 'ultrared' + ns1 = api.nvim_create_namespace 'grungy' + ns2 = api.nvim_create_namespace 'ultrared' - meths.set_hl(ns1, 'Normal', { bg = 'DarkGrey' }) - meths.set_hl(ns1, 'NonText', { bg = 'DarkOrange4', fg = 'DarkCyan', italic = true }) - meths.set_hl(ns2, 'Normal', { bg = 'DarkMagenta' }) - meths.set_hl(ns2, 'NonText', { fg = 'Crimson' }) + api.nvim_set_hl(ns1, 'Normal', { bg = 'DarkGrey' }) + api.nvim_set_hl(ns1, 'NonText', { bg = 'DarkOrange4', fg = 'DarkCyan', italic = true }) + api.nvim_set_hl(ns2, 'Normal', { bg = 'DarkMagenta' }) + api.nvim_set_hl(ns2, 'NonText', { fg = 'Crimson' }) end) it('can be used globally', function() @@ -2421,7 +2420,7 @@ describe('highlight namespaces', function() ]], } - meths.set_hl_ns(ns1) + api.nvim_set_hl_ns(ns1) screen:expect { grid = [[ {2:^ }| @@ -2430,7 +2429,7 @@ describe('highlight namespaces', function() ]], } - meths.set_hl_ns(ns2) + api.nvim_set_hl_ns(ns2) screen:expect { grid = [[ {4:^ }| @@ -2439,7 +2438,7 @@ describe('highlight namespaces', function() ]], } - meths.set_hl_ns(0) + api.nvim_set_hl_ns(0) screen:expect { grid = [[ ^ | @@ -2450,13 +2449,13 @@ describe('highlight namespaces', function() end) it('can be used per window', function() - local win1 = meths.get_current_win() + local win1 = api.nvim_get_current_win() command 'split' - local win2 = meths.get_current_win() + local win2 = api.nvim_get_current_win() command 'split' - meths.win_set_hl_ns(win1, ns1) - meths.win_set_hl_ns(win2, ns2) + api.nvim_win_set_hl_ns(win1, ns1) + api.nvim_win_set_hl_ns(win2, ns2) screen:expect { grid = [[ @@ -2483,7 +2482,7 @@ describe('highlight namespaces', function() ]], } - meths.set_hl(0, 'EndOfBuffer', { fg = '#333333' }) + api.nvim_set_hl(0, 'EndOfBuffer', { fg = '#333333' }) screen:expect { grid = [[ ^ | @@ -2508,7 +2507,7 @@ describe('highlight namespaces', function() it('Normal in set_hl #25474', function() command('highlight Ignore guifg=bg ctermfg=White') - meths.set_hl(0, 'Normal', { bg = '#333333' }) + api.nvim_set_hl(0, 'Normal', { bg = '#333333' }) command('highlight Ignore') screen:expect { grid = [[ diff --git a/test/functional/ui/hlstate_spec.lua b/test/functional/ui/hlstate_spec.lua index 8147636326..278e6e5272 100644 --- a/test/functional/ui/hlstate_spec.lua +++ b/test/functional/ui/hlstate_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear, insert = helpers.clear, helpers.insert local command = helpers.command -local meths = helpers.meths +local api = helpers.api local testprg = helpers.testprg local thelpers = require('test.functional.terminal.helpers') local skip = helpers.skip @@ -28,8 +28,8 @@ describe('ext_hlstate detailed highlights', function() insert([[ these are some lines with colorful text]]) - meths.buf_add_highlight(0, -1, 'String', 0, 10, 14) - meths.buf_add_highlight(0, -1, 'Statement', 1, 5, -1) + api.nvim_buf_add_highlight(0, -1, 'String', 0, 10, 14) + api.nvim_buf_add_highlight(0, -1, 'Statement', 1, 5, -1) command('/th co') screen:expect( diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index 6b64928622..f4347a460e 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -7,15 +7,14 @@ local eval = helpers.eval local expect = helpers.expect local feed = helpers.feed local insert = helpers.insert -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local neq = helpers.neq local ok = helpers.ok local retry = helpers.retry local source = helpers.source local poke_eventloop = helpers.poke_eventloop -local nvim = helpers.nvim -local sleep = helpers.sleep +local sleep = vim.uv.sleep local testprg = helpers.testprg local assert_alive = helpers.assert_alive @@ -158,19 +157,19 @@ describe(":substitute, 'inccommand' preserves", function() common_setup(screen, 'nosplit', ('abc\ndef\n'):rep(50)) feed('ggyG') - local X = meths.get_vvar('maxcol') - eq({ 0, 1, 1, 0 }, funcs.getpos("'[")) - eq({ 0, 101, X, 0 }, funcs.getpos("']")) + local X = api.nvim_get_vvar('maxcol') + eq({ 0, 1, 1, 0 }, fn.getpos("'[")) + eq({ 0, 101, X, 0 }, fn.getpos("']")) feed(":'[,']s/def/") poke_eventloop() - eq({ 0, 1, 1, 0 }, funcs.getpos("'[")) - eq({ 0, 101, X, 0 }, funcs.getpos("']")) + eq({ 0, 1, 1, 0 }, fn.getpos("'[")) + eq({ 0, 101, X, 0 }, fn.getpos("']")) feed('DEF/g') poke_eventloop() - eq({ 0, 1, 1, 0 }, funcs.getpos("'[")) - eq({ 0, 101, X, 0 }, funcs.getpos("']")) + eq({ 0, 1, 1, 0 }, fn.getpos("'[")) + eq({ 0, 101, X, 0 }, fn.getpos("']")) feed('<CR>') expect(('abc\nDEF\n'):rep(50)) @@ -205,8 +204,8 @@ describe(":substitute, 'inccommand' preserves", function() feed(':%s/as/glork/') poke_eventloop() feed('<enter>') - eq(meths.get_option_value('undolevels', { scope = 'global' }), 139) - eq(meths.get_option_value('undolevels', { buf = 0 }), 34) + eq(api.nvim_get_option_value('undolevels', { scope = 'global' }), 139) + eq(api.nvim_get_option_value('undolevels', { buf = 0 }), 34) end) end @@ -1099,7 +1098,7 @@ describe(':substitute, inccommand=split', function() feed('<CR>') poke_eventloop() feed(':vs tmp<enter>') - eq(3, funcs.bufnr('$')) + eq(3, fn.bufnr('$')) end) it('works with the n flag', function() @@ -1119,7 +1118,7 @@ describe(':substitute, inccommand=split', function() it("deactivates if 'redrawtime' is exceeded #5602", function() -- prevent redraws from 'incsearch' - meths.set_option_value('incsearch', false, {}) + api.nvim_set_option_value('incsearch', false, {}) -- Assert that 'inccommand' is ENABLED initially. eq('split', eval('&inccommand')) -- Set 'redrawtime' to minimal value, to ensure timeout is triggered. @@ -1752,7 +1751,7 @@ describe("'inccommand' autocommands", function() end local function register_autocmd(event) - meths.set_var(event .. '_fired', {}) + api.nvim_set_var(event .. '_fired', {}) command('autocmd ' .. event .. ' * call add(g:' .. event .. "_fired, expand('<abuf>'))") end @@ -1768,14 +1767,14 @@ describe("'inccommand' autocommands", function() feed(':%s/tw') for event, _ in pairs(eventsExpected) do - eventsObserved[event].open = meths.get_var(event .. '_fired') - meths.set_var(event .. '_fired', {}) + eventsObserved[event].open = api.nvim_get_var(event .. '_fired') + api.nvim_set_var(event .. '_fired', {}) end feed('/<enter>') for event, _ in pairs(eventsExpected) do - eventsObserved[event].close = meths.get_var(event .. '_fired') + eventsObserved[event].close = api.nvim_get_var(event .. '_fired') end for event, _ in pairs(eventsExpected) do @@ -1898,20 +1897,20 @@ describe("'inccommand' with 'gdefault'", function() common_setup(nil, 'nosplit', '{') command('set gdefault') feed(':s/{\\n') - eq({ mode = 'c', blocking = false }, nvim('get_mode')) + eq({ mode = 'c', blocking = false }, api.nvim_get_mode()) feed('/A<Enter>') expect('A') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('with multiline text and range, does not lock up #7244', function() common_setup(nil, 'nosplit', '{\n\n{') command('set gdefault') feed(':%s/{\\n') - eq({ mode = 'c', blocking = false }, nvim('get_mode')) + eq({ mode = 'c', blocking = false }, api.nvim_get_mode()) feed('/A<Enter>') expect('A\nA') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('does not crash on zero-width matches #7485', function() @@ -1920,9 +1919,9 @@ describe("'inccommand' with 'gdefault'", function() feed('gg') feed('Vj') feed(':s/\\%V') - eq({ mode = 'c', blocking = false }, nvim('get_mode')) + eq({ mode = 'c', blocking = false }, api.nvim_get_mode()) feed('<Esc>') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) it('removes highlights after abort for a zero-width match', function() @@ -2614,8 +2613,8 @@ it(':substitute with inccommand, allows :redraw before first separator is typed local screen = Screen.new(30, 6) common_setup(screen, 'split', 'foo bar baz\nbar baz fox\nbar foo baz') command('hi! link NormalFloat CursorLine') - local float_buf = meths.create_buf(false, true) - meths.open_win(float_buf, false, { + local float_buf = api.nvim_create_buf(false, true) + api.nvim_open_win(float_buf, false, { relative = 'editor', height = 1, width = 5, @@ -2641,7 +2640,7 @@ it(':substitute with inccommand, allows :redraw before first separator is typed {15:~ }| :%s^ | ]]) - meths.buf_set_lines(float_buf, 0, -1, true, { 'foo' }) + api.nvim_buf_set_lines(float_buf, 0, -1, true, { 'foo' }) command('redraw') screen:expect([[ foo bar baz | @@ -2745,7 +2744,7 @@ it(':substitute with inccommand works properly if undo is not synced #20029', fu clear() local screen = Screen.new(30, 6) common_setup(screen, 'nosplit', 'foo\nbar\nbaz') - meths.set_keymap('x', '<F2>', '<Esc>`<Oaaaaa asdf<Esc>`>obbbbb asdf<Esc>V`<k:s/asdf/', {}) + api.nvim_set_keymap('x', '<F2>', '<Esc>`<Oaaaaa asdf<Esc>`>obbbbb asdf<Esc>V`<k:s/asdf/', {}) feed('gg0<C-V>lljj<F2>') screen:expect([[ aaaaa | diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index 92bc6a7f76..80862b668f 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -4,10 +4,10 @@ local feed, next_msg, eq = helpers.feed, helpers.next_msg, helpers.eq local command = helpers.command local expect = helpers.expect local curbuf_contents = helpers.curbuf_contents -local meths = helpers.meths +local api = helpers.api local exec_lua = helpers.exec_lua local write_file = helpers.write_file -local funcs = helpers.funcs +local fn = helpers.fn local eval = helpers.eval local Screen = require('test.functional.ui.screen') @@ -154,7 +154,7 @@ describe('input split utf sequences', function() it('ok', function() local str = '►' feed('i' .. str:sub(1, 1)) - helpers.sleep(10) + vim.uv.sleep(10) feed(str:sub(2, 3)) expect('►') end) @@ -163,7 +163,7 @@ describe('input split utf sequences', function() command('inoremap ► E296BA') local str = '►' feed('i' .. str:sub(1, 1)) - helpers.sleep(10) + vim.uv.sleep(10) feed(str:sub(2, 3)) expect('E296BA') end) @@ -244,7 +244,7 @@ it('Ctrl-6 is Ctrl-^ vim-patch:8.1.2333', function() command('split aaa') command('edit bbb') feed('<C-6>') - eq('aaa', funcs.bufname()) + eq('aaa', fn.bufname()) end) it('c_CTRL-R_CTRL-R, i_CTRL-R_CTRL-R, i_CTRL-G_CTRL-K work properly vim-patch:8.1.2346', function() @@ -303,7 +303,7 @@ it('unsimplified mapping works when there was a partial match vim-patch:8.2.4504 command('nnoremap <C-J> a') command('nnoremap <NL> x') command('nnoremap <C-J>x <Nop>') - funcs.setline(1, 'x') + fn.setline(1, 'x') -- CTRL-J b should have trigger the <C-J> mapping and then insert "b" feed('<C-J>b<Esc>') expect('xb') @@ -392,7 +392,7 @@ end) describe('event processing and input', function() it('not blocked by event bursts', function() - meths.set_keymap( + api.nvim_set_keymap( '', '<f2>', "<cmd>lua vim.rpcnotify(1, 'stop') winning = true <cr>", diff --git a/test/functional/ui/linematch_spec.lua b/test/functional/ui/linematch_spec.lua index ca02fa6403..40df5cadf1 100644 --- a/test/functional/ui/linematch_spec.lua +++ b/test/functional/ui/linematch_spec.lua @@ -1118,9 +1118,9 @@ describe('regressions', function() screen = Screen.new(100, 20) screen:attach() -- line must be greater than MATCH_CHAR_MAX_LEN - helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1000) .. 'hello' }) + helpers.api.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1000) .. 'hello' }) helpers.exec 'vnew' - helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1010) .. 'world' }) + helpers.api.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1010) .. 'world' }) helpers.exec 'windo diffthis' end) @@ -1133,9 +1133,9 @@ describe('regressions', function() for i = 0, 29 do lines[#lines + 1] = tostring(i) end - helpers.curbufmeths.set_lines(0, -1, false, lines) + helpers.api.nvim_buf_set_lines(0, 0, -1, false, lines) helpers.exec 'vnew' - helpers.curbufmeths.set_lines(0, -1, false, { '00', '29' }) + helpers.api.nvim_buf_set_lines(0, 0, -1, false, { '00', '29' }) helpers.exec 'windo diffthis' feed('<C-e>') screen:expect { diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 2a402437fd..4f95cd909c 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -5,7 +5,7 @@ local eval = helpers.eval local eq = helpers.eq local command = helpers.command local set_method_error = helpers.set_method_error -local meths = helpers.meths +local api = helpers.api local async_meths = helpers.async_meths local test_build_dir = helpers.test_build_dir local nvim_prog = helpers.nvim_prog @@ -17,7 +17,7 @@ local poke_eventloop = helpers.poke_eventloop local assert_alive = helpers.assert_alive local is_os = helpers.is_os local is_ci = helpers.is_ci -local funcs = helpers.funcs +local fn = helpers.fn local skip = helpers.skip describe('ui/ext_messages', function() @@ -1445,7 +1445,7 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim it('prints lines in Ex mode correctly with a burst of carriage returns #19341', function() command('set number') - meths.buf_set_lines(0, 0, 0, true, { 'aaa', 'bbb', 'ccc' }) + api.nvim_buf_set_lines(0, 0, 0, true, { 'aaa', 'bbb', 'ccc' }) feed('gggQ<CR><CR>1<CR><CR>vi') screen:expect([[ Entering Ex mode. Type "visual" to go to Normal mode. | @@ -1542,7 +1542,7 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim {1:~ }|*5 | ]]) - eq(1, meths.get_option_value('cmdheight', {})) + eq(1, api.nvim_get_option_value('cmdheight', {})) end) it('using nvim_echo in VimResized does not cause hit-enter prompt #26139', function() @@ -1553,7 +1553,7 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim {1:~ }|*3 | ]]) - eq({ mode = 'n', blocking = false }, meths.get_mode()) + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) end) end) @@ -1675,9 +1675,9 @@ describe('ui/ext_messages', function() }) feed(':set mouse=a<cr>') - meths.input_mouse('left', 'press', '', 0, 12, 10) + api.nvim_input_mouse('left', 'press', '', 0, 12, 10) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 11, 10) + api.nvim_input_mouse('left', 'drag', '', 0, 11, 10) feed('<c-l>') feed(':set cmdheight<cr>') screen:expect({ @@ -2183,7 +2183,7 @@ aliquip ex ea commodo consequat.]] end) it('with :!cmd does not crash on resize', function() - skip(funcs.executable('sleep') == 0, 'missing "sleep" command') + skip(fn.executable('sleep') == 0, 'missing "sleep" command') feed(':!sleep 1<cr>') screen:expect { grid = [[ diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index d1479c13fe..a7710ab584 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, meths = helpers.clear, helpers.feed, helpers.meths +local clear, feed, api = helpers.clear, helpers.feed, helpers.api local insert, feed_command = helpers.insert, helpers.feed_command -local eq, funcs = helpers.eq, helpers.funcs +local eq, fn = helpers.eq, helpers.fn local poke_eventloop = helpers.poke_eventloop local command = helpers.command local exec = helpers.exec @@ -12,8 +12,8 @@ describe('ui/mouse/input', function() before_each(function() clear() - meths.set_option_value('mouse', 'a', {}) - meths.set_option_value('list', true, {}) + api.nvim_set_option_value('mouse', 'a', {}) + api.nvim_set_option_value('list', true, {}) -- NB: this is weird, but mostly irrelevant to the test -- So I didn't bother to change it command('set listchars=eol:$') @@ -69,7 +69,7 @@ describe('ui/mouse/input', function() end) it("in external ui works with unset 'mouse'", function() - meths.set_option_value('mouse', '', {}) + api.nvim_set_option_value('mouse', '', {}) feed('<LeftMouse><2,1>') screen:expect { grid = [[ @@ -379,7 +379,7 @@ describe('ui/mouse/input', function() end) it('left click in default tabline (position 24) closes tab', function() - meths.set_option_value('hidden', true, {}) + api.nvim_set_option_value('hidden', true, {}) feed_command('%delete') insert('this is foo') feed_command('silent file foo | tabnew | file bar') @@ -399,7 +399,7 @@ describe('ui/mouse/input', function() end) it('double click in default tabline (position 4) opens new tab', function() - meths.set_option_value('hidden', true, {}) + api.nvim_set_option_value('hidden', true, {}) feed_command('%delete') insert('this is foo') feed_command('silent file foo | tabnew | file bar') @@ -432,8 +432,8 @@ describe('ui/mouse/input', function() return call('Test', a:000 + [2]) endfunction ]]) - meths.set_option_value('tabline', '%@Test@test%X-%5@Test2@test2', {}) - meths.set_option_value('showtabline', 2, {}) + api.nvim_set_option_value('tabline', '%@Test@test%X-%5@Test2@test2', {}) + api.nvim_set_option_value('showtabline', 2, {}) screen:expect([[ {fill:test-test2 }| testing | @@ -441,17 +441,17 @@ describe('ui/mouse/input', function() support and selectio^n | | ]]) - meths.set_var('reply', {}) + api.nvim_set_var('reply', {}) end) local check_reply = function(expected) - eq(expected, meths.get_var('reply')) - meths.set_var('reply', {}) + eq(expected, api.nvim_get_var('reply')) + api.nvim_set_var('reply', {}) end local test_click = function(name, click_str, click_num, mouse_button, modifiers) local function doit(do_click) - eq(1, funcs.has('tablineat')) + eq(1, fn.has('tablineat')) do_click(0, 3) check_reply({ 0, click_num, mouse_button, modifiers }) do_click(0, 4) @@ -475,7 +475,7 @@ describe('ui/mouse/input', function() for char in string.gmatch(modifiers, '%w') do modstr = modstr .. char .. '-' -- - not needed but should be accepted end - meths.input_mouse(buttons[mouse_button], 'press', modstr, 0, row, col) + api.nvim_input_mouse(buttons[mouse_button], 'press', modstr, 0, row, col) end) end) end @@ -609,7 +609,7 @@ describe('ui/mouse/input', function() ]], } - meths.input_mouse('left', 'press', '', 0, 6, 27) + api.nvim_input_mouse('left', 'press', '', 0, 6, 27) screen:expect { grid = [[ testing │testing | @@ -624,7 +624,7 @@ describe('ui/mouse/input', function() | ]], } - meths.input_mouse('left', 'drag', '', 0, 7, 30) + api.nvim_input_mouse('left', 'drag', '', 0, 7, 30) screen:expect { grid = [[ @@ -779,7 +779,7 @@ describe('ui/mouse/input', function() end) it('ctrl + left click will search for a tag', function() - meths.set_option_value('tags', './non-existent-tags-file', {}) + api.nvim_set_option_value('tags', './non-existent-tags-file', {}) feed('<C-LeftMouse><0,0>') screen:expect([[ {6:E433: No tags file} | @@ -792,28 +792,28 @@ describe('ui/mouse/input', function() end) it('x1 and x2 can be triggered by api', function() - meths.set_var('x1_pressed', 0) - meths.set_var('x1_released', 0) - meths.set_var('x2_pressed', 0) - meths.set_var('x2_released', 0) + api.nvim_set_var('x1_pressed', 0) + api.nvim_set_var('x1_released', 0) + api.nvim_set_var('x2_pressed', 0) + api.nvim_set_var('x2_released', 0) command('nnoremap <X1Mouse> <Cmd>let g:x1_pressed += 1<CR>') command('nnoremap <X1Release> <Cmd>let g:x1_released += 1<CR>') command('nnoremap <X2Mouse> <Cmd>let g:x2_pressed += 1<CR>') command('nnoremap <X2Release> <Cmd>let g:x2_released += 1<CR>') - meths.input_mouse('x1', 'press', '', 0, 0, 0) - meths.input_mouse('x1', 'release', '', 0, 0, 0) - meths.input_mouse('x2', 'press', '', 0, 0, 0) - meths.input_mouse('x2', 'release', '', 0, 0, 0) - eq(1, meths.get_var('x1_pressed'), 'x1 pressed once') - eq(1, meths.get_var('x1_released'), 'x1 released once') - eq(1, meths.get_var('x2_pressed'), 'x2 pressed once') - eq(1, meths.get_var('x2_released'), 'x2 released once') + api.nvim_input_mouse('x1', 'press', '', 0, 0, 0) + api.nvim_input_mouse('x1', 'release', '', 0, 0, 0) + api.nvim_input_mouse('x2', 'press', '', 0, 0, 0) + api.nvim_input_mouse('x2', 'release', '', 0, 0, 0) + eq(1, api.nvim_get_var('x1_pressed'), 'x1 pressed once') + eq(1, api.nvim_get_var('x1_released'), 'x1 released once') + eq(1, api.nvim_get_var('x2_pressed'), 'x2 pressed once') + eq(1, api.nvim_get_var('x2_released'), 'x2 released once') end) it('dragging vertical separator', function() screen:try_resize(45, 5) command('setlocal nowrap') - local oldwin = meths.get_current_win().id + local oldwin = api.nvim_get_current_win().id command('rightbelow vnew') screen:expect([[ testing │{0:^$} | @@ -822,9 +822,9 @@ describe('ui/mouse/input', function() {4:[No Name] [+] }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'press', '', 0, 0, 22) + api.nvim_input_mouse('left', 'press', '', 0, 0, 22) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 1, 12) + api.nvim_input_mouse('left', 'drag', '', 0, 1, 12) screen:expect([[ testing │{0:^$} | mouse │{0:~ }| @@ -832,7 +832,7 @@ describe('ui/mouse/input', function() {4:< Name] [+] }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'drag', '', 0, 2, 2) + api.nvim_input_mouse('left', 'drag', '', 0, 2, 2) screen:expect([[ te│{0:^$} | mo│{0:~ }| @@ -840,17 +840,17 @@ describe('ui/mouse/input', function() {4:< }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'release', '', 0, 2, 2) - meths.set_option_value('statuscolumn', 'foobar', { win = oldwin }) + api.nvim_input_mouse('left', 'release', '', 0, 2, 2) + api.nvim_set_option_value('statuscolumn', 'foobar', { win = oldwin }) screen:expect([[ {8:fo}│{0:^$} | {8:fo}│{0:~ }|*2 {4:< }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'press', '', 0, 0, 2) + api.nvim_input_mouse('left', 'press', '', 0, 0, 2) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 1, 12) + api.nvim_input_mouse('left', 'drag', '', 0, 1, 12) screen:expect([[ {8:foobar}testin│{0:^$} | {8:foobar}mouse │{0:~ }| @@ -858,7 +858,7 @@ describe('ui/mouse/input', function() {4:< Name] [+] }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'drag', '', 0, 2, 22) + api.nvim_input_mouse('left', 'drag', '', 0, 2, 22) screen:expect([[ {8:foobar}testing │{0:^$} | {8:foobar}mouse │{0:~ }| @@ -866,7 +866,7 @@ describe('ui/mouse/input', function() {4:[No Name] [+] }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'release', '', 0, 2, 22) + api.nvim_input_mouse('left', 'release', '', 0, 2, 22) end) local function wheel(use_api) @@ -901,7 +901,7 @@ describe('ui/mouse/input', function() :vsp | ]]) if use_api then - meths.input_mouse('wheel', 'down', '', 0, 0, 0) + api.nvim_input_mouse('wheel', 'down', '', 0, 0, 0) else feed('<ScrollWheelDown><0,0>') end @@ -922,7 +922,7 @@ describe('ui/mouse/input', function() :vsp | ]]) if use_api then - meths.input_mouse('wheel', 'up', '', 0, 0, 27) + api.nvim_input_mouse('wheel', 'up', '', 0, 0, 27) else feed('<ScrollWheelUp><27,0>') end @@ -943,8 +943,8 @@ describe('ui/mouse/input', function() :vsp | ]]) if use_api then - meths.input_mouse('wheel', 'up', '', 0, 7, 27) - meths.input_mouse('wheel', 'up', '', 0, 7, 27) + api.nvim_input_mouse('wheel', 'up', '', 0, 7, 27) + api.nvim_input_mouse('wheel', 'up', '', 0, 7, 27) else feed('<ScrollWheelUp><27,7><ScrollWheelUp>') end @@ -1016,7 +1016,7 @@ describe('ui/mouse/input', function() | ]]) - meths.input_mouse('wheel', 'left', '', 0, 0, 27) + api.nvim_input_mouse('wheel', 'left', '', 0, 0, 27) screen:expect([[ |*2 n bbbbbbbbbbbbbbbbbbb^b | @@ -1025,7 +1025,7 @@ describe('ui/mouse/input', function() ]]) feed('^') - meths.input_mouse('wheel', 'right', '', 0, 0, 0) + api.nvim_input_mouse('wheel', 'right', '', 0, 0, 0) screen:expect([[ g | | @@ -1048,7 +1048,7 @@ describe('ui/mouse/input', function() | ]]) - meths.input_mouse('wheel', 'right', '', 0, 0, 27) + api.nvim_input_mouse('wheel', 'right', '', 0, 0, 27) screen:expect([[ g | | @@ -1068,7 +1068,7 @@ describe('ui/mouse/input', function() | ]]) - meths.input_mouse('wheel', 'right', '', 0, 0, 27) + api.nvim_input_mouse('wheel', 'right', '', 0, 0, 27) screen:expect([[ g | | @@ -1605,39 +1605,39 @@ describe('ui/mouse/input', function() describe('(matchadd())', function() before_each(function() - funcs.matchadd('Conceal', [[\*]]) - funcs.matchadd('Conceal', [[cats]], 10, -1, { conceal = 'X' }) - funcs.matchadd('Conceal', [[\n\@<=x]], 10, -1, { conceal = '>' }) + fn.matchadd('Conceal', [[\*]]) + fn.matchadd('Conceal', [[cats]], 10, -1, { conceal = 'X' }) + fn.matchadd('Conceal', [[\n\@<=x]], 10, -1, { conceal = '>' }) end) test_mouse_click_conceal() end) describe('(extmarks)', function() before_each(function() - local ns = meths.create_namespace('conceal') - meths.buf_set_extmark(0, ns, 0, 11, { end_col = 12, conceal = '' }) - meths.buf_set_extmark(0, ns, 0, 14, { end_col = 15, conceal = '' }) - meths.buf_set_extmark(0, ns, 1, 5, { end_col = 6, conceal = '' }) - meths.buf_set_extmark(0, ns, 1, 8, { end_col = 9, conceal = '' }) - meths.buf_set_extmark(0, ns, 1, 10, { end_col = 11, conceal = '' }) - meths.buf_set_extmark(0, ns, 1, 13, { end_col = 14, conceal = '' }) - meths.buf_set_extmark(0, ns, 1, 15, { end_col = 16, conceal = '' }) - meths.buf_set_extmark(0, ns, 1, 18, { end_col = 19, conceal = '' }) - meths.buf_set_extmark(0, ns, 2, 24, { end_col = 25, conceal = '' }) - meths.buf_set_extmark(0, ns, 2, 29, { end_col = 30, conceal = '' }) - meths.buf_set_extmark(0, ns, 2, 25, { end_col = 29, conceal = 'X' }) - meths.buf_set_extmark(0, ns, 2, 0, { end_col = 1, conceal = '>' }) + local ns = api.nvim_create_namespace('conceal') + api.nvim_buf_set_extmark(0, ns, 0, 11, { end_col = 12, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 0, 14, { end_col = 15, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 5, { end_col = 6, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 8, { end_col = 9, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 10, { end_col = 11, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 13, { end_col = 14, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 15, { end_col = 16, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 18, { end_col = 19, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 2, 24, { end_col = 25, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 2, 29, { end_col = 30, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 2, 25, { end_col = 29, conceal = 'X' }) + api.nvim_buf_set_extmark(0, ns, 2, 0, { end_col = 1, conceal = '>' }) end) test_mouse_click_conceal() end) end) it('getmousepos() works correctly', function() - local winwidth = meths.get_option_value('winwidth', {}) + local winwidth = api.nvim_get_option_value('winwidth', {}) -- Set winwidth=1 so that window sizes don't change. - meths.set_option_value('winwidth', 1, {}) + api.nvim_set_option_value('winwidth', 1, {}) command('tabedit') - local tabpage = meths.get_current_tabpage() + local tabpage = api.nvim_get_current_tabpage() insert('hello') command('vsplit') local opts = { @@ -1651,19 +1651,19 @@ describe('ui/mouse/input', function() border = 'single', focusable = 1, } - local float = meths.open_win(meths.get_current_buf(), false, opts) + local float = api.nvim_open_win(api.nvim_get_current_buf(), false, opts) command('redraw') - local lines = meths.get_option_value('lines', {}) - local columns = meths.get_option_value('columns', {}) + local lines = api.nvim_get_option_value('lines', {}) + local columns = api.nvim_get_option_value('columns', {}) -- Test that screenrow and screencol are set properly for all positions. for row = 0, lines - 1 do for col = 0, columns - 1 do -- Skip the X button that would close the tab. if row ~= 0 or col ~= columns - 1 then - meths.input_mouse('left', 'press', '', 0, row, col) - meths.set_current_tabpage(tabpage) - local mousepos = funcs.getmousepos() + api.nvim_input_mouse('left', 'press', '', 0, row, col) + api.nvim_set_current_tabpage(tabpage) + local mousepos = fn.getmousepos() eq(row + 1, mousepos.screenrow) eq(col + 1, mousepos.screencol) -- All other values should be 0 when clicking on the command line. @@ -1686,8 +1686,8 @@ describe('ui/mouse/input', function() for win_col = 0, opts.width + 1 do local row = win_row + opts.row local col = win_col + opts.col - meths.input_mouse('left', 'press', '', 0, row, col) - local mousepos = funcs.getmousepos() + api.nvim_input_mouse('left', 'press', '', 0, row, col) + local mousepos = fn.getmousepos() eq(float.id, mousepos.winid) eq(win_row + 1, mousepos.winrow) eq(win_col + 1, mousepos.wincol) @@ -1702,8 +1702,8 @@ describe('ui/mouse/input', function() then -- Because of border, win_row and win_col don't need to be -- incremented by 1. - line = math.min(win_row, funcs.line('$')) - column = math.min(win_col, #funcs.getline(line) + 1) + line = math.min(win_row, fn.line('$')) + column = math.min(win_col, #fn.getline(line) + 1) coladd = win_col - column end eq(line, mousepos.line) @@ -1715,19 +1715,19 @@ describe('ui/mouse/input', function() -- Test that mouse position values are properly set for the floating -- window, after removing the border. opts.border = 'none' - meths.win_set_config(float, opts) + api.nvim_win_set_config(float, opts) command('redraw') for win_row = 0, opts.height - 1 do for win_col = 0, opts.width - 1 do local row = win_row + opts.row local col = win_col + opts.col - meths.input_mouse('left', 'press', '', 0, row, col) - local mousepos = funcs.getmousepos() + api.nvim_input_mouse('left', 'press', '', 0, row, col) + local mousepos = fn.getmousepos() eq(float.id, mousepos.winid) eq(win_row + 1, mousepos.winrow) eq(win_col + 1, mousepos.wincol) - local line = math.min(win_row + 1, funcs.line('$')) - local column = math.min(win_col + 1, #funcs.getline(line) + 1) + local line = math.min(win_row + 1, fn.line('$')) + local column = math.min(win_col + 1, #fn.getline(line) + 1) local coladd = win_col + 1 - column eq(line, mousepos.line) eq(column, mousepos.column) @@ -1740,20 +1740,20 @@ describe('ui/mouse/input', function() -- that getmousepos() does not consider unfocusable floats. (see discussion -- in PR #14937 for details). opts.focusable = false - meths.win_set_config(float, opts) + api.nvim_win_set_config(float, opts) command('redraw') for nr = 1, 2 do - for win_row = 0, funcs.winheight(nr) - 1 do - for win_col = 0, funcs.winwidth(nr) - 1 do - local row = win_row + funcs.win_screenpos(nr)[1] - 1 - local col = win_col + funcs.win_screenpos(nr)[2] - 1 - meths.input_mouse('left', 'press', '', 0, row, col) - local mousepos = funcs.getmousepos() - eq(funcs.win_getid(nr), mousepos.winid) + for win_row = 0, fn.winheight(nr) - 1 do + for win_col = 0, fn.winwidth(nr) - 1 do + local row = win_row + fn.win_screenpos(nr)[1] - 1 + local col = win_col + fn.win_screenpos(nr)[2] - 1 + api.nvim_input_mouse('left', 'press', '', 0, row, col) + local mousepos = fn.getmousepos() + eq(fn.win_getid(nr), mousepos.winid) eq(win_row + 1, mousepos.winrow) eq(win_col + 1, mousepos.wincol) - local line = math.min(win_row + 1, funcs.line('$')) - local column = math.min(win_col + 1, #funcs.getline(line) + 1) + local line = math.min(win_row + 1, fn.line('$')) + local column = math.min(win_col + 1, #fn.getline(line) + 1) local coladd = win_col + 1 - column eq(line, mousepos.line) eq(column, mousepos.column) @@ -1764,34 +1764,34 @@ describe('ui/mouse/input', function() -- Restore state and release mouse. command('tabclose!') - meths.set_option_value('winwidth', winwidth, {}) - meths.input_mouse('left', 'release', '', 0, 0, 0) + api.nvim_set_option_value('winwidth', winwidth, {}) + api.nvim_input_mouse('left', 'release', '', 0, 0, 0) end) it('scroll keys are not translated into multiclicks and can be mapped #6211 #6989', function() - meths.set_var('mouse_up', 0) - meths.set_var('mouse_up2', 0) + api.nvim_set_var('mouse_up', 0) + api.nvim_set_var('mouse_up2', 0) command('nnoremap <ScrollWheelUp> <Cmd>let g:mouse_up += 1<CR>') command('nnoremap <2-ScrollWheelUp> <Cmd>let g:mouse_up2 += 1<CR>') feed('<ScrollWheelUp><0,0>') feed('<ScrollWheelUp><0,0>') - meths.input_mouse('wheel', 'up', '', 0, 0, 0) - meths.input_mouse('wheel', 'up', '', 0, 0, 0) - eq(4, meths.get_var('mouse_up')) - eq(0, meths.get_var('mouse_up2')) + api.nvim_input_mouse('wheel', 'up', '', 0, 0, 0) + api.nvim_input_mouse('wheel', 'up', '', 0, 0, 0) + eq(4, api.nvim_get_var('mouse_up')) + eq(0, api.nvim_get_var('mouse_up2')) end) it('<MouseMove> is not translated into multiclicks and can be mapped', function() - meths.set_var('mouse_move', 0) - meths.set_var('mouse_move2', 0) + api.nvim_set_var('mouse_move', 0) + api.nvim_set_var('mouse_move2', 0) command('nnoremap <MouseMove> <Cmd>let g:mouse_move += 1<CR>') command('nnoremap <2-MouseMove> <Cmd>let g:mouse_move2 += 1<CR>') feed('<MouseMove><0,0>') feed('<MouseMove><0,0>') - meths.input_mouse('move', '', '', 0, 0, 0) - meths.input_mouse('move', '', '', 0, 0, 0) - eq(4, meths.get_var('mouse_move')) - eq(0, meths.get_var('mouse_move2')) + api.nvim_input_mouse('move', '', '', 0, 0, 0) + api.nvim_input_mouse('move', '', '', 0, 0, 0) + eq(4, api.nvim_get_var('mouse_move')) + eq(0, api.nvim_get_var('mouse_move2')) end) it('feeding <MouseMove> in Normal mode does not use uninitialized memory #19480', function() @@ -1818,127 +1818,127 @@ describe('ui/mouse/input', function() vmenu PopUp.baz y:<C-U>let g:menustr = 'baz'<CR> ]]) - meths.win_set_cursor(0, { 1, 0 }) - meths.input_mouse('right', 'press', '', 0, 0, 4) - meths.input_mouse('right', 'release', '', 0, 0, 4) + api.nvim_win_set_cursor(0, { 1, 0 }) + api.nvim_input_mouse('right', 'press', '', 0, 0, 4) + api.nvim_input_mouse('right', 'release', '', 0, 0, 4) feed('<Down><Down><CR>') - eq('bar', meths.get_var('menustr')) - eq({ 1, 4 }, meths.win_get_cursor(0)) + eq('bar', api.nvim_get_var('menustr')) + eq({ 1, 4 }, api.nvim_win_get_cursor(0)) -- Test for right click in visual mode inside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 9 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 9 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 0, 11) - meths.input_mouse('right', 'release', '', 0, 0, 11) + api.nvim_input_mouse('right', 'press', '', 0, 0, 11) + api.nvim_input_mouse('right', 'release', '', 0, 0, 11) feed('<Down><CR>') - eq({ 1, 9 }, meths.win_get_cursor(0)) - eq('ran away', funcs.getreg('"')) + eq({ 1, 9 }, api.nvim_win_get_cursor(0)) + eq('ran away', fn.getreg('"')) -- Test for right click in visual mode right before the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 9 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 9 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 0, 8) - meths.input_mouse('right', 'release', '', 0, 0, 8) + api.nvim_input_mouse('right', 'press', '', 0, 0, 8) + api.nvim_input_mouse('right', 'release', '', 0, 0, 8) feed('<Down><CR>') - eq({ 1, 8 }, meths.win_get_cursor(0)) - eq('', funcs.getreg('"')) + eq({ 1, 8 }, api.nvim_win_get_cursor(0)) + eq('', fn.getreg('"')) -- Test for right click in visual mode right after the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 9 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 9 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 0, 17) - meths.input_mouse('right', 'release', '', 0, 0, 17) + api.nvim_input_mouse('right', 'press', '', 0, 0, 17) + api.nvim_input_mouse('right', 'release', '', 0, 0, 17) feed('<Down><CR>') - eq({ 1, 17 }, meths.win_get_cursor(0)) - eq('', funcs.getreg('"')) + eq({ 1, 17 }, api.nvim_win_get_cursor(0)) + eq('', fn.getreg('"')) -- Test for right click in block-wise visual mode inside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 15 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('<C-V>j3l') - meths.input_mouse('right', 'press', '', 0, 1, 16) - meths.input_mouse('right', 'release', '', 0, 1, 16) + api.nvim_input_mouse('right', 'press', '', 0, 1, 16) + api.nvim_input_mouse('right', 'release', '', 0, 1, 16) feed('<Down><CR>') - eq({ 1, 15 }, meths.win_get_cursor(0)) - eq('\0224', funcs.getregtype('"')) + eq({ 1, 15 }, api.nvim_win_get_cursor(0)) + eq('\0224', fn.getregtype('"')) -- Test for right click in block-wise visual mode outside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 15 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('<C-V>j3l') - meths.input_mouse('right', 'press', '', 0, 1, 1) - meths.input_mouse('right', 'release', '', 0, 1, 1) + api.nvim_input_mouse('right', 'press', '', 0, 1, 1) + api.nvim_input_mouse('right', 'release', '', 0, 1, 1) feed('<Down><CR>') - eq({ 2, 1 }, meths.win_get_cursor(0)) - eq('v', funcs.getregtype('"')) - eq('', funcs.getreg('"')) + eq({ 2, 1 }, api.nvim_win_get_cursor(0)) + eq('v', fn.getregtype('"')) + eq('', fn.getreg('"')) -- Test for right click in line-wise visual mode inside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 15 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('V') - meths.input_mouse('right', 'press', '', 0, 0, 9) - meths.input_mouse('right', 'release', '', 0, 0, 9) + api.nvim_input_mouse('right', 'press', '', 0, 0, 9) + api.nvim_input_mouse('right', 'release', '', 0, 0, 9) feed('<Down><CR>') - eq({ 1, 0 }, meths.win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 - eq('V', funcs.getregtype('"')) - eq(1, #funcs.getreg('"', 1, true)) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 + eq('V', fn.getregtype('"')) + eq(1, #fn.getreg('"', 1, true)) -- Test for right click in multi-line line-wise visual mode inside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 15 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('Vj') - meths.input_mouse('right', 'press', '', 0, 1, 19) - meths.input_mouse('right', 'release', '', 0, 1, 19) + api.nvim_input_mouse('right', 'press', '', 0, 1, 19) + api.nvim_input_mouse('right', 'release', '', 0, 1, 19) feed('<Down><CR>') - eq({ 1, 0 }, meths.win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 - eq('V', funcs.getregtype('"')) - eq(2, #funcs.getreg('"', 1, true)) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 + eq('V', fn.getregtype('"')) + eq(2, #fn.getreg('"', 1, true)) -- Test for right click in line-wise visual mode outside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 15 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('V') - meths.input_mouse('right', 'press', '', 0, 1, 9) - meths.input_mouse('right', 'release', '', 0, 1, 9) + api.nvim_input_mouse('right', 'press', '', 0, 1, 9) + api.nvim_input_mouse('right', 'release', '', 0, 1, 9) feed('<Down><CR>') - eq({ 2, 9 }, meths.win_get_cursor(0)) - eq('', funcs.getreg('"')) + eq({ 2, 9 }, api.nvim_win_get_cursor(0)) + eq('', fn.getreg('"')) -- Try clicking outside the window - funcs.setreg('"', '') - meths.win_set_cursor(0, { 2, 1 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 2, 1 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 6, 1) - meths.input_mouse('right', 'release', '', 0, 6, 1) + api.nvim_input_mouse('right', 'press', '', 0, 6, 1) + api.nvim_input_mouse('right', 'release', '', 0, 6, 1) feed('<Down><CR>') - eq(2, funcs.winnr()) - eq('', funcs.getreg('"')) + eq(2, fn.winnr()) + eq('', fn.getreg('"')) -- Test for right click in visual mode inside the selection with vertical splits command('wincmd t') command('rightbelow vsplit') - funcs.setreg('"', '') - meths.win_set_cursor(0, { 1, 9 }) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 9 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 0, 52) - meths.input_mouse('right', 'release', '', 0, 0, 52) + api.nvim_input_mouse('right', 'press', '', 0, 0, 52) + api.nvim_input_mouse('right', 'release', '', 0, 0, 52) feed('<Down><CR>') - eq({ 1, 9 }, meths.win_get_cursor(0)) - eq('ran away', funcs.getreg('"')) + eq({ 1, 9 }, api.nvim_win_get_cursor(0)) + eq('ran away', fn.getreg('"')) -- Test for right click inside visual selection at bottom of window with winbar command('setlocal winbar=WINBAR') feed('2yyP') - funcs.setreg('"', '') + fn.setreg('"', '') feed('G$vbb') - meths.input_mouse('right', 'press', '', 0, 4, 61) - meths.input_mouse('right', 'release', '', 0, 4, 61) + api.nvim_input_mouse('right', 'press', '', 0, 4, 61) + api.nvim_input_mouse('right', 'release', '', 0, 4, 61) feed('<Down><CR>') - eq({ 4, 20 }, meths.win_get_cursor(0)) - eq('the moon', funcs.getreg('"')) + eq({ 4, 20 }, api.nvim_win_get_cursor(0)) + eq('the moon', fn.getreg('"')) end) end) diff --git a/test/functional/ui/multibyte_spec.lua b/test/functional/ui/multibyte_spec.lua index 8077194533..d38bc27a51 100644 --- a/test/functional/ui/multibyte_spec.lua +++ b/test/functional/ui/multibyte_spec.lua @@ -5,9 +5,9 @@ local command = helpers.command local feed = helpers.feed local feed_command = helpers.feed_command local insert = helpers.insert -local funcs = helpers.funcs -local meths = helpers.meths -local split = helpers.split +local fn = helpers.fn +local api = helpers.api +local split = vim.split local dedent = helpers.dedent describe('multibyte rendering', function() @@ -85,7 +85,7 @@ describe('multibyte rendering', function() ]]) -- check double-with char is temporarily hidden when overlapped - funcs.complete(4, { 'xx', 'yy' }) + fn.complete(4, { 'xx', 'yy' }) screen:expect([[ ab xx^ | - {2: xx } | @@ -118,7 +118,7 @@ describe('multibyte rendering', function() it('works with a lot of unicode (zalgo) text', function() screen:try_resize(65, 10) - meths.buf_set_lines( + api.nvim_buf_set_lines( 0, 0, -1, @@ -156,7 +156,7 @@ describe('multibyte rendering', function() -- nvim will reset the zalgo text^W^W glyph cache if it gets too full. -- this should be exceedingly rare, but fake it to make sure it works - meths._invalidate_glyph_cache() + api.nvim__invalidate_glyph_cache() screen:expect { grid = [[ ^L̓̉̑̒̌̚ơ̗̌̒̄̀ŕ̈̈̎̐̕è̇̅̄̄̐m̖̟̟̅̄̚ ̛̓̑̆̇̍i̗̟̞̜̅̐p̗̞̜̉̆̕s̟̜̘̍̑̏ū̟̞̎̃̉ḿ̘̙́́̐ ̖̍̌̇̉̚d̞̄̃̒̉̎ò́̌̌̂̐l̞̀̄̆̌̚ȯ̖̞̋̀̐r̓̇̌̃̃̚ ̗̘̀̏̍́s̜̀̎̎̑̕i̟̗̐̄̄̚t̝̎̆̓̐̒ ̘̇̔̓̊̚ȃ̛̟̗̏̅m̜̟̙̞̈̓é̘̞̟̔̆t̝̂̂̈̑̔,̜̜̖̅̄̍ ̛̗̊̓̆̚c̟̍̆̍̈̔ȯ̖̖̝̑̀n̜̟̎̊̃̚s̟̏̇̎̒̚e̙̐̈̓̌̚c̙̍̈̏̅̕ť̇̄̇̆̓e̛̓̌̈̓̈t̟̍̀̉̆̅u̝̞̎̂̄̚r̘̀̅̈̅̐ ̝̞̓́̇̉ã̏̀̆̅̕d̛̆̐̉̆̋ȉ̞̟̍̃̚p̛̜̊̍̂̓ȋ̏̅̃̋̚ṥ̛̏̃̕č̛̞̝̀̂í̗̘̌́̎n̔̎́̒̂̕ǧ̗̜̋̇̂ ̛̜̔̄̎̃ê̛̔̆̇̕l̘̝̏̐̊̏ĩ̛̍̏̏̄t̟̐́̀̐̎,̙̘̍̆̉̐ ̋̂̏̄̌̅s̙̓̌̈́̇e̛̗̋̒̎̏d̜̗̊̍̊̚ | @@ -227,7 +227,7 @@ describe('multibyte rendering', function() -- If we would increase the schar_t size, say from 32 to 64 bytes, we need to extend the -- test text with even more zalgo energy to still touch this edge case. - meths.buf_set_lines(0, 0, -1, true, { 'سلام့̀́̂̃̄̅̆̇̈̉̊̋̌' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'سلام့̀́̂̃̄̅̆̇̈̉̊̋̌' }) command('set noarabicshape') screen:expect { diff --git a/test/functional/ui/multigrid_spec.lua b/test/functional/ui/multigrid_spec.lua index 0253b28cd5..c77363e584 100644 --- a/test/functional/ui/multigrid_spec.lua +++ b/test/functional/ui/multigrid_spec.lua @@ -3,9 +3,9 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local feed, command, insert = helpers.feed, helpers.command, helpers.insert local eq = helpers.eq -local funcs = helpers.funcs -local meths = helpers.meths -local curwin = helpers.curwin +local fn = helpers.fn +local api = helpers.api +local curwin = helpers.api.nvim_get_current_win local poke_eventloop = helpers.poke_eventloop @@ -454,17 +454,17 @@ describe('ext_multigrid', function() end) it('winwidth() winheight() getwininfo() return inner width and height #19743', function() - eq(60, funcs.winwidth(0)) - eq(20, funcs.winheight(0)) - local win_info = funcs.getwininfo(curwin().id)[1] + eq(60, fn.winwidth(0)) + eq(20, fn.winheight(0)) + local win_info = fn.getwininfo(curwin().id)[1] eq(60, win_info.width) eq(20, win_info.height) end) it("'scroll' option works properly", function() - eq(10, meths.get_option_value('scroll', { win = 0 })) - meths.set_option_value('scroll', 15, { win = 0 }) - eq(15, meths.get_option_value('scroll', { win = 0 })) + eq(10, api.nvim_get_option_value('scroll', { win = 0 })) + api.nvim_set_option_value('scroll', 15, { win = 0 }) + eq(15, api.nvim_get_option_value('scroll', { win = 0 })) end) it('gets written till grid width', function() @@ -592,8 +592,8 @@ describe('ext_multigrid', function() ## grid 3 | ]]} - local float_buf = meths.create_buf(false, false) - meths.open_win(float_buf, false, { + local float_buf = api.nvim_create_buf(false, false) + api.nvim_open_win(float_buf, false, { relative = 'win', win = curwin(), bufpos = {0, 1018}, @@ -984,7 +984,7 @@ describe('ext_multigrid', function() | ]]} - meths.input_mouse('left', 'press', '', 2, 0, 5) + api.nvim_input_mouse('left', 'press', '', 2, 0, 5) screen:expect{grid=[[ ## grid 1 [2:-----------------------------------------------------]|*12 @@ -1020,7 +1020,7 @@ describe('ext_multigrid', function() {1:~ }|*4 ]]} - meths.input_mouse('left', 'press', '', 2, 1, 6) + api.nvim_input_mouse('left', 'press', '', 2, 1, 6) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*6 @@ -1040,7 +1040,7 @@ describe('ext_multigrid', function() {1:~ }|*4 ]]} - meths.input_mouse('left', 'press', '', 4, 1, 4) + api.nvim_input_mouse('left', 'press', '', 4, 1, 4) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*6 @@ -1079,7 +1079,7 @@ describe('ext_multigrid', function() {1:~ }| ]]} - meths.input_mouse('left', 'press', '', 4, 0, 64) + api.nvim_input_mouse('left', 'press', '', 4, 0, 64) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*6 @@ -1099,12 +1099,12 @@ describe('ext_multigrid', function() ]]} -- XXX: mouse_check_grid() doesn't work properly when clicking on grid 1 - meths.input_mouse('left', 'press', '', 1, 6, 20) + api.nvim_input_mouse('left', 'press', '', 1, 6, 20) -- TODO(bfredl): "batching" input_mouse is formally not supported yet. -- Normally it should work fine in async context when nvim is not blocked, -- but add a poke_eventloop be sure. poke_eventloop() - meths.input_mouse('left', 'drag', '', 1, 4, 20) + api.nvim_input_mouse('left', 'drag', '', 1, 4, 20) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -1146,9 +1146,9 @@ describe('ext_multigrid', function() {1:~ }|*5 ]]} - meths.input_mouse('left', 'press', '', 1, 8, 26) + api.nvim_input_mouse('left', 'press', '', 1, 8, 26) poke_eventloop() - meths.input_mouse('left', 'drag', '', 1, 6, 30) + api.nvim_input_mouse('left', 'drag', '', 1, 6, 30) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -1173,8 +1173,8 @@ describe('ext_multigrid', function() command('aunmenu PopUp | vmenu PopUp.Copy y') - funcs.setreg('"', '') - meths.input_mouse('left', 'press', '2', 2, 1, 6) + fn.setreg('"', '') + api.nvim_input_mouse('left', 'press', '2', 2, 1, 6) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -1196,8 +1196,8 @@ describe('ext_multigrid', function() to be {20:clicked} | {1:~ }|*5 ]]} - meths.input_mouse('right', 'press', '', 2, 1, 6) - meths.input_mouse('right', 'release', '', 2, 1, 6) + api.nvim_input_mouse('right', 'press', '', 2, 1, 6) + api.nvim_input_mouse('right', 'release', '', 2, 1, 6) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -1245,10 +1245,10 @@ describe('ext_multigrid', function() to be clicked | {1:~ }|*5 ]]} - eq('clicked', funcs.getreg('"')) + eq('clicked', fn.getreg('"')) - funcs.setreg('"', '') - meths.input_mouse('left', 'press', '2', 4, 0, 64) + fn.setreg('"', '') + api.nvim_input_mouse('left', 'press', '2', 4, 0, 64) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -1270,8 +1270,8 @@ describe('ext_multigrid', function() to be clicked | {1:~ }|*5 ]]} - meths.input_mouse('right', 'press', '', 4, 0, 64) - meths.input_mouse('right', 'release', '', 4, 0, 64) + api.nvim_input_mouse('right', 'press', '', 4, 0, 64) + api.nvim_input_mouse('right', 'release', '', 4, 0, 64) screen:expect{grid=[[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -1319,7 +1319,7 @@ describe('ext_multigrid', function() to be clicked | {1:~ }|*5 ]]} - eq('eiusmo', funcs.getreg('"')) + eq('eiusmo', fn.getreg('"')) command('wincmd J') screen:try_resize_grid(4, 7, 10) @@ -1353,8 +1353,8 @@ describe('ext_multigrid', function() {1:~ }|*3 ]]} - funcs.setreg('"', '') - meths.input_mouse('left', 'press', '2', 4, 9, 1) + fn.setreg('"', '') + api.nvim_input_mouse('left', 'press', '2', 4, 9, 1) screen:expect{grid=[[ ## grid 1 [5:------------------------------]│[2:----------------------]|*5 @@ -1384,8 +1384,8 @@ describe('ext_multigrid', function() to be clicked | {1:~ }|*3 ]]} - meths.input_mouse('right', 'press', '', 4, 9, 1) - meths.input_mouse('right', 'release', '', 4, 9, 1) + api.nvim_input_mouse('right', 'press', '', 4, 9, 1) + api.nvim_input_mouse('right', 'release', '', 4, 9, 1) screen:expect{grid=[[ ## grid 1 [5:------------------------------]│[2:----------------------]|*5 @@ -1449,7 +1449,7 @@ describe('ext_multigrid', function() to be clicked | {1:~ }|*3 ]]} - eq('eiusmo', funcs.getreg('"')) + eq('eiusmo', fn.getreg('"')) screen:try_resize_grid(4, 7, 11) screen:expect{grid=[[ @@ -1483,8 +1483,8 @@ describe('ext_multigrid', function() {1:~ }|*3 ]]} - funcs.setreg('"', '') - meths.input_mouse('left', 'press', '2', 4, 9, 1) + fn.setreg('"', '') + api.nvim_input_mouse('left', 'press', '2', 4, 9, 1) screen:expect{grid=[[ ## grid 1 [5:------------------------------]│[2:----------------------]|*5 @@ -1515,8 +1515,8 @@ describe('ext_multigrid', function() to be clicked | {1:~ }|*3 ]]} - meths.input_mouse('right', 'press', '', 4, 9, 1) - meths.input_mouse('right', 'release', '', 4, 9, 1) + api.nvim_input_mouse('right', 'press', '', 4, 9, 1) + api.nvim_input_mouse('right', 'release', '', 4, 9, 1) screen:expect{grid=[[ ## grid 1 [5:------------------------------]│[2:----------------------]|*5 @@ -1582,7 +1582,7 @@ describe('ext_multigrid', function() to be clicked | {1:~ }|*3 ]]} - eq('eiusmo', funcs.getreg('"')) + eq('eiusmo', fn.getreg('"')) end) it('supports mouse drag with mouse=a', function() @@ -1593,9 +1593,9 @@ describe('ext_multigrid', function() command('enew') feed('ifoo\nbar<esc>') - meths.input_mouse('left', 'press', '', 5, 0, 0) + api.nvim_input_mouse('left', 'press', '', 5, 0, 0) poke_eventloop() - meths.input_mouse('left', 'drag', '', 5, 1, 2) + api.nvim_input_mouse('left', 'drag', '', 5, 1, 2) screen:expect{grid=[[ ## grid 1 @@ -1752,7 +1752,7 @@ describe('ext_multigrid', function() }} -- handles non-current window - meths.win_set_cursor(1000, {1, 10}) + api.nvim_win_set_cursor(1000, {1, 10}) screen:expect{grid=[[ ## grid 1 [4:------------------------------------------------]|*3 @@ -2257,9 +2257,9 @@ describe('ext_multigrid', function() [2] = {win = {id = 1000}, topline = 5, botline = 11, curline = 10, curcol = 7, linecount = 11, sum_scroll_delta = 5}, }} - meths.input_mouse('left', 'press', '', 1,5, 1) + api.nvim_input_mouse('left', 'press', '', 1,5, 1) poke_eventloop() - meths.input_mouse('left', 'drag', '', 1, 6, 1) + api.nvim_input_mouse('left', 'drag', '', 1, 6, 1) screen:expect{grid=[[ ## grid 1 @@ -2357,7 +2357,7 @@ describe('ext_multigrid', function() end) it('with winbar dragging statusline with mouse works correctly', function() - meths.set_option_value('winbar', 'Set Up The Bars', {}) + api.nvim_set_option_value('winbar', 'Set Up The Bars', {}) command('split') screen:expect([[ ## grid 1 @@ -2378,9 +2378,9 @@ describe('ext_multigrid', function() {1:~ }|*4 ]]) - meths.input_mouse('left', 'press', '', 1, 6, 20) + api.nvim_input_mouse('left', 'press', '', 1, 6, 20) poke_eventloop() - meths.input_mouse('left', 'drag', '', 1, 7, 20) + api.nvim_input_mouse('left', 'drag', '', 1, 7, 20) screen:expect([[ ## grid 1 [4:-----------------------------------------------------]|*7 @@ -2400,7 +2400,7 @@ describe('ext_multigrid', function() {1:~ }|*5 ]]) - meths.input_mouse('left', 'drag', '', 1, 4, 20) + api.nvim_input_mouse('left', 'drag', '', 1, 4, 20) screen:expect([[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -2420,9 +2420,9 @@ describe('ext_multigrid', function() {1:~ }|*2 ]]) - meths.input_mouse('left', 'press', '', 1, 12, 10) + api.nvim_input_mouse('left', 'press', '', 1, 12, 10) poke_eventloop() - meths.input_mouse('left', 'drag', '', 1, 10, 10) + api.nvim_input_mouse('left', 'drag', '', 1, 10, 10) screen:expect([[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -2441,9 +2441,9 @@ describe('ext_multigrid', function() ^ | {1:~ }|*2 ]]) - eq(3, meths.get_option_value('cmdheight', {})) + eq(3, api.nvim_get_option_value('cmdheight', {})) - meths.input_mouse('left', 'drag', '', 1, 12, 10) + api.nvim_input_mouse('left', 'drag', '', 1, 12, 10) screen:expect([[ ## grid 1 [4:-----------------------------------------------------]|*4 @@ -2462,6 +2462,6 @@ describe('ext_multigrid', function() ^ | {1:~ }|*2 ]]) - eq(1, meths.get_option_value('cmdheight', {})) + eq(1, api.nvim_get_option_value('cmdheight', {})) end) end) diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index da0a68edcb..941b8b69bf 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -4,10 +4,10 @@ local assert_alive = helpers.assert_alive local clear, feed = helpers.clear, helpers.feed local source = helpers.source local insert = helpers.insert -local meths = helpers.meths +local api = helpers.api local async_meths = helpers.async_meths local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local eq = helpers.eq local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua @@ -117,7 +117,7 @@ describe('ui/ext_popupmenu', function() }, } - meths.select_popupmenu_item(1, false, false, {}) + api.nvim_select_popupmenu_item(1, false, false, {}) screen:expect { grid = [[ | @@ -132,7 +132,7 @@ describe('ui/ext_popupmenu', function() }, } - meths.select_popupmenu_item(2, true, false, {}) + api.nvim_select_popupmenu_item(2, true, false, {}) screen:expect { grid = [[ | @@ -147,7 +147,7 @@ describe('ui/ext_popupmenu', function() }, } - meths.select_popupmenu_item(0, true, true, {}) + api.nvim_select_popupmenu_item(0, true, true, {}) screen:expect([[ | foo^ | @@ -170,7 +170,7 @@ describe('ui/ext_popupmenu', function() }, } - meths.select_popupmenu_item(-1, false, false, {}) + api.nvim_select_popupmenu_item(-1, false, false, {}) screen:expect { grid = [[ | @@ -185,7 +185,7 @@ describe('ui/ext_popupmenu', function() }, } - meths.select_popupmenu_item(1, true, false, {}) + api.nvim_select_popupmenu_item(1, true, false, {}) screen:expect { grid = [[ | @@ -200,7 +200,7 @@ describe('ui/ext_popupmenu', function() }, } - meths.select_popupmenu_item(-1, true, false, {}) + api.nvim_select_popupmenu_item(-1, true, false, {}) screen:expect { grid = [[ | @@ -215,7 +215,7 @@ describe('ui/ext_popupmenu', function() }, } - meths.select_popupmenu_item(0, true, false, {}) + api.nvim_select_popupmenu_item(0, true, false, {}) screen:expect { grid = [[ | @@ -230,7 +230,7 @@ describe('ui/ext_popupmenu', function() }, } - meths.select_popupmenu_item(-1, true, true, {}) + api.nvim_select_popupmenu_item(-1, true, true, {}) screen:expect([[ | ^ | @@ -262,7 +262,7 @@ describe('ui/ext_popupmenu', function() }, }) - meths.select_popupmenu_item(-1, true, false, {}) + api.nvim_select_popupmenu_item(-1, true, false, {}) screen:expect({ grid = [[ |*2 @@ -276,7 +276,7 @@ describe('ui/ext_popupmenu', function() }, }) - meths.select_popupmenu_item(5, true, false, {}) + api.nvim_select_popupmenu_item(5, true, false, {}) screen:expect({ grid = [[ |*2 @@ -290,7 +290,7 @@ describe('ui/ext_popupmenu', function() }, }) - meths.select_popupmenu_item(-1, true, true, {}) + api.nvim_select_popupmenu_item(-1, true, true, {}) screen:expect({ grid = [[ |*2 @@ -313,7 +313,7 @@ describe('ui/ext_popupmenu', function() }, }) - meths.select_popupmenu_item(5, true, true, {}) + api.nvim_select_popupmenu_item(5, true, true, {}) screen:expect({ grid = [[ |*2 @@ -608,7 +608,7 @@ describe('ui/ext_popupmenu', function() } local pum_height = 6 feed('o<C-r>=TestCompleteMonth()<CR>') - meths.ui_pum_set_height(pum_height) + api.nvim_ui_pum_set_height(pum_height) feed('<PageDown>') -- pos becomes pum_height-2 because it is subtracting 2 to keep some -- context in ins_compl_key2count() @@ -628,14 +628,14 @@ describe('ui/ext_popupmenu', function() end) it('an error occurs if set 0 or less', function() - meths.ui_pum_set_height(1) - eq('Expected pum height > 0', pcall_err(meths.ui_pum_set_height, 0)) + api.nvim_ui_pum_set_height(1) + eq('Expected pum height > 0', pcall_err(api.nvim_ui_pum_set_height, 0)) end) it('an error occurs when ext_popupmenu is false', function() - meths.ui_pum_set_height(1) + api.nvim_ui_pum_set_height(1) screen:set_option('ext_popupmenu', false) - eq('It must support the ext_popupmenu option', pcall_err(meths.ui_pum_set_height, 1)) + eq('It must support the ext_popupmenu option', pcall_err(api.nvim_ui_pum_set_height, 1)) end) end) @@ -658,9 +658,9 @@ describe('ui/ext_popupmenu', function() } local pum_height = 6 feed('o<C-r>=TestCompleteMonth()<CR>') - meths.ui_pum_set_height(pum_height) + api.nvim_ui_pum_set_height(pum_height) -- set bounds w h r c - meths.ui_pum_set_bounds(10.5, 5.2, 6.3, 7.4) + api.nvim_ui_pum_set_bounds(10.5, 5.2, 6.3, 7.4) feed('<PageDown>') -- pos becomes pum_height-2 because it is subtracting 2 to keep some -- context in ins_compl_key2count() @@ -680,23 +680,23 @@ describe('ui/ext_popupmenu', function() end) it('no error occurs if row or col set less than 0', function() - meths.ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) - meths.ui_pum_set_bounds(1.0, 1.0, -1.0, 0.0) - meths.ui_pum_set_bounds(1.0, 1.0, 0.0, -1.0) + api.nvim_ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) + api.nvim_ui_pum_set_bounds(1.0, 1.0, -1.0, 0.0) + api.nvim_ui_pum_set_bounds(1.0, 1.0, 0.0, -1.0) end) it('an error occurs if width or height set 0 or less', function() - meths.ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) - eq('Expected width > 0', pcall_err(meths.ui_pum_set_bounds, 0.0, 1.0, 1.0, 0.0)) - eq('Expected height > 0', pcall_err(meths.ui_pum_set_bounds, 1.0, -1.0, 1.0, 0.0)) + api.nvim_ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) + eq('Expected width > 0', pcall_err(api.nvim_ui_pum_set_bounds, 0.0, 1.0, 1.0, 0.0)) + eq('Expected height > 0', pcall_err(api.nvim_ui_pum_set_bounds, 1.0, -1.0, 1.0, 0.0)) end) it('an error occurs when ext_popupmenu is false', function() - meths.ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) + api.nvim_ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) screen:set_option('ext_popupmenu', false) eq( 'UI must support the ext_popupmenu option', - pcall_err(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) + pcall_err(api.nvim_ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) ) end) end) @@ -768,7 +768,7 @@ describe('ui/ext_popupmenu', function() {1:~ }|*8 :sign ^ | ]]) - eq(0, funcs.wildmenumode()) + eq(0, fn.wildmenumode()) feed('<tab>') screen:expect { @@ -779,7 +779,7 @@ describe('ui/ext_popupmenu', function() ]], popupmenu = { items = wild_expected, pos = 0, anchor = { 1, 9, 6 } }, } - eq(1, funcs.wildmenumode()) + eq(1, fn.wildmenumode()) feed('<left>') screen:expect { @@ -820,7 +820,7 @@ describe('ui/ext_popupmenu', function() popupmenu = { items = wild_expected, pos = 5, anchor = { 1, 9, 6 } }, } feed('<esc>') - eq(0, funcs.wildmenumode()) + eq(0, fn.wildmenumode()) -- check positioning with multibyte char in pattern command('e långfile1') @@ -1055,7 +1055,7 @@ describe("builtin popupmenu 'pumblend'", function() {20:-- Keyword Local completion (^N^P) }{21:match 1 of 65} | ]]) - meths.input_mouse('wheel', 'down', '', 0, 9, 40) + api.nvim_input_mouse('wheel', 'down', '', 0, 9, 40) screen:expect([[ Lorem ipsum d{1:ol}or sit amet, consectetur | adipisicing elit, sed do eiusmod tempor | @@ -1650,7 +1650,7 @@ describe('builtin popupmenu', function() -- test nvim_complete_set_info feed('<C-N><C-N>') - helpers.sleep(10) + vim.uv.sleep(10) if multigrid then screen:expect { grid = [[ @@ -2014,7 +2014,7 @@ describe('builtin popupmenu', function() {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} | ]]) - meths.input_mouse('wheel', 'down', '', 0, 9, 40) + api.nvim_input_mouse('wheel', 'down', '', 0, 9, 40) screen:expect([[ Est ^ | L{n: sunt }{s: }sit amet, consectetur | @@ -2050,7 +2050,7 @@ describe('builtin popupmenu', function() {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} | ]]) - meths.input_mouse('wheel', 'up', '', 0, 9, 40) + api.nvim_input_mouse('wheel', 'up', '', 0, 9, 40) screen:expect([[ Est e^ | L{n: elit } sit amet, consectetur | @@ -2086,7 +2086,7 @@ describe('builtin popupmenu', function() {2:-- Keyword Local completion (^N^P) }{5:match 1 of 65} | ]]) - meths.input_mouse('wheel', 'down', '', 0, 9, 40) + api.nvim_input_mouse('wheel', 'down', '', 0, 9, 40) screen:expect([[ Est es^ | L{n: esse } sit amet, consectetur | @@ -2140,7 +2140,7 @@ describe('builtin popupmenu', function() {2:-- Keyword Local completion (^N^P) }{5:match 22 of 65} | ]]) - meths.input_mouse('wheel', 'down', '', 0, 9, 40) + api.nvim_input_mouse('wheel', 'down', '', 0, 9, 40) screen:expect([[ Est eu^ | L{n: elit } sit amet, consectetur | @@ -2158,10 +2158,7 @@ describe('builtin popupmenu', function() {2:-- Keyword Local completion (^N^P) }{5:match 22 of 65} | ]]) - funcs.complete( - 4, - { 'ea', 'eeeeeeeeeeeeeeeeee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö' } - ) + fn.complete(4, { 'ea', 'eeeeeeeeeeeeeeeeee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö' }) screen:expect([[ Est eu^ | {s: ea }t amet, consectetur | @@ -2179,7 +2176,7 @@ describe('builtin popupmenu', function() {2:-- Keyword Local completion (^N^P) }{5:match 1 of 9} | ]]) - funcs.complete(4, { 'ea', 'eee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö' }) + fn.complete(4, { 'ea', 'eee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö' }) screen:expect([[ Est eu^ | {s: ea }r sit amet, consectetur | @@ -2215,7 +2212,7 @@ describe('builtin popupmenu', function() {2:-- INSERT --} | ]]) - funcs.complete(6, { 'foo', 'bar' }) + fn.complete(6, { 'foo', 'bar' }) screen:expect([[ Esteee^ | Lo{s: foo }sit amet, consectetur | @@ -2256,7 +2253,7 @@ describe('builtin popupmenu', function() feed('isome long prefix before the ') command('set completeopt+=noinsert,noselect') command('set linebreak') - funcs.complete(29, { 'word', 'choice', 'text', 'thing' }) + fn.complete(29, { 'word', 'choice', 'text', 'thing' }) screen:expect([[ some long prefix before the ^ | {1:~ }{n: word }| @@ -2360,7 +2357,7 @@ describe('builtin popupmenu', function() command('set completeopt+=noinsert,noselect') command('autocmd VimResized * redraw!') command('set linebreak') - funcs.complete(29, { 'word', 'choice', 'text', 'thing' }) + fn.complete(29, { 'word', 'choice', 'text', 'thing' }) screen:expect([[ some long prefix before the ^ | {1:~ }{n: word }| @@ -2395,7 +2392,7 @@ describe('builtin popupmenu', function() ]]) command('set completeopt+=noinsert,noselect') - funcs.complete(16, { 'word', 'choice', 'text', 'thing' }) + fn.complete(16, { 'word', 'choice', 'text', 'thing' }) screen:expect([[ ^ tfelthgir emos| {1: }{n: drow }{1: ~}| @@ -2458,7 +2455,7 @@ describe('builtin popupmenu', function() command('set completeopt+=noinsert,noselect') command('set pumheight=2') feed('isome rightleft ') - funcs.complete(16, { 'word', 'choice', 'text', 'thing' }) + fn.complete(16, { 'word', 'choice', 'text', 'thing' }) if multigrid then screen:expect { grid = [[ @@ -2493,7 +2490,7 @@ describe('builtin popupmenu', function() ]]) end feed('<C-E><CR>') - funcs.complete(1, { 'word', 'choice', 'text', 'thing' }) + fn.complete(1, { 'word', 'choice', 'text', 'thing' }) if multigrid then screen:expect { grid = [[ @@ -2603,7 +2600,7 @@ describe('builtin popupmenu', function() screen:try_resize(40, 8) feed('ixx<cr>') command('imap <f2> <cmd>echoerr "very"\\|echoerr "much"\\|echoerr "error"<cr>') - funcs.complete(1, { 'word', 'choice', 'text', 'thing' }) + fn.complete(1, { 'word', 'choice', 'text', 'thing' }) screen:expect([[ xx | word^ | @@ -2663,7 +2660,7 @@ describe('builtin popupmenu', function() {2:-- INSERT --} | ]]) - meths.input_mouse('wheel', 'down', '', 0, 6, 15) + api.nvim_input_mouse('wheel', 'down', '', 0, 6, 15) screen:expect { grid = [[ xx | @@ -2682,7 +2679,7 @@ describe('builtin popupmenu', function() it('with kind, menu and abbr attributes', function() screen:try_resize(40, 8) feed('ixx ') - funcs.complete(4, { + fn.complete(4, { { word = 'wordey', kind = 'x', menu = 'extrainfo' }, 'thing', { word = 'secret', abbr = 'sneaky', menu = 'bar' }, @@ -3317,7 +3314,7 @@ describe('builtin popupmenu', function() :sign un^ | ]], } - eq(0, funcs.wildmenumode()) + eq(0, fn.wildmenumode()) -- pressing <Tab> should display the wildmenu feed('<Tab>') @@ -3330,7 +3327,7 @@ describe('builtin popupmenu', function() :sign undefine^ | ]], } - eq(1, funcs.wildmenumode()) + eq(1, fn.wildmenumode()) -- pressing <Tab> second time should select the next entry in the menu feed('<Tab>') @@ -3347,7 +3344,7 @@ describe('builtin popupmenu', function() it('wildoptions=pum with a wrapped line in buffer vim-patch:8.2.4655', function() screen:try_resize(32, 10) - meths.buf_set_lines(0, 0, -1, true, { ('a'):rep(100) }) + api.nvim_buf_set_lines(0, 0, -1, true, { ('a'):rep(100) }) command('set wildoptions+=pum') feed('$') feed(':sign <Tab>') @@ -3461,7 +3458,7 @@ describe('builtin popupmenu', function() command('set completeopt+=noinsert,noselect') command('set linebreak') command('set pumheight=2') - funcs.complete(29, { 'word', 'choice', 'text', 'thing' }) + fn.complete(29, { 'word', 'choice', 'text', 'thing' }) if multigrid then screen:expect { grid = [[ @@ -3498,7 +3495,7 @@ describe('builtin popupmenu', function() command('set completeopt+=noinsert,noselect') command('set linebreak') command('set pumwidth=8') - funcs.complete(29, { 'word', 'choice', 'text', 'thing' }) + fn.complete(29, { 'word', 'choice', 'text', 'thing' }) if multigrid then screen:expect { grid = [[ @@ -3544,7 +3541,7 @@ describe('builtin popupmenu', function() command('set rightleft') command('call setline(1, repeat(" ", &columns - ' .. max_len .. '))') feed('$i') - funcs.complete(col - max_len, items) + fn.complete(col - max_len, items) feed('<c-y>') assert_alive() end) @@ -3553,7 +3550,7 @@ describe('builtin popupmenu', function() screen:try_resize(32, 8) command('set completeopt+=menuone,noselect') feed('i' .. string.rep(' ', 13)) - funcs.complete(14, { '哦哦哦哦哦哦哦哦哦哦' }) + fn.complete(14, { '哦哦哦哦哦哦哦哦哦哦' }) if multigrid then screen:expect({ grid = [[ @@ -3589,7 +3586,7 @@ describe('builtin popupmenu', function() for _ = 1, 8 do table.insert(items, { word = '哦哦哦哦哦哦哦哦哦哦', equal = 1, dup = 1 }) end - funcs.complete(13, items) + fn.complete(13, items) if multigrid then screen:expect({ grid = [[ @@ -3631,7 +3628,7 @@ describe('builtin popupmenu', function() ]]) if multigrid then - meths.input_mouse('right', 'press', '', 2, 0, 4) + api.nvim_input_mouse('right', 'press', '', 2, 0, 4) screen:expect({ grid = [[ ## grid 1 @@ -3739,10 +3736,10 @@ describe('builtin popupmenu', function() :let g:menustr = 'bar' | ]]) end - eq('bar', meths.get_var('menustr')) + eq('bar', api.nvim_get_var('menustr')) if multigrid then - meths.input_mouse('right', 'press', '', 2, 2, 20) + api.nvim_input_mouse('right', 'press', '', 2, 2, 20) screen:expect({ grid = [[ ## grid 1 @@ -3771,7 +3768,7 @@ describe('builtin popupmenu', function() ]]) end if multigrid then - meths.input_mouse('right', 'press', '', 2, 0, 18) + api.nvim_input_mouse('right', 'press', '', 2, 0, 18) screen:expect { grid = [[ ## grid 1 @@ -3803,7 +3800,7 @@ describe('builtin popupmenu', function() ]]) end if multigrid then - meths.input_mouse('right', 'press', '', 4, 1, 3) + api.nvim_input_mouse('right', 'press', '', 4, 1, 3) screen:expect({ grid = [[ ## grid 1 @@ -3832,7 +3829,7 @@ describe('builtin popupmenu', function() ]]) end if multigrid then - meths.input_mouse('left', 'press', '', 4, 2, 2) + api.nvim_input_mouse('left', 'press', '', 4, 2, 2) screen:expect({ grid = [[ ## grid 1 @@ -3853,10 +3850,10 @@ describe('builtin popupmenu', function() :let g:menustr = 'baz' | ]]) end - eq('baz', meths.get_var('menustr')) + eq('baz', api.nvim_get_var('menustr')) if multigrid then - meths.input_mouse('right', 'press', '', 2, 0, 4) + api.nvim_input_mouse('right', 'press', '', 2, 0, 4) screen:expect({ grid = [[ ## grid 1 @@ -3886,7 +3883,7 @@ describe('builtin popupmenu', function() ]]) end if multigrid then - meths.input_mouse('right', 'drag', '', 2, 3, 6) + api.nvim_input_mouse('right', 'drag', '', 2, 3, 6) screen:expect({ grid = [[ ## grid 1 @@ -3916,7 +3913,7 @@ describe('builtin popupmenu', function() ]]) end if multigrid then - meths.input_mouse('right', 'release', '', 2, 1, 6) + api.nvim_input_mouse('right', 'release', '', 2, 1, 6) screen:expect({ grid = [[ ## grid 1 @@ -3937,11 +3934,11 @@ describe('builtin popupmenu', function() :let g:menustr = 'foo' | ]]) end - eq('foo', meths.get_var('menustr')) + eq('foo', api.nvim_get_var('menustr')) eq(false, screen.options.mousemoveevent) if multigrid then - meths.input_mouse('right', 'press', '', 2, 0, 4) + api.nvim_input_mouse('right', 'press', '', 2, 0, 4) screen:expect({ grid = [[ ## grid 1 @@ -3972,7 +3969,7 @@ describe('builtin popupmenu', function() end eq(true, screen.options.mousemoveevent) if multigrid then - meths.input_mouse('move', '', '', 2, 3, 6) + api.nvim_input_mouse('move', '', '', 2, 3, 6) screen:expect({ grid = [[ ## grid 1 @@ -4003,7 +4000,7 @@ describe('builtin popupmenu', function() end eq(true, screen.options.mousemoveevent) if multigrid then - meths.input_mouse('left', 'press', '', 2, 2, 6) + api.nvim_input_mouse('left', 'press', '', 2, 2, 6) screen:expect({ grid = [[ ## grid 1 @@ -4025,11 +4022,11 @@ describe('builtin popupmenu', function() ]]) end eq(false, screen.options.mousemoveevent) - eq('bar', meths.get_var('menustr')) + eq('bar', api.nvim_get_var('menustr')) command('set laststatus=0 | botright split') if multigrid then - meths.input_mouse('right', 'press', '', 5, 1, 20) + api.nvim_input_mouse('right', 'press', '', 5, 1, 20) screen:expect({ grid = [[ ## grid 1 @@ -4064,7 +4061,7 @@ describe('builtin popupmenu', function() ]]) end if multigrid then - meths.input_mouse('left', 'press', '', 4, 2, 2) + api.nvim_input_mouse('left', 'press', '', 4, 2, 2) screen:expect({ grid = [[ ## grid 1 @@ -4093,11 +4090,11 @@ describe('builtin popupmenu', function() :let g:menustr = 'baz' | ]]) end - eq('baz', meths.get_var('menustr')) + eq('baz', api.nvim_get_var('menustr')) command('set winwidth=1 | rightbelow vsplit') if multigrid then - meths.input_mouse('right', 'press', '', 6, 1, 14) + api.nvim_input_mouse('right', 'press', '', 6, 1, 14) screen:expect({ grid = [[ ## grid 1 @@ -4135,7 +4132,7 @@ describe('builtin popupmenu', function() ]]) end if multigrid then - meths.input_mouse('left', 'press', '', 4, 0, 2) + api.nvim_input_mouse('left', 'press', '', 4, 0, 2) screen:expect({ grid = [[ ## grid 1 @@ -4167,11 +4164,11 @@ describe('builtin popupmenu', function() :let g:menustr = 'foo' | ]]) end - eq('foo', meths.get_var('menustr')) + eq('foo', api.nvim_get_var('menustr')) command('setlocal winbar=WINBAR') if multigrid then - meths.input_mouse('right', 'press', '', 6, 1, 14) + api.nvim_input_mouse('right', 'press', '', 6, 1, 14) screen:expect({ grid = [[ ## grid 1 @@ -4209,7 +4206,7 @@ describe('builtin popupmenu', function() ]]) end if multigrid then - meths.input_mouse('left', 'press', '', 4, 1, 2) + api.nvim_input_mouse('left', 'press', '', 4, 1, 2) screen:expect({ grid = [[ ## grid 1 @@ -4241,7 +4238,7 @@ describe('builtin popupmenu', function() :let g:menustr = 'bar' | ]]) end - eq('bar', meths.get_var('menustr')) + eq('bar', api.nvim_get_var('menustr')) end) if not multigrid then diff --git a/test/functional/ui/quickfix_spec.lua b/test/functional/ui/quickfix_spec.lua index 612a2a947d..40f8ef353a 100644 --- a/test/functional/ui/quickfix_spec.lua +++ b/test/functional/ui/quickfix_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, meths = helpers.clear, helpers.feed, helpers.meths +local clear, feed, api = helpers.clear, helpers.feed, helpers.api local insert, command = helpers.insert, helpers.command describe('quickfix selection highlight', function() @@ -26,7 +26,7 @@ describe('quickfix selection highlight', function() [12] = { foreground = Screen.colors.Brown, background = Screen.colors.Fuchsia }, }) - meths.set_option_value('errorformat', '%m %l', {}) + api.nvim_set_option_value('errorformat', '%m %l', {}) command('syntax on') command('highlight Search guibg=Green') diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 47e343789a..dba70f27e4 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -72,17 +72,17 @@ local helpers = require('test.functional.helpers')(nil) local busted = require('busted') -local deepcopy = helpers.deepcopy +local deepcopy = vim.deepcopy local shallowcopy = helpers.shallowcopy local concat_tables = helpers.concat_tables -local pesc = helpers.pesc +local pesc = vim.pesc local run_session = helpers.run_session local eq = helpers.eq local dedent = helpers.dedent local get_session = helpers.get_session local create_callindex = helpers.create_callindex -local inspect = require('vim.inspect') +local inspect = vim.inspect local function isempty(v) return type(v) == 'table' and next(v) == nil diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 4ee2438f88..42e2b4d4b5 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -4,7 +4,7 @@ local spawn, set_session, clear = helpers.spawn, helpers.set_session, helpers.cl local feed, command = helpers.feed, helpers.command local insert = helpers.insert local eq = helpers.eq -local funcs, meths = helpers.funcs, helpers.meths +local fn, api = helpers.fn, helpers.api describe('screen', function() local screen @@ -597,7 +597,7 @@ local function screen_tests(linegrid) command([[autocmd VimResized * redrawtabline]]) command([[autocmd VimResized * lua vim.api.nvim_echo({ { 'Hello' } }, false, {})]]) command([[autocmd VimResized * let g:echospace = v:echospace]]) - meths.set_option_value('showtabline', 2, {}) + api.nvim_set_option_value('showtabline', 2, {}) screen:expect([[ {2: + [No Name] }{3: }| resiz^e | @@ -611,7 +611,7 @@ local function screen_tests(linegrid) {0:~ }|*3 | ]]) - eq(29, meths.get_var('echospace')) + eq(29, api.nvim_get_var('echospace')) end) it('messages from the same Ex command as resize are visible #22225', function() @@ -779,33 +779,33 @@ it('CTRL-F or CTRL-B scrolls a page after UI attach/resize #20605', function() clear() local screen = Screen.new(100, 100) screen:attach() - eq(100, meths.get_option_value('lines', {})) - eq(99, meths.get_option_value('window', {})) - eq(99, meths.win_get_height(0)) + eq(100, api.nvim_get_option_value('lines', {})) + eq(99, api.nvim_get_option_value('window', {})) + eq(99, api.nvim_win_get_height(0)) feed('1000o<Esc>') - eq(903, funcs.line('w0')) + eq(903, fn.line('w0')) feed('<C-B>') - eq(806, funcs.line('w0')) + eq(806, fn.line('w0')) feed('<C-B>') - eq(709, funcs.line('w0')) + eq(709, fn.line('w0')) feed('<C-F>') - eq(806, funcs.line('w0')) + eq(806, fn.line('w0')) feed('<C-F>') - eq(903, funcs.line('w0')) + eq(903, fn.line('w0')) feed('G') screen:try_resize(50, 50) - eq(50, meths.get_option_value('lines', {})) - eq(49, meths.get_option_value('window', {})) - eq(49, meths.win_get_height(0)) - eq(953, funcs.line('w0')) + eq(50, api.nvim_get_option_value('lines', {})) + eq(49, api.nvim_get_option_value('window', {})) + eq(49, api.nvim_win_get_height(0)) + eq(953, fn.line('w0')) feed('<C-B>') - eq(906, funcs.line('w0')) + eq(906, fn.line('w0')) feed('<C-B>') - eq(859, funcs.line('w0')) + eq(859, fn.line('w0')) feed('<C-F>') - eq(906, funcs.line('w0')) + eq(906, fn.line('w0')) feed('<C-F>') - eq(953, funcs.line('w0')) + eq(953, fn.line('w0')) end) it("showcmd doesn't cause empty grid_line with redrawdebug=compositor #22593", function() diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua index 68596f27ad..f745cdb97b 100644 --- a/test/functional/ui/searchhl_spec.lua +++ b/test/functional/ui/searchhl_spec.lua @@ -5,7 +5,7 @@ local command = helpers.command local feed_command = helpers.feed_command local eq = helpers.eq local eval = helpers.eval -local funcs = helpers.funcs +local fn = helpers.fn local testprg = helpers.testprg describe('search highlighting', function() @@ -458,13 +458,13 @@ describe('search highlighting', function() command([[let @/ = 'i']]) -- moves to next match of previous search pattern, just like /<cr> feed('/<c-g><cr>') - eq({ 0, 1, 6, 0 }, funcs.getpos('.')) + eq({ 0, 1, 6, 0 }, fn.getpos('.')) -- moves to next match of previous search pattern, just like /<cr> feed('/<cr>') - eq({ 0, 1, 12, 0 }, funcs.getpos('.')) + eq({ 0, 1, 12, 0 }, fn.getpos('.')) -- moves to next match of previous search pattern, just like /<cr> feed('/<c-t><cr>') - eq({ 0, 2, 1, 0 }, funcs.getpos('.')) + eq({ 0, 2, 1, 0 }, fn.getpos('.')) -- 8.0.1304, test that C-g and C-t works with incsearch and empty pattern feed('<esc>/fi<CR>') diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua index 53fa4b6d65..5e45c3113b 100644 --- a/test/functional/ui/sign_spec.lua +++ b/test/functional/ui/sign_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, exec, meths = helpers.clear, helpers.feed, helpers.exec, helpers.meths +local clear, feed, exec, api = helpers.clear, helpers.feed, helpers.exec, helpers.api describe('Signs', function() local screen @@ -423,7 +423,7 @@ describe('Signs', function() {0:~ }|*7 | ]]) - meths.buf_set_extmark(0, meths.create_namespace('test'), 0, 0, { + api.nvim_buf_set_extmark(0, api.nvim_create_namespace('test'), 0, 0, { virt_lines = { { { 'VIRT LINES' } } }, virt_lines_above = true, }) @@ -468,7 +468,7 @@ describe('Signs', function() end) it('signcolumn width is updated when removing all signs after deleting lines', function() - meths.buf_set_lines(0, 0, 1, true, { 'a', 'b', 'c', 'd', 'e' }) + api.nvim_buf_set_lines(0, 0, 1, true, { 'a', 'b', 'c', 'd', 'e' }) exec('sign define piet text=>>') exec('sign place 10001 line=1 name=piet') exec('sign place 10002 line=5 name=piet') @@ -494,7 +494,7 @@ describe('Signs', function() end) it('signcolumn width is updated when removing all signs after inserting lines', function() - meths.buf_set_lines(0, 0, 1, true, { 'a', 'b', 'c', 'd', 'e' }) + api.nvim_buf_set_lines(0, 0, 1, true, { 'a', 'b', 'c', 'd', 'e' }) exec('sign define piet text=>>') exec('sign place 10001 line=1 name=piet') exec('sign place 10002 line=5 name=piet') diff --git a/test/functional/ui/spell_spec.lua b/test/functional/ui/spell_spec.lua index 13c3b24cc1..8b5644ee42 100644 --- a/test/functional/ui/spell_spec.lua +++ b/test/functional/ui/spell_spec.lua @@ -6,8 +6,7 @@ local clear = helpers.clear local exec = helpers.exec local feed = helpers.feed local insert = helpers.insert -local meths = helpers.meths -local curbufmeths = helpers.curbufmeths +local api = helpers.api local is_os = helpers.is_os describe("'spell'", function() @@ -260,9 +259,9 @@ describe("'spell'", function() {6:search hit BOTTOM, continuing at TOP} | ]]) exec('echo ""') - local ns = meths.create_namespace('spell') + local ns = api.nvim_create_namespace('spell') -- extmark with spell=true enables spell - local id = curbufmeths.set_extmark(ns, 1, 4, { end_row = 1, end_col = 10, spell = true }) + local id = api.nvim_buf_set_extmark(0, ns, 1, 4, { end_row = 1, end_col = 10, spell = true }) screen:expect([[ {3:#include }{4:<stdbool.h>} | {5:bool} {1:func}({5:void}); | @@ -278,9 +277,9 @@ describe("'spell'", function() {0:~ }|*4 | ]]) - curbufmeths.del_extmark(ns, id) + api.nvim_buf_del_extmark(0, ns, id) -- extmark with spell=false disables spell - id = curbufmeths.set_extmark(ns, 2, 18, { end_row = 2, end_col = 26, spell = false }) + id = api.nvim_buf_set_extmark(0, ns, 2, 18, { end_row = 2, end_col = 26, spell = false }) screen:expect([[ {3:#include }{4:<stdbool.h>} | {5:bool} ^func({5:void}); | @@ -297,7 +296,7 @@ describe("'spell'", function() {6:search hit TOP, continuing at BOTTOM} | ]]) exec('echo ""') - curbufmeths.del_extmark(ns, id) + api.nvim_buf_del_extmark(0, ns, id) screen:expect([[ {3:#include }{4:<stdbool.h>} | {5:bool} func({5:void}); | @@ -368,8 +367,8 @@ describe("'spell'", function() syntax match Constant "^.*$" call setline(1, "This is some text without any spell errors.") ]]) - local ns = meths.create_namespace('spell') - curbufmeths.set_extmark(ns, 0, 0, { hl_group = 'WarningMsg', end_col = 43 }) + local ns = api.nvim_create_namespace('spell') + api.nvim_buf_set_extmark(0, ns, 0, 0, { hl_group = 'WarningMsg', end_col = 43 }) screen:expect([[ {6:^This is some text without any spell errors.}| {0:~ }| diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index a27524c9f2..dec696d3c3 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -7,7 +7,7 @@ local exec = helpers.exec local eval = helpers.eval local exec_lua = helpers.exec_lua local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -543,56 +543,56 @@ describe('statuscolumn', function() end) it('clicks work with mousemodel=' .. model, function() - meths.set_option_value('statuscolumn', '%0@MyClickFunc@%=%l%T', {}) - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_set_option_value('statuscolumn', '%0@MyClickFunc@%=%l%T', {}) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) eq('0 1 l 4', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) eq('0 2 l 4', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) eq('0 3 l 4', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) eq('0 4 l 4', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 3, 0) + api.nvim_input_mouse('right', 'press', '', 0, 3, 0) eq('0 1 r 7', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 3, 0) + api.nvim_input_mouse('right', 'press', '', 0, 3, 0) eq('0 2 r 7', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 3, 0) + api.nvim_input_mouse('right', 'press', '', 0, 3, 0) eq('0 3 r 7', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 3, 0) + api.nvim_input_mouse('right', 'press', '', 0, 3, 0) eq('0 4 r 7', eval('g:testvar')) command('rightbelow vsplit') - meths.input_mouse('left', 'press', '', 0, 0, 27) + api.nvim_input_mouse('left', 'press', '', 0, 0, 27) eq('0 1 l 4', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 3, 27) + api.nvim_input_mouse('right', 'press', '', 0, 3, 27) eq('0 1 r 7', eval('g:testvar')) command('setlocal rightleft') - meths.input_mouse('left', 'press', '', 0, 0, 52) + api.nvim_input_mouse('left', 'press', '', 0, 0, 52) eq('0 1 l 4', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 3, 52) + api.nvim_input_mouse('right', 'press', '', 0, 3, 52) eq('0 1 r 7', eval('g:testvar')) command('wincmd H') - meths.input_mouse('left', 'press', '', 0, 0, 25) + api.nvim_input_mouse('left', 'press', '', 0, 0, 25) eq('0 1 l 4', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 3, 25) + api.nvim_input_mouse('right', 'press', '', 0, 3, 25) eq('0 1 r 7', eval('g:testvar')) command('close') command('set laststatus=2 winbar=%f') command('let g:testvar = ""') -- Check that winbar click doesn't register as statuscolumn click - meths.input_mouse('right', 'press', '', 0, 0, 0) + api.nvim_input_mouse('right', 'press', '', 0, 0, 0) eq('', eval('g:testvar')) -- Check that statusline click doesn't register as statuscolumn click - meths.input_mouse('right', 'press', '', 0, 12, 0) + api.nvim_input_mouse('right', 'press', '', 0, 12, 0) eq('', eval('g:testvar')) -- Check that cmdline click doesn't register as statuscolumn click - meths.input_mouse('right', 'press', '', 0, 13, 0) + api.nvim_input_mouse('right', 'press', '', 0, 13, 0) eq('', eval('g:testvar')) end) it('clicks and highlights work with control characters', function() - meths.set_option_value('statuscolumn', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {}) + api.nvim_set_option_value('statuscolumn', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {}) screen:expect { grid = [[ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |*4 @@ -605,13 +605,13 @@ describe('statuscolumn', function() [1] = { foreground = Screen.colors.Brown }, -- LineNr }, } - meths.input_mouse('right', 'press', '', 0, 4, 3) + api.nvim_input_mouse('right', 'press', '', 0, 4, 3) eq('', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 5, 8) + api.nvim_input_mouse('left', 'press', '', 0, 5, 8) eq('', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 4) + api.nvim_input_mouse('right', 'press', '', 0, 6, 4) eq('0 1 r 10', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 7, 7) + api.nvim_input_mouse('left', 'press', '', 0, 7, 7) eq('0 1 l 11', eval('g:testvar')) end) @@ -621,7 +621,7 @@ describe('statuscolumn', function() [0] = { foreground = Screen.colors.Brown }, [1] = { background = Screen.colors.Plum1 }, }) - meths.set_option_value('statuscolumn', '%0@MyClickFunc@%l%T', {}) + api.nvim_set_option_value('statuscolumn', '%0@MyClickFunc@%l%T', {}) exec([[ function! MyClickFunc(minwid, clicks, button, mods) let g:testvar = printf("%d %d %s %d", a:minwid, a:clicks, a:button, getmousepos().line) @@ -630,26 +630,26 @@ describe('statuscolumn', function() endfunction ]]) -- clicking an item does not drag mouse - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) screen:expect([[ {0:8 }^aaaaa | {1: Echo } | ]]) - meths.input_mouse('left', 'press', '', 0, 1, 5) - meths.input_mouse('left', 'release', '', 0, 1, 5) + api.nvim_input_mouse('left', 'press', '', 0, 1, 5) + api.nvim_input_mouse('left', 'release', '', 0, 1, 5) screen:expect([[ {0:8 }^aaaaa | 0 1 l 8 | ]]) command('echo') -- clicking outside to close the menu does not drag mouse - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) screen:expect([[ {0:8 }^aaaaa | {1: Echo } | ]]) - meths.input_mouse('left', 'press', '', 0, 0, 10) - meths.input_mouse('left', 'release', '', 0, 0, 10) + api.nvim_input_mouse('left', 'press', '', 0, 0, 10) + api.nvim_input_mouse('left', 'release', '', 0, 0, 10) screen:expect([[ {0:8 }^aaaaa | | diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua index 873f529097..d1bf163ab8 100644 --- a/test/functional/ui/statusline_spec.lua +++ b/test/functional/ui/statusline_spec.lua @@ -5,12 +5,12 @@ local clear = helpers.clear local command = helpers.command local feed = helpers.feed local eq = helpers.eq -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local exec = helpers.exec local exec_lua = helpers.exec_lua local eval = helpers.eval -local sleep = helpers.sleep +local sleep = vim.uv.sleep local mousemodels = { 'extend', 'popup', 'popup_setpos' } @@ -39,31 +39,31 @@ for _, model in ipairs(mousemodels) do end) it('works', function() - meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) - meths.input_mouse('left', 'press', '', 0, 6, 16) + api.nvim_set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) + api.nvim_input_mouse('left', 'press', '', 0, 6, 16) eq('', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 29) + api.nvim_input_mouse('right', 'press', '', 0, 6, 29) eq('', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 6, 17) + api.nvim_input_mouse('left', 'press', '', 0, 6, 17) eq('0 1 l', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 6, 17) + api.nvim_input_mouse('left', 'press', '', 0, 6, 17) eq('0 2 l', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 6, 17) + api.nvim_input_mouse('left', 'press', '', 0, 6, 17) eq('0 3 l', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 6, 17) + api.nvim_input_mouse('left', 'press', '', 0, 6, 17) eq('0 4 l', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 28) + api.nvim_input_mouse('right', 'press', '', 0, 6, 28) eq('0 1 r', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 28) + api.nvim_input_mouse('right', 'press', '', 0, 6, 28) eq('0 2 r', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 28) + api.nvim_input_mouse('right', 'press', '', 0, 6, 28) eq('0 3 r', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 28) + api.nvim_input_mouse('right', 'press', '', 0, 6, 28) eq('0 4 r', eval('g:testvar')) end) it('works with control characters and highlight', function() - meths.set_option_value('statusline', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {}) + api.nvim_set_option_value('statusline', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {}) screen:expect { grid = [[ ^ | @@ -72,50 +72,50 @@ for _, model in ipairs(mousemodels) do | ]], } - meths.input_mouse('right', 'press', '', 0, 6, 3) + api.nvim_input_mouse('right', 'press', '', 0, 6, 3) eq('', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 6, 8) + api.nvim_input_mouse('left', 'press', '', 0, 6, 8) eq('', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 4) + api.nvim_input_mouse('right', 'press', '', 0, 6, 4) eq('0 1 r', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 6, 7) + api.nvim_input_mouse('left', 'press', '', 0, 6, 7) eq('0 1 l', eval('g:testvar')) end) it('works for winbar', function() - meths.set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) - meths.input_mouse('left', 'press', '', 0, 0, 17) + api.nvim_set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) + api.nvim_input_mouse('left', 'press', '', 0, 0, 17) eq('0 1 l', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 0, 17) + api.nvim_input_mouse('right', 'press', '', 0, 0, 17) eq('0 1 r', eval('g:testvar')) end) it('works for winbar in floating window', function() - meths.open_win( + api.nvim_open_win( 0, true, { width = 30, height = 4, relative = 'editor', row = 1, col = 5, border = 'single' } ) - meths.set_option_value( + api.nvim_set_option_value( 'winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', { scope = 'local' } ) - meths.input_mouse('left', 'press', '', 0, 2, 23) + api.nvim_input_mouse('left', 'press', '', 0, 2, 23) eq('0 1 l', eval('g:testvar')) end) it('works when there are multiple windows', function() command('split') - meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) - meths.set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) - meths.input_mouse('left', 'press', '', 0, 0, 17) + api.nvim_set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) + api.nvim_set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) + api.nvim_input_mouse('left', 'press', '', 0, 0, 17) eq('0 1 l', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 4, 17) + api.nvim_input_mouse('right', 'press', '', 0, 4, 17) eq('0 1 r', eval('g:testvar')) - meths.input_mouse('middle', 'press', '', 0, 3, 17) + api.nvim_input_mouse('middle', 'press', '', 0, 3, 17) eq('0 1 m', eval('g:testvar')) - meths.input_mouse('left', 'press', '', 0, 6, 17) + api.nvim_input_mouse('left', 'press', '', 0, 6, 17) eq('0 1 l', eval('g:testvar')) end) @@ -125,64 +125,64 @@ for _, model in ipairs(mousemodels) do vim.g.testvar = string.format("%d %d %s", minwid, clicks, button) end ]]) - meths.set_option_value( + api.nvim_set_option_value( 'statusline', 'Not clicky stuff %0@v:lua.clicky_func@Clicky stuff%T', {} ) - meths.input_mouse('left', 'press', '', 0, 6, 17) + api.nvim_input_mouse('left', 'press', '', 0, 6, 17) eq('0 1 l', eval('g:testvar')) end) it('ignores unsupported click items', function() command('tabnew | tabprevious') - meths.set_option_value('statusline', '%2TNot clicky stuff%T', {}) - meths.input_mouse('left', 'press', '', 0, 6, 0) - eq(1, meths.get_current_tabpage().id) - meths.set_option_value('statusline', '%2XNot clicky stuff%X', {}) - meths.input_mouse('left', 'press', '', 0, 6, 0) - eq(2, #meths.list_tabpages()) + api.nvim_set_option_value('statusline', '%2TNot clicky stuff%T', {}) + api.nvim_input_mouse('left', 'press', '', 0, 6, 0) + eq(1, api.nvim_get_current_tabpage().id) + api.nvim_set_option_value('statusline', '%2XNot clicky stuff%X', {}) + api.nvim_input_mouse('left', 'press', '', 0, 6, 0) + eq(2, #api.nvim_list_tabpages()) end) it("right click works when statusline isn't focused #18994", function() - meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) - meths.input_mouse('right', 'press', '', 0, 6, 17) + api.nvim_set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) + api.nvim_input_mouse('right', 'press', '', 0, 6, 17) eq('0 1 r', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 17) + api.nvim_input_mouse('right', 'press', '', 0, 6, 17) eq('0 2 r', eval('g:testvar')) end) it('works with modifiers #18994', function() - meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) + api.nvim_set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {}) -- Note: alternate between left and right mouse buttons to avoid triggering multiclicks - meths.input_mouse('left', 'press', 'S', 0, 6, 17) + api.nvim_input_mouse('left', 'press', 'S', 0, 6, 17) eq('0 1 l(s )', eval('g:testvar')) - meths.input_mouse('right', 'press', 'S', 0, 6, 17) + api.nvim_input_mouse('right', 'press', 'S', 0, 6, 17) eq('0 1 r(s )', eval('g:testvar')) - meths.input_mouse('left', 'press', 'A', 0, 6, 17) + api.nvim_input_mouse('left', 'press', 'A', 0, 6, 17) eq('0 1 l( a )', eval('g:testvar')) - meths.input_mouse('right', 'press', 'A', 0, 6, 17) + api.nvim_input_mouse('right', 'press', 'A', 0, 6, 17) eq('0 1 r( a )', eval('g:testvar')) - meths.input_mouse('left', 'press', 'AS', 0, 6, 17) + api.nvim_input_mouse('left', 'press', 'AS', 0, 6, 17) eq('0 1 l(s a )', eval('g:testvar')) - meths.input_mouse('right', 'press', 'AS', 0, 6, 17) + api.nvim_input_mouse('right', 'press', 'AS', 0, 6, 17) eq('0 1 r(s a )', eval('g:testvar')) - meths.input_mouse('left', 'press', 'T', 0, 6, 17) + api.nvim_input_mouse('left', 'press', 'T', 0, 6, 17) eq('0 1 l( m)', eval('g:testvar')) - meths.input_mouse('right', 'press', 'T', 0, 6, 17) + api.nvim_input_mouse('right', 'press', 'T', 0, 6, 17) eq('0 1 r( m)', eval('g:testvar')) - meths.input_mouse('left', 'press', 'TS', 0, 6, 17) + api.nvim_input_mouse('left', 'press', 'TS', 0, 6, 17) eq('0 1 l(s m)', eval('g:testvar')) - meths.input_mouse('right', 'press', 'TS', 0, 6, 17) + api.nvim_input_mouse('right', 'press', 'TS', 0, 6, 17) eq('0 1 r(s m)', eval('g:testvar')) - meths.input_mouse('left', 'press', 'C', 0, 6, 17) + api.nvim_input_mouse('left', 'press', 'C', 0, 6, 17) eq('0 1 l( c )', eval('g:testvar')) -- <C-RightMouse> is for tag jump end) it('works for global statusline with vertical splits #19186', function() command('set laststatus=3') - meths.set_option_value( + api.nvim_set_option_value( 'statusline', '%0@MyClickFunc@Clicky stuff%T %= %0@MyClickFunc@Clicky stuff%T', {} @@ -198,15 +198,15 @@ for _, model in ipairs(mousemodels) do } -- clickable area on the right - meths.input_mouse('left', 'press', '', 0, 6, 35) + api.nvim_input_mouse('left', 'press', '', 0, 6, 35) eq('0 1 l', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 35) + api.nvim_input_mouse('right', 'press', '', 0, 6, 35) eq('0 1 r', eval('g:testvar')) -- clickable area on the left - meths.input_mouse('left', 'press', '', 0, 6, 5) + api.nvim_input_mouse('left', 'press', '', 0, 6, 5) eq('0 1 l', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 5) + api.nvim_input_mouse('right', 'press', '', 0, 6, 5) eq('0 1 r', eval('g:testvar')) end) @@ -214,9 +214,9 @@ for _, model in ipairs(mousemodels) do command([[ let &stl = '%@Test@%T%@MyClickFunc@%=%T%@Test@' ]]) - meths.input_mouse('left', 'press', '', 0, 6, 0) + api.nvim_input_mouse('left', 'press', '', 0, 6, 0) eq('0 1 l', eval('g:testvar')) - meths.input_mouse('right', 'press', '', 0, 6, 39) + api.nvim_input_mouse('right', 'press', '', 0, 6, 39) eq('0 1 r', eval('g:testvar')) end) @@ -224,7 +224,7 @@ for _, model in ipairs(mousemodels) do command([[ let &stl = '%@MyClickFunc@foo%X' .. repeat('a', 40) .. '%<t%@Test@bar%X%@Test@baz' ]]) - meths.input_mouse('left', 'press', '', 0, 6, 2) + api.nvim_input_mouse('left', 'press', '', 0, 6, 2) eq('0 1 l', eval('g:testvar')) end) end) @@ -366,38 +366,38 @@ describe('global statusline', function() end) it('win_move_statusline() can reduce cmdheight to 1', function() - eq(1, meths.get_option_value('cmdheight', {})) - funcs.win_move_statusline(0, -1) - eq(2, meths.get_option_value('cmdheight', {})) - funcs.win_move_statusline(0, -1) - eq(3, meths.get_option_value('cmdheight', {})) - funcs.win_move_statusline(0, 1) - eq(2, meths.get_option_value('cmdheight', {})) - funcs.win_move_statusline(0, 1) - eq(1, meths.get_option_value('cmdheight', {})) + eq(1, api.nvim_get_option_value('cmdheight', {})) + fn.win_move_statusline(0, -1) + eq(2, api.nvim_get_option_value('cmdheight', {})) + fn.win_move_statusline(0, -1) + eq(3, api.nvim_get_option_value('cmdheight', {})) + fn.win_move_statusline(0, 1) + eq(2, api.nvim_get_option_value('cmdheight', {})) + fn.win_move_statusline(0, 1) + eq(1, api.nvim_get_option_value('cmdheight', {})) end) it('mouse dragging can reduce cmdheight to 1', function() command('set mouse=a') - meths.input_mouse('left', 'press', '', 0, 14, 10) - eq(1, meths.get_option_value('cmdheight', {})) - meths.input_mouse('left', 'drag', '', 0, 13, 10) - eq(2, meths.get_option_value('cmdheight', {})) - meths.input_mouse('left', 'drag', '', 0, 12, 10) - eq(3, meths.get_option_value('cmdheight', {})) - meths.input_mouse('left', 'drag', '', 0, 13, 10) - eq(2, meths.get_option_value('cmdheight', {})) - meths.input_mouse('left', 'drag', '', 0, 14, 10) - eq(1, meths.get_option_value('cmdheight', {})) - meths.input_mouse('left', 'drag', '', 0, 15, 10) - eq(1, meths.get_option_value('cmdheight', {})) - meths.input_mouse('left', 'drag', '', 0, 14, 10) - eq(1, meths.get_option_value('cmdheight', {})) + api.nvim_input_mouse('left', 'press', '', 0, 14, 10) + eq(1, api.nvim_get_option_value('cmdheight', {})) + api.nvim_input_mouse('left', 'drag', '', 0, 13, 10) + eq(2, api.nvim_get_option_value('cmdheight', {})) + api.nvim_input_mouse('left', 'drag', '', 0, 12, 10) + eq(3, api.nvim_get_option_value('cmdheight', {})) + api.nvim_input_mouse('left', 'drag', '', 0, 13, 10) + eq(2, api.nvim_get_option_value('cmdheight', {})) + api.nvim_input_mouse('left', 'drag', '', 0, 14, 10) + eq(1, api.nvim_get_option_value('cmdheight', {})) + api.nvim_input_mouse('left', 'drag', '', 0, 15, 10) + eq(1, api.nvim_get_option_value('cmdheight', {})) + api.nvim_input_mouse('left', 'drag', '', 0, 14, 10) + eq(1, api.nvim_get_option_value('cmdheight', {})) end) it('cmdline row is correct after setting cmdheight #20514', function() command('botright split test/functional/fixtures/bigfile.txt') - meths.set_option_value('cmdheight', 1, {}) + api.nvim_set_option_value('cmdheight', 1, {}) feed('L') screen:expect([[ | @@ -428,7 +428,7 @@ describe('global statusline', function() {2:test/functional/fixtures/bigfile.txt 8,1 0%}| | ]]) - meths.set_option_value('showtabline', 2, {}) + api.nvim_set_option_value('showtabline', 2, {}) screen:expect([[ {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| | @@ -443,7 +443,7 @@ describe('global statusline', function() {2:test/functional/fixtures/bigfile.txt 8,1 0%}| | ]]) - meths.set_option_value('cmdheight', 0, {}) + api.nvim_set_option_value('cmdheight', 0, {}) screen:expect([[ {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| | @@ -458,7 +458,7 @@ describe('global statusline', function() ^0007;<control>;Cc;0;BN;;;;;N;BELL;;;; | {2:test/functional/fixtures/bigfile.txt 8,1 0%}| ]]) - meths.set_option_value('cmdheight', 1, {}) + api.nvim_set_option_value('cmdheight', 1, {}) screen:expect([[ {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| | @@ -478,8 +478,8 @@ end) it('statusline does not crash if it has Arabic characters #19447', function() clear() - meths.set_option_value('statusline', 'غً', {}) - meths.set_option_value('laststatus', 2, {}) + api.nvim_set_option_value('statusline', 'غً', {}) + api.nvim_set_option_value('laststatus', 2, {}) command('redraw!') assert_alive() end) diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index f270d298cb..d58155ef0c 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, command, eq = helpers.clear, helpers.command, helpers.eq local insert = helpers.insert -local meths = helpers.meths +local api = helpers.api local assert_alive = helpers.assert_alive describe('ui/ext_tabline', function() @@ -138,7 +138,7 @@ describe('tabline', function() command('tabnew') insert('tab2') command('tabprev') - meths.set_option_value('tabline', '%1T口口%2Ta' .. ('b'):rep(38) .. '%999Xc', {}) + api.nvim_set_option_value('tabline', '%1T口口%2Ta' .. ('b'):rep(38) .. '%999Xc', {}) screen:expect { grid = [[ {1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }| @@ -148,7 +148,7 @@ describe('tabline', function() ]], } assert_alive() - meths.input_mouse('left', 'press', '', 0, 0, 1) + api.nvim_input_mouse('left', 'press', '', 0, 0, 1) screen:expect { grid = [[ {1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }| @@ -157,7 +157,7 @@ describe('tabline', function() | ]], } - meths.input_mouse('left', 'press', '', 0, 0, 0) + api.nvim_input_mouse('left', 'press', '', 0, 0, 0) screen:expect { grid = [[ {1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }| @@ -166,7 +166,7 @@ describe('tabline', function() | ]], } - meths.input_mouse('left', 'press', '', 0, 0, 39) + api.nvim_input_mouse('left', 'press', '', 0, 0, 39) screen:expect { grid = [[ {1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }| @@ -175,7 +175,7 @@ describe('tabline', function() | ]], } - meths.input_mouse('left', 'press', '', 0, 0, 40) + api.nvim_input_mouse('left', 'press', '', 0, 0, 40) screen:expect { grid = [[ tab^1 | diff --git a/test/functional/ui/title_spec.lua b/test/functional/ui/title_spec.lua index 6f86b61431..c77e836d21 100644 --- a/test/functional/ui/title_spec.lua +++ b/test/functional/ui/title_spec.lua @@ -2,12 +2,12 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command -local curwin = helpers.curwin +local curwin = helpers.api.nvim_get_current_win local eq = helpers.eq local exec_lua = helpers.exec_lua local feed = helpers.feed -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local is_os = helpers.is_os describe('title', function() @@ -44,7 +44,7 @@ describe('title', function() before_each(function() command('edit ' .. file1) - buf2 = funcs.bufadd(file2) + buf2 = fn.bufadd(file2) command('set title') end) @@ -58,7 +58,7 @@ describe('title', function() end) it('an RPC call to nvim_set_option_value in a hidden buffer', function() - meths.set_option_value('autoindent', true, { buf = buf2 }) + api.nvim_set_option_value('autoindent', true, { buf = buf2 }) command('redraw!') screen:expect(function() eq(expected, screen.title) @@ -98,7 +98,7 @@ describe('title', function() it('setting the buffer of another window using RPC', function() local oldwin = curwin().id command('split') - meths.win_set_buf(oldwin, buf2) + api.nvim_win_set_buf(oldwin, buf2) command('redraw!') screen:expect(function() eq(expected, screen.title) @@ -124,7 +124,7 @@ describe('title', function() end) it('creating a floating window using RPC', function() - meths.open_win(buf2, false, { + api.nvim_open_win(buf2, false, { relative = 'editor', width = 5, height = 5, diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua index 749ddf72f8..4ad0326851 100644 --- a/test/functional/ui/wildmode_spec.lua +++ b/test/functional/ui/wildmode_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, feed, command = helpers.clear, helpers.feed, helpers.command -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local eq = helpers.eq local eval = helpers.eval local retry = helpers.retry @@ -413,12 +413,12 @@ describe("'wildmenu'", function() } -- Wildcharm? where we are going we aint't no need no wildcharm. - eq(0, meths.get_option_value('wildcharm', {})) + eq(0, api.nvim_get_option_value('wildcharm', {})) -- Don't mess the defaults yet (neovim is about backwards compatibility) - eq(9, meths.get_option_value('wildchar', {})) + eq(9, api.nvim_get_option_value('wildchar', {})) -- Lol what is cnoremap? Some say it can define mappings. command 'set wildchar=0' - eq(0, meths.get_option_value('wildchar', {})) + eq(0, api.nvim_get_option_value('wildchar', {})) command 'cnoremap <f2> <c-z>' feed(':syntax <f2>') @@ -483,7 +483,7 @@ describe('command line completion', function() end) it('lists directories with empty PATH', function() - local tmp = funcs.tempname() + local tmp = fn.tempname() command('e ' .. tmp) command('cd %:h') command("call mkdir('Xtest-functional-viml-compl-dir')") @@ -525,9 +525,9 @@ describe('command line completion', function() end) it('does not leak memory with <S-Tab> with wildmenu and only one match #19874', function() - meths.set_option_value('wildmenu', true, {}) - meths.set_option_value('wildmode', 'full', {}) - meths.set_option_value('wildoptions', 'pum', {}) + api.nvim_set_option_value('wildmenu', true, {}) + api.nvim_set_option_value('wildmode', 'full', {}) + api.nvim_set_option_value('wildoptions', 'pum', {}) feed(':sign unpla<S-Tab>') screen:expect([[ @@ -545,8 +545,8 @@ describe('command line completion', function() end) it('does not show matches with <S-Tab> without wildmenu with wildmode=full', function() - meths.set_option_value('wildmenu', false, {}) - meths.set_option_value('wildmode', 'full', {}) + api.nvim_set_option_value('wildmenu', false, {}) + api.nvim_set_option_value('wildmode', 'full', {}) feed(':sign <S-Tab>') screen:expect([[ @@ -557,8 +557,8 @@ describe('command line completion', function() end) it('shows matches with <S-Tab> without wildmenu with wildmode=list', function() - meths.set_option_value('wildmenu', false, {}) - meths.set_option_value('wildmode', 'list', {}) + api.nvim_set_option_value('wildmenu', false, {}) + api.nvim_set_option_value('wildmode', 'list', {}) feed(':sign <S-Tab>') screen:expect([[ diff --git a/test/functional/ui/winbar_spec.lua b/test/functional/ui/winbar_spec.lua index 502c61a31b..858a537d3a 100644 --- a/test/functional/ui/winbar_spec.lua +++ b/test/functional/ui/winbar_spec.lua @@ -3,12 +3,11 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command local insert = helpers.insert -local meths = helpers.meths +local api = helpers.api local eq = helpers.eq local poke_eventloop = helpers.poke_eventloop local feed = helpers.feed -local funcs = helpers.funcs -local curwin = helpers.curwin +local fn = helpers.fn local pcall_err = helpers.pcall_err describe('winbar', function() @@ -40,7 +39,7 @@ describe('winbar', function() foreground = Screen.colors.Magenta, }, }) - meths.set_option_value('winbar', 'Set Up The Bars', {}) + api.nvim_set_option_value('winbar', 'Set Up The Bars', {}) end) it('works', function() @@ -51,8 +50,8 @@ describe('winbar', function() | ]]) -- winbar is excluded from the heights returned by winheight() and getwininfo() - eq(11, funcs.winheight(0)) - local win_info = funcs.getwininfo(curwin().id)[1] + eq(11, fn.winheight(0)) + local win_info = fn.getwininfo(api.nvim_get_current_win().id)[1] eq(11, win_info.height) eq(1, win_info.winbar) end) @@ -185,7 +184,7 @@ describe('winbar', function() insert [[ just some random text]] - meths.set_option_value('winbar', 'Hello, I am a ruler: %l,%c', {}) + api.nvim_set_option_value('winbar', 'Hello, I am a ruler: %l,%c', {}) screen:expect { grid = [[ {1:Hello, I am a ruler: 2,11 }| @@ -265,7 +264,7 @@ describe('winbar', function() line sin(theta) line 8]]) - meths.input_mouse('left', 'press', '', 0, 5, 1) + api.nvim_input_mouse('left', 'press', '', 0, 5, 1) screen:expect([[ {1:Set Up The Bars }| line 1 | @@ -279,9 +278,9 @@ describe('winbar', function() {3:~ }|*3 | ]]) - eq({ 5, 1 }, meths.win_get_cursor(0)) + eq({ 5, 1 }, api.nvim_win_get_cursor(0)) - meths.input_mouse('left', 'drag', '', 0, 6, 2) + api.nvim_input_mouse('left', 'drag', '', 0, 6, 2) screen:expect([[ {1:Set Up The Bars }| line 1 | @@ -295,9 +294,9 @@ describe('winbar', function() {3:~ }|*3 {1:-- VISUAL --} | ]]) - eq({ 6, 2 }, meths.win_get_cursor(0)) + eq({ 6, 2 }, api.nvim_win_get_cursor(0)) - meths.input_mouse('left', 'drag', '', 0, 1, 2) + api.nvim_input_mouse('left', 'drag', '', 0, 1, 2) screen:expect([[ {1:Set Up The Bars }| li^n{7:e 1} | @@ -311,11 +310,11 @@ describe('winbar', function() {3:~ }|*3 {1:-- VISUAL --} | ]]) - eq({ 1, 2 }, meths.win_get_cursor(0)) + eq({ 1, 2 }, api.nvim_win_get_cursor(0)) - meths.input_mouse('left', 'drag', '', 0, 0, 2) + api.nvim_input_mouse('left', 'drag', '', 0, 0, 2) screen:expect_unchanged() - eq({ 1, 2 }, meths.win_get_cursor(0)) + eq({ 1, 2 }, api.nvim_win_get_cursor(0)) end) it('dragging statusline with mouse works correctly', function() @@ -332,9 +331,9 @@ describe('winbar', function() | ]]) - meths.input_mouse('left', 'press', '', 1, 5, 10) + api.nvim_input_mouse('left', 'press', '', 1, 5, 10) poke_eventloop() - meths.input_mouse('left', 'drag', '', 1, 6, 10) + api.nvim_input_mouse('left', 'drag', '', 1, 6, 10) screen:expect([[ {1:Set Up The Bars }| ^ | @@ -347,7 +346,7 @@ describe('winbar', function() | ]]) - meths.input_mouse('left', 'drag', '', 1, 4, 10) + api.nvim_input_mouse('left', 'drag', '', 1, 4, 10) screen:expect([[ {1:Set Up The Bars }| ^ | @@ -360,9 +359,9 @@ describe('winbar', function() | ]]) - meths.input_mouse('left', 'press', '', 1, 11, 10) + api.nvim_input_mouse('left', 'press', '', 1, 11, 10) poke_eventloop() - meths.input_mouse('left', 'drag', '', 1, 9, 10) + api.nvim_input_mouse('left', 'drag', '', 1, 9, 10) screen:expect([[ {1:Set Up The Bars }| ^ | @@ -374,9 +373,9 @@ describe('winbar', function() {2:[No Name] }| |*3 ]]) - eq(3, meths.get_option_value('cmdheight', {})) + eq(3, api.nvim_get_option_value('cmdheight', {})) - meths.input_mouse('left', 'drag', '', 1, 11, 10) + api.nvim_input_mouse('left', 'drag', '', 1, 11, 10) screen:expect([[ {1:Set Up The Bars }| ^ | @@ -388,7 +387,7 @@ describe('winbar', function() {2:[No Name] }| | ]]) - eq(1, meths.get_option_value('cmdheight', {})) + eq(1, api.nvim_get_option_value('cmdheight', {})) end) it('properly equalizes window height for window-local value', function() @@ -413,9 +412,12 @@ describe('winbar', function() end) it('requires window-local value for floating windows', function() - local win = - meths.open_win(0, false, { relative = 'editor', row = 2, col = 10, height = 7, width = 30 }) - meths.set_option_value('winbar', 'bar', {}) + local win = api.nvim_open_win( + 0, + false, + { relative = 'editor', row = 2, col = 10, height = 7, width = 30 } + ) + api.nvim_set_option_value('winbar', 'bar', {}) screen:expect { grid = [[ {1:bar }| @@ -426,7 +428,7 @@ describe('winbar', function() | ]], } - meths.set_option_value('winbar', 'floaty bar', { scope = 'local', win = win.id }) + api.nvim_set_option_value('winbar', 'floaty bar', { scope = 'local', win = win.id }) screen:expect { grid = [[ {1:bar }| @@ -529,7 +531,7 @@ describe('local winbar with tabs', function() [3] = { bold = true, foreground = Screen.colors.Blue }, [4] = { underline = true, background = Screen.colors.LightGray }, }) - meths.set_option_value('winbar', 'foo', { scope = 'local', win = 0 }) + api.nvim_set_option_value('winbar', 'foo', { scope = 'local', win = 0 }) end) it('works', function() diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 05876c43d1..200ad40c3a 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local neq, eq, command = helpers.neq, helpers.eq, helpers.command -local clear, curbufmeths = helpers.clear, helpers.curbufmeths +local clear = helpers.clear local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval local insert, pcall_err = helpers.insert, helpers.pcall_err local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local feed = helpers.feed describe('eval-API', function() @@ -80,36 +80,36 @@ describe('eval-API', function() -- Text-changing functions gave a "Failed to save undo information" error when called from an -- <expr> mapping outside do_cmdline() (msg_list == NULL), so use feed() to test this. command("inoremap <expr> <f2> nvim_buf_set_text(0, 0, 0, 0, 0, ['hi'])") - meths.set_vvar('errmsg', '') + api.nvim_set_vvar('errmsg', '') feed('i<f2><esc>') eq( 'E5555: API call: E565: Not allowed to change text or change window', - meths.get_vvar('errmsg') + api.nvim_get_vvar('errmsg') ) -- Some functions checking textlock (usually those that may change the current window or buffer) -- also ought to not be usable in the cmdwin. - local old_win = meths.get_current_win() + local old_win = api.nvim_get_current_win() feed('q:') eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.set_current_win, old_win) + pcall_err(api.nvim_set_current_win, old_win) ) -- But others, like nvim_buf_set_lines(), which just changes text, is OK. - curbufmeths.set_lines(0, -1, 1, { 'wow!' }) - eq({ 'wow!' }, curbufmeths.get_lines(0, -1, 1)) + api.nvim_buf_set_lines(0, 0, -1, 1, { 'wow!' }) + eq({ 'wow!' }, api.nvim_buf_get_lines(0, 0, -1, 1)) -- Turning the cmdwin buffer into a terminal buffer would be pretty weird. eq( 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits', - pcall_err(meths.open_term, 0, {}) + pcall_err(api.nvim_open_term, 0, {}) ) -- But turning a different buffer into a terminal from the cmdwin is OK. - local term_buf = meths.create_buf(false, true) - meths.open_term(term_buf, {}) - eq('terminal', meths.get_option_value('buftype', { buf = term_buf })) + local term_buf = api.nvim_create_buf(false, true) + api.nvim_open_term(term_buf, {}) + eq('terminal', api.nvim_get_option_value('buftype', { buf = term_buf })) end) it('use buffer numbers and windows ids as handles', function() @@ -143,11 +143,11 @@ describe('eval-API', function() end) it('get_lines and set_lines use NL to represent NUL', function() - curbufmeths.set_lines(0, -1, true, { 'aa\0', 'b\0b' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'aa\0', 'b\0b' }) eq({ 'aa\n', 'b\nb' }, eval('nvim_buf_get_lines(0, 0, -1, 1)')) command('call nvim_buf_set_lines(0, 1, 2, v:true, ["xx", "\\nyy"])') - eq({ 'aa\0', 'xx', '\0yy' }, curbufmeths.get_lines(0, -1, 1)) + eq({ 'aa\0', 'xx', '\0yy' }, api.nvim_buf_get_lines(0, 0, -1, 1)) end) it('that are FUNC_ATTR_NOEVAL cannot be called', function() @@ -207,7 +207,7 @@ describe('eval-API', function() 'Vim(call):E48: Not allowed in sandbox', pcall_err(command, "sandbox call nvim_input('ievil')") ) - eq({ '' }, meths.buf_get_lines(0, 0, -1, true)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, true)) end) it('converts blobs to API strings', function() diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua index c17edfad62..5557ce6788 100644 --- a/test/functional/vimscript/buf_functions_spec.lua +++ b/test/functional/vimscript/buf_functions_spec.lua @@ -1,17 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') - local eq = helpers.eq local clear = helpers.clear -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local command = helpers.command local exc_exec = helpers.exc_exec -local bufmeths = helpers.bufmeths -local curbufmeths = helpers.curbufmeths -local curwinmeths = helpers.curwinmeths -local curtabmeths = helpers.curtabmeths local get_pathsep = helpers.get_pathsep local rmdir = helpers.rmdir local pcall_err = helpers.pcall_err @@ -71,12 +65,12 @@ end describe('bufname() function', function() it('returns empty string when buffer was not found', function() command('file ' .. fname) - eq('', funcs.bufname(2)) - eq('', funcs.bufname('non-existent-buffer')) - eq('', funcs.bufname('#')) + eq('', fn.bufname(2)) + eq('', fn.bufname('non-existent-buffer')) + eq('', fn.bufname('#')) command('edit ' .. fname2) - eq(2, funcs.bufnr('%')) - eq('', funcs.bufname('X')) + eq(2, fn.bufnr('%')) + eq('', fn.bufname('X')) end) before_each(function() mkdir(dirname) @@ -85,80 +79,80 @@ describe('bufname() function', function() rmdir(dirname) end) it('returns expected buffer name', function() - eq('', funcs.bufname('%')) -- Buffer has no name yet + eq('', fn.bufname('%')) -- Buffer has no name yet command('file ' .. fname) - local wd = luv.cwd() + local wd = vim.uv.cwd() local sep = get_pathsep() - local curdirname = funcs.fnamemodify(wd, ':t') + local curdirname = fn.fnamemodify(wd, ':t') for _, arg in ipairs({ '%', 1, 'X', wd }) do - eq(fname, funcs.bufname(arg)) - meths.set_current_dir('..') - eq(curdirname .. sep .. fname, funcs.bufname(arg)) - meths.set_current_dir(curdirname) - meths.set_current_dir(dirname) - eq(wd .. sep .. fname, funcs.bufname(arg)) - meths.set_current_dir('..') - eq(fname, funcs.bufname(arg)) + eq(fname, fn.bufname(arg)) + api.nvim_set_current_dir('..') + eq(curdirname .. sep .. fname, fn.bufname(arg)) + api.nvim_set_current_dir(curdirname) + api.nvim_set_current_dir(dirname) + eq(wd .. sep .. fname, fn.bufname(arg)) + api.nvim_set_current_dir('..') + eq(fname, fn.bufname(arg)) command('enew') end - eq('', funcs.bufname('%')) - eq('', funcs.bufname('$')) - eq(2, funcs.bufnr('%')) + eq('', fn.bufname('%')) + eq('', fn.bufname('$')) + eq(2, fn.bufnr('%')) end) end) describe('bufnr() function', function() it('returns -1 when buffer was not found', function() command('file ' .. fname) - eq(-1, funcs.bufnr(2)) - eq(-1, funcs.bufnr('non-existent-buffer')) - eq(-1, funcs.bufnr('#')) + eq(-1, fn.bufnr(2)) + eq(-1, fn.bufnr('non-existent-buffer')) + eq(-1, fn.bufnr('#')) command('edit ' .. fname2) - eq(2, funcs.bufnr('%')) - eq(-1, funcs.bufnr('X')) + eq(2, fn.bufnr('%')) + eq(-1, fn.bufnr('X')) end) it('returns expected buffer number', function() - eq(1, funcs.bufnr('%')) + eq(1, fn.bufnr('%')) command('file ' .. fname) - local wd = luv.cwd() - local curdirname = funcs.fnamemodify(wd, ':t') - eq(1, funcs.bufnr(fname)) - eq(1, funcs.bufnr(wd)) - eq(1, funcs.bufnr(curdirname)) - eq(1, funcs.bufnr('X')) + local wd = vim.uv.cwd() + local curdirname = fn.fnamemodify(wd, ':t') + eq(1, fn.bufnr(fname)) + eq(1, fn.bufnr(wd)) + eq(1, fn.bufnr(curdirname)) + eq(1, fn.bufnr('X')) end) it('returns number of last buffer with "$"', function() - eq(1, funcs.bufnr('$')) + eq(1, fn.bufnr('$')) command('new') - eq(2, funcs.bufnr('$')) + eq(2, fn.bufnr('$')) command('new') - eq(3, funcs.bufnr('$')) + eq(3, fn.bufnr('$')) command('only') - eq(3, funcs.bufnr('$')) - eq(3, funcs.bufnr('%')) + eq(3, fn.bufnr('$')) + eq(3, fn.bufnr('%')) command('buffer 1') - eq(3, funcs.bufnr('$')) - eq(1, funcs.bufnr('%')) + eq(3, fn.bufnr('$')) + eq(1, fn.bufnr('%')) command('bwipeout 2') - eq(3, funcs.bufnr('$')) - eq(1, funcs.bufnr('%')) + eq(3, fn.bufnr('$')) + eq(1, fn.bufnr('%')) command('bwipeout 3') - eq(1, funcs.bufnr('$')) - eq(1, funcs.bufnr('%')) + eq(1, fn.bufnr('$')) + eq(1, fn.bufnr('%')) command('new') - eq(4, funcs.bufnr('$')) + eq(4, fn.bufnr('$')) end) end) describe('bufwinnr() function', function() it('returns -1 when buffer was not found', function() command('file ' .. fname) - eq(-1, funcs.bufwinnr(2)) - eq(-1, funcs.bufwinnr('non-existent-buffer')) - eq(-1, funcs.bufwinnr('#')) + eq(-1, fn.bufwinnr(2)) + eq(-1, fn.bufwinnr('non-existent-buffer')) + eq(-1, fn.bufwinnr('#')) command('split ' .. fname2) -- It would be OK if there was one window - eq(2, funcs.bufnr('%')) - eq(-1, funcs.bufwinnr('X')) + eq(2, fn.bufnr('%')) + eq(-1, fn.bufwinnr('X')) end) before_each(function() mkdir(dirname) @@ -167,105 +161,105 @@ describe('bufwinnr() function', function() rmdir(dirname) end) it('returns expected window number', function() - eq(1, funcs.bufwinnr('%')) + eq(1, fn.bufwinnr('%')) command('file ' .. fname) command('vsplit') command('split ' .. fname2) - eq(2, funcs.bufwinnr(fname)) - eq(1, funcs.bufwinnr(fname2)) - eq(-1, funcs.bufwinnr(fname:sub(1, #fname - 1))) - meths.set_current_dir(dirname) - eq(2, funcs.bufwinnr(fname)) - eq(1, funcs.bufwinnr(fname2)) - eq(-1, funcs.bufwinnr(fname:sub(1, #fname - 1))) - eq(1, funcs.bufwinnr('%')) - eq(2, funcs.bufwinnr(1)) - eq(1, funcs.bufwinnr(2)) - eq(-1, funcs.bufwinnr(3)) - eq(1, funcs.bufwinnr('$')) + eq(2, fn.bufwinnr(fname)) + eq(1, fn.bufwinnr(fname2)) + eq(-1, fn.bufwinnr(fname:sub(1, #fname - 1))) + api.nvim_set_current_dir(dirname) + eq(2, fn.bufwinnr(fname)) + eq(1, fn.bufwinnr(fname2)) + eq(-1, fn.bufwinnr(fname:sub(1, #fname - 1))) + eq(1, fn.bufwinnr('%')) + eq(2, fn.bufwinnr(1)) + eq(1, fn.bufwinnr(2)) + eq(-1, fn.bufwinnr(3)) + eq(1, fn.bufwinnr('$')) end) end) describe('getbufline() function', function() it('returns empty list when buffer was not found', function() command('file ' .. fname) - eq({}, funcs.getbufline(2, 1)) - eq({}, funcs.getbufline('non-existent-buffer', 1)) - eq({}, funcs.getbufline('#', 1)) + eq({}, fn.getbufline(2, 1)) + eq({}, fn.getbufline('non-existent-buffer', 1)) + eq({}, fn.getbufline('#', 1)) command('edit ' .. fname2) - eq(2, funcs.bufnr('%')) - eq({}, funcs.getbufline('X', 1)) + eq(2, fn.bufnr('%')) + eq({}, fn.getbufline('X', 1)) end) it('returns empty list when range is invalid', function() - eq({}, funcs.getbufline(1, 0)) - curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'baz' }) - eq({}, funcs.getbufline(1, 2, 1)) - eq({}, funcs.getbufline(1, -10, -20)) - eq({}, funcs.getbufline(1, -2, -1)) - eq({}, funcs.getbufline(1, -1, 9999)) + eq({}, fn.getbufline(1, 0)) + api.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'baz' }) + eq({}, fn.getbufline(1, 2, 1)) + eq({}, fn.getbufline(1, -10, -20)) + eq({}, fn.getbufline(1, -2, -1)) + eq({}, fn.getbufline(1, -1, 9999)) end) it('returns expected lines', function() - meths.set_option_value('hidden', true, {}) + api.nvim_set_option_value('hidden', true, {}) command('file ' .. fname) - curbufmeths.set_lines(0, 1, false, { 'foo\0', '\0bar', 'baz' }) + api.nvim_buf_set_lines(0, 0, 1, false, { 'foo\0', '\0bar', 'baz' }) command('edit ' .. fname2) - curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' }) - eq({ 'foo\n', '\nbar', 'baz' }, funcs.getbufline(1, 1, 9999)) - eq({ 'abc\n', '\ndef', 'ghi' }, funcs.getbufline(2, 1, 9999)) - eq({ 'foo\n', '\nbar', 'baz' }, funcs.getbufline(1, 1, '$')) - eq({ 'baz' }, funcs.getbufline(1, '$', '$')) - eq({ 'baz' }, funcs.getbufline(1, '$', 9999)) + api.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' }) + eq({ 'foo\n', '\nbar', 'baz' }, fn.getbufline(1, 1, 9999)) + eq({ 'abc\n', '\ndef', 'ghi' }, fn.getbufline(2, 1, 9999)) + eq({ 'foo\n', '\nbar', 'baz' }, fn.getbufline(1, 1, '$')) + eq({ 'baz' }, fn.getbufline(1, '$', '$')) + eq({ 'baz' }, fn.getbufline(1, '$', 9999)) end) end) describe('getbufvar() function', function() it('returns empty list when buffer was not found', function() command('file ' .. fname) - eq('', funcs.getbufvar(2, '&autoindent')) - eq('', funcs.getbufvar('non-existent-buffer', '&autoindent')) - eq('', funcs.getbufvar('#', '&autoindent')) + eq('', fn.getbufvar(2, '&autoindent')) + eq('', fn.getbufvar('non-existent-buffer', '&autoindent')) + eq('', fn.getbufvar('#', '&autoindent')) command('edit ' .. fname2) - eq(2, funcs.bufnr('%')) - eq('', funcs.getbufvar('X', '&autoindent')) + eq(2, fn.bufnr('%')) + eq('', fn.getbufvar('X', '&autoindent')) end) it('returns empty list when variable/option/etc was not found', function() command('file ' .. fname) - eq('', funcs.getbufvar(1, '&autondent')) - eq('', funcs.getbufvar(1, 'changedtic')) + eq('', fn.getbufvar(1, '&autondent')) + eq('', fn.getbufvar(1, 'changedtic')) end) it('returns expected option value', function() - eq(0, funcs.getbufvar(1, '&autoindent')) - eq(0, funcs.getbufvar(1, '&l:autoindent')) - eq(0, funcs.getbufvar(1, '&g:autoindent')) + eq(0, fn.getbufvar(1, '&autoindent')) + eq(0, fn.getbufvar(1, '&l:autoindent')) + eq(0, fn.getbufvar(1, '&g:autoindent')) -- Also works with global-only options - eq(1, funcs.getbufvar(1, '&hidden')) - eq(1, funcs.getbufvar(1, '&l:hidden')) - eq(1, funcs.getbufvar(1, '&g:hidden')) + eq(1, fn.getbufvar(1, '&hidden')) + eq(1, fn.getbufvar(1, '&l:hidden')) + eq(1, fn.getbufvar(1, '&g:hidden')) -- Also works with window-local options - eq(0, funcs.getbufvar(1, '&number')) - eq(0, funcs.getbufvar(1, '&l:number')) - eq(0, funcs.getbufvar(1, '&g:number')) + eq(0, fn.getbufvar(1, '&number')) + eq(0, fn.getbufvar(1, '&l:number')) + eq(0, fn.getbufvar(1, '&g:number')) command('new') -- But with window-local options it probably does not what you expect command('setl number') -- (note that current window’s buffer is 2, but getbufvar() receives 1) - eq({ id = 2 }, curwinmeths.get_buf()) - eq(1, funcs.getbufvar(1, '&number')) - eq(1, funcs.getbufvar(1, '&l:number')) + eq({ id = 2 }, api.nvim_win_get_buf(0)) + eq(1, fn.getbufvar(1, '&number')) + eq(1, fn.getbufvar(1, '&l:number')) -- You can get global value though, if you find this useful. - eq(0, funcs.getbufvar(1, '&g:number')) + eq(0, fn.getbufvar(1, '&g:number')) end) it('returns expected variable value', function() - eq(2, funcs.getbufvar(1, 'changedtick')) - curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' }) - eq(3, funcs.getbufvar(1, 'changedtick')) - curbufmeths.set_var('test', true) - eq(true, funcs.getbufvar(1, 'test')) - eq({ test = true, changedtick = 3 }, funcs.getbufvar(1, '')) + eq(2, fn.getbufvar(1, 'changedtick')) + api.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' }) + eq(3, fn.getbufvar(1, 'changedtick')) + api.nvim_buf_set_var(0, 'test', true) + eq(true, fn.getbufvar(1, 'test')) + eq({ test = true, changedtick = 3 }, fn.getbufvar(1, '')) command('new') - eq(3, funcs.getbufvar(1, 'changedtick')) - eq(true, funcs.getbufvar(1, 'test')) - eq({ test = true, changedtick = 3 }, funcs.getbufvar(1, '')) + eq(3, fn.getbufvar(1, 'changedtick')) + eq(true, fn.getbufvar(1, 'test')) + eq({ test = true, changedtick = 3 }, fn.getbufvar(1, '')) end) end) @@ -279,50 +273,50 @@ describe('setbufvar() function', function() ) eq(0, exc_exec('call setbufvar("#", "&autoindent", 0)')) command('edit ' .. fname2) - eq(2, funcs.bufnr('%')) + eq(2, fn.bufnr('%')) eq( 'Vim(call):E93: More than one match for X', exc_exec('call setbufvar("X", "&autoindent", 0)') ) end) it('may set options, including window-local and global values', function() - local buf1 = meths.get_current_buf() - eq(false, meths.get_option_value('number', {})) + local buf1 = api.nvim_get_current_buf() + eq(false, api.nvim_get_option_value('number', {})) command('split') command('new') - eq(2, bufmeths.get_number(curwinmeths.get_buf())) - funcs.setbufvar(1, '&number', true) - local windows = curtabmeths.list_wins() - eq(false, meths.get_option_value('number', { win = windows[1].id })) - eq(true, meths.get_option_value('number', { win = windows[2].id })) - eq(false, meths.get_option_value('number', { win = windows[3].id })) - eq(false, meths.get_option_value('number', { win = meths.get_current_win().id })) + eq(2, api.nvim_buf_get_number(api.nvim_win_get_buf(0))) + fn.setbufvar(1, '&number', true) + local windows = api.nvim_tabpage_list_wins(0) + eq(false, api.nvim_get_option_value('number', { win = windows[1].id })) + eq(true, api.nvim_get_option_value('number', { win = windows[2].id })) + eq(false, api.nvim_get_option_value('number', { win = windows[3].id })) + eq(false, api.nvim_get_option_value('number', { win = api.nvim_get_current_win().id })) - eq(true, meths.get_option_value('hidden', {})) - funcs.setbufvar(1, '&hidden', 0) - eq(false, meths.get_option_value('hidden', {})) + eq(true, api.nvim_get_option_value('hidden', {})) + fn.setbufvar(1, '&hidden', 0) + eq(false, api.nvim_get_option_value('hidden', {})) - eq(false, meths.get_option_value('autoindent', { buf = buf1.id })) - funcs.setbufvar(1, '&autoindent', true) - eq(true, meths.get_option_value('autoindent', { buf = buf1.id })) + eq(false, api.nvim_get_option_value('autoindent', { buf = buf1.id })) + fn.setbufvar(1, '&autoindent', true) + eq(true, api.nvim_get_option_value('autoindent', { buf = buf1.id })) eq('Vim(call):E355: Unknown option: xxx', exc_exec('call setbufvar(1, "&xxx", 0)')) end) it('may set variables', function() - local buf1 = meths.get_current_buf() + local buf1 = api.nvim_get_current_buf() command('split') command('new') - eq(2, curbufmeths.get_number()) - funcs.setbufvar(1, 'number', true) - eq(true, bufmeths.get_var(buf1, 'number')) + eq(2, api.nvim_buf_get_number(0)) + fn.setbufvar(1, 'number', true) + eq(true, api.nvim_buf_get_var(buf1, 'number')) eq('Vim(call):E461: Illegal variable name: b:', exc_exec('call setbufvar(1, "", 0)')) - eq(true, bufmeths.get_var(buf1, 'number')) + eq(true, api.nvim_buf_get_var(buf1, 'number')) eq( 'Vim:E46: Cannot change read-only variable "b:changedtick"', - pcall_err(funcs.setbufvar, 1, 'changedtick', true) + pcall_err(fn.setbufvar, 1, 'changedtick', true) ) - eq(2, funcs.getbufvar(1, 'changedtick')) + eq(2, fn.getbufvar(1, 'changedtick')) end) it('throws error when setting a string option to a boolean value vim-patch:9.0.0090', function() - eq('Vim:E928: String required', pcall_err(funcs.setbufvar, '', '&errorformat', true)) + eq('Vim:E928: String required', pcall_err(fn.setbufvar, '', '&errorformat', true)) end) end) diff --git a/test/functional/vimscript/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua index 1ff580e570..85928921c5 100644 --- a/test/functional/vimscript/changedtick_spec.lua +++ b/test/functional/vimscript/changedtick_spec.lua @@ -4,25 +4,24 @@ local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed local clear = helpers.clear -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err local exec_capture = helpers.exec_capture -local curbufmeths = helpers.curbufmeths before_each(clear) local function changedtick() - local ct = curbufmeths.get_changedtick() - eq(ct, curbufmeths.get_var('changedtick')) - eq(ct, curbufmeths.get_var('changedtick')) + local ct = api.nvim_buf_get_changedtick(0) + eq(ct, api.nvim_buf_get_var(0, 'changedtick')) + eq(ct, api.nvim_buf_get_var(0, 'changedtick')) eq(ct, eval('b:changedtick')) eq(ct, eval('b:["changedtick"]')) eq(ct, eval('b:.changedtick')) - eq(ct, funcs.getbufvar('%', 'changedtick')) - eq(ct, funcs.getbufvar('%', '').changedtick) + eq(ct, fn.getbufvar('%', 'changedtick')) + eq(ct, fn.getbufvar('%', '').changedtick) eq(ct, eval('b:').changedtick) return ct end @@ -32,7 +31,7 @@ describe('b:changedtick', function() it('increments', function() -- Test_changedtick_increments -- New buffer has an empty line, tick starts at 2 eq(2, changedtick()) - funcs.setline(1, 'hello') + fn.setline(1, 'hello') eq(3, changedtick()) eq(0, exc_exec('undo')) -- Somehow undo counts as two changes @@ -41,16 +40,16 @@ describe('b:changedtick', function() it('is present in b: dictionary', function() eq(2, changedtick()) command('let d = b:') - eq(2, meths.get_var('d').changedtick) + eq(2, api.nvim_get_var('d').changedtick) end) it('increments at bdel', function() command('new') eq(2, changedtick()) - local bnr = curbufmeths.get_number() + local bnr = api.nvim_buf_get_number(0) eq(2, bnr) command('bdel') - eq(3, funcs.getbufvar(bnr, 'changedtick')) - eq(1, curbufmeths.get_number()) + eq(3, fn.getbufvar(bnr, 'changedtick')) + eq(1, api.nvim_buf_get_number(0)) end) it('fails to be changed by user', function() local ct = changedtick() @@ -72,7 +71,7 @@ describe('b:changedtick', function() 'Vim(let):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'let d.changedtick = ' .. ctn) ) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.set_var, 'changedtick', ctn)) + eq('Key is read-only: changedtick', pcall_err(api.nvim_buf_set_var, 0, 'changedtick', ctn)) eq( 'Vim(unlet):E795: Cannot delete variable b:changedtick', @@ -90,7 +89,7 @@ describe('b:changedtick', function() 'Vim(unlet):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'unlet d.changedtick') ) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, 'changedtick')) + eq('Key is read-only: changedtick', pcall_err(api.nvim_buf_del_var, 0, 'changedtick')) eq(ct, changedtick()) eq( @@ -108,7 +107,7 @@ describe('b:changedtick', function() eq(ct, changedtick()) - funcs.setline(1, 'hello') + fn.setline(1, 'hello') eq(ct + 1, changedtick()) end) @@ -117,8 +116,8 @@ describe('b:changedtick', function() end) it('fails to unlock b:changedtick', function() eq(0, exc_exec('let d = b:')) - eq(0, funcs.islocked('b:changedtick')) - eq(0, funcs.islocked('d.changedtick')) + eq(0, fn.islocked('b:changedtick')) + eq(0, fn.islocked('d.changedtick')) eq( 'Vim(unlockvar):E940: Cannot lock or unlock variable b:changedtick', pcall_err(command, 'unlockvar b:changedtick') @@ -127,8 +126,8 @@ describe('b:changedtick', function() 'Vim(unlockvar):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'unlockvar d.changedtick') ) - eq(0, funcs.islocked('b:changedtick')) - eq(0, funcs.islocked('d.changedtick')) + eq(0, fn.islocked('b:changedtick')) + eq(0, fn.islocked('d.changedtick')) eq( 'Vim(lockvar):E940: Cannot lock or unlock variable b:changedtick', pcall_err(command, 'lockvar b:changedtick') @@ -137,12 +136,12 @@ describe('b:changedtick', function() 'Vim(lockvar):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'lockvar d.changedtick') ) - eq(0, funcs.islocked('b:changedtick')) - eq(0, funcs.islocked('d.changedtick')) + eq(0, fn.islocked('b:changedtick')) + eq(0, fn.islocked('d.changedtick')) end) it('is being completed', function() feed(':echo b:<Tab><Home>let cmdline="<End>"<CR>') - eq('echo b:changedtick', meths.get_var('cmdline')) + eq('echo b:changedtick', api.nvim_get_var('cmdline')) end) it('cannot be changed by filter() or map()', function() eq(2, changedtick()) diff --git a/test/functional/vimscript/container_functions_spec.lua b/test/functional/vimscript/container_functions_spec.lua index cb5644cf2d..1b34ea0165 100644 --- a/test/functional/vimscript/container_functions_spec.lua +++ b/test/functional/vimscript/container_functions_spec.lua @@ -2,23 +2,23 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local eval = helpers.eval -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear before_each(clear) describe('extend()', function() it('succeeds to extend list with itself', function() - meths.set_var('l', { 1, {} }) + api.nvim_set_var('l', { 1, {} }) eq({ 1, {}, 1, {} }, eval('extend(l, l)')) - eq({ 1, {}, 1, {} }, meths.get_var('l')) + eq({ 1, {}, 1, {} }, api.nvim_get_var('l')) - meths.set_var('l', { 1, {} }) + api.nvim_set_var('l', { 1, {} }) eq({ 1, {}, 1, {} }, eval('extend(l, l, 0)')) - eq({ 1, {}, 1, {} }, meths.get_var('l')) + eq({ 1, {}, 1, {} }, api.nvim_get_var('l')) - meths.set_var('l', { 1, {} }) + api.nvim_set_var('l', { 1, {} }) eq({ 1, 1, {}, {} }, eval('extend(l, l, 1)')) - eq({ 1, 1, {}, {} }, meths.get_var('l')) + eq({ 1, 1, {}, {} }, api.nvim_get_var('l')) end) end) diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua index 01daeddbab..b8f9bbc92d 100644 --- a/test/functional/vimscript/ctx_functions_spec.lua +++ b/test/functional/vimscript/ctx_functions_spec.lua @@ -6,12 +6,12 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local map = helpers.tbl_map -local nvim = helpers.nvim +local map = vim.tbl_map +local api = helpers.api local parse_context = helpers.parse_context local exec_capture = helpers.exec_capture local source = helpers.source -local trim = helpers.trim +local trim = vim.trim local write_file = helpers.write_file local pcall_err = helpers.pcall_err @@ -126,16 +126,16 @@ describe('context functions', function() end) it('saves and restores global variables properly', function() - nvim('set_var', 'one', 1) - nvim('set_var', 'Two', 2) - nvim('set_var', 'THREE', 3) + api.nvim_set_var('one', 1) + api.nvim_set_var('Two', 2) + api.nvim_set_var('THREE', 3) eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) call('ctxpush') call('ctxpush', { 'gvars' }) - nvim('del_var', 'one') - nvim('del_var', 'Two') - nvim('del_var', 'THREE') + api.nvim_del_var('one') + api.nvim_del_var('Two') + api.nvim_del_var('THREE') eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one')) eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two')) eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE')) @@ -143,9 +143,9 @@ describe('context functions', function() call('ctxpop') eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) - nvim('del_var', 'one') - nvim('del_var', 'Two') - nvim('del_var', 'THREE') + api.nvim_del_var('one') + api.nvim_del_var('Two') + api.nvim_del_var('THREE') eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one')) eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two')) eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE')) @@ -300,9 +300,9 @@ describe('context functions', function() feed('G') feed('gg') command('edit ' .. fname2) - nvim('set_var', 'one', 1) - nvim('set_var', 'Two', 2) - nvim('set_var', 'THREE', 3) + api.nvim_set_var('one', 1) + api.nvim_set_var('Two', 2) + api.nvim_set_var('THREE', 3) local with_regs = { ['regs'] = { @@ -412,14 +412,14 @@ describe('context functions', function() end) it('sets context dictionary at index in context stack', function() - nvim('set_var', 'one', 1) - nvim('set_var', 'Two', 2) - nvim('set_var', 'THREE', 3) + api.nvim_set_var('one', 1) + api.nvim_set_var('Two', 2) + api.nvim_set_var('THREE', 3) call('ctxpush') local ctx1 = call('ctxget') - nvim('set_var', 'one', 'a') - nvim('set_var', 'Two', 'b') - nvim('set_var', 'THREE', 'c') + api.nvim_set_var('one', 'a') + api.nvim_set_var('Two', 'b') + api.nvim_set_var('THREE', 'c') call('ctxpush') call('ctxpush') local ctx2 = call('ctxget') @@ -431,7 +431,7 @@ describe('context functions', function() eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) call('ctxpop') eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) - nvim('set_var', 'one', 1.5) + api.nvim_set_var('one', 1.5) eq({ 1.5, 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) call('ctxpop') eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) diff --git a/test/functional/vimscript/environ_spec.lua b/test/functional/vimscript/environ_spec.lua index c5821567ff..0763def84e 100644 --- a/test/functional/vimscript/environ_spec.lua +++ b/test/functional/vimscript/environ_spec.lua @@ -1,13 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local environ = helpers.funcs.environ -local exists = helpers.funcs.exists -local system = helpers.funcs.system +local environ = helpers.fn.environ +local exists = helpers.fn.exists +local system = helpers.fn.system local nvim_prog = helpers.nvim_prog local command = helpers.command local eval = helpers.eval -local setenv = helpers.funcs.setenv +local setenv = helpers.fn.setenv describe('environment variables', function() it('environ() handles empty env variable', function() diff --git a/test/functional/vimscript/errorlist_spec.lua b/test/functional/vimscript/errorlist_spec.lua index b2afafe08c..1e405e7e64 100644 --- a/test/functional/vimscript/errorlist_spec.lua +++ b/test/functional/vimscript/errorlist_spec.lua @@ -4,10 +4,10 @@ local clear = helpers.clear local command = helpers.command local eq = helpers.eq local exc_exec = helpers.exc_exec -local get_cur_win_var = helpers.curwinmeths.get_var +local get_win_var = helpers.api.nvim_win_get_var describe('setqflist()', function() - local setqflist = helpers.funcs.setqflist + local setqflist = helpers.fn.setqflist before_each(clear) @@ -26,15 +26,15 @@ describe('setqflist()', function() it('sets w:quickfix_title', function() setqflist({ '' }, 'r', 'foo') command('copen') - eq('foo', get_cur_win_var('quickfix_title')) + eq('foo', get_win_var(0, 'quickfix_title')) setqflist({}, 'r', { ['title'] = 'qf_title' }) - eq('qf_title', get_cur_win_var('quickfix_title')) + eq('qf_title', get_win_var(0, 'quickfix_title')) end) it('allows string {what} for backwards compatibility', function() setqflist({}, 'r', '5') command('copen') - eq('5', get_cur_win_var('quickfix_title')) + eq('5', get_win_var(0, 'quickfix_title')) end) it('requires a dict for {what}', function() @@ -46,7 +46,7 @@ describe('setqflist()', function() end) describe('setloclist()', function() - local setloclist = helpers.funcs.setloclist + local setloclist = helpers.fn.setloclist before_each(clear) @@ -67,9 +67,9 @@ describe('setloclist()', function() setloclist(1, {}, 'r', 'foo') setloclist(2, {}, 'r', 'bar') command('lopen') - eq('bar', get_cur_win_var('quickfix_title')) + eq('bar', get_win_var(0, 'quickfix_title')) command('lclose | wincmd w | lopen') - eq('foo', get_cur_win_var('quickfix_title')) + eq('foo', get_win_var(0, 'quickfix_title')) end) it("doesn't crash when when window is closed in the middle #13721", function() diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index a562f6f888..e337959810 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -22,8 +22,8 @@ local exec_capture = helpers.exec_capture local eval = helpers.eval local command = helpers.command local write_file = helpers.write_file -local meths = helpers.meths -local sleep = helpers.sleep +local api = helpers.api +local sleep = vim.uv.sleep local matches = helpers.matches local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -33,13 +33,13 @@ local expect_exit = helpers.expect_exit describe('Up to MAX_FUNC_ARGS arguments are handled by', function() local max_func_args = 20 -- from eval.h - local range = helpers.funcs.range + local range = helpers.fn.range before_each(clear) it('printf()', function() - local printf = helpers.funcs.printf - local rep = helpers.funcs['repeat'] + local printf = helpers.fn.printf + local rep = helpers.fn['repeat'] local expected = '2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,' eq(expected, printf(rep('%d,', max_func_args - 1), unpack(range(2, max_func_args)))) local ret = exc_exec('call printf("", 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') @@ -47,7 +47,7 @@ describe('Up to MAX_FUNC_ARGS arguments are handled by', function() end) it('rpcnotify()', function() - local rpcnotify = helpers.funcs.rpcnotify + local rpcnotify = helpers.fn.rpcnotify local ret = rpcnotify(0, 'foo', unpack(range(3, max_func_args))) eq(1, ret) ret = exc_exec('call rpcnotify(0, "foo", 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') @@ -121,7 +121,7 @@ describe('List support code', function() let bl = range(%u) let dur = reltimestr(reltime(rt)) ]]):format(len)) - dur = tonumber(meths.get_var('dur')) + dur = tonumber(api.nvim_get_var('dur')) if dur >= min_dur then -- print(('Using len %u, dur %g'):format(len, dur)) break @@ -136,7 +136,7 @@ describe('List support code', function() feed('<C-c>') poke_eventloop() command('let t_dur = reltimestr(reltime(t_rt))') - local t_dur = tonumber(meths.get_var('t_dur')) + local t_dur = tonumber(api.nvim_get_var('t_dur')) if t_dur >= dur / 8 then eq(nil, ('Took too long to cancel: %g >= %g'):format(t_dur, dur / 8)) end @@ -147,7 +147,7 @@ describe('List support code', function() feed('<C-c>') poke_eventloop() command('let t_dur = reltimestr(reltime(t_rt))') - local t_dur = tonumber(meths.get_var('t_dur')) + local t_dur = tonumber(api.nvim_get_var('t_dur')) print(('t_dur: %g'):format(t_dur)) if t_dur >= dur / 8 then eq(nil, ('Took too long to cancel: %g >= %g'):format(t_dur, dur / 8)) diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index 3124c02c2f..29488ed31c 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -5,7 +5,7 @@ local clear = helpers.clear local source = helpers.source local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err -local funcs = helpers.funcs +local fn = helpers.fn local Screen = require('test.functional.ui.screen') local command = helpers.command local feed = helpers.feed @@ -22,16 +22,16 @@ describe('execute()', function() silent! messages redir END ]]) - eq(eval('g:__redir_output'), funcs.execute('messages')) + eq(eval('g:__redir_output'), fn.execute('messages')) end) it('captures the concatenated outputs of a List of commands', function() - eq('foobar', funcs.execute({ 'echon "foo"', 'echon "bar"' })) - eq('\nfoo\nbar', funcs.execute({ 'echo "foo"', 'echo "bar"' })) + eq('foobar', fn.execute({ 'echon "foo"', 'echon "bar"' })) + eq('\nfoo\nbar', fn.execute({ 'echo "foo"', 'echo "bar"' })) end) it('supports nested execute("execute(...)")', function() - eq('42', funcs.execute([[echon execute("echon execute('echon 42')")]])) + eq('42', fn.execute([[echon execute("echon execute('echon 42')")]])) end) it('supports nested :redir to a variable', function() @@ -54,7 +54,7 @@ describe('execute()', function() return a endfunction ]]) - eq('top1bar1foobar2bar3', funcs.execute('echon "top1"|call g:Bar()')) + eq('top1bar1foobar2bar3', fn.execute('echon "top1"|call g:Bar()')) end) it('supports nested :redir to a register', function() @@ -76,17 +76,17 @@ describe('execute()', function() return @a endfunction ]]) - eq('top1bar1foobar2bar3', funcs.execute('echon "top1"|call g:Bar()')) + eq('top1bar1foobar2bar3', fn.execute('echon "top1"|call g:Bar()')) -- :redir itself doesn't nest, so the redirection ends in g:Foo eq('bar1foo', eval('@a')) end) it('captures a transformed string', function() - eq('^A', funcs.execute('echon "\\<C-a>"')) + eq('^A', fn.execute('echon "\\<C-a>"')) end) it('returns empty string if the argument list is empty', function() - eq('', funcs.execute({})) + eq('', fn.execute({})) eq(0, exc_exec('let g:ret = execute(v:_null_list)')) eq('', eval('g:ret')) end) @@ -255,7 +255,7 @@ describe('execute()', function() -- with how nvim currently displays the output. it('captures shell-command output', function() local win_lf = is_os('win') and '\13' or '' - eq('\n:!echo foo\r\n\nfoo' .. win_lf .. '\n', funcs.execute('!echo foo')) + eq('\n:!echo foo\r\n\nfoo' .. win_lf .. '\n', fn.execute('!echo foo')) end) describe('{silent} argument', function() @@ -275,11 +275,11 @@ describe('execute()', function() command('split') eq( 'Vim(windo):E493: Backwards range given: 2,1windo echo', - pcall_err(funcs.execute, '2,1windo echo', '') + pcall_err(fn.execute, '2,1windo echo', '') ) eq( 'Vim(windo):E493: Backwards range given: 2,1windo echo', - pcall_err(funcs.execute, { '2,1windo echo' }, '') + pcall_err(fn.execute, { '2,1windo echo' }, '') ) end) diff --git a/test/functional/vimscript/fnamemodify_spec.lua b/test/functional/vimscript/fnamemodify_spec.lua index 6e49bcb0c5..4a134fe23c 100644 --- a/test/functional/vimscript/fnamemodify_spec.lua +++ b/test/functional/vimscript/fnamemodify_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local fnamemodify = helpers.funcs.fnamemodify -local getcwd = helpers.funcs.getcwd +local fnamemodify = helpers.fn.fnamemodify +local getcwd = helpers.fn.getcwd local command = helpers.command local write_file = helpers.write_file local alter_slashes = helpers.alter_slashes diff --git a/test/functional/vimscript/glob_spec.lua b/test/functional/vimscript/glob_spec.lua index ea49552310..77351f95fa 100644 --- a/test/functional/vimscript/glob_spec.lua +++ b/test/functional/vimscript/glob_spec.lua @@ -1,4 +1,3 @@ -local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local clear, command, eval, eq = helpers.clear, helpers.command, helpers.eval, helpers.eq local mkdir = helpers.mkdir @@ -12,7 +11,7 @@ before_each(function() end) after_each(function() - luv.fs_rmdir('test-glob') + vim.uv.fs_rmdir('test-glob') end) describe('glob()', function() diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua index 4e232daeb3..82b3db5b67 100644 --- a/test/functional/vimscript/has_spec.lua +++ b/test/functional/vimscript/has_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local connect = helpers.connect local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local is_os = helpers.is_os local nvim_prog = helpers.nvim_prog @@ -11,84 +11,83 @@ describe('has()', function() before_each(clear) it('"nvim-x.y.z"', function() - eq(0, funcs.has('nvim-')) - eq(0, funcs.has('nvim- ')) - eq(0, funcs.has('nvim- \t ')) - eq(0, funcs.has('nvim-0. 1. 1')) - eq(0, funcs.has('nvim-0. 1.1')) - eq(0, funcs.has('nvim-0.1. 1')) - eq(0, funcs.has('nvim-a')) - eq(0, funcs.has('nvim-a.b.c')) - eq(0, funcs.has('nvim-0.b.c')) - eq(0, funcs.has('nvim-0.0.c')) - eq(0, funcs.has('nvim-0.b.0')) - eq(0, funcs.has('nvim-a.b.0')) - eq(0, funcs.has('nvim-.0.0.0')) - eq(0, funcs.has('nvim-.0')) - eq(0, funcs.has('nvim-0.')) - eq(0, funcs.has('nvim-0..')) - eq(0, funcs.has('nvim-.')) - eq(0, funcs.has('nvim-..')) - eq(0, funcs.has('nvim-...')) - eq(0, funcs.has('nvim-42')) - eq(0, funcs.has('nvim-9999')) - eq(0, funcs.has('nvim-99.001.05')) + eq(0, fn.has('nvim-')) + eq(0, fn.has('nvim- ')) + eq(0, fn.has('nvim- \t ')) + eq(0, fn.has('nvim-0. 1. 1')) + eq(0, fn.has('nvim-0. 1.1')) + eq(0, fn.has('nvim-0.1. 1')) + eq(0, fn.has('nvim-a')) + eq(0, fn.has('nvim-a.b.c')) + eq(0, fn.has('nvim-0.b.c')) + eq(0, fn.has('nvim-0.0.c')) + eq(0, fn.has('nvim-0.b.0')) + eq(0, fn.has('nvim-a.b.0')) + eq(0, fn.has('nvim-.0.0.0')) + eq(0, fn.has('nvim-.0')) + eq(0, fn.has('nvim-0.')) + eq(0, fn.has('nvim-0..')) + eq(0, fn.has('nvim-.')) + eq(0, fn.has('nvim-..')) + eq(0, fn.has('nvim-...')) + eq(0, fn.has('nvim-42')) + eq(0, fn.has('nvim-9999')) + eq(0, fn.has('nvim-99.001.05')) - eq(1, funcs.has('nvim')) - eq(1, funcs.has('nvim-0')) - eq(1, funcs.has('nvim-0.1')) - eq(1, funcs.has('nvim-0.0.0')) - eq(1, funcs.has('nvim-0.1.1.')) - eq(1, funcs.has('nvim-0.1.1.abc')) - eq(1, funcs.has('nvim-0.1.1..')) - eq(1, funcs.has('nvim-0.1.1.. ..')) - eq(1, funcs.has('nvim-0.1.1.... ')) - eq(1, funcs.has('nvim-0.0.0')) - eq(1, funcs.has('nvim-0.0.1')) - eq(1, funcs.has('nvim-0.1.0')) - eq(1, funcs.has('nvim-0.1.1')) - eq(1, funcs.has('nvim-0.1.5')) - eq(1, funcs.has('nvim-0000.001.05')) - eq(1, funcs.has('nvim-0.01.005')) - eq(1, funcs.has('nvim-00.001.05')) + eq(1, fn.has('nvim')) + eq(1, fn.has('nvim-0')) + eq(1, fn.has('nvim-0.1')) + eq(1, fn.has('nvim-0.0.0')) + eq(1, fn.has('nvim-0.1.1.')) + eq(1, fn.has('nvim-0.1.1.abc')) + eq(1, fn.has('nvim-0.1.1..')) + eq(1, fn.has('nvim-0.1.1.. ..')) + eq(1, fn.has('nvim-0.1.1.... ')) + eq(1, fn.has('nvim-0.0.0')) + eq(1, fn.has('nvim-0.0.1')) + eq(1, fn.has('nvim-0.1.0')) + eq(1, fn.has('nvim-0.1.1')) + eq(1, fn.has('nvim-0.1.5')) + eq(1, fn.has('nvim-0000.001.05')) + eq(1, fn.has('nvim-0.01.005')) + eq(1, fn.has('nvim-00.001.05')) end) it('"unnamedplus"', function() - if (not is_os('win')) and funcs.has('clipboard') == 1 then - eq(1, funcs.has('unnamedplus')) + if (not is_os('win')) and fn.has('clipboard') == 1 then + eq(1, fn.has('unnamedplus')) else - eq(0, funcs.has('unnamedplus')) + eq(0, fn.has('unnamedplus')) end end) it('"wsl"', function() - local luv = require('luv') - local is_wsl = luv.os_uname()['release']:lower():match('microsoft') and true or false + local is_wsl = vim.uv.os_uname()['release']:lower():match('microsoft') and true or false if is_wsl then - eq(1, funcs.has('wsl')) + eq(1, fn.has('wsl')) else - eq(0, funcs.has('wsl')) + eq(0, fn.has('wsl')) end end) it('"gui_running"', function() - eq(0, funcs.has('gui_running')) + eq(0, fn.has('gui_running')) local tui = Screen.new(50, 15) - local gui_session = connect(funcs.serverstart()) + local gui_session = connect(fn.serverstart()) local gui = Screen.new(50, 15) - eq(0, funcs.has('gui_running')) + eq(0, fn.has('gui_running')) tui:attach({ ext_linegrid = true, rgb = true, stdin_tty = true, stdout_tty = true }) gui:attach({ ext_multigrid = true, rgb = true }, gui_session) - eq(1, funcs.has('gui_running')) + eq(1, fn.has('gui_running')) tui:detach() - eq(1, funcs.has('gui_running')) + eq(1, fn.has('gui_running')) gui:detach() - eq(0, funcs.has('gui_running')) + eq(0, fn.has('gui_running')) end) it('does not change v:shell_error', function() - funcs.system({ nvim_prog, '-es', '+73cquit' }) - funcs.has('python3') -- use a call whose implementation shells out - eq(73, funcs.eval('v:shell_error')) + fn.system({ nvim_prog, '-es', '+73cquit' }) + fn.has('python3') -- use a call whose implementation shells out + eq(73, fn.eval('v:shell_error')) end) end) diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index 8a634a6700..6dd22078d6 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -3,14 +3,14 @@ local Screen = require('test.functional.ui.screen') local eq = helpers.eq local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local source = helpers.source local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err local async_meths = helpers.async_meths -local NIL = helpers.NIL +local NIL = vim.NIL local screen @@ -110,7 +110,7 @@ describe('input()', function() end) it('allows unequal numeric values when using {opts} dictionary', function() command('echohl Test') - meths.set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) + api.nvim_set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) feed([[:echo input(opts)<CR>]]) screen:expect([[ | @@ -132,7 +132,7 @@ describe('input()', function() end) it('works with redraw', function() command('echohl Test') - meths.set_var('opts', { prompt = 'Foo>', default = 'Bar' }) + api.nvim_set_var('opts', { prompt = 'Foo>', default = 'Bar' }) feed([[:echo inputdialog(opts)<CR>]]) screen:expect([[ | @@ -176,34 +176,34 @@ describe('input()', function() it('supports completion', function() feed(':let var = input("", "", "custom,CustomCompl")<CR>') feed('<Tab><CR>') - eq('TEST', meths.get_var('var')) + eq('TEST', api.nvim_get_var('var')) feed(':let var = input({"completion": "customlist,CustomListCompl"})<CR>') feed('<Tab><CR>') - eq('FOO', meths.get_var('var')) + eq('FOO', api.nvim_get_var('var')) end) it('supports cancelreturn', function() feed(':let var = input({"cancelreturn": "BAR"})<CR>') feed('<Esc>') - eq('BAR', meths.get_var('var')) + eq('BAR', api.nvim_get_var('var')) feed(':let var = input({"cancelreturn": []})<CR>') feed('<Esc>') - eq({}, meths.get_var('var')) + eq({}, api.nvim_get_var('var')) feed(':let var = input({"cancelreturn": v:false})<CR>') feed('<Esc>') - eq(false, meths.get_var('var')) + eq(false, api.nvim_get_var('var')) feed(':let var = input({"cancelreturn": v:null})<CR>') feed('<Esc>') - eq(NIL, meths.get_var('var')) + eq(NIL, api.nvim_get_var('var')) end) it('supports default string', function() feed(':let var = input("", "DEF1")<CR>') feed('<CR>') - eq('DEF1', meths.get_var('var')) + eq('DEF1', api.nvim_get_var('var')) feed(':let var = input({"default": "DEF2"})<CR>') feed('<CR>') - eq('DEF2', meths.get_var('var')) + eq('DEF2', api.nvim_get_var('var')) end) it('errors out on invalid inputs', function() eq('Vim(call):E730: Using a List as a String', exc_exec('call input([])')) @@ -292,7 +292,7 @@ describe('inputdialog()', function() end) it('allows unequal numeric values when using {opts} dictionary', function() command('echohl Test') - meths.set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) + api.nvim_set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) feed([[:echo input(opts)<CR>]]) screen:expect([[ | @@ -314,7 +314,7 @@ describe('inputdialog()', function() end) it('works with redraw', function() command('echohl Test') - meths.set_var('opts', { prompt = 'Foo>', default = 'Bar' }) + api.nvim_set_var('opts', { prompt = 'Foo>', default = 'Bar' }) feed([[:echo input(opts)<CR>]]) screen:expect([[ | @@ -358,25 +358,25 @@ describe('inputdialog()', function() it('supports completion', function() feed(':let var = inputdialog({"completion": "customlist,CustomListCompl"})<CR>') feed('<Tab><CR>') - eq('FOO', meths.get_var('var')) + eq('FOO', api.nvim_get_var('var')) end) it('supports cancelreturn', function() feed(':let var = inputdialog("", "", "CR1")<CR>') feed('<Esc>') - eq('CR1', meths.get_var('var')) + eq('CR1', api.nvim_get_var('var')) feed(':let var = inputdialog({"cancelreturn": "BAR"})<CR>') feed('<Esc>') - eq('BAR', meths.get_var('var')) + eq('BAR', api.nvim_get_var('var')) end) it('supports default string', function() feed(':let var = inputdialog("", "DEF1")<CR>') feed('<CR>') - eq('DEF1', meths.get_var('var')) + eq('DEF1', api.nvim_get_var('var')) feed(':let var = inputdialog({"default": "DEF2"})<CR>') feed('<CR>') - eq('DEF2', meths.get_var('var')) + eq('DEF2', api.nvim_get_var('var')) end) it('errors out on invalid inputs', function() eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog([])')) @@ -409,8 +409,8 @@ end) describe('confirm()', function() -- oldtest: Test_confirm() it('works', function() - meths.set_option_value('more', false, {}) -- Avoid hit-enter prompt - meths.set_option_value('laststatus', 2, {}) + api.nvim_set_option_value('more', false, {}) -- Avoid hit-enter prompt + api.nvim_set_option_value('laststatus', 2, {}) -- screen:expect() calls are needed to avoid feeding input too early screen:expect({ any = '%[No Name%]' }) @@ -418,19 +418,19 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('o') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.get_var('a')) + eq(1, api.nvim_get_var('a')) async_meths.command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.get_var('a')) + eq(1, api.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('n') screen:expect({ any = '%[No Name%]' }) - eq(2, meths.get_var('a')) + eq(2, api.nvim_get_var('a')) -- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim. @@ -439,26 +439,26 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('<Esc>') screen:expect({ any = '%[No Name%]' }) - eq(0, meths.get_var('a')) + eq(0, api.nvim_get_var('a')) -- Default choice is returned when pressing <CR>. async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('<CR>') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.get_var('a')) + eq(1, api.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('<CR>') screen:expect({ any = '%[No Name%]' }) - eq(2, meths.get_var('a')) + eq(2, api.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('<CR>') screen:expect({ any = '%[No Name%]' }) - eq(0, meths.get_var('a')) + eq(0, api.nvim_get_var('a')) -- Test with the {type} 4th argument for _, type in ipairs({ 'Error', 'Question', 'Info', 'Warning', 'Generic' }) do @@ -466,7 +466,7 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.get_var('a')) + eq(1, api.nvim_get_var('a')) end eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm([])')) diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua index a93caf8405..ef0359263e 100644 --- a/test/functional/vimscript/json_functions_spec.lua +++ b/test/functional/vimscript/json_functions_spec.lua @@ -1,13 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local eq = helpers.eq local eval = helpers.eval local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err -local NIL = helpers.NIL +local NIL = vim.NIL local source = helpers.source describe('json_decode() function', function() @@ -59,13 +59,13 @@ describe('json_decode() function', function() before_each(restart) local speq = function(expected, actual_expr) - eq(1, funcs.EvalEq(expected, actual_expr)) + eq(1, fn.EvalEq(expected, actual_expr)) end it('accepts readfile()-style list', function() eq( { Test = 1 }, - funcs.json_decode({ + fn.json_decode({ '{', '\t"Test": 1', '}', @@ -76,7 +76,7 @@ describe('json_decode() function', function() it('accepts strings with newlines', function() eq( { Test = 1 }, - funcs.json_decode([[ + fn.json_decode([[ { "Test": 1 } @@ -85,9 +85,9 @@ describe('json_decode() function', function() end) it('parses null, true, false', function() - eq(NIL, funcs.json_decode('null')) - eq(true, funcs.json_decode('true')) - eq(false, funcs.json_decode('false')) + eq(NIL, fn.json_decode('null')) + eq(true, fn.json_decode('true')) + eq(false, fn.json_decode('false')) end) it('fails to parse incomplete null, true, false', function() @@ -109,12 +109,12 @@ describe('json_decode() function', function() end) it('parses integer numbers', function() - eq(100000, funcs.json_decode('100000')) - eq(-100000, funcs.json_decode('-100000')) - eq(100000, funcs.json_decode(' 100000 ')) - eq(-100000, funcs.json_decode(' -100000 ')) - eq(0, funcs.json_decode('0')) - eq(0, funcs.json_decode('-0')) + eq(100000, fn.json_decode('100000')) + eq(-100000, fn.json_decode('-100000')) + eq(100000, fn.json_decode(' 100000 ')) + eq(-100000, fn.json_decode(' -100000 ')) + eq(0, fn.json_decode('0')) + eq(0, fn.json_decode('-0')) end) it('fails to parse +numbers and .number', function() @@ -158,35 +158,35 @@ describe('json_decode() function', function() it('parses floating-point numbers', function() -- Also test method call (->) syntax eq('100000.0', eval('"100000.0"->json_decode()->string()')) - eq(100000.5, funcs.json_decode('100000.5')) - eq(-100000.5, funcs.json_decode('-100000.5')) - eq(-100000.5e50, funcs.json_decode('-100000.5e50')) - eq(100000.5e50, funcs.json_decode('100000.5e50')) - eq(100000.5e50, funcs.json_decode('100000.5e+50')) - eq(-100000.5e-50, funcs.json_decode('-100000.5e-50')) - eq(100000.5e-50, funcs.json_decode('100000.5e-50')) - eq(100000e-50, funcs.json_decode('100000e-50')) - eq(0.5, funcs.json_decode('0.5')) - eq(0.005, funcs.json_decode('0.005')) - eq(0.005, funcs.json_decode('0.00500')) - eq(0.5, funcs.json_decode('0.00500e+002')) - eq(0.00005, funcs.json_decode('0.00500e-002')) - - eq(-0.0, funcs.json_decode('-0.0')) - eq(-0.0, funcs.json_decode('-0.0e0')) - eq(-0.0, funcs.json_decode('-0.0e+0')) - eq(-0.0, funcs.json_decode('-0.0e-0')) - eq(-0.0, funcs.json_decode('-0e-0')) - eq(-0.0, funcs.json_decode('-0e-2')) - eq(-0.0, funcs.json_decode('-0e+2')) - - eq(0.0, funcs.json_decode('0.0')) - eq(0.0, funcs.json_decode('0.0e0')) - eq(0.0, funcs.json_decode('0.0e+0')) - eq(0.0, funcs.json_decode('0.0e-0')) - eq(0.0, funcs.json_decode('0e-0')) - eq(0.0, funcs.json_decode('0e-2')) - eq(0.0, funcs.json_decode('0e+2')) + eq(100000.5, fn.json_decode('100000.5')) + eq(-100000.5, fn.json_decode('-100000.5')) + eq(-100000.5e50, fn.json_decode('-100000.5e50')) + eq(100000.5e50, fn.json_decode('100000.5e50')) + eq(100000.5e50, fn.json_decode('100000.5e+50')) + eq(-100000.5e-50, fn.json_decode('-100000.5e-50')) + eq(100000.5e-50, fn.json_decode('100000.5e-50')) + eq(100000e-50, fn.json_decode('100000e-50')) + eq(0.5, fn.json_decode('0.5')) + eq(0.005, fn.json_decode('0.005')) + eq(0.005, fn.json_decode('0.00500')) + eq(0.5, fn.json_decode('0.00500e+002')) + eq(0.00005, fn.json_decode('0.00500e-002')) + + eq(-0.0, fn.json_decode('-0.0')) + eq(-0.0, fn.json_decode('-0.0e0')) + eq(-0.0, fn.json_decode('-0.0e+0')) + eq(-0.0, fn.json_decode('-0.0e-0')) + eq(-0.0, fn.json_decode('-0e-0')) + eq(-0.0, fn.json_decode('-0e-2')) + eq(-0.0, fn.json_decode('-0e+2')) + + eq(0.0, fn.json_decode('0.0')) + eq(0.0, fn.json_decode('0.0e0')) + eq(0.0, fn.json_decode('0.0e+0')) + eq(0.0, fn.json_decode('0.0e-0')) + eq(0.0, fn.json_decode('0e-0')) + eq(0.0, fn.json_decode('0e-2')) + eq(0.0, fn.json_decode('0e+2')) end) it('fails to parse numbers with spaces inside', function() @@ -210,7 +210,7 @@ describe('json_decode() function', function() end) it('parses empty containers', function() - eq({}, funcs.json_decode('[]')) + eq({}, fn.json_decode('[]')) eq('[]', eval('string(json_decode("[]"))')) end) @@ -301,12 +301,12 @@ describe('json_decode() function', function() end) it('parses containers', function() - eq({ 1 }, funcs.json_decode('[1]')) - eq({ NIL, 1 }, funcs.json_decode('[null, 1]')) - eq({ ['1'] = 2 }, funcs.json_decode('{"1": 2}')) + eq({ 1 }, fn.json_decode('[1]')) + eq({ NIL, 1 }, fn.json_decode('[null, 1]')) + eq({ ['1'] = 2 }, fn.json_decode('{"1": 2}')) eq( { ['1'] = 2, ['3'] = { { ['4'] = { ['5'] = { {}, 1 } } } } }, - funcs.json_decode('{"1": 2, "3": [{"4": {"5": [[], 1]}}]}') + fn.json_decode('{"1": 2, "3": [{"4": {"5": [[], 1]}}]}') ) end) @@ -363,10 +363,10 @@ describe('json_decode() function', function() end) it('parses strings properly', function() - eq('\n', funcs.json_decode('"\\n"')) - eq('', funcs.json_decode('""')) - eq('\\/"\t\b\n\r\f', funcs.json_decode([["\\\/\"\t\b\n\r\f"]])) - eq('/a', funcs.json_decode([["\/a"]])) + eq('\n', fn.json_decode('"\\n"')) + eq('', fn.json_decode('""')) + eq('\\/"\t\b\n\r\f', fn.json_decode([["\\\/\"\t\b\n\r\f"]])) + eq('/a', fn.json_decode([["\/a"]])) -- Unicode characters: 2-byte, 3-byte, 4-byte eq( { @@ -374,7 +374,7 @@ describe('json_decode() function', function() 'ફ', '\240\144\128\128', }, - funcs.json_decode({ + fn.json_decode({ '[', '"«",', '"ફ",', @@ -472,29 +472,29 @@ describe('json_decode() function', function() end) it('parses surrogate pairs properly', function() - eq('\240\144\128\128', funcs.json_decode('"\\uD800\\uDC00"')) - eq('\237\160\128a\237\176\128', funcs.json_decode('"\\uD800a\\uDC00"')) - eq('\237\160\128\t\237\176\128', funcs.json_decode('"\\uD800\\t\\uDC00"')) + eq('\240\144\128\128', fn.json_decode('"\\uD800\\uDC00"')) + eq('\237\160\128a\237\176\128', fn.json_decode('"\\uD800a\\uDC00"')) + eq('\237\160\128\t\237\176\128', fn.json_decode('"\\uD800\\t\\uDC00"')) - eq('\237\160\128', funcs.json_decode('"\\uD800"')) - eq('\237\160\128a', funcs.json_decode('"\\uD800a"')) - eq('\237\160\128\t', funcs.json_decode('"\\uD800\\t"')) + eq('\237\160\128', fn.json_decode('"\\uD800"')) + eq('\237\160\128a', fn.json_decode('"\\uD800a"')) + eq('\237\160\128\t', fn.json_decode('"\\uD800\\t"')) - eq('\237\176\128', funcs.json_decode('"\\uDC00"')) - eq('\237\176\128a', funcs.json_decode('"\\uDC00a"')) - eq('\237\176\128\t', funcs.json_decode('"\\uDC00\\t"')) + eq('\237\176\128', fn.json_decode('"\\uDC00"')) + eq('\237\176\128a', fn.json_decode('"\\uDC00a"')) + eq('\237\176\128\t', fn.json_decode('"\\uDC00\\t"')) - eq('\237\176\128', funcs.json_decode('"\\uDC00"')) - eq('a\237\176\128', funcs.json_decode('"a\\uDC00"')) - eq('\t\237\176\128', funcs.json_decode('"\\t\\uDC00"')) + eq('\237\176\128', fn.json_decode('"\\uDC00"')) + eq('a\237\176\128', fn.json_decode('"a\\uDC00"')) + eq('\t\237\176\128', fn.json_decode('"\\t\\uDC00"')) - eq('\237\160\128¬', funcs.json_decode('"\\uD800\\u00AC"')) + eq('\237\160\128¬', fn.json_decode('"\\uD800\\u00AC"')) - eq('\237\160\128\237\160\128', funcs.json_decode('"\\uD800\\uD800"')) + eq('\237\160\128\237\160\128', fn.json_decode('"\\uD800\\uD800"')) end) local sp_decode_eq = function(expected, json) - meths.set_var('__json', json) + api.nvim_set_var('__json', json) speq(expected, 'json_decode(g:__json)') command('unlet! g:__json') end @@ -570,10 +570,10 @@ describe('json_decode() function', function() end) it('parses dictionaries with empty keys', function() - eq({ [''] = 4 }, funcs.json_decode('{"": 4}')) + eq({ [''] = 4 }, fn.json_decode('{"": 4}')) eq( { b = 3, a = 1, c = 4, d = 2, [''] = 4 }, - funcs.json_decode('{"b": 3, "a": 1, "c": 4, "d": 2, "": 4}') + fn.json_decode('{"b": 3, "a": 1, "c": 4, "d": 2, "": 4}') ) end) @@ -602,7 +602,7 @@ describe('json_decode() function', function() end) it('parses U+00C3 correctly', function() - eq('\195\131', funcs.json_decode('"\195\131"')) + eq('\195\131', fn.json_decode('"\195\131"')) end) it('fails to parse empty string', function() @@ -622,7 +622,7 @@ describe('json_decode() function', function() local s = ' \t\n\r \t\r\n \n\t\r \n\r\t \r\t\n \r\n\t\t \n\r\t \r\n\t\n \r\t\n\r \t\r \n\t\r\n \n \t\r\n \r\t\n\t \r\n\t\r \n\r \t\n\r\t \r \t\n\r \n\t\r\t \n\r\t\n \r\n \t\r\n\t' local str = ('%s{%s"key"%s:%s[%s"val"%s,%s"val2"%s]%s,%s"key2"%s:%s1%s}%s'):gsub('%%s', s) - eq({ key = { 'val', 'val2' }, key2 = 1 }, funcs.json_decode(str)) + eq({ key = { 'val', 'val2' }, key2 = 1 }, fn.json_decode(str)) end) it('does not overflow when writing error message about decoding ["", ""]', function() @@ -640,12 +640,12 @@ describe('json_encode() function', function() end) it('dumps strings', function() - eq('"Test"', funcs.json_encode('Test')) - eq('""', funcs.json_encode('')) - eq('"\\t"', funcs.json_encode('\t')) - eq('"\\n"', funcs.json_encode('\n')) - eq('"\\u001B"', funcs.json_encode('\27')) - eq('"þÿþ"', funcs.json_encode('þÿþ')) + eq('"Test"', fn.json_encode('Test')) + eq('""', fn.json_encode('')) + eq('"\\t"', fn.json_encode('\t')) + eq('"\\n"', fn.json_encode('\n')) + eq('"\\u001B"', fn.json_encode('\27')) + eq('"þÿþ"', fn.json_encode('þÿþ')) end) it('dumps blobs', function() @@ -654,17 +654,17 @@ describe('json_encode() function', function() end) it('dumps numbers', function() - eq('0', funcs.json_encode(0)) - eq('10', funcs.json_encode(10)) - eq('-10', funcs.json_encode(-10)) + eq('0', fn.json_encode(0)) + eq('10', fn.json_encode(10)) + eq('-10', fn.json_encode(-10)) end) it('dumps floats', function() -- Also test method call (->) syntax eq('0.0', eval('0.0->json_encode()')) - eq('10.5', funcs.json_encode(10.5)) - eq('-10.5', funcs.json_encode(-10.5)) - eq('-1.0e-5', funcs.json_encode(-1e-5)) + eq('10.5', fn.json_encode(10.5)) + eq('-10.5', fn.json_encode(-10.5)) + eq('-1.0e-5', fn.json_encode(-1e-5)) eq('1.0e50', eval('1.0e50->json_encode()')) end) @@ -684,17 +684,17 @@ describe('json_encode() function', function() end) it('dumps lists', function() - eq('[]', funcs.json_encode({})) - eq('[[]]', funcs.json_encode({ {} })) - eq('[[], []]', funcs.json_encode({ {}, {} })) + eq('[]', fn.json_encode({})) + eq('[[]]', fn.json_encode({ {} })) + eq('[[], []]', fn.json_encode({ {}, {} })) end) it('dumps dictionaries', function() eq('{}', eval('json_encode({})')) - eq('{"d": []}', funcs.json_encode({ d = {} })) - eq('{"d": [], "e": []}', funcs.json_encode({ d = {}, e = {} })) + eq('{"d": []}', fn.json_encode({ d = {} })) + eq('{"d": [], "e": []}', fn.json_encode({ d = {}, e = {} })) -- Empty keys are allowed per JSON spec (and Vim dicts, and msgpack). - eq('{"": []}', funcs.json_encode({ [''] = {} })) + eq('{"": []}', fn.json_encode({ [''] = {} })) end) it('cannot dump generic mapping with generic mapping keys and values', function() @@ -892,9 +892,9 @@ describe('json_encode() function', function() end) it('ignores improper values in &isprint', function() - meths.set_option_value('isprint', '1', {}) + api.nvim_set_option_value('isprint', '1', {}) eq(1, eval('"\1" =~# "\\\\p"')) - eq('"\\u0001"', funcs.json_encode('\1')) + eq('"\\u0001"', fn.json_encode('\1')) end) it('fails when using surrogate character in a UTF-8 string', function() diff --git a/test/functional/vimscript/let_spec.lua b/test/functional/vimscript/let_spec.lua index 6cb52badb6..15d4b189b8 100644 --- a/test/functional/vimscript/let_spec.lua +++ b/test/functional/vimscript/let_spec.lua @@ -4,7 +4,7 @@ local eq = helpers.eq local clear = helpers.clear local command = helpers.command local eval = helpers.eval -local meths = helpers.meths +local api = helpers.api local exec = helpers.exec local exec_capture = helpers.exec_capture local expect_exit = helpers.expect_exit @@ -15,12 +15,12 @@ before_each(clear) describe(':let', function() it('correctly lists variables with curly-braces', function() - meths.set_var('v', { 0 }) + api.nvim_set_var('v', { 0 }) eq('v [0]', exec_capture('let {"v"}')) end) it('correctly lists variables with subscript', function() - meths.set_var('v', { 0 }) + api.nvim_set_var('v', { 0 }) eq('v[0] #0', exec_capture('let v[0]')) eq('g:["v"][0] #0', exec_capture('let g:["v"][0]')) eq('{"g:"}["v"][0] #0', exec_capture('let {"g:"}["v"][0]')) @@ -100,17 +100,17 @@ describe(':let', function() end) it('can apply operator to boolean option', function() - eq(true, meths.get_option_value('equalalways', {})) + eq(true, api.nvim_get_option_value('equalalways', {})) command('let &equalalways -= 1') - eq(false, meths.get_option_value('equalalways', {})) + eq(false, api.nvim_get_option_value('equalalways', {})) command('let &equalalways += 1') - eq(true, meths.get_option_value('equalalways', {})) + eq(true, api.nvim_get_option_value('equalalways', {})) command('let &equalalways *= 1') - eq(true, meths.get_option_value('equalalways', {})) + eq(true, api.nvim_get_option_value('equalalways', {})) command('let &equalalways /= 1') - eq(true, meths.get_option_value('equalalways', {})) + eq(true, api.nvim_get_option_value('equalalways', {})) command('let &equalalways %= 1') - eq(false, meths.get_option_value('equalalways', {})) + eq(false, api.nvim_get_option_value('equalalways', {})) end) end) diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index b0c4a9747a..59d427ca90 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -7,9 +7,8 @@ local exec = helpers.exec local exec_lua = helpers.exec_lua local expect = helpers.expect local feed = helpers.feed -local funcs = helpers.funcs -local meths = helpers.meths -local nvim = helpers.nvim +local fn = helpers.fn +local api = helpers.api local source = helpers.source local command = helpers.command local exec_capture = helpers.exec_capture @@ -37,47 +36,47 @@ describe('maparg()', function() } it('returns a dictionary', function() - nvim('command', 'nnoremap foo bar') - eq('bar', funcs.maparg('foo')) - eq(foo_bar_map_table, funcs.maparg('foo', 'n', false, true)) + command('nnoremap foo bar') + eq('bar', fn.maparg('foo')) + eq(foo_bar_map_table, fn.maparg('foo', 'n', false, true)) end) it('returns 1 for silent when <silent> is used', function() - nvim('command', 'nnoremap <silent> foo bar') - eq(1, funcs.maparg('foo', 'n', false, true)['silent']) + command('nnoremap <silent> foo bar') + eq(1, fn.maparg('foo', 'n', false, true)['silent']) - nvim('command', 'nnoremap baz bat') - eq(0, funcs.maparg('baz', 'n', false, true)['silent']) + command('nnoremap baz bat') + eq(0, fn.maparg('baz', 'n', false, true)['silent']) end) it('returns an empty string when no map is present', function() - eq('', funcs.maparg('not a mapping')) + eq('', fn.maparg('not a mapping')) end) it('returns an empty dictionary when no map is present and dict is requested', function() - eq({}, funcs.maparg('not a mapping', 'n', false, true)) + eq({}, fn.maparg('not a mapping', 'n', false, true)) end) it('returns the same value for noremap and <script>', function() - nvim('command', 'inoremap <script> hello world') - nvim('command', 'inoremap this that') + command('inoremap <script> hello world') + command('inoremap this that') eq( - funcs.maparg('hello', 'i', false, true)['noremap'], - funcs.maparg('this', 'i', false, true)['noremap'] + fn.maparg('hello', 'i', false, true)['noremap'], + fn.maparg('this', 'i', false, true)['noremap'] ) end) it('returns a boolean for buffer', function() -- Open enough windows to know we aren't on buffer number 1 - nvim('command', 'new') - nvim('command', 'new') - nvim('command', 'new') - nvim('command', 'cnoremap <buffer> this that') - eq(1, funcs.maparg('this', 'c', false, true)['buffer']) + command('new') + command('new') + command('new') + command('cnoremap <buffer> this that') + eq(1, fn.maparg('this', 'c', false, true)['buffer']) -- Global will return 0 always - nvim('command', 'nnoremap other another') - eq(0, funcs.maparg('other', 'n', false, true)['buffer']) + command('nnoremap other another') + eq(0, fn.maparg('other', 'n', false, true)['buffer']) end) it('returns script numbers', function() @@ -88,8 +87,8 @@ describe('maparg()', function() nnoremap fizz :call <SID>maparg_test_function()<CR> ]]) - eq(1, funcs.maparg('fizz', 'n', false, true)['sid']) - eq('testing', nvim('call_function', '<SNR>1_maparg_test_function', {})) + eq(1, fn.maparg('fizz', 'n', false, true)['sid']) + eq('testing', api.nvim_call_function('<SNR>1_maparg_test_function', {})) end) it('works with <F12> and others', function() @@ -104,7 +103,7 @@ describe('maparg()', function() ]]) eq(1, eval('g:maparg_test_var')) - eq(':let g:maparg_test_var = 1<CR>', funcs.maparg('<F12>', 'n', false, true)['rhs']) + eq(':let g:maparg_test_var = 1<CR>', fn.maparg('<F12>', 'n', false, true)['rhs']) end) it('works with <expr>', function() @@ -127,7 +126,7 @@ describe('maparg()', function() ]]) eq(1, eval('g:counter')) - local map_dict = funcs.maparg('<C-L>', 'i', false, true) + local map_dict = fn.maparg('<C-L>', 'i', false, true) eq(1, map_dict['expr']) eq('i', map_dict['mode']) end) @@ -144,10 +143,10 @@ describe('maparg()', function() nnoremap c` d nnoremap e` f` ]])) - eq(ac('b`'), funcs.maparg(ac('a'))) - eq(ac(''), funcs.maparg(ac('c'))) - eq(ac('d'), funcs.maparg(ac('c`'))) - eq(ac('f`'), funcs.maparg(ac('e`'))) + eq(ac('b`'), fn.maparg(ac('a'))) + eq(ac(''), fn.maparg(ac('c'))) + eq(ac('d'), fn.maparg(ac('c`'))) + eq(ac('f`'), fn.maparg(ac('e`'))) local function acmap(lhs, rhs) return { @@ -170,10 +169,10 @@ describe('maparg()', function() } end - eq({}, funcs.maparg(ac('c'), 'n', 0, 1)) - eq(acmap('a', 'b`'), funcs.maparg(ac('a'), 'n', 0, 1)) - eq(acmap('c`', 'd'), funcs.maparg(ac('c`'), 'n', 0, 1)) - eq(acmap('e`', 'f`'), funcs.maparg(ac('e`'), 'n', 0, 1)) + eq({}, fn.maparg(ac('c'), 'n', 0, 1)) + eq(acmap('a', 'b`'), fn.maparg(ac('a'), 'n', 0, 1)) + eq(acmap('c`', 'd'), fn.maparg(ac('c`'), 'n', 0, 1)) + eq(acmap('e`', 'f`'), fn.maparg(ac('e`'), 'n', 0, 1)) end) end) @@ -181,34 +180,34 @@ describe('mapset()', function() before_each(clear) it('can restore mapping with backslash in lhs', function() - meths.set_keymap('n', '\\ab', 'a', {}) + api.nvim_set_keymap('n', '\\ab', 'a', {}) eq('\nn \\ab a', exec_capture('nmap \\ab')) - local mapargs = funcs.maparg('\\ab', 'n', false, true) - meths.set_keymap('n', '\\ab', 'b', {}) + local mapargs = fn.maparg('\\ab', 'n', false, true) + api.nvim_set_keymap('n', '\\ab', 'b', {}) eq('\nn \\ab b', exec_capture('nmap \\ab')) - funcs.mapset('n', false, mapargs) + fn.mapset('n', false, mapargs) eq('\nn \\ab a', exec_capture('nmap \\ab')) end) it('can restore mapping description from the dict returned by maparg()', function() - meths.set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) + api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) eq('\nn lhs rhs\n map description', exec_capture('nmap lhs')) - local mapargs = funcs.maparg('lhs', 'n', false, true) - meths.set_keymap('n', 'lhs', 'rhs', { desc = 'MAP DESCRIPTION' }) + local mapargs = fn.maparg('lhs', 'n', false, true) + api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'MAP DESCRIPTION' }) eq('\nn lhs rhs\n MAP DESCRIPTION', exec_capture('nmap lhs')) - funcs.mapset('n', false, mapargs) + fn.mapset('n', false, mapargs) eq('\nn lhs rhs\n map description', exec_capture('nmap lhs')) end) it('can restore "replace_keycodes" from the dict returned by maparg()', function() - meths.set_keymap('i', 'foo', [['<l' .. 't>']], { expr = true, replace_keycodes = true }) + api.nvim_set_keymap('i', 'foo', [['<l' .. 't>']], { expr = true, replace_keycodes = true }) feed('Afoo') expect('<') - local mapargs = funcs.maparg('foo', 'i', false, true) - meths.set_keymap('i', 'foo', [['<l' .. 't>']], { expr = true }) + local mapargs = fn.maparg('foo', 'i', false, true) + api.nvim_set_keymap('i', 'foo', [['<l' .. 't>']], { expr = true }) feed('foo') expect('<<lt>') - funcs.mapset('i', false, mapargs) + fn.mapset('i', false, mapargs) feed('foo') expect('<<lt><') end) @@ -218,12 +217,12 @@ describe('mapset()', function() eq('\ni foo * bar', exec_capture('iabbr foo')) feed('ifoo ') expect('bar ') - local mapargs = funcs.maparg('foo', 'i', true, true) + local mapargs = fn.maparg('foo', 'i', true, true) command('inoreabbr foo BAR') eq('\ni foo * BAR', exec_capture('iabbr foo')) feed('foo ') expect('bar BAR ') - funcs.mapset('i', true, mapargs) + fn.mapset('i', true, mapargs) eq('\ni foo * bar', exec_capture('iabbr foo')) feed('foo<Esc>') expect('bar BAR bar') diff --git a/test/functional/vimscript/match_functions_spec.lua b/test/functional/vimscript/match_functions_spec.lua index 8092d140c8..3db612e472 100644 --- a/test/functional/vimscript/match_functions_spec.lua +++ b/test/functional/vimscript/match_functions_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local eq = helpers.eq local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command local exc_exec = helpers.exc_exec @@ -12,7 +12,7 @@ before_each(clear) describe('setmatches()', function() it('correctly handles case when both group and pattern entries are numbers', function() command('hi def link 1 PreProc') - eq(0, funcs.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4 } })) + eq(0, fn.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4 } })) eq({ { group = '1', @@ -20,8 +20,8 @@ describe('setmatches()', function() id = 3, priority = 4, }, - }, funcs.getmatches()) - eq(0, funcs.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4, conceal = 5 } })) + }, fn.getmatches()) + eq(0, fn.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4, conceal = 5 } })) eq({ { group = '1', @@ -30,10 +30,10 @@ describe('setmatches()', function() priority = 4, conceal = '5', }, - }, funcs.getmatches()) + }, fn.getmatches()) eq( 0, - funcs.setmatches({ + fn.setmatches({ { group = 1, pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = 5 }, }) ) @@ -46,21 +46,21 @@ describe('setmatches()', function() priority = 4, conceal = '5', }, - }, funcs.getmatches()) + }, fn.getmatches()) end) it('does not fail if highlight group is not defined', function() - eq(0, funcs.setmatches { { group = 1, pattern = 2, id = 3, priority = 4 } }) - eq({ { group = '1', pattern = '2', id = 3, priority = 4 } }, funcs.getmatches()) + eq(0, fn.setmatches { { group = 1, pattern = 2, id = 3, priority = 4 } }) + eq({ { group = '1', pattern = '2', id = 3, priority = 4 } }, fn.getmatches()) eq( 0, - funcs.setmatches { + fn.setmatches { { group = 1, pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = 5 }, } ) eq( { { group = '1', pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = '5' } }, - funcs.getmatches() + fn.getmatches() ) end) end) @@ -68,7 +68,7 @@ end) describe('matchadd()', function() it('correctly works when first two arguments and conceal are numbers at once', function() command('hi def link 1 PreProc') - eq(4, funcs.matchadd(1, 2, 3, 4, { conceal = 5 })) + eq(4, fn.matchadd(1, 2, 3, 4, { conceal = 5 })) eq({ { group = '1', @@ -77,7 +77,7 @@ describe('matchadd()', function() id = 4, conceal = '5', }, - }, funcs.getmatches()) + }, fn.getmatches()) end) end) @@ -99,7 +99,7 @@ describe('matchaddpos()', function() end) it('works with 0 lnum', function() command('hi clear PreProc') - eq(4, funcs.matchaddpos('PreProc', { 1 }, 3, 4)) + eq(4, fn.matchaddpos('PreProc', { 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -107,9 +107,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { { 0 }, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { { 0 }, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -117,9 +117,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { 0, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { 0, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -127,11 +127,11 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) + }, fn.getmatches()) end) it('works with negative numbers', function() command('hi clear PreProc') - eq(4, funcs.matchaddpos('PreProc', { -10, 1 }, 3, 4)) + eq(4, fn.matchaddpos('PreProc', { -10, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -139,9 +139,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { { -10 }, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { { -10 }, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -149,9 +149,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { { 2, -1 }, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { { 2, -1 }, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -159,9 +159,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { { 2, 0, -1 }, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { { 2, 0, -1 }, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -169,14 +169,14 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) + }, fn.getmatches()) end) it('works with zero length', function() local screen = Screen.new(40, 5) screen:attach() - funcs.setline(1, 'abcdef') + fn.setline(1, 'abcdef') command('hi PreProc guifg=Red') - eq(4, funcs.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4)) + eq(4, fn.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4)) eq({ { group = 'PreProc', @@ -184,7 +184,7 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) + }, fn.getmatches()) screen:expect( [[ ^a{1:b}cdef | diff --git a/test/functional/vimscript/minmax_functions_spec.lua b/test/functional/vimscript/minmax_functions_spec.lua index a618782f88..c4a986bc8c 100644 --- a/test/functional/vimscript/minmax_functions_spec.lua +++ b/test/functional/vimscript/minmax_functions_spec.lua @@ -4,7 +4,7 @@ local eq = helpers.eq local eval = helpers.eval local command = helpers.command local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local pcall_err = helpers.pcall_err before_each(clear) @@ -30,12 +30,12 @@ for _, func in ipairs({ 'min', 'max' }) do end end) it('works with arrays/dictionaries with zero items', function() - eq(0, funcs[func]({})) + eq(0, fn[func]({})) eq(0, eval(func .. '({})')) end) it('works with arrays/dictionaries with one item', function() - eq(5, funcs[func]({ 5 })) - eq(5, funcs[func]({ test = 5 })) + eq(5, fn[func]({ 5 })) + eq(5, fn[func]({ test = 5 })) end) it('works with NULL arrays/dictionaries', function() eq(0, eval(func .. '(v:_null_list)')) diff --git a/test/functional/vimscript/msgpack_functions_spec.lua b/test/functional/vimscript/msgpack_functions_spec.lua index 824c1e8751..609a706155 100644 --- a/test/functional/vimscript/msgpack_functions_spec.lua +++ b/test/functional/vimscript/msgpack_functions_spec.lua @@ -1,9 +1,9 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local eval, eq = helpers.eval, helpers.eq local command = helpers.command -local nvim = helpers.nvim +local api = helpers.api local exc_exec = helpers.exc_exec local is_os = helpers.is_os @@ -12,7 +12,7 @@ describe('msgpack*() functions', function() local obj_test = function(msg, obj) it(msg, function() - nvim('set_var', 'obj', obj) + api.nvim_set_var('obj', obj) eq(obj, eval('msgpackparse(msgpackdump(g:obj))')) eq(obj, eval('msgpackparse(msgpackdump(g:obj, "B"))')) end) @@ -406,7 +406,7 @@ local parse_eq = function(expect, list_arg) .. blobstr(list_arg):gsub('(.)', function(c) return ('%.2x'):format(c:byte()) end) - eq(expect, funcs.msgpackparse(list_arg)) + eq(expect, fn.msgpackparse(list_arg)) command('let g:parsed = msgpackparse(' .. blob_expr .. ')') eq(expect, eval('g:parsed')) end diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua index acdd844aff..805cd13844 100644 --- a/test/functional/vimscript/null_spec.lua +++ b/test/functional/vimscript/null_spec.lua @@ -1,23 +1,22 @@ local helpers = require('test.functional.helpers')(after_each) -local curbufmeths = helpers.curbufmeths local exc_exec = helpers.exc_exec local command = helpers.command local clear = helpers.clear -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local eq = helpers.eq local function redir_exec(cmd) - meths.set_var('__redir_exec_cmd', cmd) + api.nvim_set_var('__redir_exec_cmd', cmd) command([[ redir => g:__redir_exec_output silent! execute g:__redir_exec_cmd redir END ]]) - local ret = meths.get_var('__redir_exec_output') - meths.del_var('__redir_exec_output') - meths.del_var('__redir_exec_cmd') + local ret = api.nvim_get_var('__redir_exec_output') + api.nvim_del_var('__redir_exec_output') + api.nvim_del_var('__redir_exec_cmd') return ret end @@ -42,9 +41,9 @@ describe('NULL', function() it(name, function() eq((err == 0) and '' or ('\n' .. err), redir_exec('let g:_var = ' .. expr)) if val == nil then - eq(0, funcs.exists('g:_var')) + eq(0, fn.exists('g:_var')) else - eq(val, meths.get_var('_var')) + eq(val, api.nvim_get_var('_var')) end if after ~= nil then after() @@ -72,10 +71,10 @@ describe('NULL', function() null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) null_expr_test('does not crash append()', 'append(0, L)', 0, 0, function() - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) null_expr_test('does not crash setline()', 'setline(1, L)', 0, 0, function() - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) null_expr_test('is identical to itself', 'L is L', 0, 1) null_expr_test('can be sliced', 'L[:]', 0, {}) @@ -184,7 +183,7 @@ describe('NULL', function() 0, '', function() - eq({ '' }, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false)) end ) null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, 0) diff --git a/test/functional/vimscript/printf_spec.lua b/test/functional/vimscript/printf_spec.lua index 248a33c92b..4fa4ea7f4c 100644 --- a/test/functional/vimscript/printf_spec.lua +++ b/test/functional/vimscript/printf_spec.lua @@ -3,56 +3,56 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local exc_exec = helpers.exc_exec describe('printf()', function() before_each(clear) it('works with zero and %b', function() - eq('0', funcs.printf('%lb', 0)) - eq('0', funcs.printf('%llb', 0)) - eq('0', funcs.printf('%zb', 0)) + eq('0', fn.printf('%lb', 0)) + eq('0', fn.printf('%llb', 0)) + eq('0', fn.printf('%zb', 0)) end) it('works with one and %b', function() - eq('1', funcs.printf('%b', 1)) - eq('1', funcs.printf('%lb', 1)) - eq('1', funcs.printf('%llb', 1)) - eq('1', funcs.printf('%zb', 1)) + eq('1', fn.printf('%b', 1)) + eq('1', fn.printf('%lb', 1)) + eq('1', fn.printf('%llb', 1)) + eq('1', fn.printf('%zb', 1)) end) it('works with 0xff and %b', function() - eq('11111111', funcs.printf('%b', 0xff)) - eq('11111111', funcs.printf('%lb', 0xff)) - eq('11111111', funcs.printf('%llb', 0xff)) - eq('11111111', funcs.printf('%zb', 0xff)) + eq('11111111', fn.printf('%b', 0xff)) + eq('11111111', fn.printf('%lb', 0xff)) + eq('11111111', fn.printf('%llb', 0xff)) + eq('11111111', fn.printf('%zb', 0xff)) end) it('accepts width modifier with %b', function() - eq(' 1', funcs.printf('%3b', 1)) + eq(' 1', fn.printf('%3b', 1)) end) it('accepts prefix modifier with %b', function() - eq('0b1', funcs.printf('%#b', 1)) + eq('0b1', fn.printf('%#b', 1)) end) it('writes capital B with %B', function() - eq('0B1', funcs.printf('%#B', 1)) + eq('0B1', fn.printf('%#B', 1)) end) it('accepts prefix, zero-fill and width modifiers with %b', function() - eq('0b001', funcs.printf('%#05b', 1)) + eq('0b001', fn.printf('%#05b', 1)) end) it('accepts prefix and width modifiers with %b', function() - eq(' 0b1', funcs.printf('%#5b', 1)) + eq(' 0b1', fn.printf('%#5b', 1)) end) it('does not write prefix for zero with prefix and width modifier used with %b', function() - eq(' 0', funcs.printf('%#5b', 0)) + eq(' 0', fn.printf('%#5b', 0)) end) it('accepts precision modifier with %b', function() - eq('00000', funcs.printf('%.5b', 0)) + eq('00000', fn.printf('%.5b', 0)) end) it('accepts all modifiers with %b at once', function() -- zero-fill modifier is ignored when used with left-align -- force-sign and add-blank are ignored -- use-grouping-characters modifier is ignored always - eq('0b00011 ', funcs.printf("% '+#0-10.5b", 3)) + eq('0b00011 ', fn.printf("% '+#0-10.5b", 3)) end) it('errors out when %b modifier is used for a list', function() eq('Vim(call):E745: Using a List as a Number', exc_exec('call printf("%b", [])')) @@ -65,12 +65,12 @@ describe('printf()', function() local seen_rets = {} -- Collect all args in an array to avoid possible allocation of the same -- address after freeing unreferenced values. - meths.set_var('__args', {}) + api.nvim_set_var('__args', {}) local function check_printf(expr, is_null) eq(0, exc_exec('call add(__args, ' .. expr .. ')')) eq(0, exc_exec('let __result = printf("%p", __args[-1])')) local id_ret = eval('id(__args[-1])') - eq(id_ret, meths.get_var('__result')) + eq(id_ret, api.nvim_get_var('__result')) if is_null then if null_ret then eq(null_ret, id_ret) @@ -81,7 +81,7 @@ describe('printf()', function() eq(nil, seen_rets[id_ret]) seen_rets[id_ret] = expr end - meths.del_var('__result') + api.nvim_del_var('__result') end check_printf('v:_null_list', true) check_printf('v:_null_dict', true) diff --git a/test/functional/vimscript/reltime_spec.lua b/test/functional/vimscript/reltime_spec.lua index 29a57ad8ff..7cdb78e4ce 100644 --- a/test/functional/vimscript/reltime_spec.lua +++ b/test/functional/vimscript/reltime_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok -local neq, command, funcs = helpers.neq, helpers.command, helpers.funcs -local reltime, reltimestr, reltimefloat = funcs.reltime, funcs.reltimestr, funcs.reltimefloat +local neq, command, fn = helpers.neq, helpers.command, helpers.fn +local reltime, reltimestr, reltimefloat = fn.reltime, fn.reltimestr, fn.reltimefloat describe('reltimestr(), reltimefloat()', function() before_each(clear) diff --git a/test/functional/vimscript/screenchar_spec.lua b/test/functional/vimscript/screenchar_spec.lua index 767e3c57ef..48b6893865 100644 --- a/test/functional/vimscript/screenchar_spec.lua +++ b/test/functional/vimscript/screenchar_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq -local command, meths, funcs = helpers.command, helpers.meths, helpers.funcs -local tbl_deep_extend = helpers.tbl_deep_extend +local command, api, fn = helpers.command, helpers.api, helpers.fn +local tbl_deep_extend = vim.tbl_deep_extend -- Set up two overlapping floating windows local setup_floating_windows = function() @@ -14,15 +14,15 @@ local setup_floating_windows = function() border = 'none', } - local bufnr_1 = meths.create_buf(false, true) - meths.buf_set_lines(bufnr_1, 0, -1, true, { 'aa' }) + local bufnr_1 = api.nvim_create_buf(false, true) + api.nvim_buf_set_lines(bufnr_1, 0, -1, true, { 'aa' }) local opts_1 = tbl_deep_extend('force', { row = 0, col = 0, zindex = 11 }, base_opts) - meths.open_win(bufnr_1, false, opts_1) + api.nvim_open_win(bufnr_1, false, opts_1) - local bufnr_2 = meths.create_buf(false, true) - meths.buf_set_lines(bufnr_2, 0, -1, true, { 'bb' }) + local bufnr_2 = api.nvim_create_buf(false, true) + api.nvim_buf_set_lines(bufnr_2, 0, -1, true, { 'bb' }) local opts_2 = tbl_deep_extend('force', { row = 0, col = 1, zindex = 10 }, base_opts) - meths.open_win(bufnr_2, false, opts_2) + api.nvim_open_win(bufnr_2, false, opts_2) command('redraw') end @@ -32,38 +32,38 @@ describe('screenchar() and family respect floating windows', function() clear() -- These commands result into visible text `aabc`. -- `aab` - from floating windows, `c` - from text in regular window. - meths.buf_set_lines(0, 0, -1, true, { 'cccc' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'cccc' }) setup_floating_windows() end) it('screenattr()', function() - local attr_1 = funcs.screenattr(1, 1) - local attr_2 = funcs.screenattr(1, 2) - local attr_3 = funcs.screenattr(1, 3) - local attr_4 = funcs.screenattr(1, 4) + local attr_1 = fn.screenattr(1, 1) + local attr_2 = fn.screenattr(1, 2) + local attr_3 = fn.screenattr(1, 3) + local attr_4 = fn.screenattr(1, 4) eq(attr_1, attr_2) eq(attr_1, attr_3) neq(attr_1, attr_4) end) it('screenchar()', function() - eq(97, funcs.screenchar(1, 1)) - eq(97, funcs.screenchar(1, 2)) - eq(98, funcs.screenchar(1, 3)) - eq(99, funcs.screenchar(1, 4)) + eq(97, fn.screenchar(1, 1)) + eq(97, fn.screenchar(1, 2)) + eq(98, fn.screenchar(1, 3)) + eq(99, fn.screenchar(1, 4)) end) it('screenchars()', function() - eq({ 97 }, funcs.screenchars(1, 1)) - eq({ 97 }, funcs.screenchars(1, 2)) - eq({ 98 }, funcs.screenchars(1, 3)) - eq({ 99 }, funcs.screenchars(1, 4)) + eq({ 97 }, fn.screenchars(1, 1)) + eq({ 97 }, fn.screenchars(1, 2)) + eq({ 98 }, fn.screenchars(1, 3)) + eq({ 99 }, fn.screenchars(1, 4)) end) it('screenstring()', function() - eq('a', funcs.screenstring(1, 1)) - eq('a', funcs.screenstring(1, 2)) - eq('b', funcs.screenstring(1, 3)) - eq('c', funcs.screenstring(1, 4)) + eq('a', fn.screenstring(1, 1)) + eq('a', fn.screenstring(1, 2)) + eq('b', fn.screenstring(1, 3)) + eq('c', fn.screenstring(1, 4)) end) end) diff --git a/test/functional/vimscript/screenpos_spec.lua b/test/functional/vimscript/screenpos_spec.lua index 934dd1cfe1..b951d830a6 100644 --- a/test/functional/vimscript/screenpos_spec.lua +++ b/test/functional/vimscript/screenpos_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, eq, meths = helpers.clear, helpers.eq, helpers.meths -local command, funcs = helpers.command, helpers.funcs +local clear, eq, api = helpers.clear, helpers.eq, helpers.api +local command, fn = helpers.command, helpers.fn local feed = helpers.feed before_each(clear) @@ -18,33 +18,33 @@ describe('screenpos() function', function() border = 'none', focusable = 1, } - local float = meths.open_win(meths.create_buf(false, true), false, opts) + local float = api.nvim_open_win(api.nvim_create_buf(false, true), false, opts) command('redraw') - eq({ row = 7, col = 9, endcol = 9, curscol = 9 }, funcs.screenpos(float, 1, 1)) + eq({ row = 7, col = 9, endcol = 9, curscol = 9 }, fn.screenpos(float, 1, 1)) -- only left border opts.border = { '', '', '', '', '', '', '', '|' } - meths.win_set_config(float, opts) + api.nvim_win_set_config(float, opts) command('redraw') - eq({ row = 7, col = 10, endcol = 10, curscol = 10 }, funcs.screenpos(float, 1, 1)) + eq({ row = 7, col = 10, endcol = 10, curscol = 10 }, fn.screenpos(float, 1, 1)) -- only top border opts.border = { '', '_', '', '', '', '', '', '' } - meths.win_set_config(float, opts) + api.nvim_win_set_config(float, opts) command('redraw') - eq({ row = 8, col = 9, endcol = 9, curscol = 9 }, funcs.screenpos(float, 1, 1)) + eq({ row = 8, col = 9, endcol = 9, curscol = 9 }, fn.screenpos(float, 1, 1)) -- both left and top border opts.border = 'single' - meths.win_set_config(float, opts) + api.nvim_win_set_config(float, opts) command('redraw') - eq({ row = 8, col = 10, endcol = 10, curscol = 10 }, funcs.screenpos(float, 1, 1)) + eq({ row = 8, col = 10, endcol = 10, curscol = 10 }, fn.screenpos(float, 1, 1)) end) it('works for folded line with virt_lines attached to line above', function() - meths.buf_set_lines(0, 0, -1, true, { 'aaa', 'bbb', 'ccc', 'ddd' }) - local ns = meths.create_namespace('') - meths.buf_set_extmark( + api.nvim_buf_set_lines(0, 0, -1, true, { 'aaa', 'bbb', 'ccc', 'ddd' }) + local ns = api.nvim_create_namespace('') + api.nvim_buf_set_extmark( 0, ns, 0, @@ -52,28 +52,28 @@ describe('screenpos() function', function() { virt_lines = { { { 'abb' } }, { { 'acc' } }, { { 'add' } } } } ) command('2,3fold') - eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 2, 1)) - eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 3, 1)) - eq({ row = 6, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 4, 1)) + eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1)) + eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1)) + eq({ row = 6, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1)) feed('<C-E>') - eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 2, 1)) - eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 3, 1)) - eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 4, 1)) + eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1)) + eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1)) + eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1)) feed('<C-E>') - eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 2, 1)) - eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 3, 1)) - eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 4, 1)) + eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1)) + eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1)) + eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1)) feed('<C-E>') - eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 2, 1)) - eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 3, 1)) - eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 4, 1)) + eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1)) + eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1)) + eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1)) feed('<C-E>') - eq({ row = 1, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 2, 1)) - eq({ row = 1, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 3, 1)) - eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, funcs.screenpos(0, 4, 1)) + eq({ row = 1, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1)) + eq({ row = 1, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1)) + eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1)) end) end) diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index 7b8a98d5fc..360fcf0dfe 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local assert_log = helpers.assert_log local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval -local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths +local clear, fn, api = helpers.clear, helpers.fn, helpers.api local ok = helpers.ok local matches = helpers.matches local pcall_err = helpers.pcall_err @@ -11,8 +11,8 @@ local is_os = helpers.is_os local testlog = 'Xtest-server-log' local function clear_serverlist() - for _, server in pairs(funcs.serverlist()) do - funcs.serverstop(server) + for _, server in pairs(fn.serverlist()) do + fn.serverstop(server) end end @@ -25,9 +25,9 @@ describe('server', function() local dir = 'Xtest_xdg_run' mkdir(dir) clear({ env = { XDG_RUNTIME_DIR = dir } }) - matches(dir, funcs.stdpath('run')) + matches(dir, fn.stdpath('run')) if not is_os('win') then - matches(dir, funcs.serverstart()) + matches(dir, fn.serverstart()) end end) @@ -45,37 +45,37 @@ describe('server', function() clear({ env = { NVIM_LISTEN_ADDRESS = '.' } }) -- Cleared on startup. eq('', eval('$NVIM_LISTEN_ADDRESS')) - local servers = funcs.serverlist() + local servers = fn.serverlist() eq(1, #servers) ok(string.len(servers[1]) > 4) -- "~/.local/state/nvim…/…" or "\\.\pipe\…" end) it('sets v:servername at startup or if all servers were stopped', function() clear() - local initial_server = meths.get_vvar('servername') + local initial_server = api.nvim_get_vvar('servername') assert(initial_server ~= nil and initial_server:len() > 0, 'v:servername was not initialized') -- v:servername is readonly so we cannot unset it--but we can test that it -- does not get set again thereafter. - local s = funcs.serverstart() + local s = fn.serverstart() assert(s ~= nil and s:len() > 0, 'serverstart() returned empty') neq(initial_server, s) -- serverstop() does _not_ modify v:servername... - eq(1, funcs.serverstop(s)) - eq(initial_server, meths.get_vvar('servername')) + eq(1, fn.serverstop(s)) + eq(initial_server, api.nvim_get_vvar('servername')) -- ...unless we stop _all_ servers. - eq(1, funcs.serverstop(funcs.serverlist()[1])) - eq('', meths.get_vvar('servername')) + eq(1, fn.serverstop(fn.serverlist()[1])) + eq('', api.nvim_get_vvar('servername')) -- v:servername and $NVIM take the next available server. local servername = ( is_os('win') and [[\\.\pipe\Xtest-functional-server-pipe]] or './Xtest-functional-server-socket' ) - funcs.serverstart(servername) - eq(servername, meths.get_vvar('servername')) + fn.serverstart(servername) + eq(servername, api.nvim_get_vvar('servername')) -- Not set in the current process, only in children. eq('', eval('$NVIM')) end) @@ -96,50 +96,47 @@ describe('server', function() NVIM_LISTEN_ADDRESS = '.', } } clear_serverlist() - eq({}, funcs.serverlist()) + eq({}, fn.serverlist()) - local s = funcs.serverstart('127.0.0.1:0') -- assign random port + local s = fn.serverstart('127.0.0.1:0') -- assign random port if #s > 0 then assert(string.match(s, '127.0.0.1:%d+')) - eq(s, funcs.serverlist()[1]) + eq(s, fn.serverlist()[1]) clear_serverlist() end - s = funcs.serverstart('127.0.0.1:') -- assign random port + s = fn.serverstart('127.0.0.1:') -- assign random port if #s > 0 then assert(string.match(s, '127.0.0.1:%d+')) - eq(s, funcs.serverlist()[1]) + eq(s, fn.serverlist()[1]) clear_serverlist() end local expected = {} local v4 = '127.0.0.1:12345' - local status, _ = pcall(funcs.serverstart, v4) + local status, _ = pcall(fn.serverstart, v4) if status then table.insert(expected, v4) - pcall(funcs.serverstart, v4) -- exists already; ignore + pcall(fn.serverstart, v4) -- exists already; ignore assert_log('Failed to start server: address already in use: 127%.0%.0%.1', testlog, 10) end local v6 = '::1:12345' - status, _ = pcall(funcs.serverstart, v6) + status, _ = pcall(fn.serverstart, v6) if status then table.insert(expected, v6) - pcall(funcs.serverstart, v6) -- exists already; ignore + pcall(fn.serverstart, v6) -- exists already; ignore assert_log('Failed to start server: address already in use: ::1', testlog, 10) end - eq(expected, funcs.serverlist()) + eq(expected, fn.serverlist()) clear_serverlist() -- Address without slashes is a "name" which is appended to a generated path. #8519 - matches([[.*[/\\]xtest1%.2%.3%.4[^/\\]*]], funcs.serverstart('xtest1.2.3.4')) + matches([[.*[/\\]xtest1%.2%.3%.4[^/\\]*]], fn.serverstart('xtest1.2.3.4')) clear_serverlist() - eq( - 'Vim:Failed to start server: invalid argument', - pcall_err(funcs.serverstart, '127.0.0.1:65536') - ) -- invalid port - eq({}, funcs.serverlist()) + eq('Vim:Failed to start server: invalid argument', pcall_err(fn.serverstart, '127.0.0.1:65536')) -- invalid port + eq({}, fn.serverlist()) end) it('serverlist() returns the list of servers', function() @@ -175,20 +172,20 @@ describe('startup --listen', function() clear() local cmd = { unpack(helpers.nvim_argv) } table.insert(cmd, '--listen') - matches('nvim.*: Argument missing after: "%-%-listen"', funcs.system(cmd)) + matches('nvim.*: Argument missing after: "%-%-listen"', fn.system(cmd)) cmd = { unpack(helpers.nvim_argv) } table.insert(cmd, '--listen2') - matches('nvim.*: Garbage after option argument: "%-%-listen2"', funcs.system(cmd)) + matches('nvim.*: Garbage after option argument: "%-%-listen2"', fn.system(cmd)) end) it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function() local addr = (is_os('win') and [[\\.\pipe\Xtest-listen-pipe]] or './Xtest-listen-pipe') clear({ env = { NVIM_LISTEN_ADDRESS = './Xtest-env-pipe' }, args = { '--listen', addr } }) - eq(addr, meths.get_vvar('servername')) + eq(addr, api.nvim_get_vvar('servername')) -- Address without slashes is a "name" which is appended to a generated path. #8519 clear({ args = { '--listen', 'test-name' } }) - matches([[.*[/\\]test%-name[^/\\]*]], meths.get_vvar('servername')) + matches([[.*[/\\]test%-name[^/\\]*]], api.nvim_get_vvar('servername')) end) end) diff --git a/test/functional/vimscript/setpos_spec.lua b/test/functional/vimscript/setpos_spec.lua index 15ab76e78e..a26e48f469 100644 --- a/test/functional/vimscript/setpos_spec.lua +++ b/test/functional/vimscript/setpos_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local setpos = helpers.funcs.setpos -local getpos = helpers.funcs.getpos +local setpos = helpers.fn.setpos +local getpos = helpers.fn.getpos local insert = helpers.insert local clear = helpers.clear local command = helpers.command diff --git a/test/functional/vimscript/sort_spec.lua b/test/functional/vimscript/sort_spec.lua index a5119a737f..bd3d0da146 100644 --- a/test/functional/vimscript/sort_spec.lua +++ b/test/functional/vimscript/sort_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq -local NIL = helpers.NIL +local NIL = vim.NIL local eval = helpers.eval local clear = helpers.clear -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err @@ -21,7 +21,7 @@ describe('sort()', function() end) it('sorts “wrong” values between -0.0001 and 0.0001, preserving order', function() - meths.set_var('list', { + api.nvim_set_var('list', { true, false, NIL, @@ -32,7 +32,7 @@ describe('sort()', function() -0.0001, }) command('call insert(g:list, function("tr"))') - local error_lines = funcs.split(funcs.execute('silent! call sort(g:list, "f")'), '\n') + local error_lines = fn.split(fn.execute('silent! call sort(g:list, "f")'), '\n') local errors = {} for _, err in ipairs(error_lines) do errors[err] = true diff --git a/test/functional/vimscript/special_vars_spec.lua b/test/functional/vimscript/special_vars_spec.lua index 4266336652..590d409141 100644 --- a/test/functional/vimscript/special_vars_spec.lua +++ b/test/functional/vimscript/special_vars_spec.lua @@ -1,12 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local exc_exec = helpers.exc_exec local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local clear = helpers.clear local eval = helpers.eval local eq = helpers.eq -local meths = helpers.meths -local NIL = helpers.NIL +local api = helpers.api +local NIL = vim.NIL describe('Special values', function() before_each(clear) @@ -25,15 +25,15 @@ describe('Special values', function() end) it('work with empty()', function() - eq(0, funcs.empty(true)) - eq(1, funcs.empty(false)) - eq(1, funcs.empty(NIL)) + eq(0, fn.empty(true)) + eq(1, fn.empty(false)) + eq(1, fn.empty(NIL)) end) it('can be stringified and eval’ed back', function() - eq(true, funcs.eval(funcs.string(true))) - eq(false, funcs.eval(funcs.string(false))) - eq(NIL, funcs.eval(funcs.string(NIL))) + eq(true, fn.eval(fn.string(true))) + eq(false, fn.eval(fn.string(false))) + eq(NIL, fn.eval(fn.string(NIL))) end) it('work with is/isnot properly', function() @@ -107,8 +107,8 @@ describe('Special values', function() end) it('does not work with +=/-=/.=', function() - meths.set_var('true', true) - meths.set_var('false', false) + api.nvim_set_var('true', true) + api.nvim_set_var('false', false) command('let null = v:null') eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let true += 1')) @@ -137,19 +137,19 @@ describe('Special values', function() end) it('work with type()', function() - eq(6, funcs.type(true)) - eq(6, funcs.type(false)) - eq(7, funcs.type(NIL)) + eq(6, fn.type(true)) + eq(6, fn.type(false)) + eq(7, fn.type(NIL)) end) it('work with copy() and deepcopy()', function() - eq(true, funcs.deepcopy(true)) - eq(false, funcs.deepcopy(false)) - eq(NIL, funcs.deepcopy(NIL)) + eq(true, fn.deepcopy(true)) + eq(false, fn.deepcopy(false)) + eq(NIL, fn.deepcopy(NIL)) - eq(true, funcs.copy(true)) - eq(false, funcs.copy(false)) - eq(NIL, funcs.copy(NIL)) + eq(true, fn.copy(true)) + eq(false, fn.copy(false)) + eq(NIL, fn.copy(NIL)) end) it('fails in index', function() @@ -159,20 +159,20 @@ describe('Special values', function() end) it('is accepted by assert_true and assert_false', function() - funcs.assert_false(false) - funcs.assert_false(true) - funcs.assert_false(NIL) + fn.assert_false(false) + fn.assert_false(true) + fn.assert_false(NIL) - funcs.assert_true(false) - funcs.assert_true(true) - funcs.assert_true(NIL) + fn.assert_true(false) + fn.assert_true(true) + fn.assert_true(NIL) eq({ 'Expected False but got v:true', 'Expected False but got v:null', 'Expected True but got v:false', 'Expected True but got v:null', - }, meths.get_vvar('errors')) + }, api.nvim_get_vvar('errors')) end) describe('compat', function() diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index e93989ef80..7179806e36 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -4,7 +4,7 @@ local eq = helpers.eq local exec = helpers.exec local exec_lua = helpers.exec_lua local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local poke_eventloop = helpers.poke_eventloop before_each(clear) @@ -12,7 +12,7 @@ before_each(clear) describe('state() function', function() -- oldtest: Test_state() it('works', function() - meths.ui_attach(80, 24, {}) -- Allow hit-enter-prompt + api.nvim_ui_attach(80, 24, {}) -- Allow hit-enter-prompt exec_lua([[ function _G.Get_state_mode() @@ -48,7 +48,7 @@ describe('state() function', function() -- Halfway a mapping feed([[:call v:lua.Run_timer()<CR>;]]) - meths.get_mode() -- Process pending input and luv timer callback + api.nvim_get_mode() -- Process pending input and luv timer callback feed(';') eq({ 'mS', 'n' }, exec_lua('return _G.res')) @@ -79,7 +79,7 @@ describe('state() function', function() -- messages scrolled feed([[:call v:lua.Run_timer() | echo "one\ntwo\nthree"<CR>]]) - meths.get_mode() -- Process pending input and luv timer callback + api.nvim_get_mode() -- Process pending input and luv timer callback feed('<CR>') eq({ 'Ss', 'r' }, exec_lua('return _G.res')) end) diff --git a/test/functional/vimscript/string_spec.lua b/test/functional/vimscript/string_spec.lua index 719fea2c96..6a7fe1bad9 100644 --- a/test/functional/vimscript/string_spec.lua +++ b/test/functional/vimscript/string_spec.lua @@ -2,12 +2,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq local command = helpers.command -local meths = helpers.meths +local api = helpers.api local eval = helpers.eval local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err -local funcs = helpers.funcs -local NIL = helpers.NIL +local fn = helpers.fn +local NIL = vim.NIL local source = helpers.source describe('string() function', function() @@ -24,8 +24,8 @@ describe('string() function', function() end) it('dumps regular values', function() - eq('1.5', funcs.string(1.5)) - eq('1.56e-20', funcs.string(1.56000e-020)) + eq('1.5', fn.string(1.5)) + eq('1.56e-20', fn.string(1.56000e-020)) eq('0.0', eval('string(0.0)')) end) @@ -33,58 +33,58 @@ describe('string() function', function() eq('v:true', eval('string(v:true)')) eq('v:false', eval('string(v:false)')) eq('v:null', eval('string(v:null)')) - eq('v:true', funcs.string(true)) - eq('v:false', funcs.string(false)) - eq('v:null', funcs.string(NIL)) + eq('v:true', fn.string(true)) + eq('v:false', fn.string(false)) + eq('v:null', fn.string(NIL)) end) it('dumps values with at most six digits after the decimal point', function() - eq('1.234568e-20', funcs.string(1.23456789123456789123456789e-020)) - eq('1.234568', funcs.string(1.23456789123456789123456789)) + eq('1.234568e-20', fn.string(1.23456789123456789123456789e-020)) + eq('1.234568', fn.string(1.23456789123456789123456789)) end) it('dumps values with at most seven digits before the decimal point', function() - eq('1234567.891235', funcs.string(1234567.89123456789123456789)) - eq('1.234568e7', funcs.string(12345678.9123456789123456789)) + eq('1234567.891235', fn.string(1234567.89123456789123456789)) + eq('1.234568e7', fn.string(12345678.9123456789123456789)) end) it('dumps negative values', function() - eq('-1.5', funcs.string(-1.5)) - eq('-1.56e-20', funcs.string(-1.56000e-020)) - eq('-1.234568e-20', funcs.string(-1.23456789123456789123456789e-020)) - eq('-1.234568', funcs.string(-1.23456789123456789123456789)) - eq('-1234567.891235', funcs.string(-1234567.89123456789123456789)) - eq('-1.234568e7', funcs.string(-12345678.9123456789123456789)) + eq('-1.5', fn.string(-1.5)) + eq('-1.56e-20', fn.string(-1.56000e-020)) + eq('-1.234568e-20', fn.string(-1.23456789123456789123456789e-020)) + eq('-1.234568', fn.string(-1.23456789123456789123456789)) + eq('-1234567.891235', fn.string(-1234567.89123456789123456789)) + eq('-1.234568e7', fn.string(-12345678.9123456789123456789)) end) end) describe('used to represent numbers', function() it('dumps regular values', function() - eq('0', funcs.string(0)) - eq('-1', funcs.string(-1)) - eq('1', funcs.string(1)) + eq('0', fn.string(0)) + eq('-1', fn.string(-1)) + eq('1', fn.string(1)) end) it('dumps large values', function() - eq('2147483647', funcs.string(2 ^ 31 - 1)) - eq('-2147483648', funcs.string(-2 ^ 31)) + eq('2147483647', fn.string(2 ^ 31 - 1)) + eq('-2147483648', fn.string(-2 ^ 31)) end) end) describe('used to represent strings', function() it('dumps regular strings', function() - eq("'test'", funcs.string('test')) + eq("'test'", fn.string('test')) end) it('dumps empty strings', function() - eq("''", funcs.string('')) + eq("''", fn.string('')) end) it("dumps strings with ' inside", function() - eq("''''''''", funcs.string("'''")) - eq("'a''b'''''", funcs.string("a'b''")) - eq("'''b''''d'", funcs.string("'b''d")) - eq("'a''b''c''d'", funcs.string("a'b'c'd")) + eq("''''''''", fn.string("'''")) + eq("'a''b'''''", fn.string("a'b''")) + eq("'''b''''d'", fn.string("'b''d")) + eq("'a''b''c''d'", fn.string("a'b'c'd")) end) it('dumps NULL strings', function() @@ -161,7 +161,7 @@ describe('string() function', function() end) it('does not crash or halt when dumping partials with reference cycles in self', function() - meths.set_var('d', { v = true }) + api.nvim_set_var('d', { v = true }) eq( [[Vim(echo):E724: unable to correctly dump variable with self-referencing container]], pcall_err(command, 'echo string(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))') @@ -186,7 +186,7 @@ describe('string() function', function() end) it('does not crash or halt when dumping partials with reference cycles in arguments', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') -- Regression: the below line used to crash (add returns original list and -- there was error in dumping partials). Tested explicitly in @@ -201,8 +201,8 @@ describe('string() function', function() it( 'does not crash or halt when dumping partials with reference cycles in self and arguments', function() - meths.set_var('d', { v = true }) - meths.set_var('l', {}) + api.nvim_set_var('d', { v = true }) + api.nvim_set_var('l', {}) eval('add(l, l)') eval('add(l, function("Test1", l))') eval('add(l, function("Test1", d))') @@ -219,19 +219,19 @@ describe('string() function', function() describe('used to represent lists', function() it('dumps empty list', function() - eq('[]', funcs.string({})) + eq('[]', fn.string({})) end) it('dumps nested lists', function() - eq('[[[[[]]]]]', funcs.string({ { { { {} } } } })) + eq('[[[[[]]]]]', fn.string({ { { { {} } } } })) end) it('dumps nested non-empty lists', function() - eq('[1, [[3, [[5], 4]], 2]]', funcs.string({ 1, { { 3, { { 5 }, 4 } }, 2 } })) + eq('[1, [[3, [[5], 4]], 2]]', fn.string({ 1, { { 3, { { 5 }, 4 } }, 2 } })) end) it('errors when dumping recursive lists', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') eq( 'Vim(echo):E724: unable to correctly dump variable with self-referencing container', @@ -240,7 +240,7 @@ describe('string() function', function() end) it('dumps recursive lists despite the error', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') eq( 'Vim(echo):E724: unable to correctly dump variable with self-referencing container', @@ -266,11 +266,11 @@ describe('string() function', function() end) it('dumps non-empty dictionary', function() - eq("{'t''est': 1}", funcs.string({ ["t'est"] = 1 })) + eq("{'t''est': 1}", fn.string({ ["t'est"] = 1 })) end) it('errors when dumping recursive dictionaries', function() - meths.set_var('d', { d = 1 }) + api.nvim_set_var('d', { d = 1 }) eval('extend(d, {"d": d})') eq( 'Vim(echo):E724: unable to correctly dump variable with self-referencing container', @@ -279,7 +279,7 @@ describe('string() function', function() end) it('dumps recursive dictionaries despite the error', function() - meths.set_var('d', { d = 1 }) + api.nvim_set_var('d', { d = 1 }) eval('extend(d, {"d": d})') eq( 'Vim(echo):E724: unable to correctly dump variable with self-referencing container', diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index e1faf1e464..d44f68e152 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -4,14 +4,14 @@ local helpers = require('test.functional.helpers')(after_each) local assert_alive = helpers.assert_alive local testprg = helpers.testprg -local eq, call, clear, eval, feed_command, feed, nvim = +local eq, call, clear, eval, feed_command, feed, api = helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command, helpers.feed, - helpers.nvim + helpers.api local command = helpers.command local insert = helpers.insert local expect = helpers.expect @@ -220,8 +220,8 @@ describe('system()', function() end) it('prints verbose information', function() - nvim('set_option_value', 'shell', 'fake_shell', {}) - nvim('set_option_value', 'shellcmdflag', 'cmdflag', {}) + api.nvim_set_option_value('shell', 'fake_shell', {}) + api.nvim_set_option_value('shellcmdflag', 'cmdflag', {}) screen:try_resize(72, 14) feed(':4verbose echo system("echo hi")<cr>') @@ -247,8 +247,8 @@ describe('system()', function() feed(':edit ' .. tempfile .. '<cr>') - local command_total_time = tonumber(helpers.funcs.split(helpers.funcs.getline(7))[2]) - local command_self_time = tonumber(helpers.funcs.split(helpers.funcs.getline(7))[3]) + local command_total_time = tonumber(helpers.fn.split(helpers.fn.getline(7))[2]) + local command_self_time = tonumber(helpers.fn.split(helpers.fn.getline(7))[3]) helpers.neq(nil, command_total_time) helpers.neq(nil, command_self_time) @@ -346,7 +346,7 @@ describe('system()', function() input[#input + 1] = '01234567890ABCDEFabcdef' end input = table.concat(input, '\n') - nvim('set_var', 'input', input) + api.nvim_set_var('input', input) eq(input, eval('system("cat -", g:input)')) end) end) @@ -480,7 +480,7 @@ describe('systemlist()', function() for _ = 1, 0xffff do input[#input + 1] = '01234567890ABCDEFabcdef' end - nvim('set_var', 'input', input) + api.nvim_set_var('input', input) eq(input, eval('systemlist("cat -", g:input)')) end) end) diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 0293d30380..3f53c21e7a 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -2,9 +2,9 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run -local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs +local clear, command, fn = helpers.clear, helpers.command, helpers.fn local exc_exec = helpers.exc_exec -local curbufmeths = helpers.curbufmeths +local api = helpers.api local load_adjust = helpers.load_adjust local retry = helpers.retry @@ -111,7 +111,7 @@ describe('timers', function() [1] = { bold = true, foreground = Screen.colors.Blue }, }) - curbufmeths.set_lines(0, -1, true, { 'ITEM 1', 'ITEM 2' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' }) source([[ let g:cont = 0 func! AddItem(timer) @@ -165,7 +165,7 @@ describe('timers', function() local t_init_val = eval("[timer_start(5, 'MyHandler', {'repeat': -1}), g:val]") eq(0, t_init_val[2]) run(nil, nil, nil, load_adjust(30)) - funcs.timer_stop(t_init_val[1]) + fn.timer_stop(t_init_val[1]) local count = eval('g:val') run(nil, load_adjust(300), nil, load_adjust(30)) local count2 = eval('g:val') diff --git a/test/functional/vimscript/wait_spec.lua b/test/functional/vimscript/wait_spec.lua index 03cdbc12fa..4ee3b183b3 100644 --- a/test/functional/vimscript/wait_spec.lua +++ b/test/functional/vimscript/wait_spec.lua @@ -7,14 +7,14 @@ local eq = helpers.eq local feed = helpers.feed local feed_command = helpers.feed_command local next_msg = helpers.next_msg -local nvim = helpers.nvim +local api = helpers.api local source = helpers.source local pcall_err = helpers.pcall_err before_each(function() clear() - local channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + local channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) end) describe('wait()', function() @@ -61,13 +61,13 @@ describe('wait()', function() -- XXX: flaky (#11137) helpers.retry(nil, nil, function() - nvim('set_var', 'counter', 0) + api.nvim_set_var('counter', 0) eq(-1, call('wait', 20, 'Count() >= 5', 99999)) end) - nvim('set_var', 'counter', 0) + api.nvim_set_var('counter', 0) eq(0, call('wait', 10000, 'Count() >= 5', 5)) - eq(5, nvim('get_var', 'counter')) + eq(5, api.nvim_get_var('counter')) end) it('validates args', function() diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index b83d6c4a25..051e3794a3 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -1,11 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local mkdir = helpers.mkdir local clear = helpers.clear local eq = helpers.eq -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local exc_exec = helpers.exc_exec local read_file = helpers.read_file local write_file = helpers.write_file @@ -28,26 +27,26 @@ end) after_each(function() os.remove(fname) os.remove(dfname) - luv.fs_rmdir(ddname) - luv.fs_rmdir(dname) + vim.uv.fs_rmdir(ddname) + vim.uv.fs_rmdir(dname) end) describe('writefile()', function() it('writes empty list to a file', function() eq(nil, read_file(fname)) - eq(0, funcs.writefile({}, fname)) + eq(0, fn.writefile({}, fname)) eq('', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({}, fname, 'b')) + eq(0, fn.writefile({}, fname, 'b')) eq('', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({}, fname, 'ab')) + eq(0, fn.writefile({}, fname, 'ab')) eq('', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({}, fname, 'a')) + eq(0, fn.writefile({}, fname, 'a')) eq('', read_file(fname)) end) @@ -67,41 +66,41 @@ describe('writefile()', function() it('appends to a file', function() eq(nil, read_file(fname)) - eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, fname)) + eq(0, fn.writefile({ 'abc', 'def', 'ghi' }, fname)) eq('abc\ndef\nghi\n', read_file(fname)) - eq(0, funcs.writefile({ 'jkl' }, fname, 'a')) + eq(0, fn.writefile({ 'jkl' }, fname, 'a')) eq('abc\ndef\nghi\njkl\n', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, fname, 'b')) + eq(0, fn.writefile({ 'abc', 'def', 'ghi' }, fname, 'b')) eq('abc\ndef\nghi', read_file(fname)) - eq(0, funcs.writefile({ 'jkl' }, fname, 'ab')) + eq(0, fn.writefile({ 'jkl' }, fname, 'ab')) eq('abc\ndef\nghijkl', read_file(fname)) end) it('correctly treats NLs', function() - eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'b')) + eq(0, fn.writefile({ '\na\nb\n' }, fname, 'b')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({ 'a\n\n\nb' }, fname, 'b')) + eq(0, fn.writefile({ 'a\n\n\nb' }, fname, 'b')) eq('a\0\0\0b', read_file(fname)) end) it('writes with s and S', function() - eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'bs')) + eq(0, fn.writefile({ '\na\nb\n' }, fname, 'bs')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({ 'a\n\n\nb' }, fname, 'bS')) + eq(0, fn.writefile({ 'a\n\n\nb' }, fname, 'bS')) eq('a\0\0\0b', read_file(fname)) end) it('correctly overwrites file', function() - eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'b')) + eq(0, fn.writefile({ '\na\nb\n' }, fname, 'b')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({ 'a\n' }, fname, 'b')) + eq(0, fn.writefile({ 'a\n' }, fname, 'b')) eq('a\0', read_file(fname)) end) it('shows correct file name when supplied numbers', function() - meths.set_current_dir(dname) + api.nvim_set_current_dir(dname) eq( "Vim(call):E482: Can't open file 2 for writing: illegal operation on a directory", pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail)) @@ -111,12 +110,12 @@ describe('writefile()', function() it('writefile(..., "p") creates missing parent directories', function() os.remove(dname) eq(nil, read_file(dfname)) - eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, dfname, 'p')) + eq(0, fn.writefile({ 'abc', 'def', 'ghi' }, dfname, 'p')) eq('abc\ndef\nghi\n', read_file(dfname)) os.remove(dfname) os.remove(dname) eq(nil, read_file(dfname)) - eq(0, funcs.writefile({ '\na\nb\n' }, dfname, 'pb')) + eq(0, fn.writefile({ '\na\nb\n' }, dfname, 'pb')) eq('\0a\0b\0', read_file(dfname)) os.remove(dfname) os.remove(dname) diff --git a/test/helpers.lua b/test/helpers.lua index 83f87c856b..83d7a0ece6 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -1,18 +1,19 @@ -local shared = vim local luaassert = require('luassert') local busted = require('busted') -local luv = require('luv') +local uv = vim.uv local Paths = require('test.cmakeconfig.paths') luaassert:set_parameter('TableFormatLevel', 100) local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) + +--- @param str string +--- @return string local function shell_quote(str) if string.find(str, quote_me) or str == '' then return '"' .. str:gsub('[$%%"\\]', '\\%0') .. '"' - else - return str end + return str end --- @class test.helpers @@ -24,7 +25,7 @@ local module = { --- @return string local function relpath(p) p = vim.fs.normalize(p) - local cwd = luv.cwd() + local cwd = uv.cwd() return p:gsub('^' .. cwd) end @@ -34,7 +35,7 @@ function module.isdir(path) if not path then return false end - local stat = luv.fs_stat(path) + local stat = uv.fs_stat(path) if not stat then return false end @@ -47,7 +48,7 @@ function module.isfile(path) if not path then return false end - local stat = luv.fs_stat(path) + local stat = uv.fs_stat(path) if not stat then return false end @@ -74,11 +75,6 @@ function module.popen_r(...) return io.popen(module.argss_to_cmd(...), 'r') end --- sleeps the test runner (_not_ the nvim instance) -function module.sleep(ms) - luv.sleep(ms) -end - -- Calls fn() until it succeeds, up to `max` times or until `max_ms` -- milliseconds have passed. function module.retry(max, max_ms, fn) @@ -86,18 +82,18 @@ function module.retry(max, max_ms, fn) luaassert(max_ms == nil or max_ms > 0) local tries = 1 local timeout = (max_ms and max_ms or 10000) - local start_time = luv.now() + local start_time = uv.now() while true do local status, result = pcall(fn) if status then return result end - luv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). - if (max and tries >= max) or (luv.now() - start_time > timeout) then + uv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). + if (max and tries >= max) or (uv.now() - start_time > timeout) then busted.fail(string.format('retry() attempts: %d\n%s', tries, tostring(result)), 2) end tries = tries + 1 - luv.sleep(20) -- Avoid hot loop... + uv.sleep(20) -- Avoid hot loop... end end @@ -290,7 +286,7 @@ function module.glob(initial_path, re, exc_re) local full_path = cur_path .. '/' .. e local checked_path = full_path:sub(#initial_path + 1) if (not is_excluded(checked_path)) and e:sub(1, 1) ~= '.' then - local stat = luv.fs_stat(full_path) + local stat = uv.fs_stat(full_path) if stat then local check_key = stat.dev .. ':' .. tostring(stat.ino) if not checked_files[check_key] then @@ -357,7 +353,7 @@ function module.check_logs() end function module.sysname() - local platform = luv.os_uname() + local platform = uv.os_uname() if platform and platform.sysname then return platform.sysname:lower() end @@ -377,7 +373,7 @@ function module.is_os(s) end function module.is_arch(s) - local machine = luv.os_uname().machine + local machine = uv.os_uname().machine if s == 'arm64' or s == 'aarch64' then return machine == 'arm64' or machine == 'aarch64' end @@ -949,11 +945,13 @@ function module.read_nvim_log(logfile, ci_rename) return log end +--- @param path string +--- @return string function module.mkdir(path) -- 493 is 0755 in decimal - return luv.fs_mkdir(path, 493) + return uv.fs_mkdir(path, 493) end -module = shared.tbl_extend('error', module, Paths, shared, require('test.deprecated')) +module = vim.tbl_extend('error', module, Paths, require('test.deprecated')) return module diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index edc1d7439a..8210fc2310 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -431,11 +431,11 @@ func Test_highlight_completion() " A cleared group does not show up in completions. hi Anders ctermfg=green - call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) + call assert_equal(['Aardig', 'Added', 'Anders'], getcompletion('A', 'highlight')) hi clear Aardig - call assert_equal(['Anders'], getcompletion('A', 'highlight')) + call assert_equal(['Added', 'Anders'], getcompletion('A', 'highlight')) hi clear Anders - call assert_equal([], getcompletion('A', 'highlight')) + call assert_equal(['Added'], getcompletion('A', 'highlight')) endfunc func Test_getcompletion() diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim index 88a29968fe..d277ff72df 100644 --- a/test/old/testdir/test_functions.vim +++ b/test/old/testdir/test_functions.vim @@ -2104,7 +2104,7 @@ func Test_trim() call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx")) call assert_equal("RESERVE", trim("你RESERVE好", "你好")) call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好")) - call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", )) + call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses")) diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index 96992c4d89..c72d83fa52 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -2240,7 +2240,7 @@ func Test_normal29_brace() [DATA] call assert_equal(expected, getline(1, '$')) - " Test with { in cpooptions + " Test with { in cpoptions %d call append(0, text) " Nvim: no "{" flag in 'cpoptions'. @@ -4186,4 +4186,4 @@ func Test_brace_single_line() bw! endfunc -" vim: shiftwidth=2 sts=2 expandtab +" vim: shiftwidth=2 sts=2 expandtab nofoldenable diff --git a/test/old/testdir/test_registers.vim b/test/old/testdir/test_registers.vim index 0817c123a9..bc90de806f 100644 --- a/test/old/testdir/test_registers.vim +++ b/test/old/testdir/test_registers.vim @@ -838,5 +838,88 @@ func Test_replay_charsearch_omap() bwipe! endfunc +" Make sure that y_append is correctly reset +" and the previous register is working as expected +func Test_register_y_append_reset() + new + call setline(1, ['1', + \ '2 ----------------------------------------------------', + \ '3', + \ '4', + \ '5 ----------------------------------------------------', + \ '6', + \ '7', + \ '8 ----------------------------------------------------', + \ '9', + \ '10 aaaaaaa 4.', + \ '11 Game Dbl-Figures Leaders:', + \ '12 Player Pts FG% 3P% FT% RB AS BL ST TO PF EFF', + \ '13 bbbbbbbbb 12 (50 /0 /67 )/ 7/ 3/ 0/ 2/ 3/ 4/+15', + \ '14 cccccc 12 (57 /67 /100)/ 2/ 1/ 1/ 0/ 1/ 3/+12', + \ '15 ddddddd 10 (63 /0 /0 )/ 1/ 3/ 0/ 3/ 5/ 3/ +9', + \ '16 4 5-15 0-3 2-2 5-12 1-1 3-4 33.3 0.0 100 41.7 100 75 12 14', + \ '17 F 23-55 2-10 9-11 23-52 3-13 26-29 41.8 20 81.8 44.2 23.1 89.7 57 75', + \ '18 4 3 6 3 2 3 3 4 3 3 7 3 1 4 6 -1 -1 +2 -1 -2', + \ '19 F 13 19 5 10 4 17 22 9 14 32 13 4 20 17 -1 -13 -4 -3 -3 +5']) + 11 + exe "norm! \"a5dd" + norm! j + exe "norm! \"bY" + norm! 2j + exe "norm! \"BY" + norm! 4k + norm! 5dd + norm! 3k + " The next put should put the content of the unnamed register, not of + " register b! + norm! p + call assert_equal(['1', + \ '2 ----------------------------------------------------', + \ '3', + \ '4', + \ '5 ----------------------------------------------------', + \ '6', + \ '10 aaaaaaa 4.', + \ '16 4 5-15 0-3 2-2 5-12 1-1 3-4 33.3 0.0 100 41.7 100 75 12 14', + \ '17 F 23-55 2-10 9-11 23-52 3-13 26-29 41.8 20 81.8 44.2 23.1 89.7 57 75', + \ '18 4 3 6 3 2 3 3 4 3 3 7 3 1 4 6 -1 -1 +2 -1 -2', + \ '19 F 13 19 5 10 4 17 22 9 14 32 13 4 20 17 -1 -13 -4 -3 -3 +5', + \ '7', + \ '8 ----------------------------------------------------', + \ '9'], getline(1,'$')) + bwipe! +endfunc + +func Test_insert_small_delete_replace_mode() + new + call setline(1, ['foo', 'bar', 'foobar', 'bar']) + let @- = 'foo' + call cursor(2, 1) + exe ":norm! R\<C-R>-\<C-R>-" + call assert_equal('foofoo', getline(2)) + call cursor(3, 1) + norm! D + call assert_equal(['foo', 'foofoo', '', 'bar'], getline(1, 4)) + call cursor(4, 2) + exe ":norm! R\<C-R>-ZZZZ" + call assert_equal(['foo', 'foofoo', '', 'bfoobarZZZZ'], getline(1, 4)) + call cursor(1, 1) + let @- = '' + exe ":norm! R\<C-R>-ZZZ" + call assert_equal(['ZZZ', 'foofoo', '', 'bfoobarZZZZ'], getline(1, 4)) + let @- = 'βbβ' + call cursor(4, 1) + exe ":norm! R\<C-R>-" + call assert_equal(['ZZZ', 'foofoo', '', 'βbβobarZZZZ'], getline(1, 4)) + let @- = 'bβb' + call cursor(4, 1) + exe ":norm! R\<C-R>-" + call assert_equal(['ZZZ', 'foofoo', '', 'bβbobarZZZZ'], getline(1, 4)) + let @- = 'βbβ' + call cursor(4, 1) + exe ":norm! R\<C-R>-" + call assert_equal(['ZZZ', 'foofoo', '', 'βbβobarZZZZ'], getline(1, 4)) + bwipe! +endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index da70b8feba..6edd164438 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -14,7 +14,7 @@ local cimport = helpers.cimport local to_cstr = helpers.to_cstr local alloc_log_new = helpers.alloc_log_new local concat_tables = helpers.concat_tables -local map = helpers.tbl_map +local map = vim.tbl_map local a = eval_helpers.alloc_logging_helpers local int = eval_helpers.int diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 86d02e8c31..47499d98fa 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -10,9 +10,9 @@ local say = require('say') local check_cores = global_helpers.check_cores local dedent = global_helpers.dedent local neq = global_helpers.neq -local map = global_helpers.tbl_map +local map = vim.tbl_map local eq = global_helpers.eq -local trim = global_helpers.trim +local trim = vim.trim -- add some standard header locations for _, p in ipairs(Paths.include_paths) do @@ -904,7 +904,7 @@ local module = { is_asan = is_asan, } --- @class test.unit.helpers: test.unit.helpers.module, test.helpers -module = global_helpers.tbl_extend('error', module, global_helpers) +module = vim.tbl_extend('error', module, global_helpers) return function() return module diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua index 30e4fad88f..385f4fa4b0 100644 --- a/test/unit/os/fileio_spec.lua +++ b/test/unit/os/fileio_spec.lua @@ -1,4 +1,4 @@ -local luv = require('luv') +local uv = vim.uv local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) @@ -36,8 +36,8 @@ before_each(function() f2:write(fcontents) f2:close() - luv.fs_symlink('file1.dat', linkf) - luv.fs_symlink('broken.dat', linkb) + uv.fs_symlink('file1.dat', linkf) + uv.fs_symlink('broken.dat', linkb) end) after_each(function() @@ -46,7 +46,7 @@ after_each(function() os.remove(linkf) os.remove(linkb) os.remove(filec) - luv.fs_rmdir(dir) + uv.fs_rmdir(dir) end) local function file_open(fname, flags, mode) @@ -120,13 +120,13 @@ describe('file_open_fd', function() eq(0, m.file_close(fp, false)) end) itp('can use file descriptor returned by os_open for writing', function() - eq(nil, luv.fs_stat(filec)) + eq(nil, uv.fs_stat(filec)) local fd = m.os_open(filec, m.kO_WRONLY + m.kO_CREAT, 384) local err, fp = file_open_fd(fd, m.kFileWriteOnly) eq(0, err) eq(4, file_write(fp, 'test')) eq(0, m.file_close(fp, false)) - eq(4, luv.fs_stat(filec).size) + eq(4, uv.fs_stat(filec).size) eq('test', io.open(filec):read('*a')) end) end) @@ -140,13 +140,13 @@ describe('file_open_fd_new', function() eq(0, m.file_free(fp, false)) end) itp('can use file descriptor returned by os_open for writing', function() - eq(nil, luv.fs_stat(filec)) + eq(nil, uv.fs_stat(filec)) local fd = m.os_open(filec, m.kO_WRONLY + m.kO_CREAT, 384) local err, fp = file_open_fd_new(fd, m.kFileWriteOnly) eq(0, err) eq(4, file_write(fp, 'test')) eq(0, m.file_free(fp, false)) - eq(4, luv.fs_stat(filec).size) + eq(4, uv.fs_stat(filec).size) eq('test', io.open(filec):read('*a')) end) end) @@ -155,7 +155,7 @@ describe('file_open', function() itp('can create a rwx------ file with kFileCreate', function() local err, fp = file_open(filec, m.kFileCreate, 448) eq(0, err) - local attrs = luv.fs_stat(filec) + local attrs = uv.fs_stat(filec) eq(33216, attrs.mode) eq(0, m.file_close(fp, false)) end) @@ -163,7 +163,7 @@ describe('file_open', function() itp('can create a rw------- file with kFileCreate', function() local err, fp = file_open(filec, m.kFileCreate, 384) eq(0, err) - local attrs = luv.fs_stat(filec) + local attrs = uv.fs_stat(filec) eq(33152, attrs.mode) eq(0, m.file_close(fp, false)) end) @@ -171,7 +171,7 @@ describe('file_open', function() itp('can create a rwx------ file with kFileCreateOnly', function() local err, fp = file_open(filec, m.kFileCreateOnly, 448) eq(0, err) - local attrs = luv.fs_stat(filec) + local attrs = uv.fs_stat(filec) eq(33216, attrs.mode) eq(0, m.file_close(fp, false)) end) @@ -179,7 +179,7 @@ describe('file_open', function() itp('can create a rw------- file with kFileCreateOnly', function() local err, fp = file_open(filec, m.kFileCreateOnly, 384) eq(0, err) - local attrs = luv.fs_stat(filec) + local attrs = uv.fs_stat(filec) eq(33152, attrs.mode) eq(0, m.file_close(fp, false)) end) @@ -231,7 +231,7 @@ describe('file_open', function() eq(0, err) eq(true, fp.wr) eq(0, m.file_close(fp, false)) - local attrs = luv.fs_stat(file1) + local attrs = uv.fs_stat(file1) eq(0, attrs.size) end) @@ -240,14 +240,14 @@ describe('file_open', function() eq(0, err) eq(true, fp.wr) eq(0, m.file_close(fp, false)) - local attrs = luv.fs_stat(file1) + local attrs = uv.fs_stat(file1) eq(4096, attrs.size) end) itp('fails to create a file with just kFileWriteOnly', function() local err, _ = file_open(filec, m.kFileWriteOnly, 384) eq(m.UV_ENOENT, err) - local attrs = luv.fs_stat(filec) + local attrs = uv.fs_stat(filec) eq(nil, attrs) end) @@ -256,7 +256,7 @@ describe('file_open', function() eq(0, err) eq(true, fp.wr) eq(0, m.file_close(fp, false)) - local attrs = luv.fs_stat(file1) + local attrs = uv.fs_stat(file1) eq(0, attrs.size) end) @@ -297,9 +297,9 @@ describe('file_close', function() eq(0, err) local wsize = file_write(fp, 'test') eq(4, wsize) - eq(0, luv.fs_stat(filec).size) + eq(0, uv.fs_stat(filec).size) eq(0, m.file_close(fp, true)) - eq(wsize, luv.fs_stat(filec).size) + eq(wsize, uv.fs_stat(filec).size) end) end) @@ -309,9 +309,9 @@ describe('file_free', function() eq(0, err) local wsize = file_write(fp, 'test') eq(4, wsize) - eq(0, luv.fs_stat(filec).size) + eq(0, uv.fs_stat(filec).size) eq(0, m.file_free(fp, true)) - eq(wsize, luv.fs_stat(filec).size) + eq(wsize, uv.fs_stat(filec).size) end) end) @@ -320,12 +320,12 @@ describe('file_fsync', function() local err, fp = file_open(filec, m.kFileCreateOnly, 384) eq(0, file_fsync(fp)) eq(0, err) - eq(0, luv.fs_stat(filec).size) + eq(0, uv.fs_stat(filec).size) local wsize = file_write(fp, 'test') eq(4, wsize) - eq(0, luv.fs_stat(filec).size) + eq(0, uv.fs_stat(filec).size) eq(0, file_fsync(fp)) - eq(wsize, luv.fs_stat(filec).size) + eq(wsize, uv.fs_stat(filec).size) eq(0, m.file_close(fp, false)) end) end) @@ -335,12 +335,12 @@ describe('file_flush', function() local err, fp = file_open(filec, m.kFileCreateOnly, 384) eq(0, file_flush(fp)) eq(0, err) - eq(0, luv.fs_stat(filec).size) + eq(0, uv.fs_stat(filec).size) local wsize = file_write(fp, 'test') eq(4, wsize) - eq(0, luv.fs_stat(filec).size) + eq(0, uv.fs_stat(filec).size) eq(0, file_flush(fp)) - eq(wsize, luv.fs_stat(filec).size) + eq(wsize, uv.fs_stat(filec).size) eq(0, m.file_close(fp, false)) end) end) @@ -411,7 +411,7 @@ describe('file_write', function() local wr = file_write(fp, fcontents) eq(#fcontents, wr) eq(0, m.file_close(fp, false)) - eq(wr, luv.fs_stat(filec).size) + eq(wr, uv.fs_stat(filec).size) eq(fcontents, io.open(filec):read('*a')) end) @@ -428,7 +428,7 @@ describe('file_write', function() shift = shift + size end eq(0, m.file_close(fp, false)) - eq(#fcontents, luv.fs_stat(filec).size) + eq(#fcontents, uv.fs_stat(filec).size) eq(fcontents, io.open(filec):read('*a')) end) @@ -445,7 +445,7 @@ describe('file_write', function() shift = shift + size end eq(0, m.file_close(fp, false)) - eq(#fcontents, luv.fs_stat(filec).size) + eq(#fcontents, uv.fs_stat(filec).size) eq(fcontents, io.open(filec):read('*a')) end) end) diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index e635fc9667..c15cd12fef 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -1,4 +1,4 @@ -local luv = require('luv') +local uv = vim.uv local bit = require('bit') local helpers = require('test.unit.helpers')(after_each) @@ -17,7 +17,7 @@ local OK = helpers.OK local FAIL = helpers.FAIL local NULL = helpers.NULL local mkdir = helpers.mkdir -local endswith = helpers.endswith +local endswith = vim.endswith local NODE_NORMAL = 0 local NODE_WRITABLE = 1 @@ -46,11 +46,11 @@ local function unset_bit(number, to_unset) end local function assert_file_exists(filepath) - neq(nil, luv.fs_stat(filepath)) + neq(nil, uv.fs_stat(filepath)) end local function assert_file_does_not_exist(filepath) - eq(nil, luv.fs_stat(filepath)) + eq(nil, uv.fs_stat(filepath)) end local function os_setperm(filename, perm) @@ -73,9 +73,9 @@ describe('fs.c', function() io.open('unit-test-directory/test.file', 'w'):close() io.open('unit-test-directory/test_2.file', 'w'):close() - luv.fs_symlink('test.file', 'unit-test-directory/test_link.file') + uv.fs_symlink('test.file', 'unit-test-directory/test_link.file') - luv.fs_symlink('non_existing_file.file', 'unit-test-directory/test_broken_link.file') + uv.fs_symlink('non_existing_file.file', 'unit-test-directory/test_broken_link.file') -- The tests are invoked with an absolute path to `busted` executable. absolute_executable = arg[0] -- Split the absolute_executable path into a directory and filename. @@ -88,19 +88,19 @@ describe('fs.c', function() os.remove('unit-test-directory/test_link.file') os.remove('unit-test-directory/test_hlink.file') os.remove('unit-test-directory/test_broken_link.file') - luv.fs_rmdir('unit-test-directory') + uv.fs_rmdir('unit-test-directory') end) describe('os_dirname', function() itp('returns OK and writes current directory to the buffer', function() - local length = string.len(luv.cwd()) + 1 + local length = string.len(uv.cwd()) + 1 local buf = cstr(length, '') eq(OK, fs.os_dirname(buf, length)) - eq(luv.cwd(), ffi.string(buf)) + eq(uv.cwd(), ffi.string(buf)) end) itp('returns FAIL if the buffer is too small', function() - local length = string.len(luv.cwd()) + 1 + local length = string.len(uv.cwd()) + 1 local buf = cstr(length - 1, '') eq(FAIL, fs.os_dirname(buf, length - 1)) end) @@ -201,20 +201,20 @@ describe('fs.c', function() end) itp('returns the absolute path when given an executable relative to the current dir', function() - local old_dir = luv.cwd() + local old_dir = uv.cwd() - luv.chdir(directory) + uv.chdir(directory) -- Rely on currentdir to resolve symlinks, if any. Testing against -- the absolute path taken from arg[0] may result in failure where -- the path has a symlink in it. - local canonical = luv.cwd() .. '/' .. executable_name + local canonical = uv.cwd() .. '/' .. executable_name local expected = exe(canonical) local relative_executable = './' .. executable_name local res = exe(relative_executable) -- Don't test yet; we need to chdir back first. - luv.chdir(old_dir) + uv.chdir(old_dir) eq(expected, res) end) end) @@ -276,11 +276,11 @@ describe('fs.c', function() describe('os_fchown', function() local filename = 'unit-test-directory/test.file' itp('does not change owner and group if respective IDs are equal to -1', function() - local uid = luv.fs_stat(filename).uid - local gid = luv.fs_stat(filename).gid + local uid = uv.fs_stat(filename).uid + local gid = uv.fs_stat(filename).gid eq(0, os_fchown(filename, -1, -1)) - eq(uid, luv.fs_stat(filename).uid) - return eq(gid, luv.fs_stat(filename).gid) + eq(uid, uv.fs_stat(filename).uid) + return eq(gid, uv.fs_stat(filename).gid) end) -- Some systems may not have `id` utility. @@ -290,7 +290,7 @@ describe('fs.c', function() itp( 'owner of a file may change the group of the file to any group of which that owner is a member', function() - local file_gid = luv.fs_stat(filename).gid + local file_gid = uv.fs_stat(filename).gid -- Gets ID of any group of which current user is a member except the -- group that owns the file. @@ -305,7 +305,7 @@ describe('fs.c', function() -- In that case we can not perform this test. if new_gid then eq(0, (os_fchown(filename, -1, new_gid))) - eq(new_gid, luv.fs_stat(filename).gid) + eq(new_gid, uv.fs_stat(filename).gid) end end ) @@ -554,7 +554,7 @@ describe('fs.c', function() --create the file local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber('700', 8)) --verify permissions - eq(33216, luv.fs_stat(new_file).mode) + eq(33216, uv.fs_stat(new_file).mode) eq(0, os_close(fd)) end) @@ -563,7 +563,7 @@ describe('fs.c', function() --create the file local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber('600', 8)) --verify permissions - eq(33152, luv.fs_stat(new_file).mode) + eq(33152, uv.fs_stat(new_file).mode) eq(0, os_close(fd)) end) @@ -793,7 +793,7 @@ describe('fs.c', function() eq(false, (os_isdir('unit-test-directory/new-dir'))) eq(0, (os_mkdir('unit-test-directory/new-dir', mode))) eq(true, (os_isdir('unit-test-directory/new-dir'))) - luv.fs_rmdir('unit-test-directory/new-dir') + uv.fs_rmdir('unit-test-directory/new-dir') end) end) @@ -831,7 +831,7 @@ describe('fs.c', function() eq(nil, failed_dir) ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse')) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) - luv.fs_rmdir('unit-test-directory/new-dir-recurse') + uv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) @@ -843,7 +843,7 @@ describe('fs.c', function() eq(nil, failed_dir) ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse')) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) - luv.fs_rmdir('unit-test-directory/new-dir-recurse') + uv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) @@ -855,7 +855,7 @@ describe('fs.c', function() eq(nil, failed_dir) ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse')) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) - luv.fs_rmdir('unit-test-directory/new-dir-recurse') + uv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) @@ -870,10 +870,10 @@ describe('fs.c', function() eq(true, os_isdir('unit-test-directory/new-dir-recurse/1')) eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2')) eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2/3')) - luv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2/3') - luv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2') - luv.fs_rmdir('unit-test-directory/new-dir-recurse/1') - luv.fs_rmdir('unit-test-directory/new-dir-recurse') + uv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2/3') + uv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2') + uv.fs_rmdir('unit-test-directory/new-dir-recurse/1') + uv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) end) @@ -1038,7 +1038,7 @@ describe('fs.c', function() file:write('some bytes to get filesize != 0') file:flush() file:close() - local size = luv.fs_stat(path).size + local size = uv.fs_stat(path).size local info = file_info_new() assert.is_true(fs.os_fileinfo(path, info)) eq(size, fs.os_fileinfo_size(info)) @@ -1052,7 +1052,7 @@ describe('fs.c', function() local info = file_info_new() assert.is_true(fs.os_fileinfo(path, info)) eq(1, fs.os_fileinfo_hardlinks(info)) - luv.fs_link(path, path_link) + uv.fs_link(path, path_link) assert.is_true(fs.os_fileinfo(path, info)) eq(2, fs.os_fileinfo_hardlinks(info)) end) @@ -1061,7 +1061,7 @@ describe('fs.c', function() describe('os_fileinfo_blocksize', function() itp('returns the correct blocksize of a file', function() local path = 'unit-test-directory/test.file' - local blksize = luv.fs_stat(path).blksize + local blksize = uv.fs_stat(path).blksize local info = file_info_new() assert.is_true(fs.os_fileinfo(path, info)) if blksize then diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 3ed25b0ba7..c564ec119e 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -1,4 +1,4 @@ -local luv = require('luv') +local uv = vim.uv local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) @@ -27,7 +27,7 @@ describe('path.c', function() end) teardown(function() - luv.fs_rmdir('unit-test-directory') + uv.fs_rmdir('unit-test-directory') end) local function path_full_dir_name(directory, buf, len) @@ -37,34 +37,34 @@ describe('path.c', function() before_each(function() -- Create empty string buffer which will contain the resulting path. - length = string.len(luv.cwd()) + 22 + length = string.len(uv.cwd()) + 22 buffer = cstr(length, '') end) itp('returns the absolute directory name of a given relative one', function() local result = path_full_dir_name('..', buffer, length) eq(OK, result) - local old_dir = luv.cwd() - luv.chdir('..') - local expected = luv.cwd() - luv.chdir(old_dir) + local old_dir = uv.cwd() + uv.chdir('..') + local expected = uv.cwd() + uv.chdir(old_dir) eq(expected, (ffi.string(buffer))) end) itp('returns the current directory name if the given string is empty', function() eq(OK, (path_full_dir_name('', buffer, length))) - eq(luv.cwd(), (ffi.string(buffer))) + eq(uv.cwd(), (ffi.string(buffer))) end) itp('works with a normal relative dir', function() local result = path_full_dir_name('unit-test-directory', buffer, length) - eq(luv.cwd() .. '/unit-test-directory', (ffi.string(buffer))) + eq(uv.cwd() .. '/unit-test-directory', (ffi.string(buffer))) eq(OK, result) end) itp('works with a non-existing relative dir', function() local result = path_full_dir_name('does-not-exist', buffer, length) - eq(luv.cwd() .. '/does-not-exist', (ffi.string(buffer))) + eq(uv.cwd() .. '/does-not-exist', (ffi.string(buffer))) eq(OK, result) end) @@ -270,27 +270,27 @@ describe('path.c', function() end) describe('path_try_shorten_fname', function() - local cwd = luv.cwd() + local cwd = uv.cwd() before_each(function() mkdir('ut_directory') end) after_each(function() - luv.chdir(cwd) - luv.fs_rmdir('ut_directory') + uv.chdir(cwd) + uv.fs_rmdir('ut_directory') end) describe('path_try_shorten_fname', function() itp('returns shortened path if possible', function() - luv.chdir('ut_directory') - local full = to_cstr(luv.cwd() .. '/subdir/file.txt') + uv.chdir('ut_directory') + local full = to_cstr(uv.cwd() .. '/subdir/file.txt') eq('subdir/file.txt', (ffi.string(cimp.path_try_shorten_fname(full)))) end) itp('returns `full_path` if a shorter version is not possible', function() - local old = luv.cwd() - luv.chdir('ut_directory') + local old = uv.cwd() + uv.chdir('ut_directory') local full = old .. '/subdir/file.txt' eq(full, (ffi.string(cimp.path_try_shorten_fname(to_cstr(full))))) end) @@ -302,7 +302,7 @@ describe('path_try_shorten_fname', function() end) describe('path.c path_guess_exepath', function() - local cwd = luv.cwd() + local cwd = uv.cwd() for _, name in ipairs({ './nvim', '.nvim', 'foo/nvim' }) do itp('"' .. name .. '" returns name catenated with CWD', function() @@ -370,7 +370,7 @@ describe('path.c', function() teardown(function() os.remove('unit-test-directory/test.file') - luv.fs_rmdir('unit-test-directory') + uv.fs_rmdir('unit-test-directory') end) describe('vim_FullName', function() @@ -422,7 +422,7 @@ describe('path.c', function() end) itp('concatenates filename if it does not contain a slash', function() - local expected = luv.cwd() .. '/test.file' + local expected = uv.cwd() .. '/test.file' local filename = 'test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -432,7 +432,7 @@ describe('path.c', function() end) itp('concatenates directory name if it does not contain a slash', function() - local expected = luv.cwd() .. '/..' + local expected = uv.cwd() .. '/..' local filename = '..' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -444,10 +444,10 @@ describe('path.c', function() itp( 'enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', function() - local old_dir = luv.cwd() - luv.chdir('..') - local expected = luv.cwd() .. '/test.file' - luv.chdir(old_dir) + local old_dir = uv.cwd() + uv.chdir('..') + local expected = uv.cwd() .. '/test.file' + uv.chdir(old_dir) local filename = '../test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -477,7 +477,7 @@ describe('path.c', function() end) itp('works with some "normal" relative path with directories', function() - local expected = luv.cwd() .. '/unit-test-directory/test.file' + local expected = uv.cwd() .. '/unit-test-directory/test.file' local filename = 'unit-test-directory/test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -487,7 +487,7 @@ describe('path.c', function() end) itp('does not modify the given filename', function() - local expected = luv.cwd() .. '/unit-test-directory/test.file' + local expected = uv.cwd() .. '/unit-test-directory/test.file' local filename = to_cstr('unit-test-directory/test.file') local buflen = string.len(expected) + 1 local buf = cstr(buflen, '') @@ -510,7 +510,7 @@ describe('path.c', function() end) itp('does not remove trailing slash from non-existing relative directory #20847', function() - local expected = luv.cwd() .. '/non_existing_dir/' + local expected = uv.cwd() .. '/non_existing_dir/' local filename = 'non_existing_dir/' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -520,7 +520,7 @@ describe('path.c', function() end) itp('expands "./" to the current directory #7117', function() - local expected = luv.cwd() .. '/unit-test-directory/test.file' + local expected = uv.cwd() .. '/unit-test-directory/test.file' local filename = './unit-test-directory/test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -530,7 +530,7 @@ describe('path.c', function() end) itp('collapses "foo/../foo" to "foo" #7117', function() - local expected = luv.cwd() .. '/unit-test-directory/test.file' + local expected = uv.cwd() .. '/unit-test-directory/test.file' local filename = 'unit-test-directory/../unit-test-directory/test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -551,7 +551,7 @@ describe('path.c', function() mkdir('CamelCase') end) after_each(function() - luv.fs_rmdir('CamelCase') + uv.fs_rmdir('CamelCase') end) if ffi.os == 'Windows' or ffi.os == 'OSX' then diff --git a/test/unit/undo_spec.lua b/test/unit/undo_spec.lua index 220a4733df..0e2f38a8c8 100644 --- a/test/unit/undo_spec.lua +++ b/test/unit/undo_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) -local luv = require('luv') +local uv = vim.uv local child_call_once = helpers.child_call_once -local sleep = helpers.sleep +local sleep = uv.sleep local ffi = helpers.ffi local cimport = helpers.cimport @@ -42,13 +42,13 @@ end) describe('u_write_undo', function() setup(function() mkdir('unit-test-directory') - luv.chdir('unit-test-directory') - options.p_udir = to_cstr(luv.cwd()) -- set p_udir to be the test dir + uv.chdir('unit-test-directory') + options.p_udir = to_cstr(uv.cwd()) -- set p_udir to be the test dir end) teardown(function() - luv.chdir('..') - local success, err = luv.fs_rmdir('unit-test-directory') + uv.chdir('..') + local success, err = uv.fs_rmdir('unit-test-directory') if not success then print(err) -- inform tester if directory fails to delete end @@ -99,7 +99,7 @@ describe('u_write_undo', function() local test_permission_file = io.open(test_file_name, 'w') test_permission_file:write('testing permissions') test_permission_file:close() - local test_permissions = luv.fs_stat(test_file_name).mode + local test_permissions = uv.fs_stat(test_file_name).mode -- Create vim buffer local c_file = to_cstr(test_file_name) @@ -112,7 +112,7 @@ describe('u_write_undo', function() local undo_file_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false)) -- Find out the permissions of the new file - local permissions = luv.fs_stat(undo_file_name).mode + local permissions = uv.fs_stat(undo_file_name).mode eq(test_permissions, permissions) -- delete the file now that we're done with it. @@ -137,7 +137,7 @@ describe('u_write_undo', function() u_write_undo(undo_file_name, false, file_buffer, buffer_hash) -- Find out the permissions of the new file - local permissions = luv.fs_stat(undo_file_name).mode + local permissions = uv.fs_stat(undo_file_name).mode eq(correct_permissions, permissions) -- delete the file now that we're done with it. @@ -169,13 +169,13 @@ describe('u_write_undo', function() u_write_undo(nil, false, file_buffer, buffer_hash) local correct_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false)) - local file_last_modified = luv.fs_stat(correct_name).mtime.sec + local file_last_modified = uv.fs_stat(correct_name).mtime.sec sleep(1000) -- Ensure difference in timestamps. file_buffer.b_u_numhead = 1 -- Mark it as if there are changes u_write_undo(nil, false, file_buffer, buffer_hash) - local file_last_modified_2 = luv.fs_stat(correct_name).mtime.sec + local file_last_modified_2 = uv.fs_stat(correct_name).mtime.sec -- print(file_last_modified, file_last_modified_2) neq(file_last_modified, file_last_modified_2) |