diff options
Diffstat (limited to 'test/functional/ui/cursor_spec.lua')
-rw-r--r-- | test/functional/ui/cursor_spec.lua | 284 |
1 files changed, 169 insertions, 115 deletions
diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 02e9422781..e6036a6b79 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -18,138 +18,155 @@ describe('ui/cursor', function() end) it("'guicursor' is published as a UI event", function() - local expected_cursor_style = { - cmdline_hover = { - mouse_shape = 0, - short_name = 'e' }, - cmdline_insert = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, - cell_percentage = 25, - cursor_shape = 'vertical', - hl_id = 46, - id_lm = 47, - mouse_shape = 0, - short_name = 'ci' }, - cmdline_normal = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + local expected_mode_info = { + [1] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 0, cursor_shape = 'block', - hl_id = 46, - id_lm = 47, + name = 'normal', + hl_id = 0, + id_lm = 0, mouse_shape = 0, - short_name = 'c' }, - cmdline_replace = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, - cell_percentage = 20, - cursor_shape = 'horizontal', - hl_id = 46, - id_lm = 47, + short_name = 'n' }, + [2] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, + cell_percentage = 0, + cursor_shape = 'block', + name = 'visual', + hl_id = 0, + id_lm = 0, mouse_shape = 0, - short_name = 'cr' }, - insert = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + short_name = 'v' }, + [3] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 25, cursor_shape = 'vertical', - hl_id = 46, - id_lm = 47, + name = 'insert', + hl_id = 0, + id_lm = 0, mouse_shape = 0, short_name = 'i' }, - more = { - mouse_shape = 0, - short_name = 'm' }, - more_lastline = { + [4] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, + cell_percentage = 20, + cursor_shape = 'horizontal', + name = 'replace', + hl_id = 0, + id_lm = 0, mouse_shape = 0, - short_name = 'ml' }, - normal = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + short_name = 'r' }, + [5] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 0, cursor_shape = 'block', - hl_id = 46, - id_lm = 47, + name = 'cmdline_normal', + hl_id = 0, + id_lm = 0, mouse_shape = 0, - short_name = 'n' }, - operator = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, - cell_percentage = 50, + short_name = 'c' }, + [6] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, + cell_percentage = 25, + cursor_shape = 'vertical', + name = 'cmdline_insert', + hl_id = 0, + id_lm = 0, + mouse_shape = 0, + short_name = 'ci' }, + [7] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, + cell_percentage = 20, cursor_shape = 'horizontal', - hl_id = 46, - id_lm = 46, + name = 'cmdline_replace', + hl_id = 0, + id_lm = 0, mouse_shape = 0, - short_name = 'o' }, - replace = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, + short_name = 'cr' }, + [8] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, cell_percentage = 20, cursor_shape = 'horizontal', - hl_id = 46, - id_lm = 47, + name = 'operator', + hl_id = 0, + id_lm = 0, mouse_shape = 0, - short_name = 'r' }, - showmatch = { - blinkoff = 150, - blinkon = 175, - blinkwait = 175, - cell_percentage = 0, - cursor_shape = 'block', - hl_id = 46, - id_lm = 46, - short_name = 'sm' }, - statusline_drag = { + short_name = 'o' }, + [9] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, + cell_percentage = 25, + cursor_shape = 'vertical', + name = 'visual_select', + hl_id = 0, + id_lm = 0, mouse_shape = 0, - short_name = 'sd' }, - statusline_hover = { + short_name = 've' }, + [10] = { + name = 'cmdline_hover', + mouse_shape = 0, + short_name = 'e' }, + [11] = { + name = 'statusline_hover', mouse_shape = 0, short_name = 's' }, - visual = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, - cell_percentage = 0, - cursor_shape = 'block', - hl_id = 46, - id_lm = 47, + [12] = { + name = 'statusline_drag', mouse_shape = 0, - short_name = 'v' }, - visual_select = { - blinkoff = 250, - blinkon = 400, - blinkwait = 700, - cell_percentage = 35, - cursor_shape = 'vertical', - hl_id = 46, - id_lm = 46, + short_name = 'sd' }, + [13] = { + name = 'vsep_hover', mouse_shape = 0, - short_name = 've' }, - vsep_drag = { + short_name = 'vs' }, + [14] = { + name = 'vsep_drag', mouse_shape = 0, short_name = 'vd' }, - vsep_hover = { + [15] = { + name = 'more', mouse_shape = 0, - short_name = 'vs' } - } + short_name = 'm' }, + [16] = { + name = 'more_lastline', + mouse_shape = 0, + short_name = 'ml' }, + [17] = { + blinkoff = 0, + blinkon = 0, + blinkwait = 0, + cell_percentage = 0, + cursor_shape = 'block', + name = 'showmatch', + hl_id = 0, + id_lm = 0, + short_name = 'sm' }, + } screen:expect(function() - -- Default 'guicursor' published on startup. - eq(expected_cursor_style, screen._cursor_style) + -- Default 'guicursor', published on startup. + eq(expected_mode_info, screen._mode_info) eq(true, screen._cursor_style_enabled) eq('normal', screen.mode) end) -- Event is published ONLY if the cursor style changed. - screen._cursor_style = nil + screen._mode_info = nil command("echo 'test'") screen:expect([[ ^ | @@ -158,20 +175,57 @@ describe('ui/cursor', function() ~ | test | ]], nil, nil, function() - eq(nil, screen._cursor_style) + eq(nil, screen._mode_info) end) -- Change the cursor style. - meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') + helpers.command('set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr-o:hor20' + ..',a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor' + ..',sm:block-blinkwait175-blinkoff150-blinkon175') + + -- Update the expected values. + for _, m in ipairs(expected_mode_info) do + if m.name == 'showmatch' then + if m.blinkon then m.blinkon = 175 end + if m.blinkoff then m.blinkoff = 150 end + if m.blinkwait then m.blinkwait = 175 end + else + if m.blinkon then m.blinkon = 250 end + if m.blinkoff then m.blinkoff = 400 end + if m.blinkwait then m.blinkwait = 700 end + end + if m.hl_id then m.hl_id = 46 end + if m.id_lm then m.id_lm = 47 end + end + + -- Assert the new expectation. screen:expect(function() - eq('vertical', screen._cursor_style.normal.cursor_shape) - eq('horizontal', screen._cursor_style.visual_select.cursor_shape) - eq('vertical', screen._cursor_style.operator.cursor_shape) - eq('block', screen._cursor_style.insert.cursor_shape) - eq('vertical', screen._cursor_style.showmatch.cursor_shape) - eq(171, screen._cursor_style.normal.blinkwait) - eq(172, screen._cursor_style.normal.blinkoff) - eq(173, screen._cursor_style.normal.blinkon) + eq(expected_mode_info, screen._mode_info) + eq(true, screen._cursor_style_enabled) + eq('normal', screen.mode) + end) + + -- Another cursor style. + meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173' + ..',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') + screen:expect(function() + local named = {} + for _, m in ipairs(screen._mode_info) do + named[m.name] = m + end + eq('vertical', named.normal.cursor_shape) + eq(35, named.normal.cell_percentage) + eq('horizontal', named.visual_select.cursor_shape) + eq(35, named.visual_select.cell_percentage) + eq('vertical', named.operator.cursor_shape) + eq(50, named.operator.cell_percentage) + eq('block', named.insert.cursor_shape) + eq('vertical', named.showmatch.cursor_shape) + eq(90, named.cmdline_replace.cell_percentage) + eq(171, named.normal.blinkwait) + eq(172, named.normal.blinkoff) + eq(173, named.normal.blinkon) + eq(42, named.showmatch.cell_percentage) end) end) @@ -180,11 +234,11 @@ describe('ui/cursor', function() screen:expect(function() -- Empty 'guicursor' sets enabled=false. eq(false, screen._cursor_style_enabled) - for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', - 'showmatch', 'normal', 'replace', 'visual', - 'visual_select', }) do - eq('block', screen._cursor_style[m].cursor_shape) - eq(0, screen._cursor_style[m].blinkon) + for _, m in ipairs(screen._mode_info) do + if m['cursor_shape'] ~= nil then + eq('block', m.cursor_shape) + eq(0, m.blinkon) + end end end) end) |