diff options
Diffstat (limited to 'test/functional/ui')
21 files changed, 2752 insertions, 856 deletions
diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua index 0221c1e0b0..ce7c9596bb 100644 --- a/test/functional/ui/cmdline_spec.lua +++ b/test/functional/ui/cmdline_spec.lua @@ -91,25 +91,27 @@ local function test_cmdline(linegrid) {1:~ }|*3 | ]], + cmdline = { { abort = true } }, } end) it('works with input()', function() feed(':call input("input", "default")<cr>') - screen:expect { + screen:expect({ grid = [[ - ^ | - {1:~ }|*3 - | - ]], + ^ | + {1:~ }|*3 + | + ]], cmdline = { { - prompt = 'input', content = { { 'default' } }, + hl_id = 0, pos = 7, + prompt = 'input', }, }, - } + }) feed('<cr>') screen:expect { @@ -118,6 +120,7 @@ local function test_cmdline(linegrid) {1:~ }|*3 | ]], + cmdline = { { abort = false } }, } end) @@ -210,6 +213,7 @@ local function test_cmdline(linegrid) content = { { 'xx3' } }, pos = 3, }, + { abort = false }, }, } @@ -220,6 +224,7 @@ local function test_cmdline(linegrid) {1:~ }|*3 | ]], + cmdline = { { abort = true } }, } end) @@ -294,6 +299,7 @@ local function test_cmdline(linegrid) {1:~ }|*3 | ]], + cmdline = { { abort = false } }, } -- Try once more, to check buffer is reinitialized. #8007 @@ -324,6 +330,7 @@ local function test_cmdline(linegrid) {1:~ }|*3 | ]], + cmdline = { { abort = false } }, } end) @@ -353,6 +360,7 @@ local function test_cmdline(linegrid) {3:[Command Line] }| | ]], + cmdline = { { abort = false } }, } -- nested cmdline @@ -404,6 +412,7 @@ local function test_cmdline(linegrid) {3:[Command Line] }| | ]], + cmdline = { [2] = { abort = true } }, } feed('<c-c>') @@ -452,6 +461,7 @@ local function test_cmdline(linegrid) cmdline = { { prompt = 'secret:', + hl_id = 0, content = { { '******' } }, pos = 6, }, @@ -495,6 +505,7 @@ local function test_cmdline(linegrid) cmdline = { { prompt = '>', + hl_id = 0, content = { { '(', 30 }, { 'a' }, @@ -797,11 +808,14 @@ local function test_cmdline(linegrid) -- 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:~ }|*3 - | - ]]) + screen:expect({ + grid = [[ + ^ | + {1:~ }|*3 + | + ]], + cmdline = { { abort = true } }, + }) end) it('does not move cursor to curwin #20309', function() @@ -827,6 +841,30 @@ local function test_cmdline(linegrid) } }, } end) + + it('show prompt hl_id', function() + screen:expect([[ + ^ | + {1:~ }|*3 + | + ]]) + feed(':echohl Error | call input("Prompt:")<CR>') + screen:expect({ + grid = [[ + ^ | + {1:~ }|*3 + | + ]], + cmdline = { + { + content = { { '' } }, + hl_id = 242, + pos = 0, + prompt = 'Prompt:', + }, + }, + }) + end) end -- the representation of cmdline and cmdline_block contents changed with ext_linegrid @@ -1000,6 +1038,36 @@ describe('cmdline redraw', function() ]], } end) + + it('silent prompt', function() + command([[nmap <silent> T :call confirm("Save changes?", "&Yes\n&No\n&Cancel")<CR>]]) + feed('T') + screen:expect([[ + | + {3: }| + | + {6:Save changes?} | + {6:[Y]es, (N)o, (C)ancel: }^ | + ]]) + end) + + it('substitute confirm prompt does not scroll', function() + screen:try_resize(75, screen._height) + command('call setline(1, "foo")') + command('set report=0') + feed(':%s/foo/bar/c<CR>') + screen:expect([[ + {2:foo} | + {1:~ }|*3 + {6:replace with bar? (y)es/(n)o/(a)ll/(q)uit/(l)ast/scroll up(^E)/down(^Y)}^ | + ]]) + feed('y') + screen:expect([[ + ^bar | + {1:~ }|*3 + 1 substitution on 1 line | + ]]) + end) end) describe('statusline is redrawn on entering cmdline', function() @@ -1447,31 +1515,29 @@ describe('cmdheight=0', function() it('when substitute text', function() command('set cmdheight=0 noruler laststatus=3') feed('ifoo<ESC>') - screen:expect { - grid = [[ + screen:try_resize(screen._width, 7) + screen:expect([[ fo^o | - {1:~ }|*3 + {1:~ }|*5 {3:[No Name] [+] }| - ]], - } + ]]) feed(':%s/foo/bar/gc<CR>') - screen:expect { - grid = [[ + screen:expect([[ {2:foo} | - {1:~ }|*3 - {6:replace wi...q/l/^E/^Y)?}^ | - ]], - } + {3: }| + |*2 + {6:replace with bar? (y)es/(}| + {6:n)o/(a)ll/(q)uit/(l)ast/s}| + {6:croll up(^E)/down(^Y)}^ | + ]]) feed('y') - screen:expect { - grid = [[ + screen:expect([[ ^bar | - {1:~ }|*3 + {1:~ }|*5 {3:[No Name] [+] }| - ]], - } + ]]) assert_alive() end) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index d7c0657820..825a90fbc8 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -190,6 +190,19 @@ describe('ui/cursor', function() attr_lm = {}, short_name = 'sm', }, + [18] = { + blinkoff = 500, + blinkon = 500, + blinkwait = 0, + cell_percentage = 0, + cursor_shape = 'block', + name = 'terminal', + hl_id = 3, + id_lm = 3, + attr = { reverse = true }, + attr_lm = { reverse = true }, + short_name = 't', + }, } screen:expect(function() @@ -245,17 +258,20 @@ describe('ui/cursor', function() end end if m.hl_id then - m.hl_id = 66 + m.hl_id = 65 m.attr = { background = Screen.colors.DarkGray } end if m.id_lm then - m.id_lm = 73 + m.id_lm = 72 + m.attr_lm = {} end end -- Assert the new expectation. screen:expect(function() - eq(expected_mode_info, screen._mode_info) + for i, v in ipairs(expected_mode_info) do + eq(v, screen._mode_info[i]) + end eq(true, screen._cursor_style_enabled) eq('normal', screen.mode) end) @@ -361,4 +377,38 @@ describe('ui/cursor', function() end end) end) + + it(':sleep does not hide cursor when sleeping', function() + n.feed(':sleep 100m | echo 42\n') + screen:expect({ + grid = [[ + ^ | + {1:~ }|*3 + :sleep 100m | echo 42 | + ]], + timeout = 100, + }) + screen:expect([[ + ^ | + {1:~ }|*3 + 42 | + ]]) + end) + + it(':sleep! hides cursor when sleeping', function() + n.feed(':sleep! 100m | echo 42\n') + screen:expect({ + grid = [[ + | + {1:~ }|*3 + :sleep! 100m | echo 42 | + ]], + timeout = 100, + }) + screen:expect([[ + ^ | + {1:~ }|*3 + 42 | + ]]) + end) end) diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index fbf16f3afe..7969dd5d3b 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -509,6 +509,69 @@ describe('decorations providers', function() ]]} end) + it('can have virtual text of the style: eol_right_align', function() + insert(mulholland) + setup_provider [[ + local hl = api.nvim_get_hl_id_by_name "ErrorMsg" + local test_ns = api.nvim_create_namespace "mulholland" + function on_do(event, ...) + if event == "line" then + local win, buf, line = ... + api.nvim_buf_set_extmark(buf, test_ns, line, 0, { + virt_text = {{'+'}, {'1234567890', 'ErrorMsg'}}; + virt_text_pos='eol_right_align'; + ephemeral = true; + }) + end + end + ]] + + screen:expect{grid=[[ + // just to see if there was an accident | + // on Mulholland Drive +{2:1234567890}| + try_start(); +{2:1234567890}| + bufref_T save_buf; +{2:1234567890}| + switch_buffer(&save_buf, buf); +{2:12345678}| + posp = getmark(mark, false); +{2:1234567890}| + restore_buffer(&save_buf);^ +{2:1234567890}| + | + ]]} + end) + + it('multiple eol_right_align', function() + insert(mulholland) + setup_provider [[ + local hl = api.nvim_get_hl_id_by_name "ErrorMsg" + local test_ns = api.nvim_create_namespace "mulholland" + function on_do(event, ...) + if event == "line" then + local win, buf, line = ... + api.nvim_buf_set_extmark(buf, test_ns, line, 0, { + virt_text = {{'11111'}}; + virt_text_pos='eol_right_align'; + ephemeral = true; + }) + api.nvim_buf_set_extmark(0, test_ns, line, 0, { + virt_text = {{'22222'}}; + virt_text_pos='eol_right_align'; + ephemeral = true; + }) + end + end + ]] + + screen:expect{grid=[[ + // just to see if there was an accident | + // on Mulholland Drive 11111 22222| + try_start(); 11111 22222| + bufref_T save_buf; 11111 22222| + switch_buffer(&save_buf, buf); 11111 222| + posp = getmark(mark, false); 11111 22222| + restore_buffer(&save_buf);^ 11111 22222| + | + ]]} + end) + it('virtual text works with wrapped lines', function() insert(mulholland) feed('ggJj3JjJ') @@ -631,7 +694,7 @@ describe('decorations providers', function() {14: }hello97 | {14: }hello98 | {14: }hello99 | - X ^hello100 | + {14:X }^hello100 | {14: }hello101 | {14: }hello102 | {14: }hello103 | @@ -744,6 +807,30 @@ describe('decorations providers', function() ]]) eq(2, exec_lua([[return _G.cnt]])) end) + + it('can do large changes to the marktree', function() + insert("line1 with a lot of text\nline2 with a lot of text") + setup_provider([[ + function on_do(event, _, _, row) + if event == 'win' or (event == 'line' and row == 1) then + vim.api.nvim_buf_clear_namespace(0, ns1, 0, -1) + for i = 0,1 do + for j = 0,23 do + vim.api.nvim_buf_set_extmark(0, ns1, i, j, {hl_group='ErrorMsg', end_col = j+1}) + end + end + end + end + ]]) + + -- Doesn't crash when modifying the marktree between line1 and line2 + screen:expect([[ + {2:line1 with a lot of text} | + {2:line2 with a lot of tex^t} | + {1:~ }|*5 + | + ]]) + end) end) local example_text = [[ @@ -810,6 +897,9 @@ describe('extmark decorations', function() [42] = {undercurl = true, special = Screen.colors.Red}; [43] = {background = Screen.colors.Yellow, undercurl = true, special = Screen.colors.Red}; [44] = {background = Screen.colors.LightMagenta}; + [45] = { background = Screen.colors.Red, special = Screen.colors.Red, foreground = Screen.colors.Red }; + [46] = { background = Screen.colors.Blue, foreground = Screen.colors.Blue, special = Screen.colors.Red }; + [47] = { background = Screen.colors.Green, foreground = Screen.colors.Blue, special = Screen.colors.Red }; } ns = api.nvim_create_namespace 'test' @@ -1900,6 +1990,46 @@ describe('extmark decorations', function() ]]} end) + it('highlight can combine multiple groups', function() + screen:try_resize(50, 3) + command('hi Group1 guibg=Red guifg=Red guisp=Red') + command('hi Group2 guibg=Blue guifg=Blue') + command('hi Group3 guibg=Green') + insert([[example text]]) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_row=1, hl_group = {} }) + screen:expect([[ + example tex^t | + {1:~ }| + | + ]]) + + api.nvim_buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_row=1, hl_group = {'Group1'} }) + screen:expect([[ + {45:example tex^t} | + {1:~ }| + | + ]]) + api.nvim_buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_row = 1, hl_group = {'Group1', 'Group2'} }) + screen:expect([[ + {46:example tex^t} | + {1:~ }| + | + ]]) + api.nvim_buf_clear_namespace(0, ns, 0, -1) + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_row = 1, hl_group = {'Group1', 'Group2', 'Group3'}, hl_eol=true }) + screen:expect([[ + {47:example tex^t }| + {1:~ }| + | + ]]) + + eq('Invalid hl_group: hl_group item', + pcall_err(api.nvim_buf_set_extmark, 0, ns, 0, 0, { end_row = 1, hl_group = {'Group1', 'Group2', {'fail'}}, hl_eol=true })) + end) + + it('highlight works after TAB with sidescroll #14201', function() screen:try_resize(50, 3) command('set nowrap') @@ -2301,13 +2431,16 @@ describe('extmark decorations', function() it('works with both hl_group and sign_hl_group', function() screen:try_resize(50, 3) + screen:add_extra_attr_ids({ + [100] = { background = Screen.colors.WebGray, foreground = Screen.colors.Blue, bold = true }, + }) insert('abcdefghijklmn') api.nvim_buf_set_extmark(0, ns, 0, 0, {sign_text='S', sign_hl_group='NonText', hl_group='Error', end_col=14}) - screen:expect{grid=[[ - {1:S }{4:abcdefghijklm^n} | + screen:expect([[ + {100:S }{9:abcdefghijklm^n} | {1:~ }| | - ]]} + ]]) end) it('virt_text_repeat_linebreak repeats virtual text on wrapped lines', function() @@ -5064,16 +5197,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S'}) - screen:expect{grid=[[ + screen:expect([[ {7: }^l1 | - S l2 | + {7:S }l2 | {7: }l3 | {7: }l4 | {7: }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('can add a single sign (with end row)', function() @@ -5082,16 +5215,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S', end_row=1}) - screen:expect{grid=[[ + screen:expect([[ {7: }^l1 | - S l2 | + {7:S }l2 | {7: }l3 | {7: }l4 | {7: }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('can add a single sign and text highlight', function() @@ -5099,16 +5232,16 @@ l5 feed 'gg' api.nvim_buf_set_extmark(0, ns, 1, 0, {sign_text='S', hl_group='Todo', end_col=1}) - screen:expect{grid=[[ + screen:expect([[ {7: }^l1 | - S {100:l}2 | + {7:S }{100:l}2 | {7: }l3 | {7: }l4 | {7: }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) api.nvim_buf_clear_namespace(0, ns, 0, -1) end) @@ -5119,16 +5252,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S', end_row = 2}) - screen:expect{grid=[[ + screen:expect([[ {7: }^l1 | - S l2 | - S l3 | + {7:S }l2 | + {7:S }l3 | {7: }l4 | {7: }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('can add multiple signs (multiple extmarks)', function() @@ -5138,16 +5271,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S1'}) api.nvim_buf_set_extmark(0, ns, 3, -1, {sign_text='S2', end_row = 4}) - screen:expect{grid=[[ + screen:expect([[ {7: }^l1 | - S1l2 | + {7:S1}l2 | {7: }l3 | - S2l4 | - S2l5 | + {7:S2}l4 | + {7:S2}l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('can add multiple signs (multiple extmarks) 2', function() @@ -5156,16 +5289,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 3, -1, {sign_text='S1'}) api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row = 3}) - screen:expect{grid=[[ + screen:expect([[ {7: }^l1 | - S2{7: }l2 | - S2{7: }l3 | - S2S1l4 | + {7:S2 }l2 | + {7:S2 }l3 | + {7:S2S1}l4 | {7: }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('can add multiple signs (multiple extmarks) 3', function() @@ -5176,16 +5309,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S1', end_row=2}) api.nvim_buf_set_extmark(0, ns, 2, -1, {sign_text='S2', end_row=3}) - screen:expect{grid=[[ + screen:expect([[ {7: }^l1 | - S1{7: }l2 | - S2S1l3 | - S2{7: }l4 | + {7:S1 }l2 | + {7:S2S1}l3 | + {7:S2 }l4 | {7: }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('can add multiple signs (multiple extmarks) 4', function() @@ -5195,16 +5328,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=0}) api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row=1}) - screen:expect{grid=[[ - S1^l1 | - S2l2 | + screen:expect([[ + {7:S1}^l1 | + {7:S2}l2 | {7: }l3 | {7: }l4 | {7: }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('works with old signs', function() @@ -5219,16 +5352,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S4'}) api.nvim_buf_set_extmark(0, ns, 2, -1, {sign_text='S5'}) - screen:expect{grid=[[ - S4S1^l1 | - S2x l2 | - S5{7: }l3 | + screen:expect([[ + {7:S4S1}^l1 | + {7:S2x }l2 | + {7:S5 }l3 | {7: }l4 | {7: }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('works with old signs (with range)', function() @@ -5244,16 +5377,16 @@ l5 api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S4'}) api.nvim_buf_set_extmark(0, ns, 2, -1, {sign_text='S5'}) - screen:expect{grid=[[ - S4S3S1^l1 | - S3S2x l2 | - S5S3{7: }l3 | - S3{7: }l4 | - S3{7: }l5 | + screen:expect([[ + {7:S4S3S1}^l1 | + {7:S3S2x }l2 | + {7:S5S3 }l3 | + {7:S3 }l4 | + {7:S3 }l5 | {7: } | {1:~ }|*3 | - ]]} + ]]) end) it('can add a ranged sign (with start out of view)', function() @@ -5264,14 +5397,14 @@ l5 api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='X', end_row=3}) - screen:expect{grid=[[ - X {7: }^l3 | - X {7: }l4 | + screen:expect([[ + {7:X }^l3 | + {7:X }l4 | {7: }l5 | {7: } | {1:~ }|*5 | - ]]} + ]]) end) it('can add lots of signs', function() @@ -5293,11 +5426,11 @@ l5 api.nvim_buf_set_extmark(0, ns, i, -1, { sign_text='Z' }) end - screen:expect{grid=[[ - Z Y X W {100:a} {100:b} {100:c} {100:d} {100:e} {100:f} {100:g} {100:h} |*8 - Z Y X W {100:a} {100:b} {100:c} {100:d} {100:e} {100:f} {100:g} {100:^h} | + screen:expect([[ + {7:Z Y X W }{100:a} {100:b} {100:c} {100:d} {100:e} {100:f} {100:g} {100:h} |*8 + {7:Z Y X W }{100:a} {100:b} {100:c} {100:d} {100:e} {100:f} {100:g} {100:^h} | | - ]]} + ]]) end) it('works with priority #19716', function() @@ -5313,20 +5446,20 @@ l5 api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S5', priority=200}) api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', priority=1}) - screen:expect{grid=[[ - S5S4O3S2S1^l1 | + screen:expect([[ + {7:S5S4O3S2S1}^l1 | {7: }l2 | | - ]]} + ]]) -- Check truncation works too api.nvim_set_option_value('signcolumn', 'auto', {}) - screen:expect{grid=[[ - S5^l1 | + screen:expect([[ + {7:S5}^l1 | {7: }l2 | | - ]]} + ]]) end) it('does not overflow with many old signs #23852', function() @@ -5343,21 +5476,21 @@ l5 command([[exe 'sign place 07 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]]) command([[exe 'sign place 08 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]]) command([[exe 'sign place 09 line=1 name=Oldsign priority=10 buffer=' . bufnr('')]]) - screen:expect{grid=[[ - O3O3O3O3O3O3O3O3O3^ | + screen:expect([[ + {7:O3O3O3O3O3O3O3O3O3}^ | {1:~ }| | - ]]} + ]]) api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', priority=1}) screen:expect_unchanged() api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S5', priority=200}) - screen:expect{grid=[[ - S5O3O3O3O3O3O3O3O3^ | + screen:expect([[ + {7:S5O3O3O3O3O3O3O3O3}^ | {1:~ }| | - ]]} + ]]) assert_alive() end) @@ -5383,12 +5516,12 @@ l5 api.nvim_buf_set_extmark(0, ns, 1, -1, {invalidate = true, sign_text='S3'}) feed('2Gdd') - screen:expect{grid=[[ - S1l1 | - S1^l3 | - S1l4 | + screen:expect([[ + {7:S1}l1 | + {7:S1}^l3 | + {7:S1}l4 | | - ]]} + ]]) end) it('correct width with multiple overlapping signs', function() @@ -5400,36 +5533,36 @@ l5 feed('gg') local s1 = [[ - S2S1^l1 | - S3S2l2 | - S3S2l3 | + {7:S2S1}^l1 | + {7:S3S2}l2 | + {7:S3S2}l3 | | ]] - screen:expect{grid=s1} + screen:expect(s1) -- Correct width when :move'ing a line with signs command('move2') - screen:expect{grid=[[ - S3{7: }l2 | - S3S2S1^l1 | + screen:expect([[ + {7:S3 }l2 | + {7:S3S2S1}^l1 | {7: }l3 | | - ]]} + ]]) command('silent undo') screen:expect{grid=s1} command('d') - screen:expect{grid=[[ - S3S2S1^l2 | - S3S2{7: }l3 | + screen:expect([[ + {7:S3S2S1}^l2 | + {7:S3S2 }l3 | {7: }l4 | | - ]]} + ]]) command('d') - screen:expect{grid=[[ - S3S2S1^l3 | + screen:expect([[ + {7:S3S2S1}^l3 | {7: }l4 | {7: }l5 | | - ]]} + ]]) end) it('correct width when adding and removing multiple signs', function() @@ -5452,12 +5585,12 @@ l5 redraw! call nvim_buf_del_extmark(0, ns, s1) ]]) - screen:expect{grid=[[ - S1^l1 | - S1l2 | - S1l3 | + screen:expect([[ + {7:S1}^l1 | + {7:S1}l2 | + {7:S1}l3 | | - ]]} + ]]) end) it('correct width when deleting lines', function() @@ -5472,12 +5605,12 @@ l5 call nvim_buf_del_extmark(0, ns, s3) norm 4Gdd ]]) - screen:e |