diff options
-rw-r--r-- | test/functional/core/job_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ex_cmds/ctrl_c_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/terminal/buffer_spec.lua | 8 | ||||
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 8 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ui/cmdline_spec.lua | 616 | ||||
-rw-r--r-- | test/functional/ui/cursor_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/ui/inccommand_spec.lua | 20 | ||||
-rw-r--r-- | test/functional/ui/mode_spec.lua | 116 | ||||
-rw-r--r-- | test/functional/ui/output_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/ui/popupmenu_spec.lua | 91 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 209 | ||||
-rw-r--r-- | test/functional/ui/tabline_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/ui/wildmode_spec.lua | 47 | ||||
-rw-r--r-- | test/functional/viml/completion_spec.lua | 101 | ||||
-rw-r--r-- | test/helpers.lua | 4 |
17 files changed, 595 insertions, 669 deletions
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 4a21444ee0..feb9c9aeaa 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -417,7 +417,7 @@ describe('jobs', function() \ }) ]]) - screen:expect("{2:E120: Using <SID> not in a script context: s:OnEvent}",nil,nil,nil,true) + screen:expect{any="{2:E120: Using <SID> not in a script context: s:OnEvent}"} end) it('does not repeat output with slow output handlers', function() diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/ex_cmds/ctrl_c_spec.lua index 8f76099f79..4c5383b712 100644 --- a/test/functional/ex_cmds/ctrl_c_spec.lua +++ b/test/functional/ex_cmds/ctrl_c_spec.lua @@ -43,7 +43,7 @@ describe("CTRL-C (mapped)", function() feed(":global/^/p<CR>") screen:sleep(ms) feed("<C-C>") - screen:expect([[Interrupt]], nil, nil, nil, true) + screen:expect{any="Interrupt"} end -- The test is time-sensitive. Try different sleep values. diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index c290031fbe..4d6b125f9f 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -207,18 +207,18 @@ describe('terminal buffer', function() feed_command('terminal') feed('<c-\\><c-n>') feed_command('confirm bdelete') - screen:expect('Close "term://', nil, true, nil, true) + screen:expect{any='Close "term://', attr_ignore=true} end) it('with &confirm', function() feed_command('terminal') feed('<c-\\><c-n>') feed_command('bdelete') - screen:expect('E89', nil, true, nil, true) + screen:expect{any='E89', attr_ignore=true} feed('<cr>') eq('terminal', eval('&buftype')) feed_command('set confirm | bdelete') - screen:expect('Close "term://', nil, true, nil, true) + screen:expect{any='Close "term://', attr_ignore=true} feed('y') neq('terminal', eval('&buftype')) end) @@ -242,7 +242,7 @@ describe('No heap-buffer-overflow when using', function() feed('$') -- Let termopen() modify the buffer feed_command('call termopen("echo")') - wait() + eq(2, eval('1+1')) -- check nvim still running feed_command('bdelete!') end) end) diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index f98add41a0..dbee9bdb49 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -54,7 +54,7 @@ describe(':terminal', function() else feed_command([[terminal printf '\e[6n'; sleep 0.5 ]]) end - screen:expect('%^%[%[1;1R', nil, nil, nil, true) + screen:expect{any='%^%[%[1;1R'} end) it("in normal-mode :split does not move cursor", function() diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index c665e64a80..5e36fea474 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -408,7 +408,7 @@ describe("'scrollback' option", function() else feed_data('for i in $(seq 1 30); do echo "line$i"; done\n') end - screen:expect('line30 ', nil, nil, nil, true) + screen:expect{any='line30 '} retry(nil, nil, function() expect_lines(7) end) screen:detach() @@ -426,7 +426,7 @@ describe("'scrollback' option", function() curbufmeths.set_option('scrollback', 200) -- Wait for prompt. - screen:expect('$', nil, nil, nil, true) + screen:expect{any='$'} wait() if iswin() then @@ -435,7 +435,7 @@ describe("'scrollback' option", function() feed_data('for i in $(seq 1 30); do echo "line$i"; done\n') end - screen:expect('line30 ', nil, nil, nil, true) + screen:expect{any='line30 '} retry(nil, nil, function() expect_lines(33, 2) end) curbufmeths.set_option('scrollback', 10) @@ -452,7 +452,7 @@ describe("'scrollback' option", function() feed_data('for i in $(seq 1 40); do echo "line$i"; done\n') end - screen:expect('line40 ', nil, nil, nil, true) + screen:expect{any='line40 '} retry(nil, nil, function() expect_lines(58) end) -- Verify off-screen state diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index c0404ff463..351038e521 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -400,7 +400,7 @@ describe('tui FocusGained/FocusLost', function() -- Exit cmdline-mode. Redraws from timers/events are blocked during -- cmdline-mode, so the buffer won't be updated until we exit cmdline-mode. feed_data('\n') - screen:expect('lost'..(' '):rep(46)..'\ngained', nil, nil, nil, true) + screen:expect{any='lost'..(' '):rep(46)..'\ngained'} end) end) @@ -740,7 +740,7 @@ describe("tui 'term' option", function() screen.timeout = 250 -- We want screen:expect() to fail quickly. retry(nil, 2 * full_timeout, function() -- Wait for TUI thread to set 'term'. feed_data(":echo 'term='.(&term)\n") - screen:expect('term='..term_expected, nil, nil, nil, true) + screen:expect{any='term='..term_expected} end) end diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index b2fc008dba..bf8cae3a0b 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -1,23 +1,16 @@ 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 clear, feed = helpers.clear, helpers.feed local source = helpers.source -local ok = helpers.ok local command = helpers.command -describe('external cmdline', function() +local function test_cmdline(newgrid) local screen - local last_level = 0 - local cmdline = {} - local block = nil - local wild_items = nil - local wild_selected = nil before_each(function() clear() - cmdline, block = {}, nil screen = Screen.new(25, 5) - screen:attach({rgb=true, ext_cmdline=true}) + screen:attach({rgb=true, ext_cmdline=true, ext_newgrid=newgrid}) screen:set_default_attr_ids({ [1] = {bold = true, foreground = Screen.colors.Blue1}, [2] = {reverse = true}, @@ -25,142 +18,73 @@ describe('external cmdline', function() [4] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, [5] = {bold = true, foreground = Screen.colors.SeaGreen4}, }) - screen:set_on_event_handler(function(name, data) - if name == "cmdline_show" then - local content, pos, firstc, prompt, indent, level = unpack(data) - ok(level > 0) - for _,item in ipairs(content) do - item[1] = screen:get_hl(item[1]) - end - 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 - local char, shift, level = unpack(data) - cmdline[level].special = {char, shift} - elseif name == "cmdline_pos" then - local pos, level = unpack(data) - cmdline[level].pos = pos - elseif name == "cmdline_block_show" then - block = data[1] - elseif name == "cmdline_block_append" then - block[#block+1] = data[1] - elseif name == "cmdline_block_hide" then - block = nil - elseif name == "wildmenu_show" then - wild_items = data[1] - elseif name == "wildmenu_select" then - wild_selected = data[1] - elseif name == "wildmenu_hide" then - wild_items, wild_selected = nil, nil - end - end) end) after_each(function() screen:detach() end) - 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(cmdline[level] and cmdline[level].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 - it('works', function() feed(':') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq(1, last_level) - --print(require('inspect')(cmdline)) - eq({{ - content = { { {}, "" } }, - firstc = ":", - indent = 0, - pos = 0, - prompt = "" - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{""}}, + pos = 0, + }}} feed('sign') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "sign" } }, - firstc = ":", - indent = 0, - pos = 4, - prompt = "" - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"sign"}}, + pos = 4, + }}} feed('<Left>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "sign" } }, - firstc = ":", - indent = 0, - pos = 3, - prompt = "" - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"sign"}}, + pos = 3, + }}} feed('<bs>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "sin" } }, - firstc = ":", - indent = 0, - pos = 2, - prompt = "" - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"sin"}}, + pos = 2, + }}} feed('<Esc>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({}, cmdline) - end) + ]]} end) describe("redraws statusline on entering", function() @@ -170,28 +94,32 @@ describe('external cmdline', function() end) it('from normal mode', function() + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {3:n }| + | + ]]} + feed(':') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {3:c }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "" } }, - firstc = ":", - indent = 0, - pos = 0, - prompt = "" - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{""}}, + pos = 0, + }}} end) it('but not with scrolled messages', function() screen:try_resize(50,10) feed(':echoerr doesnotexist<cr>') - screen:expect([[ + screen:expect{grid=[[ | {1:~ }| {1:~ }| @@ -202,9 +130,9 @@ describe('external cmdline', function() {4:E121: Undefined variable: doesnotexist} | {4:E15: Invalid expression: doesnotexist} | {5:Press ENTER or type command to continue}^ | - ]]) + ]]} feed(':echoerr doesnotexist<cr>') - screen:expect([[ + screen:expect{grid=[[ | {1:~ }| {1:~ }| @@ -215,10 +143,10 @@ describe('external cmdline', function() {4:E121: Undefined variable: doesnotexist} | {4:E15: Invalid expression: doesnotexist} | {5:Press ENTER or type command to continue}^ | - ]]) + ]]} feed(':echoerr doesnotexist<cr>') - screen:expect([[ + screen:expect{grid=[[ | {1:~ }| {3: }| @@ -229,10 +157,10 @@ describe('external cmdline', function() {4:E121: Undefined variable: doesnotexist} | {4:E15: Invalid expression: doesnotexist} | {5:Press ENTER or type command to continue}^ | - ]]) + ]]} feed('<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| @@ -243,372 +171,314 @@ describe('external cmdline', function() {1:~ }| {3:n }| | - ]]) + ]]} end) end) it("works with input()", function() feed(':call input("input", "default")<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "default" } }, - firstc = "", - indent = 0, - pos = 7, - prompt = "input" - }}, cmdline) - end) + ]], cmdline={{ + prompt = "input", + content = {{"default"}}, + pos = 7, + }}} + feed('<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({}, cmdline) - end) - + ]]} end) it("works with special chars and nested cmdline", function() feed(':xx<c-r>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "xx" } }, - firstc = ":", - indent = 0, - pos = 2, - prompt = "", - special = {'"', true}, - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"xx"}}, + pos = 2, + special = {'"', true}, + }}} feed('=') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "xx" } }, - firstc = ":", - indent = 0, - pos = 2, - prompt = "", - special = {'"', true}, - },{ - content = { { {}, "" } }, - firstc = "=", - indent = 0, - pos = 0, - prompt = "", - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"xx"}}, + pos = 2, + special = {'"', true}, + }, { + firstc = "=", + content = {{""}}, + pos = 0, + }}} feed('1+2') local expectation = {{ - content = { { {}, "xx" } }, - firstc = ":", - indent = 0, - pos = 2, - prompt = "", - special = {'"', true}, - },{ - content = { - { {}, "1" }, - { {}, "+" }, - { {}, "2" }, - }, - firstc = "=", - indent = 0, - pos = 3, - prompt = "", - }} - screen:expect([[ + firstc = ":", + content = {{"xx"}}, + pos = 2, + special = {'"', true}, + }, { + firstc = "=", + content = {{"1"}, {"+"}, {"2"}}, + pos = 3, + }} + + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq(expectation, cmdline) - end) + ]], cmdline=expectation} -- erase information, so we check if it is retransmitted - cmdline = {} + -- TODO(bfredl): when we add a flag to screen:expect{} + -- to explicitly check redraw!, it should also do this + screen.cmdline = {} command("redraw!") - -- redraw! forgets cursor position. Be OK with that, as UI should indicate - -- focus is at external cmdline anyway. - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq(expectation, cmdline) - end) + ]], cmdline=expectation} feed('<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "xx3" } }, - firstc = ":", - indent = 0, - pos = 3, - prompt = "", - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"xx3"}}, + pos = 3, + }}} feed('<esc>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({}, cmdline) - end) + ]]} end) it("works with function definitions", function() feed(':function Foo()<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "" } }, - firstc = ":", - indent = 2, - pos = 0, - prompt = "", - }}, cmdline) - eq({ { { {}, 'function Foo()'} } }, block) - end) + ]], cmdline={{ + indent = 2, + firstc = ":", + content = {{""}}, + pos = 0, + }}, cmdline_block = { + {{'function Foo()'}}, + }} feed('line1<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({ { { {}, 'function Foo()'} }, - { { {}, ' line1'} } }, block) - end) + ]], cmdline={{ + indent = 2, + firstc = ":", + content = {{""}}, + pos = 0, + }}, cmdline_block = { + {{'function Foo()'}}, + {{' line1'}}, + }} - block = {} + screen.cmdline_block = {} command("redraw!") - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({ { { {}, 'function Foo()'} }, - { { {}, ' line1'} } }, block) - end) + ]], cmdline={{ + indent = 2, + firstc = ":", + content = {{""}}, + pos = 0, + }}, cmdline_block = { + {{'function Foo()'}}, + {{' line1'}}, + }} feed('endfunction<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq(nil, block) - end) + ]]} -- Try once more, to check buffer is reinitialized. #8007 feed(':function Bar()<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "" } }, - firstc = ":", - indent = 2, - pos = 0, - prompt = "", - }}, cmdline) - eq({ { { {}, 'function Bar()'} } }, block) - end) + ]], cmdline={{ + indent = 2, + firstc = ":", + content = {{""}}, + pos = 0, + }}, cmdline_block = { + {{'function Bar()'}}, + }} feed('endfunction<cr>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq(nil, block) - end) + ]]} + end) it("works with cmdline window", function() feed(':make') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "make" } }, - firstc = ":", - indent = 0, - pos = 4, - prompt = "" - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"make"}}, + pos = 4, + }}} feed('<c-f>') - screen:expect([[ + screen:expect{grid=[[ | {2:[No Name] }| {1::}make^ | {3:[Command Line] }| | - ]], nil, nil, function() - eq({}, cmdline) - end) + ]]} -- nested cmdline feed(':yank') - screen:expect([[ + screen:expect{grid=[[ | {2:[No Name] }| {1::}make^ | {3:[Command Line] }| | - ]], nil, nil, function() - eq({nil, { - content = { { {}, "yank" } }, - firstc = ":", - indent = 0, - pos = 4, - prompt = "" - }}, cmdline) - end) + ]], cmdline={nil, { + firstc = ":", + content = {{"yank"}}, + pos = 4, + }}} - cmdline = {} + screen.cmdline = {} command("redraw!") - screen:expect([[ + screen:expect{grid=[[ | {2:[No Name] }| {1::}make^ | {3:[Command Line] }| | - ]], nil, nil, function() - eq({nil, { - content = { { {}, "yank" } }, - firstc = ":", - indent = 0, - pos = 4, - prompt = "" - }}, cmdline) - end) + ]], cmdline={nil, { + firstc = ":", + content = {{"yank"}}, + pos = 4, + }}} feed("<c-c>") - screen:expect([[ + screen:expect{grid=[[ | {2:[No Name] }| {1::}make^ | {3:[Command Line] }| | - ]], nil, nil, function() - eq({}, cmdline) - end) + ]]} feed("<c-c>") - screen:expect([[ + screen:expect{grid=[[ | {2:[No Name] }| {1::}make^ | {3:[Command Line] }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "make" } }, - firstc = ":", - indent = 0, - pos = 4, - prompt = "" - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"make"}}, + pos = 4, + }}} - cmdline = {} + screen.cmdline = {} command("redraw!") - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "make" } }, - firstc = ":", - indent = 0, - pos = 4, - prompt = "" - }}, cmdline) - end) + ]], cmdline={{ + firstc = ":", + content = {{"make"}}, + pos = 4, + }}} end) it('works with inputsecret()', function() feed(":call inputsecret('secret:')<cr>abc123") - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "******" } }, - firstc = "", - indent = 0, - pos = 6, - prompt = "secret:" - }}, cmdline) - end) + ]], cmdline={{ + prompt = "secret:", + content = {{"******"}}, + pos = 6, + }}} end) it('works with highlighted cmdline', function() @@ -648,15 +518,18 @@ describe('external cmdline', function() PE={bold = true, foreground = Screen.colors.SeaGreen4} }) feed('<f5>(a(b)a)') - screen:expect([[ + screen:expect{grid=[[ ^ | {EOB:~ }| {EOB:~ }| {EOB:~ }| | - ]], nil, nil, function() - expect_cmdline(1, '{RBP1:(}a{RBP2:(}b{RBP2:)}a{RBP1:)}') - end) + ]], cmdline={{ + prompt = '>', + content = {{'(', 'RBP1'}, {'a'}, {'(', 'RBP2'}, {'b'}, + { ')', 'RBP2'}, {'a'}, {')', 'RBP1'}}, + pos = 7, + }}} end) it('works together with ext_wildmenu', function() @@ -674,98 +547,73 @@ describe('external cmdline', function() screen:set_option('ext_wildmenu', true) feed(':sign <tab>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "sign define"} }, - firstc = ":", - indent = 0, - pos = 11, - prompt = "" - }}, cmdline) - eq(expected, wild_items) - eq(0, wild_selected) - end) + ]], cmdline={{ + firstc = ":", + content = {{"sign define"}}, + pos = 11, + }}, wildmenu_items=expected, wildmenu_pos=0} feed('<tab>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "sign jump"} }, - firstc = ":", - indent = 0, - pos = 9, - prompt = "" - }}, cmdline) - eq(expected, wild_items) - eq(1, wild_selected) - end) + ]], cmdline={{ + firstc = ":", + content = {{"sign jump"}}, + pos = 9, + }}, wildmenu_items=expected, wildmenu_pos=1} feed('<left><left>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "sign "} }, - firstc = ":", - indent = 0, - pos = 5, - prompt = "" - }}, cmdline) - eq(expected, wild_items) - eq(-1, wild_selected) - end) + ]], cmdline={{ + firstc = ":", + content = {{"sign "}}, + pos = 5, + }}, wildmenu_items=expected, wildmenu_pos=-1} feed('<right>') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "sign define"} }, - firstc = ":", - indent = 0, - pos = 11, - prompt = "" - }}, cmdline) - eq(expected, wild_items) - eq(0, wild_selected) - end) + ]], cmdline={{ + firstc = ":", + content = {{"sign define"}}, + pos = 11, + }}, wildmenu_items=expected, wildmenu_pos=0} feed('a') - screen:expect([[ + screen:expect{grid=[[ ^ | {1:~ }| {1:~ }| {1:~ }| | - ]], nil, nil, function() - eq({{ - content = { { {}, "sign definea"} }, - firstc = ":", - indent = 0, - pos = 12, - prompt = "" - }}, cmdline) - eq(nil, wild_items) - eq(nil, wild_selected) - end) + ]], cmdline={{ + firstc = ":", + content = {{"sign definea"}}, + pos = 12, + }}} end) -end) +end + +-- the representation of cmdline and cmdline_block contents changed with ext_newgrid +-- (which uses indexed highlights) so make sure to test both +describe('ui/ext_cmdline', function() test_cmdline(true) end) +describe('ui/ext_cmdline (legacy highlights)', function() test_cmdline(false) end) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index d1cddbe06a..3e0370db14 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -188,15 +188,15 @@ describe('ui/cursor', function() -- Event is published ONLY if the cursor style changed. screen._mode_info = nil command("echo 'test'") - screen:expect([[ + screen:expect{grid=[[ ^ | ~ | ~ | ~ | test | - ]], nil, nil, function() + ]], condition=function() eq(nil, screen._mode_info) - end) + end} -- Change the cursor style. helpers.command('hi Cursor guibg=DarkGray') diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index 9cc697a4b6..6a17448582 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -745,19 +745,19 @@ describe(":substitute, inccommand=split", function() it("shows preview when cmd modifiers are present", function() -- one modifier feed(':keeppatterns %s/tw/to') - screen:expect([[{12:to}o lines]], nil, nil, nil, true) + screen:expect{any=[[{12:to}o lines]]} feed('<Esc>') - screen:expect([[two lines]], nil, nil, nil, true) + screen:expect{any=[[two lines]]} -- multiple modifiers feed(':keeppatterns silent %s/tw/to') - screen:expect([[{12:to}o lines]], nil, nil, nil, true) + screen:expect{any=[[{12:to}o lines]]} feed('<Esc>') - screen:expect([[two lines]], nil, nil, nil, true) + screen:expect{any=[[two lines]]} -- non-modifier prefix feed(':silent tabedit %s/tw/to') - screen:expect([[two lines]], nil, nil, nil, true) + screen:expect{any=[[two lines]]} feed('<Esc>') end) @@ -1222,19 +1222,19 @@ describe("inccommand=nosplit", function() it("shows preview when cmd modifiers are present", function() -- one modifier feed(':keeppatterns %s/tw/to') - screen:expect([[{12:to}o lines]], nil, nil, nil, true) + screen:expect{any=[[{12:to}o lines]]} feed('<Esc>') - screen:expect([[two lines]], nil, nil, nil, true) + screen:expect{any=[[two lines]]} -- multiple modifiers feed(':keeppatterns silent %s/tw/to') - screen:expect([[{12:to}o lines]], nil, nil, nil, true) + screen:expect{any=[[{12:to}o lines]]} feed('<Esc>') - screen:expect([[two lines]], nil, nil, nil, true) + screen:expect{any=[[two lines]]} -- non-modifier prefix feed(':silent tabedit %s/tw/to') - screen:expect([[two lines]], nil, nil, nil, true) + screen:expect{any=[[two lines]]} feed('<Esc>') end) diff --git a/test/functional/ui/mode_spec.lua b/test/functional/ui/mode_spec.lua index f0cedfeeb5..f6b3c1c3c9 100644 --- a/test/functional/ui/mode_spec.lua +++ b/test/functional/ui/mode_spec.lua @@ -21,207 +21,169 @@ describe('ui mode_change event', function() end) it('works in normal mode', function() - screen:expect([[ + screen:expect{grid=[[ ^ | {0:~ }| {0:~ }| | - ]],nil,nil,function () - eq("normal", screen.mode) - end) + ]], mode="normal"} feed('d') - screen:expect([[ + screen:expect{grid=[[ ^ | {0:~ }| {0:~ }| | - ]],nil,nil,function () - eq("operator", screen.mode) - end) + ]], mode="operator"} feed('<esc>') - screen:expect([[ + screen:expect{grid=[[ ^ | {0:~ }| {0:~ }| | - ]],nil,nil,function () - eq("normal", screen.mode) - end) + ]], mode="normal"} end) it('works in insert mode', function() feed('i') - screen:expect([[ + screen:expect{grid=[[ ^ | {0:~ }| {0:~ }| {2:-- INSERT --} | - ]],nil,nil,function () - eq("insert", screen.mode) - end) + ]], mode="insert"} feed('word<esc>') - screen:expect([[ + screen:expect{grid=[[ wor^d | {0:~ }| {0:~ }| | - ]], nil, nil, function () - eq("normal", screen.mode) - end) + ]], mode="normal"} command("set showmatch") eq(eval('&matchtime'), 5) -- tenths of seconds feed('a(stuff') - screen:expect([[ + screen:expect{grid=[[ word(stuff^ | {0:~ }| {0:~ }| {2:-- INSERT --} | - ]], nil, nil, function () - eq("insert", screen.mode) - end) + ]], mode="insert"} feed(')') - screen:expect([[ + screen:expect{grid=[[ word^(stuff) | {0:~ }| {0:~ }| {2:-- INSERT --} | - ]], nil, nil, function () - eq("showmatch", screen.mode) - end) + ]], mode="showmatch"} screen:sleep(400) - screen:expect([[ + screen:expect{grid=[[ word(stuff)^ | {0:~ }| {0:~ }| {2:-- INSERT --} | - ]], nil, nil, function () - eq("insert", screen.mode) - end) + ]], mode="insert"} end) it('works in replace mode', function() feed('R') - screen:expect([[ + screen:expect{grid=[[ ^ | {0:~ }| {0:~ }| {2:-- REPLACE --} | - ]], nil, nil, function () - eq("replace", screen.mode) - end) + ]], mode="replace"} feed('word<esc>') - screen:expect([[ + screen:expect{grid=[[ wor^d | {0:~ }| {0:~ }| | - ]], nil, nil, function () - eq("normal", screen.mode) - end) + ]], mode="normal"} end) it('works in cmdline mode', function() feed(':') - screen:expect([[ + screen:expect{grid=[[ | {0:~ }| {0:~ }| :^ | - ]],nil,nil,function () - eq("cmdline_normal", screen.mode) - end) + ]], mode="cmdline_normal"} feed('x<left>') - screen:expect([[ + screen:expect{grid=[[ | {0:~ }| {0:~ }| :^x | - ]],nil,nil,function () - eq("cmdline_insert", screen.mode) - end) + ]], mode="cmdline_insert"} feed('<insert>') - screen:expect([[ + screen:expect{grid=[[ | {0:~ }| {0:~ }| :^x | - ]],nil,nil,function () - eq("cmdline_replace", screen.mode) - end) + ]], mode="cmdline_replace"} feed('<right>') - screen:expect([[ + screen:expect{grid=[[ | {0:~ }| {0:~ }| :x^ | - ]],nil,nil,function () - eq("cmdline_normal", screen.mode) - end) + ]], mode="cmdline_normal"} feed('<esc>') - screen:expect([[ + screen:expect{grid=[[ ^ | {0:~ }| {0:~ }| | - ]],nil,nil,function () - eq("normal", screen.mode) - end) + ]], mode="normal"} end) - it('works in visal mode', function() + it('works in visual mode', function() insert("text") feed('v') - screen:expect([[ + screen:expect{grid=[[ tex^t | {0:~ }| {0:~ }| {2:-- VISUAL --} | - ]],nil,nil,function () - eq("visual", screen.mode) - end) + ]], mode="visual"} feed('<esc>') - screen:expect([[ + screen:expect{grid=[[ tex^t | {0:~ }| {0:~ }| | - ]],nil,nil,function () - eq("normal", screen.mode) - end) + ]], mode="normal"} command('set selection=exclusive') feed('v') - screen:expect([[ + screen:expect{grid=[[ tex^t | {0:~ }| {0:~ }| {2:-- VISUAL --} | - ]],nil,nil,function () - eq("visual_select", screen.mode) - end) + ]], mode="visual_select"} feed('<esc>') - screen:expect([[ + screen:expect{grid=[[ tex^t | {0:~ }| {0:~ }| | - ]],nil,nil,function () - eq("normal", screen.mode) - end) + ]], mode="normal"} end) end) diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua index 93d8965cb1..0f076eac26 100644 --- a/test/functional/ui/output_spec.lua +++ b/test/functional/ui/output_spec.lua @@ -61,7 +61,7 @@ describe("shell command :!", function() ":!for i in $(seq 2 3000); do echo XXXXXXXXXX $i; done\n") -- If we observe any line starting with a dot, then throttling occurred. - screen:expect("\n.", nil, nil, nil, true) + screen:expect{any="\n."} -- Final chunk of output should always be displayed, never skipped. -- (Throttling is non-deterministic, this test is merely a sanity check.) @@ -92,7 +92,7 @@ describe("shell command :!", function() eq(2, eval('1+1')) -- Still alive? end) - it([[handles control codes]], function() + it('handles control codes', function() if iswin() then pending('missing printf', function() end) return @@ -112,14 +112,14 @@ describe("shell command :!", function() -- Print BELL control code. #4338 screen.bell = false feed([[:!printf '\007\007\007\007text'<CR>]]) - screen:expect([[ + screen:expect{grid=[[ ~ | :!printf '\007\007\007\007text' | text | Press ENTER or type command to continue^ | - ]], nil, nil, function() + ]], condition=function() eq(true, screen.bell) - end) + end} feed([[<CR>]]) -- Print BS control code. feed([[:echo system('printf ''\010\n''')<CR>]]) @@ -188,7 +188,7 @@ describe("shell command :!", function() it('handles binary and multibyte data', function() feed_command('!cat test/functional/fixtures/shell_data.txt') screen.bell = false - screen:expect([[ + screen:expect{grid=[[ | {1:~ }| {4: }| @@ -199,9 +199,9 @@ describe("shell command :!", function() t {2:<ff>} | | {3:Press ENTER or type command to continue}^ | - ]], nil, nil, function() + ]], condition=function() eq(true, screen.bell) - end) + end} end) it('handles multibyte sequences split over buffer boundaries', function() diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua new file mode 100644 index 0000000000..8c583c90fe --- /dev/null +++ b/test/functional/ui/popupmenu_spec.lua @@ -0,0 +1,91 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear, feed = helpers.clear, helpers.feed +local source = helpers.source + +describe('ui/ext_popupmenu', function() + local screen + before_each(function() + clear() + screen = Screen.new(60, 8) + screen:attach({rgb=true, ext_popupmenu=true}) + screen:set_default_attr_ids({ + [1] = {bold=true, foreground=Screen.colors.Blue}, + [2] = {bold = true}, + }) + end) + + it('works', function() + source([[ + function! TestComplete() abort + call complete(1, ['foo', 'bar', 'spam']) + return '' + endfunction + ]]) + local expected = { + {'foo', '', '', ''}, + {'bar', '', '', ''}, + {'spam', '', '', ''}, + } + feed('o<C-r>=TestComplete()<CR>') + screen:expect{grid=[[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=0, + anchor={1,0}, + }} + + feed('<c-p>') + screen:expect{grid=[[ + | + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=-1, + anchor={1,0}, + }} + + -- down moves the selection in the menu, but does not insert anything + feed('<down><down>') + screen:expect{grid=[[ + | + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=1, + anchor={1,0}, + }} + + feed('<cr>') + screen:expect{grid=[[ + | + bar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]} + end) +end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 872a9d3200..18c0fe2c2a 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -71,6 +71,8 @@ -- To help write screen tests, see Screen:snapshot_util(). -- To debug screen tests, see Screen:redraw_debug(). +local global_helpers = require('test.helpers') +local shallowcopy = global_helpers.shallowcopy local helpers = require('test.functional.helpers')(nil) local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths local eq = helpers.eq @@ -139,6 +141,11 @@ function Screen.new(width, height) suspended = false, mode = 'normal', options = {}, + popupmenu = nil, + cmdline = {}, + cmdline_block = {}, + wildmenu_items = nil, + wildmenu_selected = nil, _default_attr_ids = nil, _default_attr_ignore = nil, _mouse_enabled = true, @@ -193,32 +200,80 @@ function Screen:set_option(option, value) self._options[option] = value end --- Asserts that `expected` eventually matches the screen state. +-- Asserts that the screen state eventually matches an expected state -- --- expected: Expected screen state (string). Each line represents a screen +-- This function can either be called with the positional forms +-- +-- screen:expect(grid, [attr_ids, attr_ignore]) +-- screen:expect(condition) +-- +-- or to use additional arguments (or grid and condition at the same time) +-- the keyword form has to be used: +-- +-- screen:expect{grid=[[...]], cmdline={...}, condition=function() ... end} +-- +-- +-- grid: Expected screen state (string). Each line represents a screen -- row. Last character of each row (typically "|") is stripped. -- Common indentation is stripped. --- Used as `condition` if NOT a string; must be the ONLY arg then. -- attr_ids: Expected text attributes. Screen rows are transformed according -- to this table, as follows: each substring S composed of -- characters having the same attributes will be substituted by -- "{K:S}", where K is a key in `attr_ids`. Any unexpected -- attributes in the final state are an error. --- attr_ignore: Ignored text attributes, or `true` to ignore all. --- condition: Function asserting some arbitrary condition. --- any: true: Succeed if `expected` matches ANY screen line(s). --- false (default): `expected` must match screen exactly. -function Screen:expect(expected, attr_ids, attr_ignore, condition, any) +-- Use screen:set_default_attr_ids() to define attributes for many +-- expect() calls. +-- attr_ignore: Ignored text attributes, or `true` to ignore all. By default +-- nothing is ignored. +-- condition: Function asserting some arbitrary condition. Return value is +-- ignored, throw an error (use eq() or similar) to signal failure. +-- any: A string that should be present on any line of the screen. +-- mode: Expected mode as signaled by "mode_change" event +-- +-- The following keys should be used to expect the state of various ext_ +-- features. Note that an absent key will assert that the item is currently +-- NOT present on the screen, also when positional form is used. +-- +-- popupmenu: Expected ext_popupmenu state, +-- cmdline: Expected ext_cmdline state, as an array of cmdlines of +-- different level. +-- cmdline_block: Expected ext_cmdline block (for function definitions) +-- wildmenu_items: Expected items for ext_wildmenu +-- wildmenu_pos: Expected position for ext_wildmenu +function Screen:expect(expected, attr_ids, attr_ignore) + local grid, condition = nil, nil local expected_rows = {} - if type(expected) ~= "string" then - assert(not (attr_ids or attr_ignore or condition or any)) + if type(expected) == "table" then + assert(not (attr_ids ~= nil or attr_ignore ~= nil)) + local is_key = {grid=true, attr_ids=true, attr_ignore=true, condition=true, + any=true, mode=true, popupmenu=true, cmdline=true, + cmdline_block=true, wildmenu_items=true, wildmenu_pos=true} + for k, _ in pairs(expected) do + if not is_key[k] then + error("Screen:expect: Unknown keyword argument '"..k.."'") + end + end + grid = expected.grid + attr_ids = expected.attr_ids + attr_ignore = expected.attr_ignore + condition = expected.condition + assert(not (expected.any ~= nil and grid ~= nil)) + elseif type(expected) == "string" then + grid = expected + expected = {} + elseif type(expected) == "function" then + assert(not (attr_ids ~= nil or attr_ignore ~= nil)) condition = expected - expected = nil + expected = {} else + assert(false) + end + + if grid ~= nil then -- Remove the last line and dedent. Note that gsub returns more then one -- value. - expected = dedent(expected:gsub('\n[ ]+$', ''), 0) - for row in expected:gmatch('[^\n]+') do + grid = dedent(grid:gsub('\n[ ]+$', ''), 0) + for row in grid:gmatch('[^\n]+') do row = row:sub(1, #row - 1) -- Last char must be the screen delimiter. table.insert(expected_rows, row) end @@ -238,7 +293,7 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any) end end - if expected and not any and self._height ~= #expected_rows then + if grid ~= nil and self._height ~= #expected_rows then return ("Expected screen state's row count(" .. #expected_rows .. ') differs from configured height(' .. self._height .. ') of Screen.') end @@ -253,18 +308,18 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any) actual_rows[i] = self:_row_repr(self._rows[i], info, ignore) end - if expected == nil then - return - elseif any then - -- Search for `expected` anywhere in the screen lines. + if expected.any ~= nil then + -- Search for `any` anywhere in the screen lines. local actual_screen_str = table.concat(actual_rows, '\n') - if nil == string.find(actual_screen_str, expected) then + if nil == string.find(actual_screen_str, expected.any) then return ( 'Failed to match any screen lines.\n' - .. 'Expected (anywhere): "' .. expected .. '"\n' + .. 'Expected (anywhere): "' .. expected.any .. '"\n' .. 'Actual:\n |' .. table.concat(actual_rows, '|\n |') .. '|\n\n') end - else + end + + if grid ~= nil then -- `expected` must match the screen lines exactly. for i = 1, self._height do if expected_rows[i] ~= actual_rows[i] then @@ -284,6 +339,38 @@ screen:redraw_debug() to show all intermediate screen states. ]]) end end end + + -- Extension features. The default expectations should cover the case of + -- the ext_ feature being disabled, or the feature currently not activated + -- (for instance no external cmdline visible) + local expected_cmdline = expected.cmdline or {} + local actual_cmdline = {} + for i, entry in pairs(self.cmdline) do + entry = shallowcopy(entry) + entry.content = self:_chunks_repr(entry.content, info, ignore) + actual_cmdline[i] = entry + end + + local expected_block = expected.cmdline_block or {} + local actual_block = {} + for i, entry in ipairs(self.cmdline_block) do + actual_block[i] = self:_chunks_repr(entry, info, ignore) + end + + -- convert assertion errors into invalid screen state descriptions + local status, res = pcall(function() + eq(expected.popupmenu, self.popupmenu, "popupmenu") + eq(expected_cmdline, actual_cmdline, "cmdline") + eq(expected_block, actual_block, "cmdline_block") + eq(expected.wildmenu_items, self.wildmenu_items, "wildmenu_items") + eq(expected.wildmenu_pos, self.wildmenu_pos, "wildmenu_pos") + if expected.mode ~= nil then + eq(expected.mode, self.mode, "mode") + end + end) + if not status then + return tostring(res) + end end) end @@ -510,14 +597,6 @@ function Screen:_handle_hl_attr_define(id, rgb_attrs, cterm_attrs, info) self._new_attrs = true end -function Screen:get_hl(val) - if self._options.ext_newgrid then - return self._attr_table[val][1] - else - return val - end -end - function Screen:_handle_highlight_set(attrs) self._attrs = attrs end @@ -595,6 +674,63 @@ function Screen:_handle_option_set(name, value) self.options[name] = value end +function Screen:_handle_popupmenu_show(items, selected, row, col) + self.popupmenu = {items=items,pos=selected, anchor={row, col}} +end + +function Screen:_handle_popupmenu_select(selected) + self.popupmenu.pos = selected +end + +function Screen:_handle_popupmenu_hide() + self.popupmenu = nil +end + +function Screen:_handle_cmdline_show(content, pos, firstc, prompt, indent, level) + if firstc == '' then firstc = nil end + if prompt == '' then prompt = nil end + if indent == 0 then indent = nil end + self.cmdline[level] = {content=content, pos=pos, firstc=firstc, + prompt=prompt, indent=indent} +end + +function Screen:_handle_cmdline_hide(level) + self.cmdline[level] = nil +end + +function Screen:_handle_cmdline_special_char(char, shift, level) + -- cleared by next cmdline_show on the same level + self.cmdline[level].special = {char, shift} +end + +function Screen:_handle_cmdline_pos(pos, level) + self.cmdline[level].pos = pos +end + +function Screen:_handle_cmdline_block_show(block) + self.cmdline_block = block +end + +function Screen:_handle_cmdline_block_append(item) + self.cmdline_block[#self.cmdline_block+1] = item +end + +function Screen:_handle_cmdline_block_hide() + self.cmdline_block = {} +end + +function Screen:_handle_wildmenu_show(items) + self.wildmenu_items = items +end + +function Screen:_handle_wildmenu_select(pos) + self.wildmenu_pos = pos +end + +function Screen:_handle_wildmenu_hide() + self.wildmenu_items, self.wildmenu_pos = nil, nil +end + function Screen:_clear_block(top, bot, left, right) for i = top, bot do self:_clear_row_section(i, left, right) @@ -643,6 +779,21 @@ function Screen:_row_repr(row, attr_ids, attr_ignore) return table.concat(rv, '')--:gsub('%s+$', '') end +function Screen:_chunks_repr(chunks, attr_ids, attr_ignore) + local repr_chunks = {} + for i, chunk in ipairs(chunks) do + local hl, text = unpack(chunk) + local attrs + if self._options.ext_newgrid then + attrs = self._attr_table[hl][1] + else + attrs = hl + end + local attr_id = self:_get_attr_id(attr_ids, attr_ignore, attrs, hl) + repr_chunks[i] = {text, attr_id} + end + return repr_chunks +end function Screen:_current_screen() -- get a string that represents the current screen state(debugging helper) diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index e8271de0bf..dcab9f7ef4 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -28,27 +28,27 @@ describe('ui/ext_tabline', function() {tab = { id = 1 }, name = '[No Name]'}, {tab = { id = 2 }, name = 'another-tab'}, } - screen:expect([[ + screen:expect{grid=[[ ^ | ~ | ~ | ~ | | - ]], nil, nil, function() + ]], condition=function() eq({ id = 2 }, event_curtab) eq(expected_tabs, event_tabs) - end) + end} command("tabNext") - screen:expect([[ + screen:expect{grid=[[ ^ | ~ | ~ | ~ | | - ]], nil, nil, function() + ]], condition=function() eq({ id = 1 }, event_curtab) eq(expected_tabs, event_tabs) - end) + end} end) end) diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua index b60d520ca0..72dbef9538 100644 --- a/test/functional/ui/wildmode_spec.lua +++ b/test/functional/ui/wildmode_spec.lua @@ -167,7 +167,7 @@ describe("'wildmenu'", function() screen:sleep(10) -- Flush -- Check only the last 2 lines, because the shell output is -- system-dependent. - screen:expect('! # & < = > @ > \n:!^', nil, nil, nil, true) + screen:expect{any='! # & < = > @ > \n:!^'} end) end) @@ -204,21 +204,11 @@ end) describe('ui/ext_wildmenu', function() local screen - local items, selected = nil, nil before_each(function() clear() screen = Screen.new(25, 5) screen:attach({rgb=true, ext_wildmenu=true}) - screen:set_on_event_handler(function(name, data) - if name == "wildmenu_show" then - items = data[1] - elseif name == "wildmenu_select" then - selected = data[1] - elseif name == "wildmenu_hide" then - items, selected = nil, nil - end - end) end) after_each(function() @@ -238,63 +228,48 @@ describe('ui/ext_wildmenu', function() command('set wildmode=full') command('set wildmenu') feed(':sign <tab>') - screen:expect([[ + screen:expect{grid=[[ | ~ | ~ | ~ | :sign define^ | - ]], nil, nil, function() - eq(expected, items) - eq(0, selected) - end) + ]], wildmenu_items=expected, wildmenu_pos=0} feed('<tab>') - screen:expect([[ + screen:expect{grid=[[ | ~ | ~ | ~ | :sign jump^ | - ]], nil, nil, function() - eq(expected, items) - eq(1, selected) - end) + ]], wildmenu_items=expected, wildmenu_pos=1} feed('<left><left>') - screen:expect([[ + screen:expect{grid=[[ | ~ | ~ | ~ | :sign ^ | - ]], nil, nil, function() - eq(expected, items) - eq(-1, selected) - end) + ]], wildmenu_items=expected, wildmenu_pos=-1} feed('<right>') - screen:expect([[ + screen:expect{grid=[[ | ~ | ~ | ~ | :sign define^ | - ]], nil, nil, function() - eq(expected, items) - eq(0, selected) - end) + ]], wildmenu_items=expected, wildmenu_pos=0} feed('a') - screen:expect([[ + screen:expect{grid=[[ | ~ | ~ | ~ | :sign definea^ | - ]], nil, nil, function() - eq(nil, items) - eq(nil, selected) - end) + ]]} end) end) diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index c14f7fc1a6..3222e5783d 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -873,107 +873,6 @@ describe('completion', function() {3:-- Keyword Local completion (^N^P) }{4:match 1 of 7} | ]]) end) -end) - -describe('ui/ext_popupmenu', function() - local screen - local items, selected, anchor - before_each(function() - clear() - screen = Screen.new(60, 8) - screen:attach({rgb=true, ext_popupmenu=true}) - screen:set_default_attr_ids({ - [1] = {bold=true, foreground=Screen.colors.Blue}, - [2] = {bold = true}, - }) - screen:set_on_event_handler(function(name, data) - if name == "popupmenu_show" then - local row, col - items, selected, row, col = unpack(data) - anchor = {row, col} - elseif name == "popupmenu_select" then - selected = data[1] - elseif name == "popupmenu_hide" then - items = nil - end - end) - end) - - it('works', function() - source([[ - function! TestComplete() abort - call complete(1, ['foo', 'bar', 'spam']) - return '' - endfunction - ]]) - local expected = { - {'foo', '', '', ''}, - {'bar', '', '', ''}, - {'spam', '', '', ''}, - } - feed('o<C-r>=TestComplete()<CR>') - screen:expect([[ - | - foo^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | - ]], nil, nil, function() - eq(expected, items) - eq(0, selected) - eq({1,0}, anchor) - end) - - feed('<c-p>') - screen:expect([[ - | - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | - ]], nil, nil, function() - eq(expected, items) - eq(-1, selected) - eq({1,0}, anchor) - end) - - -- down moves the selection in the menu, but does not insert anything - feed('<down><down>') - screen:expect([[ - | - ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | - ]], nil, nil, function() - eq(expected, items) - eq(1, selected) - eq({1,0}, anchor) - end) - - feed('<cr>') - screen:expect([[ - | - bar^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {2:-- INSERT --} | - ]], nil, nil, function() - eq(nil, items) -- popupmenu was hidden - end) - end) it('TextChangedP autocommand', function() curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar'}) diff --git a/test/helpers.lua b/test/helpers.lua index 66724f6a78..22b5c68735 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -45,8 +45,8 @@ local check_logs_useless_lines = { ['See README_MISSING_SYSCALL_OR_IOCTL for guidance']=3, } -local function eq(expected, actual) - return assert.are.same(expected, actual) +local function eq(expected, actual, ctx) + return assert.are.same(expected, actual, ctx) end local function neq(expected, actual) return assert.are_not.same(expected, actual) |