aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/vim_spec.lua
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@protonmail.com>2021-10-19 01:44:17 +0600
committerGitHub <noreply@github.com>2021-10-18 12:44:17 -0700
commit9086938f7bd6d6ccb7f4a30fb78aeaf0d84e4471 (patch)
tree9e286903da8123085956beaf7eb9dd33e5741aad /test/functional/api/vim_spec.lua
parente7ea54a3dfaf937021e68bc690c4d27eed9c1cca (diff)
downloadrneovim-9086938f7bd6d6ccb7f4a30fb78aeaf0d84e4471.tar.gz
rneovim-9086938f7bd6d6ccb7f4a30fb78aeaf0d84e4471.tar.bz2
rneovim-9086938f7bd6d6ccb7f4a30fb78aeaf0d84e4471.zip
feat(api): evaluate statusline string #16020
Adds API function `nvim_eval_statusline` to allow evaluating a statusline string and obtaining information regarding it. Closes https://github.com/neovim/neovim/issues/15849
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r--test/functional/api/vim_spec.lua75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index d8914a3ab7..f030cfe00e 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -2367,4 +2367,79 @@ describe('API', function()
eq({2, 2, buf.id, mark[4]}, mark)
end)
end)
+ describe('nvim_eval_statusline', function()
+ it('works', function()
+ eq({
+ str = '%StatusLineStringWithHighlights',
+ width = 31
+ },
+ meths.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 }))
+ end)
+ describe('highlight parsing', function()
+ it('works', function()
+ eq({
+ str = "TextWithWarningHighlightTextWithUserHighlight",
+ width = 45,
+ highlights = {
+ { start = 0, group = 'WarningMsg' },
+ { start = 24, group = 'User1' }
+ },
+ },
+ meths.eval_statusline(
+ '%#WarningMsg#TextWithWarningHighlight%1*TextWithUserHighlight',
+ { highlights = true }))
+ end)
+ it('works with no highlight', function()
+ eq({
+ str = "TextWithNoHighlight",
+ width = 19,
+ highlights = {
+ { start = 0, group = 'StatusLine' },
+ },
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight',
+ { highlights = true }))
+ end)
+ it('works with inactive statusline', function()
+ command('split')
+
+ eq({
+ str = 'TextWithNoHighlightTextWithWarningHighlight',
+ width = 43,
+ highlights = {
+ { start = 0, group = 'StatusLineNC' },
+ { start = 19, group = 'WarningMsg' }
+ }
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
+ { winid = meths.list_wins()[2].id, highlights = true }))
+ end)
+ it('works with tabline', function()
+ eq({
+ str = 'TextWithNoHighlightTextWithWarningHighlight',
+ width = 43,
+ highlights = {
+ { start = 0, group = 'TabLineFill' },
+ { start = 19, group = 'WarningMsg' }
+ }
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
+ { use_tabline = true, highlights = true }))
+ end)
+ end)
+ end)
end)