aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/legacy/066_visual_block_tab_spec.lua10
-rw-r--r--test/functional/ui/highlight_spec.lua27
-rw-r--r--test/functional/ui/mouse_spec.lua84
-rw-r--r--test/functional/ui/screen.lua115
-rw-r--r--test/functional/ui/screen_basic_spec.lua254
5 files changed, 439 insertions, 51 deletions
diff --git a/test/functional/legacy/066_visual_block_tab_spec.lua b/test/functional/legacy/066_visual_block_tab_spec.lua
index cd283e6746..82bb988c67 100644
--- a/test/functional/legacy/066_visual_block_tab_spec.lua
+++ b/test/functional/legacy/066_visual_block_tab_spec.lua
@@ -23,18 +23,18 @@ describe('visual block shift and tab characters', function()
abcdefghijklmnopqrstuvwxyz]])
feed('gg')
- feed([[fe<C-v>4jR<esc>ugvr1:'<,'>yank A<cr>]])
+ feed([[fe<C-v>4jR<esc>ugvr1:'<lt>,'>yank A<cr>]])
execute('/^abcdefgh')
- feed('<C-v>4jI <esc>j<<11|D')
+ feed('<C-v>4jI <esc>j<lt><lt>11|D')
feed('j7|a <esc>')
feed('j7|a <esc>')
- feed('j7|a <esc>4k13|<C-v>4j<')
+ feed('j7|a <esc>4k13|<C-v>4j<lt>')
execute('$-5,$yank A')
execute([[$-4,$s/\s\+//g]])
- feed('<C-v>4kI <esc>j<<')
+ feed('<C-v>4kI <esc>j<lt><lt>')
feed('j7|a <esc>')
feed('j7|a <esc>')
- feed('j7|a <esc>4k13|<C-v>4j3<')
+ feed('j7|a <esc>4k13|<C-v>4j3<lt>')
execute('$-4,$yank A')
-- Put @a and clean empty lines
diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua
index 3c55c09f95..701297cc15 100644
--- a/test/functional/ui/highlight_spec.lua
+++ b/test/functional/ui/highlight_spec.lua
@@ -1,7 +1,30 @@
local helpers = require('test.functional.helpers')
local Screen = require('test.functional.ui.screen')
local clear, feed, nvim = helpers.clear, helpers.feed, helpers.nvim
-local execute = helpers.execute
+local execute, request, eq = helpers.execute, helpers.request, helpers.eq
+
+
+describe('color scheme compatibility', function()
+ before_each(function()
+ clear()
+ end)
+
+ it('t_Co is set to 256 by default', function()
+ eq('256', request('vim_eval', '&t_Co'))
+ request('vim_set_option', 't_Co', '88')
+ eq('88', request('vim_eval', '&t_Co'))
+ end)
+
+ it('emulates gui_running when a rgb UI is attached', function()
+ eq(0, request('vim_eval', 'has("gui_running")'))
+ local screen = Screen.new()
+ screen:attach()
+ eq(1, request('vim_eval', 'has("gui_running")'))
+ screen:detach()
+ eq(0, request('vim_eval', 'has("gui_running")'))
+ end)
+end)
+
describe('Default highlight groups', function()
-- Test the default attributes for highlight groups shown by the :highlight
@@ -24,7 +47,6 @@ describe('Default highlight groups', function()
after_each(function()
screen:detach()
end)
-
it('window status bar', function()
screen:set_default_attr_ids({
[1] = {reverse = true, bold = true}, -- StatusLine
@@ -142,7 +164,6 @@ describe('Default highlight groups', function()
end)
it('end of file markers', function()
- nvim('command', 'hi Normal guibg=black')
screen:expect([[
^ |
{1:~ }|
diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua
index 507b5aacae..653d8ad92c 100644
--- a/test/functional/ui/mouse_spec.lua
+++ b/test/functional/ui/mouse_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')
local Screen = require('test.functional.ui.screen')
local clear, feed, nvim = helpers.clear, helpers.feed, helpers.nvim
+local insert, execute = helpers.insert, helpers.execute
describe('Mouse input', function()
local screen, hlgroup_colors
@@ -154,4 +155,87 @@ describe('Mouse input', function()
]])
feed('<cr>')
end)
+
+ it('mouse whell will target the hovered window', function()
+ feed('ggdG')
+ insert([[
+ Inserting
+ text
+ with
+ many
+ lines
+ to
+ test
+ mouse scrolling
+ ]])
+ screen:try_resize(53, 14)
+ execute('sp', 'vsp')
+ screen:expect([[
+ lines |lines |
+ to |to |
+ test |test |
+ mouse scrolling |mouse scrolling |
+ ^ | |
+ ~ |~ |
+ [No Name] [+] [No Name] [+] |
+ to |
+ test |
+ mouse scrolling |
+ |
+ ~ |
+ [No Name] [+] |
+ :vsp |
+ ]])
+ feed('<MouseUp><0,0>')
+ screen:expect([[
+ mouse scrolling |lines |
+ ^ |to |
+ ~ |test |
+ ~ |mouse scrolling |
+ ~ | |
+ ~ |~ |
+ [No Name] [+] [No Name] [+] |
+ to |
+ test |
+ mouse scrolling |
+ |
+ ~ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('<MouseDown><27,0>')
+ screen:expect([[
+ mouse scrolling |text |
+ ^ |with |
+ ~ |many |
+ ~ |lines |
+ ~ |to |
+ ~ |test |
+ [No Name] [+] [No Name] [+] |
+ to |
+ test |
+ mouse scrolling |
+ |
+ ~ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('<MouseDown><27,7><MouseDown>')
+ screen:expect([[
+ mouse scrolling |text |
+ ^ |with |
+ ~ |many |
+ ~ |lines |
+ ~ |to |
+ ~ |test |
+ [No Name] [+] [No Name] [+] |
+ Inserting |
+ text |
+ with |
+ many |
+ lines |
+ [No Name] [+] |
+ |
+ ]])
+ end)
end)
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 8e7d1ed798..105e43843c 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -83,6 +83,21 @@ local eq, dedent = helpers.eq, helpers.dedent
local Screen = {}
Screen.__index = Screen
+local debug_screen
+
+
+function Screen.debug(command)
+ if not command then
+ command = 'pynvim -n -g -c '
+ end
+ command = command .. request('vim_eval', '$NVIM_LISTEN_ADDRESS')
+ if debug_screen then
+ debug_screen:close()
+ end
+ debug_screen = io.popen(command, 'r')
+ debug_screen:read()
+end
+
function Screen.new(width, height)
if not width then
width = 53
@@ -90,24 +105,22 @@ function Screen.new(width, height)
if not height then
height = 14
end
- return setmetatable({
+ local self = setmetatable({
+ title = '',
+ icon = '',
+ bell = false,
+ visual_bell = false,
+ suspended = false,
_default_attr_ids = nil,
- _width = width,
- _height = height,
- _rows = new_cell_grid(width, height),
_mode = 'normal',
_mouse_enabled = true,
- _bell = false,
- _visual_bell = false,
- _suspended = true,
_attrs = {},
_cursor = {
enabled = true, row = 1, col = 1
- },
- _scroll_region = {
- top = 1, bot = height, left = 1, right = width
}
}, Screen)
+ self:_handle_resize(width, height)
+ return self
end
function Screen:set_default_attr_ids(attr_ids)
@@ -115,13 +128,15 @@ function Screen:set_default_attr_ids(attr_ids)
end
function Screen:attach()
- request('attach_ui', self._width, self._height)
- self._suspended = false
+ request('ui_attach', self._width, self._height, true)
end
function Screen:detach()
- request('detach_ui')
- self._suspended = true
+ request('ui_detach')
+end
+
+function Screen:try_resize(columns, rows)
+ request('ui_try_resize', columns, rows)
end
function Screen:expect(expected, attr_ids)
@@ -134,7 +149,7 @@ function Screen:expect(expected, attr_ids)
table.insert(expected_rows, row)
end
local ids = attr_ids or self._default_attr_ids
- self:_wait(function()
+ self:wait(function()
for i = 1, self._height do
local expected_row = expected_rows[i]
local actual_row = self:_row_repr(self._rows[i], ids)
@@ -146,7 +161,7 @@ function Screen:expect(expected, attr_ids)
end)
end
-function Screen:_wait(check, timeout)
+function Screen:wait(check, timeout)
local err, checked = false
local function notification_cb(method, args)
assert(method == 'redraw')
@@ -181,16 +196,30 @@ function Screen:_redraw(updates)
end
function Screen:_handle_resize(width, height)
- self._rows = new_cell_grid(width, height)
+ local rows = {}
+ for i = 1, height do
+ local cols = {}
+ for j = 1, width do
+ table.insert(cols, {text = ' ', attrs = {}})
+ end
+ table.insert(rows, cols)
+ end
+ self._rows = rows
+ self._width = width
+ self._height = height
+ self._scroll_region = {
+ top = 1, bot = height, left = 1, right = width
+ }
end
function Screen:_handle_clear()
- self:_clear_block(1, self._height, 1, self._width)
+ self:_clear_block(self._scroll_region.top, self._scroll_region.bot,
+ self._scroll_region.left, self._scroll_region.right)
end
function Screen:_handle_eol_clear()
local row, col = self._cursor.row, self._cursor.col
- self:_clear_block(row, 1, col, self._width - col)
+ self:_clear_block(row, 1, col, self._scroll_region.right - col)
end
function Screen:_handle_cursor_goto(row, col)
@@ -250,11 +279,14 @@ function Screen:_handle_scroll(count)
for i = start, stop, step do
local target = self._rows[i]
local source = self._rows[i + count]
- self:_copy_row_section(target, source, left, right)
+ for j = left, right do
+ target[j].text = source[j].text
+ target[j].attrs = source[j].attrs
+ end
end
-- clear invalid rows
- for i = stop + 1, stop + count, step do
+ for i = stop + step, stop + count, step do
self:_clear_row_section(i, left, right)
end
end
@@ -271,15 +303,31 @@ function Screen:_handle_put(str)
end
function Screen:_handle_bell()
- self._bell = true
+ self.bell = true
end
function Screen:_handle_visual_bell()
- self._visual_bell = true
+ self.visual_bell = true
+end
+
+function Screen:_handle_update_fg(fg)
+ self._fg = fg
+end
+
+function Screen:_handle_update_bg(bg)
+ self._bg = bg
end
function Screen:_handle_suspend()
- self._suspended = true
+ self.suspended = true
+end
+
+function Screen:_handle_set_title(title)
+ self.title = title
+end
+
+function Screen:_handle_set_icon(icon)
+ self.icon = icon
end
function Screen:_clear_block(top, lines, left, columns)
@@ -296,13 +344,6 @@ function Screen:_clear_row_section(rownum, startcol, stopcol)
end
end
-function Screen:_copy_row_section(target, source, startcol, stopcol)
- for i = startcol, stopcol do
- target[i].text = source[i].text
- target[i].attrs = source[i].attrs
- end
-end
-
function Screen:_row_repr(row, attr_ids)
local rv = {}
local current_attr_id
@@ -353,18 +394,6 @@ function backward_find_meaningful(tbl, from)
return from
end
-function new_cell_grid(width, height)
- local rows = {}
- for i = 1, height do
- local cols = {}
- for j = 1, width do
- table.insert(cols, {text = ' ', attrs = {}})
- end
- table.insert(rows, cols)
- end
- return rows
-end
-
function get_attr_id(attr_ids, attrs)
if not attr_ids then
return
diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua
index a1110b3231..4ee6c43528 100644
--- a/test/functional/ui/screen_basic_spec.lua
+++ b/test/functional/ui/screen_basic_spec.lua
@@ -16,6 +16,69 @@ describe('Screen', function()
screen:detach()
end)
+ describe(':suspend', function()
+ it('is forwarded to the UI', function()
+ local function check()
+ if not screen.suspended then
+ return 'Screen was not suspended'
+ end
+ end
+ execute('suspend')
+ screen:wait(check)
+ screen.suspended = false
+ feed('<c-z>')
+ screen:wait(check)
+ end)
+ end)
+
+ describe('bell/visual bell', function()
+ it('is forwarded to the UI', function()
+ feed('<left>')
+ screen:wait(function()
+ if not screen.bell or screen.visual_bell then
+ return 'Bell was not sent'
+ end
+ end)
+ screen.bell = false
+ execute('set visualbell')
+ feed('<left>')
+ screen:wait(function()
+ if not screen.visual_bell or screen.bell then
+ return 'Visual bell was not sent'
+ end
+ end)
+ end)
+ end)
+
+ describe(':set title', function()
+ it('is forwarded to the UI', function()
+ local expected = 'test-title'
+ execute('set titlestring='..expected)
+ execute('set title')
+ screen:wait(function()
+ local actual = screen.title
+ if actual ~= expected then
+ return 'Expected title to be "'..expected..'" but was "'..actual..'"'
+ end
+ end)
+ end)
+ end)
+
+ describe(':set icon', function()
+ it('is forwarded to the UI', function()
+ local expected = 'test-icon'
+ execute('set iconstring='..expected)
+ execute('set icon')
+ screen:wait(function()
+ local actual = screen.icon
+ if actual ~= expected then
+ return 'Expected title to be "'..expected..'" but was "'..actual..'"'
+ end
+ end)
+ end)
+ end)
+
+
describe('window', function()
describe('split', function()
it('horizontal', function()
@@ -95,6 +158,8 @@ describe('Screen', function()
|
]])
end)
+
+
end)
end)
@@ -221,4 +286,193 @@ describe('Screen', function()
feed('<cr>') -- skip the "Press ENTER..." state or tests will hang
end)
end)
+
+ describe('scrolling and clearing', function()
+ before_each(function()
+ insert([[
+ Inserting
+ text
+ with
+ many
+ lines
+ to
+ test
+ scrolling
+ and
+ clearing
+ in
+ split
+ windows
+ ]])
+ execute('sp', 'vsp', 'vsp')
+ screen:expect([[
+ and |and |and |
+ clearing |clearing |clearing |
+ in |in |in |
+ split |split |split |
+ windows |windows |windows |
+ ^ | | |
+ [No Name] [+] [No Name] [+] [No Name] [+] |
+ clearing |
+ in |
+ split |
+ windows |
+ |
+ [No Name] [+] |
+ |
+ ]])
+ end)
+
+ it('only affects the current scroll region', function()
+ feed('6k')
+ screen:expect([[
+ ^crolling |and |and |
+ and |clearing |clearing |
+ clearing |in |in |
+ in |split |split |
+ split |windows |windows |
+ windows | | |
+ [No Name] [+] [No Name] [+] [No Name] [+] |
+ clearing |
+ in |
+ split |
+ windows |
+ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('<c-w>l')
+ screen:expect([[
+ scrolling |and |and |
+ and |clearing |clearing |
+ clearing |in |in |
+ in |split |split |
+ split |windows |windows |
+ windows |^ | |
+ [No Name] [+] [No Name] [+] <Name] [+] |
+ clearing |
+ in |
+ split |
+ windows |
+ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('gg')
+ screen:expect([[
+ scrolling |^nserting |and |
+ and |text |clearing |
+ clearing |with |in |
+ in |many |split |
+ split |lines |windows |
+ windows |to | |
+ [No Name] [+] [No Name] [+] <Name] [+] |
+ clearing |
+ in |
+ split |
+ windows |
+ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('7j')
+ screen:expect([[
+ scrolling |with |and |
+ and |many |clearing |
+ clearing |lines |in |
+ in |to |split |
+ split |test |windows |
+ windows |^crolling | |
+ [No Name] [+] [No Name] [+] <Name] [+] |
+ clearing |
+ in |
+ split |
+ windows |
+ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('2j')
+ screen:expect([[
+ scrolling |lines |and |
+ and |to |clearing |
+ clearing |test |in |
+ in |scrolling |split |
+ split |and |windows |
+ windows |^learing | |
+ [No Name] [+] [No Name] [+] <Name] [+] |
+ clearing |
+ in |
+ split |
+ windows |
+ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('5k')
+ screen:expect([[
+ scrolling |^ines |and |
+ and |to |clearing |
+ clearing |test |in |
+ in |scrolling |split |
+ split |and |windows |
+ windows |clearing | |
+ [No Name] [+] [No Name] [+] <Name] [+] |
+ clearing |
+ in |
+ split |
+ windows |
+ |
+ [No Name] [+] |
+ |
+ ]])
+ feed('k')
+ screen:expect([[
+ scrolling |^any |and |
+ and |lines |clearing |
+ clearing |to |in |
+ in |test |split |
+ split |scrolling |windows |
+ windows |and | |
+ [No Name] [+] [No Name] [+] <Name] [+] |
+ clearing |
+ in |
+ split |
+ windows |
+ |
+ [No Name] [+] |
+ |
+ ]])
+ end)
+ end)
+
+ describe('resize', function()
+ before_each(function()
+ screen:try_resize(25, 5)
+ feed('iresize')
+ end)
+
+ it('rebuilds the whole screen', function()
+ screen:expect([[
+ resize^ |
+ ~ |
+ ~ |
+ ~ |
+ -- INSERT -- |
+ ]])
+ end)
+
+ it('has minimum width/height values', function()
+ screen:try_resize(1, 1)
+ screen:expect([[
+ -- INS^RT --|
+ |
+ ]])
+ feed('<esc>:ls')
+ screen:expect([[
+ resize |
+ :ls^ |
+ ]])
+ end)
+ end)
end)