diff options
author | Dongdong Zhou <dzhou121@gmail.com> | 2017-02-24 07:26:39 +0000 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2017-10-26 09:35:12 +0200 |
commit | 26fd70bd18283701a2ade11407694485cd0f7e35 (patch) | |
tree | a8654cc4e98ecfd3474f49fcba7be0e09615a13d | |
parent | 6e90bc7200c87f0af448a8cf0998715db9175f15 (diff) | |
download | rneovim-26fd70bd18283701a2ade11407694485cd0f7e35.tar.gz rneovim-26fd70bd18283701a2ade11407694485cd0f7e35.tar.bz2 rneovim-26fd70bd18283701a2ade11407694485cd0f7e35.zip |
ext_cmdline: add tests
-rw-r--r-- | src/nvim/ex_getln.c | 11 | ||||
-rw-r--r-- | test/functional/ui/cmdline_spec.lua | 128 |
2 files changed, 135 insertions, 4 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a05331d13a..18d6b26595 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -283,9 +283,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) if (!cmd_silent) { s->i = msg_scrolled; msg_scrolled = 0; // avoid wait_return message - if (!cmdline_external) { - gotocmdline(true); - } + gotocmdline(true); msg_scrolled += s->i; redrawcmdprompt(); // draw prompt or indent set_cmdspos(); @@ -808,7 +806,9 @@ static int command_line_execute(VimState *state, int key) } if (!cmd_silent) { - ui_cursor_goto(msg_row, 0); + if (!cmdline_external) { + ui_cursor_goto(msg_row, 0); + } ui_flush(); } return 0; @@ -3210,6 +3210,9 @@ static void cursorcmd(void) void gotocmdline(int clr) { + if (cmdline_external) { + return; + } msg_start(); if (cmdmsg_rl) msg_col = Columns - 1; 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('<Left>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq("sign", content) + eq(true, shown) + eq(3, pos) + end) + + feed('<bs>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq("sin", content) + eq(true, shown) + eq(2, pos) + end) + + feed('<Esc>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(false, shown) + end) + + feed(':call input("input", "default")<cr>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq(true, shown) + eq("input", prompt) + eq("default", content) + end) + + feed('<cr>') + feed(':<C-R>=1+2<cr>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]], nil, nil, function() + eq("3", content) + end) + + end) + end) +end) |