test/ui: enable strict mode by default (and in existing tests)

This commit is contained in:
Björn Linse 2015-01-23 23:53:21 +01:00 committed by Thiago de Arruda
parent 97ac9f5c1d
commit b78265e9b7
3 changed files with 31 additions and 29 deletions

View File

@ -42,6 +42,8 @@ describe('Default highlight groups', function()
clear() clear()
screen = Screen.new() screen = Screen.new()
screen:attach() screen:attach()
--ignore highligting of ~-lines
screen:set_default_attr_ignore( {{bold=true, foreground=hlgroup_colors.NonText}} )
end) end)
after_each(function() after_each(function()
@ -52,8 +54,6 @@ describe('Default highlight groups', function()
[1] = {reverse = true, bold = true}, -- StatusLine [1] = {reverse = true, bold = true}, -- StatusLine
[2] = {reverse = true} -- StatusLineNC [2] = {reverse = true} -- StatusLineNC
}) })
--ignore highligting of ~-lines
screen:set_default_attr_ignore( {{}, {bold=true, foreground=hlgroup_colors.NonText}} )
execute('sp', 'vsp', 'vsp') execute('sp', 'vsp', 'vsp')
screen:expect([[ screen:expect([[
^ {2:|} {2:|} | ^ {2:|} {2:|} |

View File

@ -8,6 +8,7 @@ describe('Mouse input', function()
setup(function() setup(function()
hlgroup_colors = { hlgroup_colors = {
NonText = nvim('name_to_color', 'Blue'),
Visual = nvim('name_to_color', 'LightGrey'), Visual = nvim('name_to_color', 'LightGrey'),
} }
end) end)
@ -21,8 +22,10 @@ describe('Mouse input', function()
screen = Screen.new(25, 5) screen = Screen.new(25, 5)
screen:attach() screen:attach()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {background = hlgroup_colors.Visual} [1] = {background = hlgroup_colors.Visual},
[2] = {bold = true}
}) })
screen:set_default_attr_ignore( {{bold=true, foreground=hlgroup_colors.NonText}} )
feed('itesting<cr>mouse<cr>support and selection<esc>') feed('itesting<cr>mouse<cr>support and selection<esc>')
screen:expect([[ screen:expect([[
testing | testing |
@ -72,7 +75,7 @@ describe('Mouse input', function()
mo{1:us}^ | mo{1:us}^ |
support and selection | support and selection |
~ | ~ |
-- VISUAL -- | {2:-- VISUAL --} |
]]) ]])
feed('<LeftDrag><2,2>') feed('<LeftDrag><2,2>')
screen:expect([[ screen:expect([[
@ -80,7 +83,7 @@ describe('Mouse input', function()
mo{1:use } | mo{1:use } |
{1:su}^port and selection | {1:su}^port and selection |
~ | ~ |
-- VISUAL -- | {2:-- VISUAL --} |
]]) ]])
feed('<LeftDrag><0,0>') feed('<LeftDrag><0,0>')
screen:expect([[ screen:expect([[
@ -88,7 +91,7 @@ describe('Mouse input', function()
{1:mou}se | {1:mou}se |
support and selection | support and selection |
~ | ~ |
-- VISUAL -- | {2:-- VISUAL --} |
]]) ]])
end) end)
@ -99,7 +102,7 @@ describe('Mouse input', function()
mouse | mouse |
{1:suppor}^ and selection | {1:suppor}^ and selection |
~ | ~ |
-- VISUAL -- | {2:-- VISUAL --} |
]]) ]])
end) end)
@ -110,7 +113,7 @@ describe('Mouse input', function()
mouse | mouse |
{1:su}^{1:port and selection } | {1:su}^{1:port and selection } |
~ | ~ |
-- VISUAL LINE -- | {2:-- VISUAL LINE --} |
]]) ]])
end) end)
@ -121,7 +124,7 @@ describe('Mouse input', function()
mouse | mouse |
su^port and selection | su^port and selection |
~ | ~ |
-- VISUAL BLOCK -- | {2:-- VISUAL BLOCK --} |
]]) ]])
end) end)
@ -140,7 +143,7 @@ describe('Mouse input', function()
{1:mouse } | {1:mouse } |
{1:su}^port and selection | {1:su}^port and selection |
~ | ~ |
-- VISUAL -- | {2:-- VISUAL --} |
]]) ]])
end) end)
@ -153,7 +156,7 @@ describe('Mouse input', function()
ing | ing |
Press ENTER or type comma| Press ENTER or type comma|
nd to continue^ | nd to continue^ |
]]) ]],nil,true)
feed('<cr>') feed('<cr>')
end) end)
@ -171,6 +174,8 @@ describe('Mouse input', function()
]]) ]])
screen:try_resize(53, 14) screen:try_resize(53, 14)
execute('sp', 'vsp') execute('sp', 'vsp')
screen:set_default_attr_ignore( {{bold=true, foreground=hlgroup_colors.NonText},
{reverse=true}, {bold=true, reverse=true}} )
screen:expect([[ screen:expect([[
lines |lines | lines |lines |
to |to | to |to |

View File

@ -158,19 +158,11 @@ function Screen:expect(expected, attr_ids, attr_ignore)
table.insert(expected_rows, row) table.insert(expected_rows, row)
end end
local ids = attr_ids or self._default_attr_ids local ids = attr_ids or self._default_attr_ids
if attr_ignore == nil and self._default_attr_ignore ~= nil then local ignore = attr_ignore or self._default_attr_ignore
attr_ignore = {}
-- don't ignore something we specified in attr_ids
for i,a in pairs(self._default_attr_ignore) do
if attr_index(ids, a) == nil then
table.insert(attr_ignore, a)
end
end
end
self:wait(function() self:wait(function()
for i = 1, self._height do for i = 1, self._height do
local expected_row = expected_rows[i] local expected_row = expected_rows[i]
local actual_row = self:_row_repr(self._rows[i], ids, attr_ignore) local actual_row = self:_row_repr(self._rows[i], ids, ignore)
if expected_row ~= actual_row then if expected_row ~= actual_row then
return 'Row '..tostring(i)..' didnt match.\nExpected: "'.. return 'Row '..tostring(i)..' didnt match.\nExpected: "'..
expected_row..'"\nActual: "'..actual_row..'"' expected_row..'"\nActual: "'..actual_row..'"'
@ -417,16 +409,20 @@ function Screen:snapshot_util(attrs, ignore)
end end
end end
if ignore ~= true then
for i = 1, self._height do for i = 1, self._height do
local row = self._rows[i] local row = self._rows[i]
for j = 1, self._width do for j = 1, self._width do
local attr = row[j].attrs local attr = row[j].attrs
if attr_index(attrs, attr) == nil and attr_index(ignore, attr) == nil then if attr_index(attrs, attr) == nil and attr_index(ignore, attr) == nil then
if not equal_attrs(attr, {}) then
table.insert(attrs, attr) table.insert(attrs, attr)
end end
end end
end end
end end
end
end
local rv = {} local rv = {}
for i = 1, self._height do for i = 1, self._height do
@ -468,7 +464,7 @@ function backward_find_meaningful(tbl, from)
return from return from
end end
function get_attr_id(attr_ids, attr_ignore, attrs) function get_attr_id(attr_ids, ignore, attrs)
if not attr_ids then if not attr_ids then
return return
end end
@ -477,7 +473,8 @@ function get_attr_id(attr_ids, attr_ignore, attrs)
return id return id
end end
end end
if attr_ignore == nil or attr_index(attr_ignore, attrs) ~= nil then if equal_attrs(attrs, {}) or
ignore == true or attr_index(ignore, attrs) ~= nil then
-- ignore this attrs -- ignore this attrs
return nil return nil
end end