From 26fd70bd18283701a2ade11407694485cd0f7e35 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Fri, 24 Feb 2017 07:26:39 +0000 Subject: ext_cmdline: add tests --- test/functional/ui/cmdline_spec.lua | 128 ++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 test/functional/ui/cmdline_spec.lua (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua new file mode 100644 index 0000000000..67eff9827c --- /dev/null +++ b/test/functional/ui/cmdline_spec.lua @@ -0,0 +1,128 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear, feed, execute, eq = helpers.clear, helpers.feed, helpers.execute, helpers.eq +local funcs = helpers.funcs + +if helpers.pending_win32(pending) then return end + +describe('External command line completion', function() + local screen + local shown = false + local firstc, prompt, content, pos + + before_each(function() + clear() + screen = Screen.new(25, 5) + screen:attach({rgb=true, cmdline_external=true}) + screen:set_on_event_handler(function(name, data) + if name == "cmdline_enter" then + shown = true + elseif name == "cmdline_leave" then + shown = false + elseif name == "cmdline_firstc" then + firstc = data[1] + elseif name == "cmdline_prompt" then + prompt = data[1] + elseif name == "cmdline" then + content, pos = unpack(data) + elseif name == "cmdline_pos" then + pos = data[1] + end + end) + end) + + after_each(function() + screen:detach() + end) + + describe("'cmdline'", function() + it(':sign', function() + feed(':') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(true, shown) + eq(':', firstc) + end) + + feed('sign') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq("sign", content) + eq(4, pos) + end) + + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq("sign", content) + eq(true, shown) + eq(3, pos) + end) + + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq("sin", content) + eq(true, shown) + eq(2, pos) + end) + + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(false, shown) + end) + + feed(':call input("input", "default")') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(true, shown) + eq("input", prompt) + eq("default", content) + end) + + feed('') + feed(':=1+2') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq("3", content) + end) + + end) + end) +end) -- cgit From b7a8a76f6e3b2de1cfdf32e3ccc66d87ab8e5cad Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 27 Feb 2017 02:56:38 +0000 Subject: ext_cmdline: lint --- test/functional/ui/cmdline_spec.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 67eff9827c..d0726f5924 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1,7 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, execute, eq = helpers.clear, helpers.feed, helpers.execute, helpers.eq -local funcs = helpers.funcs +local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq if helpers.pending_win32(pending) then return end -- cgit From 550651c130c014e6c668644273db31dd96be475e Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Fri, 28 Apr 2017 06:51:16 +0100 Subject: ext_cmdline: use standard external ui functions --- test/functional/ui/cmdline_spec.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index d0726f5924..35cacbf4d0 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -7,23 +7,21 @@ if helpers.pending_win32(pending) then return end describe('External command line completion', function() local screen local shown = false - local firstc, prompt, content, pos + local firstc, prompt, content, pos, char, shift before_each(function() clear() screen = Screen.new(25, 5) - screen:attach({rgb=true, cmdline_external=true}) + screen:attach({rgb=true, ext_cmdline=true}) screen:set_on_event_handler(function(name, data) if name == "cmdline_enter" then shown = true elseif name == "cmdline_leave" then shown = false - elseif name == "cmdline_firstc" then - firstc = data[1] - elseif name == "cmdline_prompt" then - prompt = data[1] - elseif name == "cmdline" then - content, pos = unpack(data) + elseif name == "cmdline_show" then + content, pos, firstc, prompt = unpack(data) + elseif name == "cmdline_char" then + char, shift = unpack(data) elseif name == "cmdline_pos" then pos = data[1] end @@ -120,6 +118,8 @@ describe('External command line completion', function() | ]], nil, nil, function() eq("3", content) + eq("\"", char) + eq(1, shift) end) end) -- cgit From daec81ab5179c7ce8e3813af556b1e2f05fc59c6 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Fri, 28 Apr 2017 07:49:45 +0100 Subject: ext_cmdline: change the content format --- test/functional/ui/cmdline_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 35cacbf4d0..523f7065d4 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -54,7 +54,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq("sign", content) + eq({{'Normal', 'sign'}}, content) eq(4, pos) end) @@ -66,7 +66,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq("sign", content) + eq({{'Normal', 'sign'}}, content) eq(true, shown) eq(3, pos) end) @@ -79,7 +79,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq("sin", content) + eq({{'Normal', 'sin'}}, content) eq(true, shown) eq(2, pos) end) @@ -105,7 +105,7 @@ describe('External command line completion', function() ]], nil, nil, function() eq(true, shown) eq("input", prompt) - eq("default", content) + eq({{'Normal', 'default'}}, content) end) feed('') @@ -117,7 +117,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq("3", content) + eq({{'Normal', '3'}}, content) eq("\"", char) eq(1, shift) end) -- cgit From e164ba41c8460d4e5b2e7e2b929d8479a0310738 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Thu, 11 May 2017 04:48:59 +0100 Subject: ext_cmdline: fix firstc, change cmdline_leave to cmdline_hide --- test/functional/ui/cmdline_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 523f7065d4..479f5c3b7d 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -16,7 +16,7 @@ describe('External command line completion', function() screen:set_on_event_handler(function(name, data) if name == "cmdline_enter" then shown = true - elseif name == "cmdline_leave" then + elseif name == "cmdline_hide" then shown = false elseif name == "cmdline_show" then content, pos, firstc, prompt = unpack(data) -- cgit From 866dadaf753ba3733feb8c22d7da47af757bd35c Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Thu, 11 May 2017 07:51:10 +0100 Subject: ext_cmdline: added cmdline level add cchar_to_string --- test/functional/ui/cmdline_spec.lua | 52 +++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 479f5c3b7d..479d40e959 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -7,19 +7,19 @@ if helpers.pending_win32(pending) then return end describe('External command line completion', function() local screen local shown = false - local firstc, prompt, content, pos, char, shift + local firstc, prompt, content, pos, char, shift, level, current_hide_level before_each(function() clear() screen = Screen.new(25, 5) screen:attach({rgb=true, ext_cmdline=true}) screen:set_on_event_handler(function(name, data) - if name == "cmdline_enter" then - shown = true - elseif name == "cmdline_hide" then + if name == "cmdline_hide" then shown = false + current_hide_level = data[1] elseif name == "cmdline_show" then - content, pos, firstc, prompt = unpack(data) + shown = true + content, pos, firstc, prompt, level = unpack(data) elseif name == "cmdline_char" then char, shift = unpack(data) elseif name == "cmdline_pos" then @@ -107,9 +107,9 @@ describe('External command line completion', function() eq("input", prompt) eq({{'Normal', 'default'}}, content) end) - feed('') - feed(':=1+2') + + feed(':') screen:expect([[ ^ | ~ | @@ -117,9 +117,45 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq({{'Normal', '3'}}, content) + eq(1, level) + end) + + feed('=1+2') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{'Normal', '1+2'}}, content) eq("\"", char) eq(1, shift) + eq(2, level) + end) + + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{'Normal', '3'}}, content) + eq(2, current_hide_level) + eq(1, level) + end) + + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(1, current_hide_level) end) end) -- cgit From 461ae698242458bffbf5fb68de89fe8b2a3defd2 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 26 Jun 2017 11:19:40 +0100 Subject: ext_cmdline: Add function block support --- test/functional/ui/cmdline_spec.lua | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 479d40e959..9e2857bc95 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -7,7 +7,7 @@ if helpers.pending_win32(pending) then return end describe('External command line completion', function() local screen local shown = false - local firstc, prompt, content, pos, char, shift, level, current_hide_level + local firstc, prompt, content, pos, char, shift, level, current_hide_level, in_function before_each(function() clear() @@ -24,6 +24,10 @@ describe('External command line completion', function() char, shift = unpack(data) elseif name == "cmdline_pos" then pos = data[1] + elseif name == "cmdline_function_show" then + in_function = true + elseif name == "cmdline_function_hide" then + in_function = false end end) end) @@ -158,6 +162,39 @@ describe('External command line completion', function() eq(1, current_hide_level) end) + feed(':function Foo()') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(true, in_function) + end) + + feed('line1') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(true, in_function) + end) + + feed('endfunction') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(false, in_function) + end) + end) end) end) -- cgit From fb389a6b4b1e6fedb559dc2e5845dd138e8ff264 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 26 Jun 2017 15:27:49 +0100 Subject: ext_cmdline: added indent --- test/functional/ui/cmdline_spec.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 9e2857bc95..1e30ba1449 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -7,7 +7,7 @@ if helpers.pending_win32(pending) then return end describe('External command line completion', function() local screen local shown = false - local firstc, prompt, content, pos, char, shift, level, current_hide_level, in_function + local firstc, prompt, content, pos, char, shift, indent, level, current_hide_level, in_function before_each(function() clear() @@ -19,7 +19,7 @@ describe('External command line completion', function() current_hide_level = data[1] elseif name == "cmdline_show" then shown = true - content, pos, firstc, prompt, level = unpack(data) + content, pos, firstc, prompt, indent, level = unpack(data) elseif name == "cmdline_char" then char, shift = unpack(data) elseif name == "cmdline_pos" then @@ -171,6 +171,7 @@ describe('External command line completion', function() | ]], nil, nil, function() eq(true, in_function) + eq(2, indent) end) feed('line1') @@ -182,6 +183,7 @@ describe('External command line completion', function() | ]], nil, nil, function() eq(true, in_function) + eq(2, indent) end) feed('endfunction') @@ -195,6 +197,17 @@ describe('External command line completion', function() eq(false, in_function) end) + feed(':sign') + screen:expect([[ + | + [No Name] | + :sign^ | + [Command Line] | + | + ]], nil, nil, function() + eq(false, in_function) + end) + end) end) end) -- cgit From 22402fb99d05191cf140293cfb5f67902e78a8a8 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 16 Aug 2017 12:19:29 +0200 Subject: ext_cmdline: add support for highlighting --- test/functional/ui/cmdline_spec.lua | 77 ++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 6 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') 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('') @@ -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 :let x = input({'prompt':'>','highlight':'RainBowParens'}) + "map :let x = input({'prompt':'>'}) + ]]) + 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('(a(b)a)') + screen:expect([[ + ^ | + {EOB:~ }| + {EOB:~ }| + {EOB:~ }| + | + ]], nil, nil, function() + expect_cmdline('{RBP1:(}a{RBP2:(}b{RBP2:)}a{RBP1:)}') + end) + end) end) -- cgit From a68817f56517a31943806bd0b5a0030cdd35e182 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 16 Aug 2017 13:57:58 +0200 Subject: ext_cmdline: extend "function" to generic "block" mechanism --- test/functional/ui/cmdline_spec.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 8d694052ee..3b63a3bd9e 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -8,7 +8,7 @@ if helpers.pending_win32(pending) then return end describe('External command line completion', function() local screen local shown = false - local firstc, prompt, content, pos, char, shift, indent, level, current_hide_level, in_function + local firstc, prompt, content, pos, char, shift, indent, level, current_hide_level, in_block before_each(function() clear() @@ -25,10 +25,10 @@ describe('External command line completion', function() char, shift = unpack(data) elseif name == "cmdline_pos" then pos = data[1] - elseif name == "cmdline_function_show" then - in_function = true - elseif name == "cmdline_function_hide" then - in_function = false + elseif name == "cmdline_block_show" then + in_block = true + elseif name == "cmdline_block_hide" then + in_block = false end end) end) @@ -187,7 +187,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq(true, in_function) + eq(true, in_block) eq(2, indent) end) @@ -199,7 +199,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq(true, in_function) + eq(true, in_block) eq(2, indent) end) @@ -211,7 +211,7 @@ describe('External command line completion', function() ~ | | ]], nil, nil, function() - eq(false, in_function) + eq(false, in_block) end) feed(':sign') @@ -222,7 +222,7 @@ describe('External command line completion', function() [Command Line] | | ]], nil, nil, function() - eq(false, in_function) + eq(false, in_block) end) end) -- cgit From f2aaa4ae8b84f74666b4379b391f333f34868a45 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 16 Aug 2017 15:38:12 +0200 Subject: ext_cmdline: rename cmdline_char to cmdline_special_char --- test/functional/ui/cmdline_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 3b63a3bd9e..33835dd9e4 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -21,7 +21,9 @@ describe('External command line completion', function() elseif name == "cmdline_show" then shown = true content, pos, firstc, prompt, indent, level = unpack(data) - elseif name == "cmdline_char" then + -- FIXME: + --char, shift = nil, nil + elseif name == "cmdline_special_char" then char, shift = unpack(data) elseif name == "cmdline_pos" then pos = data[1] -- cgit From 91f94bfef80c1f39a597dd47806e8dbe45a22578 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 17 Aug 2017 12:26:33 +0200 Subject: ext_cmdline: restructure and improve tests --- test/functional/ui/cmdline_spec.lua | 450 ++++++++++++++++++++++-------------- 1 file changed, 274 insertions(+), 176 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 33835dd9e4..3f9ce8ad67 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -2,35 +2,42 @@ 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 +local ok = helpers.ok if helpers.pending_win32(pending) then return end -describe('External command line completion', function() +describe('external cmdline', function() local screen - local shown = false - local firstc, prompt, content, pos, char, shift, indent, level, current_hide_level, in_block + local last_level = 0 + local cmdline = {} + local block = nil before_each(function() clear() screen = Screen.new(25, 5) screen:attach({rgb=true, ext_cmdline=true}) screen:set_on_event_handler(function(name, data) - if name == "cmdline_hide" then - shown = false - current_hide_level = data[1] - elseif name == "cmdline_show" then - shown = true - content, pos, firstc, prompt, indent, level = unpack(data) - -- FIXME: - --char, shift = nil, nil + if name == "cmdline_show" then + local content, pos, firstc, prompt, indent, level = unpack(data) + ok(level > 0) + cmdline[level] = {content=content, pos=pos, firstc=firstc, + prompt=prompt, indent=indent} + last_level = level + elseif name == "cmdline_hide" then + local level = data[1] + cmdline[level] = nil elseif name == "cmdline_special_char" then - char, shift = unpack(data) + local char, shift, level = unpack(data) + cmdline[level].special = {char, shift} elseif name == "cmdline_pos" then - pos = data[1] + local pos, level = unpack(data) + cmdline[level].pos = pos elseif name == "cmdline_block_show" then - in_block = true + block = data[1] + elseif name == "cmdline_block_append" then + block[#block+1] = data[1] elseif name == "cmdline_block_hide" then - in_block = false + block = nil end end) end) @@ -39,11 +46,11 @@ describe('External command line completion', function() screen:detach() end) - function expect_cmdline(expected) + local function expect_cmdline(level, expected) local attr_ids = screen._default_attr_ids local attr_ignore = screen._default_attr_ignore local actual = '' - for _, chunk in ipairs(content or {}) do + for _, chunk in ipairs(cmdline[level] and cmdline[level].content or {}) do local attrs, text = chunk[1], chunk[2] if screen:_equal_attrs(attrs, {}) then actual = actual..text @@ -55,181 +62,272 @@ describe('External command line completion', function() eq(expected, actual) end - describe("'cmdline'", function() - it(':sign', function() - feed(':') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq(true, shown) - eq(':', firstc) - end) + it('works', function() + feed(':') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(1, last_level) + eq({{ + content = { { {}, "" } }, + firstc = ":", + indent = 0, + pos = 0, + prompt = "" + }}, cmdline) + end) - feed('sign') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq({{{}, 'sign'}}, content) - eq(4, pos) - end) + feed('sign') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "sign" } }, + firstc = ":", + indent = 0, + pos = 4, + prompt = "" + }}, cmdline) + end) - feed('') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq({{{}, 'sign'}}, content) - eq(true, shown) - eq(3, pos) - end) + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "sign" } }, + firstc = ":", + indent = 0, + pos = 3, + prompt = "" + }}, cmdline) + end) - feed('') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq({{{}, 'sin'}}, content) - eq(true, shown) - eq(2, pos) - end) + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "sin" } }, + firstc = ":", + indent = 0, + pos = 2, + prompt = "" + }}, cmdline) + end) - feed('') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq(false, shown) - end) + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({}, cmdline) + end) + end) - feed(':call input("input", "default")') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq(true, shown) - eq("input", prompt) - eq({{{}, 'default'}}, content) - end) - feed('') + it("works with input()", function() + feed(':call input("input", "default")') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "default" } }, + firstc = "", + indent = 0, + pos = 7, + prompt = "input" + }}, cmdline) + end) + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({}, cmdline) + end) - feed(':') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq(1, level) - end) + end) - feed('=1+2') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq({{{}, '1+2'}}, content) - eq("\"", char) - eq(1, shift) - eq(2, level) - end) + it("works with special chars and nested cmdline", function() + feed(':xx') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "xx" } }, + firstc = ":", + indent = 0, + pos = 2, + prompt = "", + special = {'"', true}, + }}, cmdline) + end) - feed('') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq({{{}, '3'}}, content) - eq(2, current_hide_level) - eq(1, level) - end) + feed('=') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "xx" } }, + firstc = ":", + indent = 0, + pos = 2, + prompt = "", + special = {'"', true}, + },{ + content = { { {}, "" } }, + firstc = "=", + indent = 0, + pos = 0, + prompt = "", + }}, cmdline) + end) - feed('') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq(1, current_hide_level) - end) + feed('1+2') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "xx" } }, + firstc = ":", + indent = 0, + pos = 2, + prompt = "", + special = {'"', true}, + },{ + content = { { {}, "1+2" } }, + firstc = "=", + indent = 0, + pos = 3, + prompt = "", + }}, cmdline) + end) - feed(':function Foo()') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq(true, in_block) - eq(2, indent) - end) + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "xx3" } }, + firstc = ":", + indent = 0, + pos = 3, + prompt = "", + }}, cmdline) + end) - feed('line1') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq(true, in_block) - eq(2, indent) - end) + feed('') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({}, cmdline) + end) + end) - feed('endfunction') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq(false, in_block) - end) + it("works with function definitions", function() + feed(':function Foo()') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "" } }, + firstc = ":", + indent = 2, + pos = 0, + prompt = "", + }}, cmdline) + eq({{{{}, 'function Foo()'}}}, block) + end) - feed(':sign') - screen:expect([[ - | - [No Name] | - :sign^ | - [Command Line] | - | - ]], nil, nil, function() - eq(false, in_block) - end) + feed('line1') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{{{}, 'function Foo()'}}, + {{{}, ' line1'}}}, block) + end) + feed('endfunction') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(nil, block) end) end) + pending("works with cmdline window", function() + feed(':sign') + screen:expect([[ + | + [No Name] | + :sign^ | + [Command Line] | + | + ]], nil, nil, function() + eq({}, cmdline) + end) + + feed(":blargh") + end) + it('works with highlighted cmdline', function() source([[ highlight RBP1 guibg=Red @@ -274,7 +372,7 @@ describe('External command line completion', function() {EOB:~ }| | ]], nil, nil, function() - expect_cmdline('{RBP1:(}a{RBP2:(}b{RBP2:)}a{RBP1:)}') + expect_cmdline(1, '{RBP1:(}a{RBP2:(}b{RBP2:)}a{RBP1:)}') end) end) end) -- cgit From bed0a3a8428027af32602ccb169e81767c55e257 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 20 Aug 2017 17:47:42 +0200 Subject: ext_cmdline: implement redraw! --- test/functional/ui/cmdline_spec.lua | 54 +++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 3f9ce8ad67..e4d625df8e 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear, feed, eq = helpers.clear, helpers.feed, helpers.eq local source = helpers.source local ok = helpers.ok +local command = helpers.command if helpers.pending_win32(pending) then return end @@ -218,14 +219,7 @@ describe('external cmdline', function() end) feed('1+2') - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - | - ]], nil, nil, function() - eq({{ + local expectation = {{ content = { { {}, "xx" } }, firstc = ":", indent = 0, @@ -238,16 +232,40 @@ describe('external cmdline', function() indent = 0, pos = 3, prompt = "", - }}, cmdline) + }} + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(expectation, cmdline) end) - feed('') + -- erase information, so we check if it is retransmitted + cmdline = {} + command("redraw!") + -- redraw! forgets cursor position. Be OK with that, as UI should indicate + -- focus is at external cmdline anyway. screen:expect([[ - ^ | + | ~ | ~ | ~ | + ^ | + ]], nil, nil, function() + eq(expectation, cmdline) + end) + + + feed('') + screen:expect([[ | + ~ | + ~ | + ~ | + ^ | ]], nil, nil, function() eq({{ content = { { {}, "xx3" } }, @@ -301,6 +319,20 @@ describe('external cmdline', function() {{{}, ' line1'}}}, block) end) + block = {} + command("redraw!") + screen:expect([[ + | + ~ | + ~ | + ~ | + ^ | + ]], nil, nil, function() + eq({{{{}, 'function Foo()'}}, + {{{}, ' line1'}}}, block) + end) + + feed('endfunction') screen:expect([[ ^ | -- cgit From 91d8e26bc7471378b8005b8843182dc1af90d81a Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 27 Aug 2017 09:57:30 +0200 Subject: ext_cmdline: interact with cmdline window --- test/functional/ui/cmdline_spec.lua | 107 ++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 5 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index e4d625df8e..b886596e00 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -232,7 +232,7 @@ describe('external cmdline', function() indent = 0, pos = 3, prompt = "", - }} + }} screen:expect([[ ^ | ~ | @@ -345,19 +345,116 @@ describe('external cmdline', function() end) end) - pending("works with cmdline window", function() - feed(':sign') + it("works with cmdline window", function() + feed(':make') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "make" } }, + firstc = ":", + indent = 0, + pos = 4, + prompt = "" + }}, cmdline) + end) + + feed('') + screen:expect([[ + | + [No Name] | + :make^ | + [Command Line] | + | + ]], nil, nil, function() + eq({}, cmdline) + end) + + -- nested cmdline + feed(':yank') + screen:expect([[ + | + [No Name] | + :make^ | + [Command Line] | + | + ]], nil, nil, function() + eq({nil, { + content = { { {}, "yank" } }, + firstc = ":", + indent = 0, + pos = 4, + prompt = "" + }}, cmdline) + end) + + cmdline = {} + command("redraw!") + screen:expect([[ + | + [No Name] | + :make | + [Command Line] | + ^ | + ]], nil, nil, function() + eq({nil, { + content = { { {}, "yank" } }, + firstc = ":", + indent = 0, + pos = 4, + prompt = "" + }}, cmdline) + end) + + feed("") screen:expect([[ | [No Name] | - :sign^ | + :make^ | [Command Line] | | ]], nil, nil, function() eq({}, cmdline) end) - feed(":blargh") + feed("") + screen:expect([[ + | + [No Name] | + :make^ | + [Command Line] | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "make" } }, + firstc = ":", + indent = 0, + pos = 4, + prompt = "" + }}, cmdline) + end) + + cmdline = {} + command("redraw!") + screen:expect([[ + | + ~ | + ~ | + ~ | + ^ | + ]], nil, nil, function() + eq({{ + content = { { {}, "make" } }, + firstc = ":", + indent = 0, + pos = 4, + prompt = "" + }}, cmdline) + end) end) it('works with highlighted cmdline', function() -- cgit From 445f25998c66ee7e4dc5bbfeed4108818e439b92 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 30 Aug 2017 08:51:39 +0200 Subject: ext_cmdline: fix inputsecret() --- test/functional/ui/cmdline_spec.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index b886596e00..6a9f4a22b4 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -15,6 +15,7 @@ describe('external cmdline', function() before_each(function() clear() + cmdline, block = {}, nil screen = Screen.new(25, 5) screen:attach({rgb=true, ext_cmdline=true}) screen:set_on_event_handler(function(name, data) @@ -457,6 +458,25 @@ describe('external cmdline', function() end) end) + it('works with inputsecret()', function() + feed(":call inputsecret('secret:')abc123") + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq({{ + content = { { {}, "******" } }, + firstc = "", + indent = 0, + pos = 6, + prompt = "secret:" + }}, cmdline) + end) + end) + it('works with highlighted cmdline', function() source([[ highlight RBP1 guibg=Red -- cgit From 1a93f5883105c304d496d6c2e841626ebb7d44c1 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 29 Oct 2017 00:56:00 +0200 Subject: test: ui/cmdline_spec.lua: enable on Windows --- test/functional/ui/cmdline_spec.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/functional/ui/cmdline_spec.lua') diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 6a9f4a22b4..0f8302b036 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -5,8 +5,6 @@ local source = helpers.source local ok = helpers.ok local command = helpers.command -if helpers.pending_win32(pending) then return end - describe('external cmdline', function() local screen local last_level = 0 -- cgit