tests/ui: cleanup illegitimate usages of "attr_ignore"

"attr_ignore" is an anti-pattern, with snapshot_util()
just include all the highlights already.
This commit is contained in:
Björn Linse
2019-10-12 13:29:51 +02:00
parent 5a85699425
commit a330129a28
8 changed files with 90 additions and 83 deletions

View File

@@ -14,6 +14,10 @@ describe('063: Test for ":match", "matchadd()" and related functions', function(
it('is working', function() it('is working', function()
local screen = Screen.new(40, 5) local screen = Screen.new(40, 5)
screen:attach() screen:attach()
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue},
[1] = {background = Screen.colors.Red},
})
-- Check that "matcharg()" returns the correct group and pattern if a match -- Check that "matcharg()" returns the correct group and pattern if a match
-- is defined. -- is defined.
@@ -126,22 +130,22 @@ describe('063: Test for ":match", "matchadd()" and related functions', function(
command("call matchaddpos('MyGroup1', [[1, 5], [1, 8, 3]], 10, 3)") command("call matchaddpos('MyGroup1', [[1, 5], [1, 8, 3]], 10, 3)")
screen:expect([[ screen:expect([[
abcd{1:e}fg{1:hij}klmnop^q | abcd{1:e}fg{1:hij}klmnop^q |
~ | {0:~ }|
~ | {0:~ }|
~ | {0:~ }|
| |
]], {[1] = {background = Screen.colors.Red}}, {{bold = true, foreground = Screen.colors.Blue}}) ]])
command("call clearmatches()") command("call clearmatches()")
command("call setline(1, 'abcdΣabcdef')") command("call setline(1, 'abcdΣabcdef')")
command("call matchaddpos('MyGroup1', [[1, 4, 2], [1, 9, 2]])") command("call matchaddpos('MyGroup1', [[1, 4, 2], [1, 9, 2]])")
screen:expect([[ screen:expect([[
abc{1:dΣ}ab{1:cd}e^f | abc{1:dΣ}ab{1:cd}e^f |
~ | {0:~ }|
~ | {0:~ }|
~ | {0:~ }|
| |
]],{[1] = {background = Screen.colors.Red}}, {{bold = true, foreground = Screen.colors.Blue}}) ]])
end) end)
end) end)

View File

@@ -408,10 +408,7 @@ describe('search cmdline', function()
screen = Screen.new(20, 6) screen = Screen.new(20, 6)
screen:attach() screen:attach()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
inc = {reverse = true} inc = {reverse = true},
})
screen:set_default_attr_ignore({
{bold=true, reverse=true}, {bold=true, foreground=Screen.colors.Blue1}
}) })
tenlines() tenlines()

View File

@@ -116,8 +116,6 @@ describe('health.vim', function()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
Ok = { foreground = Screen.colors.Grey3, background = 6291200 }, Ok = { foreground = Screen.colors.Grey3, background = 6291200 },
Error = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, Error = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
})
screen:set_default_attr_ignore({
Heading = { bold=true, foreground=Screen.colors.Magenta }, Heading = { bold=true, foreground=Screen.colors.Magenta },
Heading2 = { foreground = Screen.colors.SlateBlue }, Heading2 = { foreground = Screen.colors.SlateBlue },
Bar = { foreground=Screen.colors.Purple }, Bar = { foreground=Screen.colors.Purple },
@@ -126,18 +124,18 @@ describe('health.vim', function()
command("checkhealth foo success1") command("checkhealth foo success1")
command("1tabclose") command("1tabclose")
command("set laststatus=0") command("set laststatus=0")
screen:expect([[ screen:expect{grid=[[
^ | ^ |
health#foo#check | {Heading:health#foo#check} |
========================================================================| {Bar:========================================================================}|
- {Error:ERROR:} No healthcheck found for "foo" plugin. | {Bullet: -} {Error:ERROR:} No healthcheck found for "foo" plugin. |
| |
health#success1#check | {Heading:health#success1#check} |
========================================================================| {Bar:========================================================================}|
## report 1 | {Heading2:##}{Heading: report 1} |
- {Ok:OK:} everything is fine | {Bullet: -} {Ok:OK:} everything is fine |
| |
]]) ]]}
end) end)
it("gracefully handles invalid healthcheck", function() it("gracefully handles invalid healthcheck", function()

View File

@@ -19,10 +19,8 @@ describe(':Man', function()
u = { underline = true }, u = { underline = true },
bi = { bold = true, italic = true }, bi = { bold = true, italic = true },
biu = { bold = true, italic = true, underline = true }, biu = { bold = true, italic = true, underline = true },
}) c = { foreground = Screen.colors.Blue }, -- control chars
screen:set_default_attr_ignore({ eob = { bold = true, foreground = Screen.colors.Blue } -- empty line '~'s
{ foreground = Screen.colors.Blue }, -- control chars
{ bold = true, foreground = Screen.colors.Blue } -- empty line '~'s
}) })
screen:attach() screen:attach()
end) end)
@@ -36,21 +34,21 @@ describe(':Man', function()
ithis i<C-v><C-h>is<C-v><C-h>s a<C-v><C-h>a test ithis i<C-v><C-h>is<C-v><C-h>s a<C-v><C-h>a test
with _<C-v><C-h>o_<C-v><C-h>v_<C-v><C-h>e_<C-v><C-h>r_<C-v><C-h>s_<C-v><C-h>t_<C-v><C-h>r_<C-v><C-h>u_<C-v><C-h>c_<C-v><C-h>k text<ESC>]]) with _<C-v><C-h>o_<C-v><C-h>v_<C-v><C-h>e_<C-v><C-h>r_<C-v><C-h>s_<C-v><C-h>t_<C-v><C-h>r_<C-v><C-h>u_<C-v><C-h>c_<C-v><C-h>k text<ESC>]])
screen:expect([[ screen:expect{grid=[[
this i^His^Hs a^Ha test | this i{c:^H}is{c:^H}s a{c:^H}a test |
with _^Ho_^Hv_^He_^Hr_^Hs_^Ht_^Hr_^Hu_^Hc_^Hk tex^t | with _{c:^H}o_{c:^H}v_{c:^H}e_{c:^H}r_{c:^H}s_{c:^H}t_{c:^H}r_{c:^H}u_{c:^H}c_{c:^H}k tex^t |
~ | {eob:~ }|
~ | {eob:~ }|
| |
]]) ]]}
eval('man#init_pager()') eval('man#init_pager()')
screen:expect([[ screen:expect([[
^this {b:is} {b:a} test | ^this {b:is} {b:a} test |
with {u:overstruck} text | with {u:overstruck} text |
~ | {eob:~ }|
~ | {eob:~ }|
| |
]]) ]])
end) end)
@@ -60,21 +58,21 @@ describe(':Man', function()
ithis <C-v><ESC>[1mis <C-v><ESC>[3ma <C-v><ESC>[4mtest<C-v><ESC>[0m ithis <C-v><ESC>[1mis <C-v><ESC>[3ma <C-v><ESC>[4mtest<C-v><ESC>[0m
<C-v><ESC>[4mwith<C-v><ESC>[24m <C-v><ESC>[4mescaped<C-v><ESC>[24m <C-v><ESC>[4mtext<C-v><ESC>[24m<ESC>]]) <C-v><ESC>[4mwith<C-v><ESC>[24m <C-v><ESC>[4mescaped<C-v><ESC>[24m <C-v><ESC>[4mtext<C-v><ESC>[24m<ESC>]])
screen:expect([=[ screen:expect{grid=[=[
this ^[[1mis ^[[3ma ^[[4mtest^[[0m | this {c:^[}[1mis {c:^[}[3ma {c:^[}[4mtest{c:^[}[0m |
^[[4mwith^[[24m ^[[4mescaped^[[24m ^[[4mtext^[[24^m | {c:^[}[4mwith{c:^[}[24m {c:^[}[4mescaped{c:^[}[24m {c:^[}[4mtext{c:^[}[24^m |
~ | {eob:~ }|
~ | {eob:~ }|
| |
]=]) ]=]}
eval('man#init_pager()') eval('man#init_pager()')
screen:expect([[ screen:expect([[
^this {b:is }{bi:a }{biu:test} | ^this {b:is }{bi:a }{biu:test} |
{u:with} {u:escaped} {u:text} | {u:with} {u:escaped} {u:text} |
~ | {eob:~ }|
~ | {eob:~ }|
| |
]]) ]])
end) end)
@@ -88,8 +86,8 @@ describe(':Man', function()
screen:expect([[ screen:expect([[
^this {b:is} {b:あ} test | ^this {b:is} {b:あ} test |
with {u:överstrũck} te{i:xt¶} | with {u:överstrũck} te{i:xt¶} |
~ | {eob:~ }|
~ | {eob:~ }|
| |
]]) ]])
end) end)
@@ -105,7 +103,7 @@ describe(':Man', function()
{b:^_begins} | {b:^_begins} |
{b:mid_dle} | {b:mid_dle} |
{u:mid_dle} | {u:mid_dle} |
~ | {eob:~ }|
| |
]]) ]])
end) end)
@@ -121,7 +119,7 @@ describe(':Man', function()
^· {b:·} | ^· {b:·} |
{b:·} | {b:·} |
{b:·} double | {b:·} double |
~ | {eob:~ }|
| |
]]) ]])
end) end)

View File

@@ -88,6 +88,11 @@ describe('clipboard', function()
before_each(function() before_each(function()
clear() clear()
screen = Screen.new(72, 4) screen = Screen.new(72, 4)
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue},
[1] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
[2] = {bold = true, foreground = Screen.colors.SeaGreen4},
})
screen:attach() screen:attach()
command("set display-=msgsep") command("set display-=msgsep")
end) end)
@@ -103,22 +108,22 @@ describe('clipboard', function()
feed_command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END') feed_command('redir @+> | :silent echo system("cat CONTRIBUTING.md") | redir END')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {0:~ }|
~ | {0:~ }|
clipboard: No provider. Try ":checkhealth" or ":h clipboard". | clipboard: No provider. Try ":checkhealth" or ":h clipboard". |
]], nil, {{bold = true, foreground = Screen.colors.Blue}}) ]])
end) end)
it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184', it('`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184',
function() function()
command("let g:clipboard = 'bogus'") command("let g:clipboard = 'bogus'")
feed_command('redir @+> | bogus_cmd | redir END') feed_command('redir @+> | bogus_cmd | redir END')
screen:expect([[ screen:expect{grid=[[
~ | {0:~ }|
clipboard: No provider. Try ":checkhealth" or ":h clipboard". | clipboard: No provider. Try ":checkhealth" or ":h clipboard". |
E492: Not an editor command: bogus_cmd | redir END | {1:E492: Not an editor command: bogus_cmd | redir END} |
Press ENTER or type command to continue^ | {2:Press ENTER or type command to continue}^ |
]], nil, {{bold = true, foreground = Screen.colors.Blue}}) ]]}
end) end)
it('invalid g:clipboard shows hint if :redir is not active', function() it('invalid g:clipboard shows hint if :redir is not active', function()
@@ -131,10 +136,10 @@ describe('clipboard', function()
feed_command('let @+="foo"') feed_command('let @+="foo"')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {0:~ }|
~ | {0:~ }|
clipboard: No provider. Try ":checkhealth" or ":h clipboard". | clipboard: No provider. Try ":checkhealth" or ":h clipboard". |
]], nil, {{bold = true, foreground = Screen.colors.Blue}}) ]])
end) end)
it('valid g:clipboard', function() it('valid g:clipboard', function()
@@ -266,13 +271,17 @@ describe('clipboard (with fake clipboard.vim)', function()
function() function()
local screen = Screen.new(72, 4) local screen = Screen.new(72, 4)
screen:attach() screen:attach()
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue},
[1] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
})
feed_command('redir @+> | bogus_cmd | redir END') feed_command('redir @+> | bogus_cmd | redir END')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {0:~ }|
~ | {0:~ }|
E492: Not an editor command: bogus_cmd | redir END | {1:E492: Not an editor command: bogus_cmd | redir END} |
]], nil, {{bold = true, foreground = Screen.colors.Blue}}) ]])
end) end)
it('has independent "* and unnamed registers by default', function() it('has independent "* and unnamed registers by default', function()
@@ -637,6 +646,9 @@ describe('clipboard (with fake clipboard.vim)', function()
feed_command('set mouse=a') feed_command('set mouse=a')
local screen = Screen.new(30, 5) local screen = Screen.new(30, 5)
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue},
})
screen:attach() screen:attach()
insert([[ insert([[
the source the source
@@ -646,10 +658,10 @@ describe('clipboard (with fake clipboard.vim)', function()
screen:expect([[ screen:expect([[
the ^source | the ^source |
a target | a target |
~ | {0:~ }|
~ | {0:~ }|
| |
]], nil, {{bold = true, foreground = Screen.colors.Blue}}) ]])
feed('<MiddleMouse><0,1>') feed('<MiddleMouse><0,1>')
expect([[ expect([[

View File

@@ -208,18 +208,18 @@ describe(':terminal buffer', function()
feed_command('terminal') feed_command('terminal')
feed('<c-\\><c-n>') feed('<c-\\><c-n>')
feed_command('confirm bdelete') feed_command('confirm bdelete')
screen:expect{any='Close "term://', attr_ignore=true} screen:expect{any='Close "term://'}
end) end)
it('with &confirm', function() it('with &confirm', function()
feed_command('terminal') feed_command('terminal')
feed('<c-\\><c-n>') feed('<c-\\><c-n>')
feed_command('bdelete') feed_command('bdelete')
screen:expect{any='E89', attr_ignore=true} screen:expect{any='E89'}
feed('<cr>') feed('<cr>')
eq('terminal', eval('&buftype')) eq('terminal', eval('&buftype'))
feed_command('set confirm | bdelete') feed_command('set confirm | bdelete')
screen:expect{any='Close "term://', attr_ignore=true} screen:expect{any='Close "term://'}
feed('y') feed('y')
neq('terminal', eval('&buftype')) neq('terminal', eval('&buftype'))
end) end)

View File

@@ -26,6 +26,8 @@ describe('ui/mouse/input', function()
}, },
[4] = {reverse = true}, [4] = {reverse = true},
[5] = {bold = true, reverse = true}, [5] = {bold = true, reverse = true},
[6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
[7] = {bold = true, foreground = Screen.colors.SeaGreen4},
}) })
command("set display-=msgsep") command("set display-=msgsep")
feed('itesting<cr>mouse<cr>support and selection<esc>') feed('itesting<cr>mouse<cr>support and selection<esc>')
@@ -620,12 +622,12 @@ describe('ui/mouse/input', function()
meths.set_option('tags', './non-existent-tags-file') meths.set_option('tags', './non-existent-tags-file')
feed('<C-LeftMouse><0,0>') feed('<C-LeftMouse><0,0>')
screen:expect([[ screen:expect([[
E433: No tags file | {6:E433: No tags file} |
E426: tag not found: test| {6:E426: tag not found: test}|
ing | {6:ing} |
Press ENTER or type comma| {7:Press ENTER or type comma}|
nd to continue^ | {7:nd to continue}^ |
]],nil,true) ]])
feed('<cr>') feed('<cr>')
end) end)

View File

@@ -66,7 +66,6 @@
-- [1] = {reverse = true, bold = true}, -- [1] = {reverse = true, bold = true},
-- [2] = {reverse = true} -- [2] = {reverse = true}
-- }) -- })
-- screen:set_default_attr_ignore( {{}, {bold=true, foreground=NonText}} )
-- --
-- To help write screen tests, see Screen:snapshot_util(). -- To help write screen tests, see Screen:snapshot_util().
-- To debug screen tests, see Screen:redraw_debug(). -- To debug screen tests, see Screen:redraw_debug().
@@ -169,7 +168,6 @@ function Screen.new(width, height)
ruler = {}, ruler = {},
hl_groups = {}, hl_groups = {},
_default_attr_ids = nil, _default_attr_ids = nil,
_default_attr_ignore = nil,
_mouse_enabled = true, _mouse_enabled = true,
_attrs = {}, _attrs = {},
_hl_info = {[0]={}}, _hl_info = {[0]={}},
@@ -202,10 +200,6 @@ function Screen:get_default_attr_ids()
return deepcopy(self._default_attr_ids) return deepcopy(self._default_attr_ids)
end end
function Screen:set_default_attr_ignore(attr_ignore)
self._default_attr_ignore = attr_ignore
end
function Screen:set_rgb_cterm(val) function Screen:set_rgb_cterm(val)
self._rgb_cterm = val self._rgb_cterm = val
end end
@@ -361,7 +355,7 @@ function Screen:expect(expected, attr_ids, attr_ignore, ...)
end end
local attr_state = { local attr_state = {
ids = attr_ids or self._default_attr_ids, ids = attr_ids or self._default_attr_ids,
ignore = attr_ignore or self._default_attr_ignore, ignore = attr_ignore
} }
if self._options.ext_linegrid then if self._options.ext_linegrid then
attr_state.id_to_index = self:linegrid_check_attrs(attr_state.ids or {}) attr_state.id_to_index = self:linegrid_check_attrs(attr_state.ids or {})
@@ -1478,6 +1472,8 @@ function Screen:_get_attr_id(attr_state, attrs, hl_id)
return nil return nil
elseif id ~= nil then elseif id ~= nil then
return id return id
elseif attr_state.ignore == true then
return nil
end end
if attr_state.mutable then if attr_state.mutable then
id = self:_insert_hl_id(attr_state, hl_id) id = self:_insert_hl_id(attr_state, hl_id)