diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:18 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:29 +0100 |
commit | 04f2f864e270e772c6326cefdf24947f0130e492 (patch) | |
tree | 46f83f909b888a66c741032ab955afc6eab84292 /test/functional/ui/cmdline_spec.lua | |
parent | 59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff) | |
download | rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2 rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip |
refactor: format test/*
Diffstat (limited to 'test/functional/ui/cmdline_spec.lua')
-rw-r--r-- | test/functional/ui/cmdline_spec.lua | 1257 |
1 files changed, 802 insertions, 455 deletions
diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index cac070406d..82ff633fcb 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -15,16 +15,16 @@ local function new_screen(opt) local screen = Screen.new(25, 5) screen:attach(opt) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {reverse = true}, - [3] = {bold = true, reverse = true}, - [4] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [5] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [6] = {foreground = Screen.colors.Magenta}, - [7] = {bold = true, foreground = Screen.colors.Brown}, - [8] = {background = Screen.colors.LightGrey}, - [9] = {bold = true}, - [10] = {background = Screen.colors.Yellow1}; + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { reverse = true }, + [3] = { bold = true, reverse = true }, + [4] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [5] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [6] = { foreground = Screen.colors.Magenta }, + [7] = { bold = true, foreground = Screen.colors.Brown }, + [8] = { background = Screen.colors.LightGrey }, + [9] = { bold = true }, + [10] = { background = Screen.colors.Yellow1 }, }) return screen end @@ -34,326 +34,445 @@ local function test_cmdline(linegrid) before_each(function() clear() - screen = new_screen({rgb=true, ext_cmdline=true, ext_linegrid=linegrid}) + screen = new_screen({ rgb = true, ext_cmdline = true, ext_linegrid = linegrid }) end) it('works', function() feed(':') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{""}}, - pos = 0, - }}} + ]], + cmdline = { { + firstc = ':', + content = { { '' } }, + pos = 0, + } }, + } feed('sign') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign"}}, - pos = 4, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign' } }, + pos = 4, + }, + }, + } feed('<Left>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign"}}, - pos = 3, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign' } }, + pos = 3, + }, + }, + } feed('<bs>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sin"}}, - pos = 2, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sin' } }, + pos = 2, + }, + }, + } feed('<Esc>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]]} + ]], + } end) - it("works with input()", function() + it('works with input()', function() feed(':call input("input", "default")<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - prompt = "input", - content = {{"default"}}, - pos = 7, - }}} + ]], + cmdline = { + { + prompt = 'input', + content = { { 'default' } }, + pos = 7, + }, + }, + } feed('<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]]} + ]], + } end) - it("works with special chars and nested cmdline", function() + it('works with special chars and nested cmdline', function() feed(':xx<c-r>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"xx"}}, - pos = 2, - special = {'"', true}, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'xx' } }, + pos = 2, + special = { '"', true }, + }, + }, + } feed('=') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"xx"}}, - pos = 2, - special = {'"', true}, - }, { - firstc = "=", - content = {{""}}, - pos = 0, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'xx' } }, + pos = 2, + special = { '"', true }, + }, + { + firstc = '=', + content = { { '' } }, + pos = 0, + }, + }, + } feed('1+2') - local expectation = {{ - firstc = ":", - content = {{"xx"}}, - pos = 2, - special = {'"', true}, - }, { - firstc = "=", - content = {{"1", 6}, {"+", 7}, {"2", 6}}, - pos = 3, - }} - - screen:expect{grid=[[ + local expectation = { + { + firstc = ':', + content = { { 'xx' } }, + pos = 2, + special = { '"', true }, + }, + { + firstc = '=', + content = { { '1', 6 }, { '+', 7 }, { '2', 6 } }, + pos = 3, + }, + } + + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline=expectation} + ]], + cmdline = expectation, + } -- erase information, so we check if it is retransmitted - command("mode") - screen:expect{grid=[[ + command('mode') + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline=expectation, reset=true} - + ]], + cmdline = expectation, + reset = true, + } feed('<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"xx3"}}, - pos = 3, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'xx3' } }, + pos = 3, + }, + }, + } feed('<esc>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]]} + ]], + } end) - it("works with function definitions", function() + it('works with function definitions', function() feed(':function Foo()<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - indent = 2, - firstc = ":", - content = {{""}}, - pos = 0, - }}, cmdline_block = { - {{'function Foo()'}}, - }} + ]], + cmdline = { + { + indent = 2, + firstc = ':', + content = { { '' } }, + pos = 0, + }, + }, + cmdline_block = { + { { 'function Foo()' } }, + }, + } feed('line1<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - indent = 2, - firstc = ":", - content = {{""}}, - pos = 0, - }}, cmdline_block = { - {{'function Foo()'}}, - {{' line1'}}, - }} - - command("mode") - screen:expect{grid=[[ + ]], + cmdline = { + { + indent = 2, + firstc = ':', + content = { { '' } }, + pos = 0, + }, + }, + cmdline_block = { + { { 'function Foo()' } }, + { { ' line1' } }, + }, + } + + command('mode') + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - indent = 2, - firstc = ":", - content = {{""}}, - pos = 0, - }}, cmdline_block = { - {{'function Foo()'}}, - {{' line1'}}, - }, reset=true} + ]], + cmdline = { + { + indent = 2, + firstc = ':', + content = { { '' } }, + pos = 0, + }, + }, + cmdline_block = { + { { 'function Foo()' } }, + { { ' line1' } }, + }, + reset = true, + } feed('endfunction<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]]} + ]], + } -- Try once more, to check buffer is reinitialized. #8007 feed(':function Bar()<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - indent = 2, - firstc = ":", - content = {{""}}, - pos = 0, - }}, cmdline_block = { - {{'function Bar()'}}, - }} + ]], + cmdline = { + { + indent = 2, + firstc = ':', + content = { { '' } }, + pos = 0, + }, + }, + cmdline_block = { + { { 'function Bar()' } }, + }, + } feed('endfunction<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]]} - + ]], + } end) - it("works with cmdline window", function() + it('works with cmdline window', function() feed(':make') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"make"}}, - pos = 4, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'make' } }, + pos = 4, + }, + }, + } feed('<c-f>') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {2:[No Name] }| {1::}mak^e | {3:[Command Line] }| | - ]]} + ]], + } -- nested cmdline feed(':yank') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {2:[No Name] }| {1::}mak^e | {3:[Command Line] }| | - ]], cmdline={nil, { - firstc = ":", - content = {{"yank"}}, - pos = 4, - }}} - - command("mode") - screen:expect{grid=[[ + ]], + cmdline = { + nil, + { + firstc = ':', + content = { { 'yank' } }, + pos = 4, + }, + }, + } + + command('mode') + screen:expect { + grid = [[ | {2:[No Name] }| {1::}mak^e | {3:[Command Line] }| | - ]], cmdline={nil, { - firstc = ":", - content = {{"yank"}}, - pos = 4, - }}, reset=true} - - feed("<c-c>") - screen:expect{grid=[[ + ]], + cmdline = { + nil, + { + firstc = ':', + content = { { 'yank' } }, + pos = 4, + }, + }, + reset = true, + } + + feed('<c-c>') + screen:expect { + grid = [[ | {2:[No Name] }| {1::}mak^e | {3:[Command Line] }| | - ]]} + ]], + } - feed("<c-c>") - screen:expect{grid=[[ + feed('<c-c>') + screen:expect { + grid = [[ ^ | {2:[No Name] }| {1::}make | {3:[Command Line] }| | - ]], cmdline={{ - firstc = ":", - content = {{"make"}}, - pos = 4, - }}} - - command("redraw!") - screen:expect{grid=[[ + ]], + cmdline = { + { + firstc = ':', + content = { { 'make' } }, + pos = 4, + }, + }, + } + + command('redraw!') + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"make"}}, - pos = 4, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'make' } }, + pos = 4, + }, + }, + } end) it('works with inputsecret()', function() feed(":call inputsecret('secret:')<cr>abc123") - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - prompt = "secret:", - content = {{"******"}}, - pos = 6, - }}} + ]], + cmdline = { + { + prompt = 'secret:', + content = { { '******' } }, + pos = 6, + }, + }, + } end) it('works with highlighted cmdline', function() @@ -383,21 +502,33 @@ local function test_cmdline(linegrid) "map <f5> :let x = input({'prompt':'>'})<cr> ]]) screen:set_default_attr_ids({ - RBP1={background = Screen.colors.Red}, - RBP2={background = Screen.colors.Yellow}, - EOB={bold = true, foreground = Screen.colors.Blue1}, + RBP1 = { background = Screen.colors.Red }, + RBP2 = { background = Screen.colors.Yellow }, + EOB = { bold = true, foreground = Screen.colors.Blue1 }, }) feed('<f5>(a(b)a)') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {EOB:~ }|*3 | - ]], cmdline={{ - prompt = '>', - content = {{'(', 'RBP1'}, {'a'}, {'(', 'RBP2'}, {'b'}, - { ')', 'RBP2'}, {'a'}, {')', 'RBP1'}}, - pos = 7, - }}} + ]], + cmdline = { + { + prompt = '>', + content = { + { '(', 'RBP1' }, + { 'a' }, + { '(', 'RBP2' }, + { 'b' }, + { ')', 'RBP2' }, + { 'a' }, + { ')', 'RBP1' }, + }, + pos = 7, + }, + }, + } end) it('works together with ext_wildmenu', function() @@ -415,69 +546,102 @@ local function test_cmdline(linegrid) screen:set_option('ext_wildmenu', true) feed(':sign <tab>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign define"}}, - pos = 11, - }}, wildmenu_items=expected, wildmenu_pos=0} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign define' } }, + pos = 11, + }, + }, + wildmenu_items = expected, + wildmenu_pos = 0, + } feed('<tab>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign jump"}}, - pos = 9, - }}, wildmenu_items=expected, wildmenu_pos=1} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign jump' } }, + pos = 9, + }, + }, + wildmenu_items = expected, + wildmenu_pos = 1, + } feed('<left><left>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign "}}, - pos = 5, - }}, wildmenu_items=expected, wildmenu_pos=-1} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign ' } }, + pos = 5, + }, + }, + wildmenu_items = expected, + wildmenu_pos = -1, + } feed('<right>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign define"}}, - pos = 11, - }}, wildmenu_items=expected, wildmenu_pos=0} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign define' } }, + pos = 11, + }, + }, + wildmenu_items = expected, + wildmenu_pos = 0, + } feed('a') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign definea"}}, - pos = 12, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign definea' } }, + pos = 12, + }, + }, + } end) it('works together with ext_popupmenu', function() local expected = { - {'define', '', '', ''}, - {'jump', '', '', ''}, - {'list', '', '', ''}, - {'place', '', '', ''}, - {'undefine', '', '', ''}, - {'unplace', '', '', ''}, + { 'define', '', '', '' }, + { 'jump', '', '', '' }, + { 'list', '', '', '' }, + { 'place', '', '', '' }, + { 'undefine', '', '', '' }, + { 'unplace', '', '', '' }, } command('set wildmode=full') @@ -485,80 +649,115 @@ local function test_cmdline(linegrid) screen:set_option('ext_popupmenu', true) feed(':sign <tab>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign define"}}, - pos = 11, - }}, popupmenu={items=expected, pos=0, anchor={-1, 0, 5}}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign define' } }, + pos = 11, + }, + }, + popupmenu = { items = expected, pos = 0, anchor = { -1, 0, 5 } }, + } feed('<tab>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign jump"}}, - pos = 9, - }}, popupmenu={items=expected, pos=1, anchor={-1, 0, 5}}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign jump' } }, + pos = 9, + }, + }, + popupmenu = { items = expected, pos = 1, anchor = { -1, 0, 5 } }, + } feed('<left><left>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign "}}, - pos = 5, - }}, popupmenu={items=expected, pos=-1, anchor={-1, 0, 5}}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign ' } }, + pos = 5, + }, + }, + popupmenu = { items = expected, pos = -1, anchor = { -1, 0, 5 } }, + } feed('<right>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign define"}}, - pos = 11, - }}, popupmenu={items=expected, pos=0, anchor={-1, 0, 5}}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign define' } }, + pos = 11, + }, + }, + popupmenu = { items = expected, pos = 0, anchor = { -1, 0, 5 } }, + } feed('a') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign definea"}}, - pos = 12, - }}} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign definea' } }, + pos = 12, + }, + }, + } feed('<esc>') -- check positioning with multibyte char in pattern - command("e långfile1") - command("sp långfile2") + command('e långfile1') + command('sp långfile2') feed(':b lå<tab>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {3:långfile2 }| | {2:långfile1 }| | - ]], popupmenu={ - anchor = { -1, 0, 2 }, - items = {{ "långfile1", "", "", "" }, { "långfile2", "", "", "" }}, - pos = 0 - }, cmdline={{ - content = {{ "b långfile1" }}, - firstc = ":", - pos = 12 - }}} + ]], + popupmenu = { + anchor = { -1, 0, 2 }, + items = { { 'långfile1', '', '', '' }, { 'långfile2', '', '', '' } }, + pos = 0, + }, + cmdline = { + { + content = { { 'b långfile1' } }, + firstc = ':', + pos = 12, + }, + }, + } end) it('ext_wildmenu takes precedence over ext_popupmenu', function() @@ -577,15 +776,22 @@ local function test_cmdline(linegrid) screen:set_option('ext_popupmenu', true) feed(':sign <tab>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - firstc = ":", - content = {{"sign define"}}, - pos = 11, - }}, wildmenu_items=expected, wildmenu_pos=0} + ]], + cmdline = { + { + firstc = ':', + content = { { 'sign define' } }, + pos = 11, + }, + }, + wildmenu_items = expected, + wildmenu_pos = 0, + } end) it("doesn't send invalid events when aborting mapping #10000", function() @@ -593,16 +799,21 @@ local function test_cmdline(linegrid) command('cnoremap ab c') feed(':xa') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]], cmdline={{ - content = { { "x" } }, - firstc = ":", - pos = 1, - special = { "a", false } - }}} + ]], + cmdline = { + { + content = { { 'x' } }, + firstc = ':', + pos = 1, + special = { 'a', false }, + }, + }, + } -- This used to send an invalid event where pos where larger than the total -- length of content. Checked in _handle_cmdline_show. @@ -613,61 +824,75 @@ local function test_cmdline(linegrid) | ]]) end) - end -- the representation of cmdline and cmdline_block contents changed with ext_linegrid -- (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) +describe('ui/ext_cmdline', function() + test_cmdline(true) +end) +describe('ui/ext_cmdline (legacy highlights)', function() + test_cmdline(false) +end) describe('cmdline redraw', function() local screen before_each(function() clear() - screen = new_screen({rgb=true}) + screen = new_screen({ rgb = true }) end) it('with timer', function() feed(':012345678901234567890123456789') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }| {3: }| :012345678901234567890123| 456789^ | - ]]} + ]], + } command('call timer_start(0, {-> 1})') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }| {3: }| :012345678901234567890123| 456789^ | - ]], unchanged=true, timeout=100} + ]], + unchanged = true, + timeout = 100, + } end) it('with <Cmd>', function() if is_os('bsd') then pending('FIXME #10804') end - command('cmap a <Cmd>call sin(0)<CR>') -- no-op + command('cmap a <Cmd>call sin(0)<CR>') -- no-op feed(':012345678901234567890123456789') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }| {3: }| :012345678901234567890123| 456789^ | - ]]} + ]], + } feed('a') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }| {3: }| :012345678901234567890123| 456789^ | - ]], unchanged=true} + ]], + unchanged = true, + } end) it('after pressing Ctrl-C in cmdwin in Visual mode #18967', function() @@ -697,64 +922,80 @@ describe('cmdline redraw', function() it('with rightleftcmd', function() command('set rightleft rightleftcmd=search shortmess+=s') - meths.buf_set_lines(0, 0, -1, true, {"let's rock!"}) - screen:expect{grid=[[ + meths.buf_set_lines(0, 0, -1, true, { "let's rock!" }) + screen:expect { + grid = [[ !kcor s'te^l| {1: ~}|*3 | - ]]} + ]], + } feed '/' - screen:expect{grid=[[ + screen:expect { + grid = [[ !kcor s'tel| {1: ~}|*3 ^ /| - ]]} + ]], + } feed "let's" -- note: cursor looks off but looks alright in real use -- when rendered as a block so it touches the end of the text - screen:expect{grid=[[ + screen:expect { + grid = [[ !kcor {2:s'tel}| {1: ~}|*3 ^ s'tel/| - ]]} + ]], + } -- cursor movement - feed "<space>" - screen:expect{grid=[[ + feed '<space>' + screen:expect { + grid = [[ !kcor{2: s'tel}| {1: ~}|*3 ^ s'tel/| - ]]} + ]], + } - feed "rock" - screen:expect{grid=[[ + feed 'rock' + screen:expect { + grid = [[ !{2:kcor s'tel}| {1: ~}|*3 ^ kcor s'tel/| - ]]} + ]], + } - feed "<right>" - screen:expect{grid=[[ + feed '<right>' + screen:expect { + grid = [[ !{2:kcor s'tel}| {1: ~}|*3 ^kcor s'tel/| - ]]} + ]], + } - feed "<left>" - screen:expect{grid=[[ + feed '<left>' + screen:expect { + grid = [[ !{2:kcor s'tel}| {1: ~}|*3 ^ kcor s'tel/| - ]]} + ]], + } - feed "<cr>" - screen:expect{grid=[[ + feed '<cr>' + screen:expect { + grid = [[ !{10:kcor s'te^l}| {1: ~}|*3 kcor s'tel/ | - ]]} + ]], + } end) end) @@ -769,44 +1010,52 @@ describe('statusline is redrawn on entering cmdline', function() it('from normal mode', function() command('set statusline=%{mode()}') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*2 {3:n }| | - ]]} + ]], + } feed(':') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*2 {3:c }| :^ | - ]]} + ]], + } end) it('from normal mode when : is mapped', function() command('set statusline=%{mode()}') command('nnoremap ; :') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*2 {3:n }| | - ]]} + ]], + } feed(';') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*2 {3:c }| :^ | - ]]} + ]], + } end) it('with scrolled messages', function() - screen:try_resize(35,14) + screen:try_resize(35, 14) exec([[ let g:count = 0 autocmd CmdlineEnter * let g:count += 1 @@ -816,7 +1065,8 @@ describe('statusline is redrawn on entering cmdline', function() setlocal winbar=%{mode()}%{g:count} ]]) feed(':echoerr doesnotexist<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {9:c1 }| | {3:c1 }| @@ -827,9 +1077,11 @@ describe('statusline is redrawn on entering cmdline', function() {4:ist} | {5:Press ENTER or type command to cont}| {5:inue}^ | - ]]} + ]], + } feed(':echoerr doesnotexist<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {9:c2 }| | {3:c2 }| @@ -843,10 +1095,12 @@ describe('statusline is redrawn on entering cmdline', function() {4:ist} | {5:Press ENTER or type command to cont}| {5:inue}^ | - ]]} + ]], + } feed(':echoerr doesnotexist<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {9:c3 }| | {3:c3 }| @@ -861,10 +1115,12 @@ describe('statusline is redrawn on entering cmdline', function() {4:ist} | {5:Press ENTER or type command to cont}| {5:inue}^ | - ]]} + ]], + } feed('<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {9:n3 }| ^ | {3:n3 }| @@ -872,40 +1128,47 @@ describe('statusline is redrawn on entering cmdline', function() {1:~ }|*8 {2:[No Name] }| | - ]]} + ]], + } end) describe('if custom statusline is set by', function() before_each(function() command('set statusline=') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*2 {3:[No Name] }| | - ]]} + ]], + } end) it('CmdlineEnter autocommand', function() command('autocmd CmdlineEnter * set statusline=command') feed(':') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*2 {3:command }| :^ | - ]]} + ]], + } end) it('ModeChanged autocommand', function() command('autocmd ModeChanged *:c set statusline=command') feed(':') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*2 {3:command }| :^ | - ]]} + ]], + } end) end) end) @@ -914,9 +1177,9 @@ it('tabline is not redrawn in Ex mode #24122', function() clear() local screen = Screen.new(60, 5) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [1] = {bold = true, reverse = true}, -- MsgSeparator - [2] = {reverse = true}, -- TabLineFill + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [1] = { bold = true, reverse = true }, -- MsgSeparator + [2] = { reverse = true }, -- TabLineFill }) screen:attach() @@ -931,28 +1194,32 @@ it('tabline is not redrawn in Ex mode #24122', function() ]]) feed('gQ') - screen:expect{grid=[[ + screen:expect { + grid = [[ {2:foo }| | {1: }| Entering Ex mode. Type "visual" to go to Normal mode. | :^ | - ]]} + ]], + } feed('echo 1<CR>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {1: }| Entering Ex mode. Type "visual" to go to Normal mode. | :echo 1 | 1 | :^ | - ]]} + ]], + } end) -describe("cmdline height", function() +describe('cmdline height', function() before_each(clear) - it("does not crash resized screen #14263", function() + it('does not crash resized screen #14263', function() local screen = Screen.new(25, 10) screen:attach() command('set cmdheight=9999') @@ -976,254 +1243,320 @@ describe('cmdheight=0', function() clear() screen = Screen.new(25, 5) screen:set_default_attr_ids { - [1] = {bold = true, foreground = Screen.colors.Blue}; - [2] = {bold = true, reverse = true}; - [3] = {bold = true}; - [4] = {foreground = Screen.colors.White, background = Screen.colors.Red}; - [5] = {foreground = Screen.colors.SeaGreen4, bold = true}; - [6] = {reverse = true}; - [7] = {background = Screen.colors.Yellow}; + [1] = { bold = true, foreground = Screen.colors.Blue }, + [2] = { bold = true, reverse = true }, + [3] = { bold = true }, + [4] = { foreground = Screen.colors.White, background = Screen.colors.Red }, + [5] = { foreground = Screen.colors.SeaGreen4, bold = true }, + [6] = { reverse = true }, + [7] = { background = Screen.colors.Yellow }, } screen:attach() end) - it("with redrawdebug=invalid resize -1", function() - command("set redrawdebug=invalid cmdheight=0 noruler laststatus=0") - screen:expect{grid=[[ + it('with redrawdebug=invalid resize -1', function() + command('set redrawdebug=invalid cmdheight=0 noruler laststatus=0') + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]]} - feed(":resize -1<CR>") - screen:expect{grid=[[ + ]], + } + feed(':resize -1<CR>') + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]]} + ]], + } assert_alive() end) - it("with cmdheight=1 noruler laststatus=2", function() - command("set cmdheight=1 noruler laststatus=2") - screen:expect{grid=[[ + it('with cmdheight=1 noruler laststatus=2', function() + command('set cmdheight=1 noruler laststatus=2') + screen:expect { + grid = [[ ^ | {1:~ }|*2 {2:[No Name] }| | - ]]} + ]], + } end) - it("with cmdheight=0 noruler laststatus=2", function() - command("set cmdheight=0 noruler laststatus=2") - screen:expect{grid=[[ + it('with cmdheight=0 noruler laststatus=2', function() + command('set cmdheight=0 noruler laststatus=2') + screen:expect { + grid = [[ ^ | {1:~ }|*3 {2:[No Name] }| - ]]} + ]], + } end) - it("with cmdheight=0 ruler laststatus=0", function() - command("set cmdheight=0 ruler laststatus=0") - screen:expect{grid=[[ + it('with cmdheight=0 ruler laststatus=0', function() + command('set cmdheight=0 ruler laststatus=0') + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]]} + ]], + } end) - it("with cmdheight=0 ruler laststatus=0", function() - command("set cmdheight=0 noruler laststatus=0 showmode") + it('with cmdheight=0 ruler laststatus=0', function() + command('set cmdheight=0 noruler laststatus=0 showmode') feed('i') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]], showmode={}} + ]], + showmode = {}, + } feed('<Esc>') eq(0, eval('&cmdheight')) end) - it("with cmdheight=0 ruler rulerformat laststatus=0", function() - command("set cmdheight=0 noruler laststatus=0 rulerformat=%l,%c%= showmode") + it('with cmdheight=0 ruler rulerformat laststatus=0', function() + command('set cmdheight=0 noruler laststatus=0 rulerformat=%l,%c%= showmode') feed('i') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]], showmode={}} + ]], + showmode = {}, + } feed('<Esc>') eq(0, eval('&cmdheight')) end) - it("with showmode", function() - command("set cmdheight=1 noruler laststatus=0 showmode") + it('with showmode', function() + command('set cmdheight=1 noruler laststatus=0 showmode') feed('i') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 {3:-- INSERT --} | - ]]} + ]], + } feed('<Esc>') eq(1, eval('&cmdheight')) end) - it("when using command line", function() - command("set cmdheight=0 noruler laststatus=0") + it('when using command line', function() + command('set cmdheight=0 noruler laststatus=0') feed(':') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*3 :^ | - ]]} + ]], + } eq(0, eval('&cmdheight')) feed('<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]], showmode={}} + ]], + showmode = {}, + } eq(0, eval('&cmdheight')) end) - it("when using input()", function() - command("set cmdheight=0 noruler laststatus=0") + it('when using input()', function() + command('set cmdheight=0 noruler laststatus=0') feed(':call input("foo >")<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }| {2: }| :call input("foo >") | foo >^ | - ]]} + ]], + } eq(0, eval('&cmdheight')) feed('<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]], showmode={}} + ]], + showmode = {}, + } eq(0, eval('&cmdheight')) end) - it("with winbar and splits", function() - command("set cmdheight=0 noruler laststatus=3 winbar=foo") + it('with winbar and splits', function() + command('set cmdheight=0 noruler laststatus=3 winbar=foo') feed(':split<CR>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {2: }| :split | {4:E36: Not enough room} | {5:Press ENTER or type comma}| {5:nd to continue}^ | - ]]} + ]], + } feed('<CR>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {3:foo }| ^ | {1:~ }|*2 {2:[No Name] }| - ]]} + ]], + } feed(':') - screen:expect{grid=[[ + screen:expect { + grid = [[ {3:foo }| | {1:~ }|*2 :^ | - ]]} + ]], + } feed('<Esc>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {3:foo }| ^ | {1:~ }|*2 {2:[No Name] }| - ]], showmode={}} + ]], + showmode = {}, + } eq(0, eval('&cmdheight')) assert_alive() end) - it("when macro with lastline", function() - command("set cmdheight=0 display=lastline") + it('when macro with lastline', function() + command('set cmdheight=0 display=lastline') feed('qq') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]]} + ]], + } feed('q') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]], unchanged=true} + ]], + unchanged = true, + } end) - it("when substitute text", function() - command("set cmdheight=0 noruler laststatus=3") + it('when substitute text', function() + command('set cmdheight=0 noruler laststatus=3') feed('ifoo<ESC>') - screen:expect{grid=[[ + screen:expect { + grid = [[ fo^o | {1:~ }|*3 {2:[No Name] [+] }| - ]]} + ]], + } feed(':%s/foo/bar/gc<CR>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {6:foo} | {1:~ }|*3 {5:replace wi...q/l/^E/^Y)?}^ | - ]]} + ]], + } feed('y') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^bar | {1:~ }|*3 {2:[No Name] [+] }| - ]]} + ]], + } assert_alive() end) - it("when window resize", function() - command("set cmdheight=0") + it('when window resize', function() + command('set cmdheight=0') feed('<C-w>+') eq(0, eval('&cmdheight')) end) - it("with non-silent mappings with cmdline", function() - command("set cmdheight=0") - command("map <f3> :nohlsearch<cr>") + it('with non-silent mappings with cmdline', function() + command('set cmdheight=0') + command('map <f3> :nohlsearch<cr>') feed('iaabbaa<esc>/aa<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {7:^aa}bb{7:aa} | {1:~ }|*4 - ]]} + ]], + } feed('<f3>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^aabbaa | {1:~ }|*4 - ]]} + ]], + } end) it('with silent! at startup', function() - clear{args={'-c', 'set cmdheight=0', '-c', 'autocmd VimEnter * silent! call Foo()'}} + clear { args = { '-c', 'set cmdheight=0', '-c', 'autocmd VimEnter * silent! call Foo()' } } screen:attach() -- doesn't crash while not displaying silent! error message - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*4 - ]]} + ]], + } end) it('with multigrid', function() - clear{args={'--cmd', 'set cmdheight=0'}} - screen:attach{ext_multigrid=true} - meths.buf_set_lines(0, 0, -1, true, {'p'}) - screen:expect{grid=[[ + clear { args = { '--cmd', 'set cmdheight=0' } } + screen:attach { ext_multigrid = true } + meths.buf_set_lines(0, 0, -1, true, { 'p' }) + screen:expect { + grid = [[ ## grid 1 [2:-------------------------]|*5 ## grid 2 ^p | {1:~ }|*4 ## grid 3 - ]], win_viewport={ - [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; - }} + ]], + win_viewport = { + [2] = { + win = { id = 1000 }, + topline = 0, + botline = 2, + curline = 0, + curcol = 0, + linecount = 1, + sum_scroll_delta = 0, + }, + }, + } feed '/p' - screen:expect{grid=[[ + screen:expect { + grid = [[ ## grid 1 [2:-------------------------]|*4 [3:-------------------------]| @@ -1232,9 +1565,19 @@ describe('cmdheight=0', function() {1:~ }|*4 ## grid 3 /p^ | - ]], win_viewport={ - [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; - }} + ]], + win_viewport = { + [2] = { + win = { id = 1000 }, + topline = 0, + botline = 2, + curline = 0, + curcol = 0, + linecount = 1, + sum_scroll_delta = 0, + }, + }, + } end) it('winbar is redrawn on entering cmdline and :redrawstatus #20336', function() @@ -1324,18 +1667,22 @@ describe('cmdheight=0', function() | ]]) command('set cmdheight=0') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 {2:[No Name] }| - ]]} + ]], + } command('resize -1') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*2 {2:[No Name] }| | - ]]} + ]], + } command('resize +1') screen:expect([[ ^ | @@ -1344,9 +1691,9 @@ describe('cmdheight=0', function() ]]) end) - it("cannot be resized at all with external messages", function() + it('cannot be resized at all with external messages', function() clear() - screen = new_screen({rgb=true, ext_messages=true}) + screen = new_screen({ rgb = true, ext_messages = true }) command('set laststatus=2 mouse=a') command('resize -1') screen:expect([[ |