Merge #6440 'test: Remove "tickle" hack'

This commit is contained in:
Justin M. Keyes
2017-04-06 01:07:22 +02:00
4 changed files with 79 additions and 86 deletions

View File

@@ -14,17 +14,11 @@ describe('TermClose event', function()
nvim('set_option', 'shellcmdflag', 'EXE')
end)
local function eq_err(expected, actual)
if expected ~= actual then
error('expected: '..tostring(expected)..', actual: '..tostring(actual))
end
end
it('triggers when terminal job ends', function()
command('autocmd TermClose * let g:test_termclose = 23')
command('terminal')
command('call jobstop(b:terminal_job_id)')
retry(nil, nil, function() eq_err(23, eval('g:test_termclose')) end)
retry(nil, nil, function() eq(23, eval('g:test_termclose')) end)
end)
it('reports the correct <abuf>', function()
@@ -35,12 +29,12 @@ describe('TermClose event', function()
eq(2, eval('bufnr("%")'))
command('terminal')
retry(nil, nil, function() eq_err(3, eval('bufnr("%")')) end)
retry(nil, nil, function() eq(3, eval('bufnr("%")')) end)
command('buffer 1')
retry(nil, nil, function() eq_err(1, eval('bufnr("%")')) end)
retry(nil, nil, function() eq(1, eval('bufnr("%")')) end)
command('3bdelete!')
retry(nil, nil, function() eq_err('3', eval('g:abuf')) end)
retry(nil, nil, function() eq('3', eval('g:abuf')) end)
end)
end)

View File

@@ -3,7 +3,6 @@ local Screen = require('test.functional.ui.screen')
local clear, meths = helpers.clear, helpers.meths
local eq = helpers.eq
local command = helpers.command
local wait = helpers.wait
describe('ui/cursor', function()
local screen
@@ -19,8 +18,6 @@ describe('ui/cursor', function()
end)
it("'guicursor' is published as a UI event", function()
wait()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
local expected_cursor_style = {
cmdline_hover = {
mouse_shape = 0,
@@ -143,21 +140,30 @@ describe('ui/cursor', function()
mouse_shape = 0,
short_name = 'vs' }
}
screen:expect(function()
-- Default 'guicursor' published on startup.
eq(expected_cursor_style, screen._cursor_style)
eq(true, screen._cursor_style_enabled)
eq('normal', screen.mode)
end)
-- Event is published ONLY if the cursor style changed.
screen._cursor_style = nil
wait()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
command("echo 'test'")
screen:expect([[
^ |
~ |
~ |
~ |
test |
]], nil, nil, function()
eq(nil, screen._cursor_style)
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')
wait()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
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)
@@ -167,11 +173,11 @@ describe('ui/cursor', function()
eq(172, screen._cursor_style.normal.blinkoff)
eq(173, screen._cursor_style.normal.blinkon)
end)
end)
it("empty 'guicursor' sets cursor_shape=block in all modes", function()
meths.set_option('guicursor', '')
command('redraw')
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
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',
@@ -181,5 +187,6 @@ describe('ui/cursor', function()
eq(0, screen._cursor_style[m].blinkon)
end
end)
end)
end)

View File

@@ -181,6 +181,7 @@ end
-- expected: Expected screen state (string). Each line represents a screen
-- row. Last character of each row (typically "|") is stripped.
-- Common indentation is stripped.
-- Used as `condition` if NOT a string; must be the ONLY arg then.
-- attr_ids: Expected text attributes. Screen rows are transformed according
-- to this table, as follows: each substring S composed of
-- characters having the same attributes will be substituted by
@@ -191,12 +192,16 @@ end
-- any: true: Succeed if `expected` matches ANY screen line(s).
-- false (default): `expected` must match screen exactly.
function Screen:expect(expected, attr_ids, attr_ignore, condition, any)
-- remove the last line and dedent
expected = dedent(expected:gsub('\n[ ]+$', ''))
local expected_rows = {}
if type(expected) ~= "string" then
assert(not (attr_ids or attr_ignore or condition or any))
condition = expected
expected = nil
else
-- Remove the last line and dedent.
expected = dedent(expected:gsub('\n[ ]+$', ''))
for row in expected:gmatch('[^\n]+') do
-- the last character should be the screen delimiter
row = row:sub(1, #row - 1)
row = row:sub(1, #row - 1) -- Last char must be the screen delimiter.
table.insert(expected_rows, row)
end
if not any then
@@ -204,6 +209,7 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any)
"Expected screen state's row count(" .. #expected_rows
.. ') differs from configured height(' .. self._height .. ') of Screen.')
end
end
local ids = attr_ids or self._default_attr_ids
local ignore = attr_ignore or self._default_attr_ignore
self:wait(function()
@@ -218,7 +224,9 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any)
actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore)
end
if any then
if expected == nil then
return
elseif any then
-- Search for `expected` anywhere in the screen lines.
local actual_screen_str = table.concat(actual_rows, '\n')
if nil == string.find(actual_screen_str, expected) then

View File

@@ -73,33 +73,29 @@ describe('Screen', function()
describe(':suspend', function()
it('is forwarded to the UI', function()
local function check()
if not screen.suspended then
return 'Screen was not suspended'
end
eq(true, screen.suspended)
end
execute('suspend')
screen:wait(check)
screen:expect(check)
screen.suspended = false
feed('<c-z>')
screen:wait(check)
screen:expect(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
screen:expect(function()
eq(true, screen.bell)
eq(false, screen.visual_bell)
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
screen:expect(function()
eq(true, screen.visual_bell)
eq(false, screen.bell)
end)
end)
end)
@@ -109,22 +105,16 @@ describe('Screen', 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
screen:expect(function()
eq(expected, screen.title)
end)
end)
it('has correct default title with unnamed file', function()
local expected = '[No Name] - NVIM'
execute('set title')
screen:wait(function()
local actual = screen.title
if actual ~= expected then
return 'Expected title to be "'..expected..'" but was "'..actual..'"'
end
screen:expect(function()
eq(expected, screen.title)
end)
end)
@@ -132,11 +122,8 @@ describe('Screen', function()
local expected = 'myfile (/mydir) - NVIM'
execute('set title')
execute('file /mydir/myfile')
screen:wait(function()
local actual = screen.title
if actual ~= expected then
return 'Expected title to be "'..expected..'" but was "'..actual..'"'
end
screen:expect(function()
eq(expected, screen.title)
end)
end)
end)
@@ -146,11 +133,8 @@ describe('Screen', 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
screen:expect(function()
eq(expected, screen.icon)
end)
end)
end)