diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2017-08-16 12:19:29 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2017-10-26 20:28:47 +0200 |
commit | 22402fb99d05191cf140293cfb5f67902e78a8a8 (patch) | |
tree | 29868ae79bee033268489db3d0755d0393b7a581 /test/functional/ui/cmdline_spec.lua | |
parent | 5ad591ef2d0ef184f78c728b1774c2a55fe2e581 (diff) | |
download | rneovim-22402fb99d05191cf140293cfb5f67902e78a8a8.tar.gz rneovim-22402fb99d05191cf140293cfb5f67902e78a8a8.tar.bz2 rneovim-22402fb99d05191cf140293cfb5f67902e78a8a8.zip |
ext_cmdline: add support for highlighting
Diffstat (limited to 'test/functional/ui/cmdline_spec.lua')
-rw-r--r-- | test/functional/ui/cmdline_spec.lua | 77 |
1 files changed, 71 insertions, 6 deletions
diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 1e30ba1449..8d694052ee 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq +local source = helpers.source if helpers.pending_win32(pending) then return end @@ -36,6 +37,22 @@ describe('External command line completion', function() screen:detach() end) + function expect_cmdline(expected) + local attr_ids = screen._default_attr_ids + local attr_ignore = screen._default_attr_ignore + local actual = '' + for _, chunk in ipairs(content or {}) do + local attrs, text = chunk[1], chunk[2] + if screen:_equal_attrs(attrs, {}) then + actual = actual..text + else + local attr_id = screen:_get_attr_id(attr_ids, attr_ignore, attrs) + actual = actual..'{' .. attr_id .. ':' .. text .. '}' + end + end + eq(expected, actual) + end + describe("'cmdline'", function() it(':sign', function() feed(':') @@ -58,7 +75,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq({{'Normal', 'sign'}}, content) + eq({{{}, 'sign'}}, content) eq(4, pos) end) @@ -70,7 +87,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq({{'Normal', 'sign'}}, content) + eq({{{}, 'sign'}}, content) eq(true, shown) eq(3, pos) end) @@ -83,7 +100,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq({{'Normal', 'sin'}}, content) + eq({{{}, 'sin'}}, content) eq(true, shown) eq(2, pos) end) @@ -109,7 +126,7 @@ describe('External command line completion', function() ]], nil, nil, function() eq(true, shown) eq("input", prompt) - eq({{'Normal', 'default'}}, content) + eq({{{}, 'default'}}, content) end) feed('<cr>') @@ -132,7 +149,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq({{'Normal', '1+2'}}, content) + eq({{{}, '1+2'}}, content) eq("\"", char) eq(1, shift) eq(2, level) @@ -146,7 +163,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq({{'Normal', '3'}}, content) + eq({{{}, '3'}}, content) eq(2, current_hide_level) eq(1, level) end) @@ -210,4 +227,52 @@ describe('External command line completion', function() end) end) + + it('works with highlighted cmdline', function() + source([[ + highlight RBP1 guibg=Red + highlight RBP2 guibg=Yellow + highlight RBP3 guibg=Green + highlight RBP4 guibg=Blue + let g:NUM_LVLS = 4 + function RainBowParens(cmdline) + let ret = [] + let i = 0 + let lvl = 0 + while i < len(a:cmdline) + if a:cmdline[i] is# '(' + call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)]) + let lvl += 1 + elseif a:cmdline[i] is# ')' + let lvl -= 1 + call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)]) + endif + let i += 1 + endwhile + return ret + endfunction + map <f5> :let x = input({'prompt':'>','highlight':'RainBowParens'})<cr> + "map <f5> :let x = input({'prompt':'>'})<cr> + ]]) + screen:set_default_attr_ids({ + RBP1={background = Screen.colors.Red}, + RBP2={background = Screen.colors.Yellow}, + RBP3={background = Screen.colors.Green}, + RBP4={background = Screen.colors.Blue}, + EOB={bold = true, foreground = Screen.colors.Blue1}, + ERR={foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + SK={foreground = Screen.colors.Blue}, + PE={bold = true, foreground = Screen.colors.SeaGreen4} + }) + feed('<f5>(a(b)a)') + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]], nil, nil, function() + expect_cmdline('{RBP1:(}a{RBP2:(}b{RBP2:)}a{RBP1:)}') + end) + end) end) |