123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858 |
- 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
- local command = helpers.command
- local assert_alive = helpers.assert_alive
- 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},
- })
- return screen
- end
- local function test_cmdline(linegrid)
- local screen
- before_each(function()
- clear()
- screen = new_screen({rgb=true, ext_cmdline=true, ext_linegrid=linegrid})
- end)
- it('works', function()
- feed(':')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{""}},
- pos = 0,
- }}}
- feed('sign')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign"}},
- pos = 4,
- }}}
- feed('<Left>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign"}},
- pos = 3,
- }}}
- feed('<bs>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sin"}},
- pos = 2,
- }}}
- feed('<Esc>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]]}
- end)
- describe("redraws statusline on entering", function()
- before_each(function()
- command('set laststatus=2')
- command('set statusline=%{mode()}')
- end)
- it('from normal mode', function()
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {3:n }|
- |
- ]]}
- feed(':')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {3:c }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{""}},
- pos = 0,
- }}}
- end)
- it('from normal mode when : is mapped', function()
- command('nnoremap ; :')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {3:n }|
- |
- ]]}
- feed(';')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {3:c }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{""}},
- pos = 0,
- }}}
- end)
- it('but not with scrolled messages', function()
- screen:try_resize(35,10)
- feed(':echoerr doesnotexist<cr>')
- screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {3: }|
- {4:E121: Undefined variable: doesnotex}|
- {4:ist} |
- {5:Press ENTER or type command to cont}|
- {5:inue}^ |
- ]]}
- feed(':echoerr doesnotexist<cr>')
- screen:expect{grid=[[
- |
- {1:~ }|
- {3: }|
- {4:E121: Undefined variable: doesnotex}|
- {4:ist} |
- {5:Press ENTER or type command to cont}|
- {4:E121: Undefined variable: doesnotex}|
- {4:ist} |
- {5:Press ENTER or type command to cont}|
- {5:inue}^ |
- ]]}
- feed(':echoerr doesnotexist<cr>')
- screen:expect{grid=[[
- {4:E121: Undefined variable: doesnotex}|
- {4:ist} |
- {5:Press ENTER or type command to cont}|
- {4:E121: Undefined variable: doesnotex}|
- {4:ist} |
- {5:Press ENTER or type command to cont}|
- {4:E121: Undefined variable: doesnotex}|
- {4:ist} |
- {5:Press ENTER or type command to cont}|
- {5:inue}^ |
- ]]}
- feed('<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {3:n }|
- |
- ]]}
- end)
- end)
- it("works with input()", function()
- feed(':call input("input", "default")<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- prompt = "input",
- content = {{"default"}},
- pos = 7,
- }}}
- feed('<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]]}
- end)
- it("works with special chars and nested cmdline", function()
- feed(':xx<c-r>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"xx"}},
- pos = 2,
- special = {'"', true},
- }}}
- feed('=')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], 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"}, {"+"}, {"2"}},
- pos = 3,
- }}
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline=expectation}
- -- erase information, so we check if it is retransmitted
- command("mode")
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline=expectation, reset=true}
- feed('<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"xx3"}},
- pos = 3,
- }}}
- feed('<esc>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]]}
- end)
- it("works with function definitions", function()
- feed(':function Foo()<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- indent = 2,
- firstc = ":",
- content = {{""}},
- pos = 0,
- }}, cmdline_block = {
- {{'function Foo()'}},
- }}
- feed('line1<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- indent = 2,
- firstc = ":",
- content = {{""}},
- pos = 0,
- }}, cmdline_block = {
- {{'function Foo()'}},
- {{' line1'}},
- }}
- command("mode")
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- indent = 2,
- firstc = ":",
- content = {{""}},
- pos = 0,
- }}, cmdline_block = {
- {{'function Foo()'}},
- {{' line1'}},
- }, reset=true}
- feed('endfunction<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]]}
- -- Try once more, to check buffer is reinitialized. #8007
- feed(':function Bar()<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- indent = 2,
- firstc = ":",
- content = {{""}},
- pos = 0,
- }}, cmdline_block = {
- {{'function Bar()'}},
- }}
- feed('endfunction<cr>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]]}
- end)
- it("works with cmdline window", function()
- feed(':make')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"make"}},
- pos = 4,
- }}}
- feed('<c-f>')
- screen:expect{grid=[[
- |
- {2:[No Name] }|
- {1::}make^ |
- {3:[Command Line] }|
- |
- ]]}
- -- nested cmdline
- feed(':yank')
- screen:expect{grid=[[
- |
- {2:[No Name] }|
- {1::}make^ |
- {3:[Command Line] }|
- |
- ]], cmdline={nil, {
- firstc = ":",
- content = {{"yank"}},
- pos = 4,
- }}}
- command("mode")
- screen:expect{grid=[[
- |
- {2:[No Name] }|
- {1::}make^ |
- {3:[Command Line] }|
- |
- ]], cmdline={nil, {
- firstc = ":",
- content = {{"yank"}},
- pos = 4,
- }}, reset=true}
- feed("<c-c>")
- screen:expect{grid=[[
- |
- {2:[No Name] }|
- {1::}make^ |
- {3:[Command Line] }|
- |
- ]]}
- 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=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"make"}},
- pos = 4,
- }}}
- end)
- it('works with inputsecret()', function()
- feed(":call inputsecret('secret:')<cr>abc123")
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- prompt = "secret:",
- content = {{"******"}},
- pos = 6,
- }}}
- end)
- it('works with highlighted cmdline', function()
- source([[
- highlight RBP1 guibg=Red
- highlight RBP2 guibg=Yellow
- highlight RBP3 guibg=Green
- highlight RBP4 guibg=Blue
- let g:NUM_LVLS = 4
- function RainBowParens(cmdline)
- let ret = []
- let i = 0
- let lvl = 0
- while i < len(a:cmdline)
- if a:cmdline[i] is# '('
- call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
- let lvl += 1
- elseif a:cmdline[i] is# ')'
- let lvl -= 1
- call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
- endif
- let i += 1
- endwhile
- return ret
- endfunction
- map <f5> :let x = input({'prompt':'>','highlight':'RainBowParens'})<cr>
- "map <f5> :let x = input({'prompt':'>'})<cr>
- ]])
- screen:set_default_attr_ids({
- RBP1={background = Screen.colors.Red},
- RBP2={background = Screen.colors.Yellow},
- EOB={bold = true, foreground = Screen.colors.Blue1},
- })
- feed('<f5>(a(b)a)')
- screen:expect{grid=[[
- ^ |
- {EOB:~ }|
- {EOB:~ }|
- {EOB:~ }|
- |
- ]], cmdline={{
- prompt = '>',
- content = {{'(', 'RBP1'}, {'a'}, {'(', 'RBP2'}, {'b'},
- { ')', 'RBP2'}, {'a'}, {')', 'RBP1'}},
- pos = 7,
- }}}
- end)
- it('works together with ext_wildmenu', function()
- local expected = {
- 'define',
- 'jump',
- 'list',
- 'place',
- 'undefine',
- 'unplace',
- }
- command('set wildmode=full')
- command('set wildmenu')
- screen:set_option('ext_wildmenu', true)
- feed(':sign <tab>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign define"}},
- pos = 11,
- }}, wildmenu_items=expected, wildmenu_pos=0}
- feed('<tab>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign jump"}},
- pos = 9,
- }}, wildmenu_items=expected, wildmenu_pos=1}
- feed('<left><left>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign "}},
- pos = 5,
- }}, wildmenu_items=expected, wildmenu_pos=-1}
- feed('<right>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign define"}},
- pos = 11,
- }}, wildmenu_items=expected, wildmenu_pos=0}
- feed('a')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign definea"}},
- pos = 12,
- }}}
- end)
- it('works together with ext_popupmenu', function()
- local expected = {
- {'define', '', '', ''},
- {'jump', '', '', ''},
- {'list', '', '', ''},
- {'place', '', '', ''},
- {'undefine', '', '', ''},
- {'unplace', '', '', ''},
- }
- command('set wildmode=full')
- command('set wildmenu')
- screen:set_option('ext_popupmenu', true)
- feed(':sign <tab>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign define"}},
- pos = 11,
- }}, popupmenu={items=expected, pos=0, anchor={-1, 0, 5}}}
- feed('<tab>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign jump"}},
- pos = 9,
- }}, popupmenu={items=expected, pos=1, anchor={-1, 0, 5}}}
- feed('<left><left>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign "}},
- pos = 5,
- }}, popupmenu={items=expected, pos=-1, anchor={-1, 0, 5}}}
- feed('<right>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign define"}},
- pos = 11,
- }}, popupmenu={items=expected, pos=0, anchor={-1, 0, 5}}}
- feed('a')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], cmdline={{
- firstc = ":",
- content = {{"sign definea"}},
- pos = 12,
- }}}
- feed('<esc>')
- -- check positioning with multibyte char in pattern
- command("e långfile1")
- command("sp långfile2")
- feed(':b lå<tab>')
- 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
- }}}
- end)
- it('ext_wildmenu takes precedence over ext_popupmenu', function()
- local expected = {
- 'define',
- 'jump',
- 'list',
- 'place',
- 'undefine',
- 'unplace',
- }
- command('set wildmode=full')
- command('set wildmenu')
- screen:set_option('ext_wildmenu', true)
- screen:set_option('ext_popupmenu', true)
- feed(':sign <tab>')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], 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()
- command('set notimeout')
- command('cnoremap ab c')
- feed(':xa')
- screen:expect{grid=[[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]], 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.
- feed('<esc>')
- screen:expect([[
- ^ |
- {1:~ }|
- {1:~ }|
- {1:~ }|
- |
- ]])
- 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('cmdline redraw', function()
- local screen
- before_each(function()
- clear()
- screen = new_screen({rgb=true})
- end)
- it('with timer', function()
- feed(':012345678901234567890123456789')
- screen:expect{grid=[[
- |
- {1:~ }|
- {3: }|
- :012345678901234567890123|
- 456789^ |
- ]]}
- command('call timer_start(0, {-> 1})')
- screen:expect{grid=[[
- |
- {1:~ }|
- {3: }|
- :012345678901234567890123|
- 456789^ |
- ]], unchanged=true, timeout=100}
- end)
- it('with <Cmd>', function()
- if 'openbsd' == helpers.uname() then
- pending('FIXME #10804')
- end
- command('cmap a <Cmd>call sin(0)<CR>') -- no-op
- feed(':012345678901234567890123456789')
- screen:expect{grid=[[
- |
- {1:~ }|
- {3: }|
- :012345678901234567890123|
- 456789^ |
- ]]}
- feed('a')
- screen:expect{grid=[[
- |
- {1:~ }|
- {3: }|
- :012345678901234567890123|
- 456789^ |
- ]], unchanged=true}
- end)
- end)
- describe("cmdline height", function()
- it("does not crash resized screen #14263", function()
- clear()
- local screen = Screen.new(25, 10)
- screen:attach()
- command('set cmdheight=9999')
- screen:try_resize(25, 5)
- assert_alive()
- end)
- end)
|