test/Screen:expect: replace "{IGNORE}" with "{MATCH:…}"

ref #11004
This commit is contained in:
Justin M. Keyes 2019-11-09 22:22:24 -08:00
parent c0abaf9ca6
commit 4abb67c027
4 changed files with 20 additions and 22 deletions

View File

@ -449,7 +449,7 @@ describe("'scrollback' option", function()
38: line | 38: line |
39: line | 39: line |
40: line | 40: line |
{IGNORE}| {MATCH:.*}|
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]} ]]}
end end

View File

@ -578,7 +578,7 @@ describe('TUI', function()
| |
{4:~ }| {4:~ }|
{5: }| {5: }|
{8:paste: Error executing lua: vim.lua:214: Vim:E21: }| {MATCH:paste: Error executing lua: vim.lua:%d+: Vim:E21: }|
{8:Cannot make changes, 'modifiable' is off} | {8:Cannot make changes, 'modifiable' is off} |
{10:Press ENTER or type command to continue}{1: } | {10:Press ENTER or type command to continue}{1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |

View File

@ -122,7 +122,7 @@ describe('ui/ext_messages', function()
feed('G$x') feed('G$x')
screen:expect{grid=[[ screen:expect{grid=[[
line 1 | line 1 |
{IGNORE}| {MATCH:.*}|
{1:~ }| {1:~ }|
{1:~ }| {1:~ }|
{1:~ }| {1:~ }|
@ -966,7 +966,7 @@ describe('ui/ext_messages', function()
{1:~ }| {1:~ }|
{1:~ }| {1:~ }|
{1:~ }| {1:~ }|
{IGNORE}| {MATCH:.*}|
{1:~ }| {1:~ }|
{1:~ }Nvim is open source and freely distributable{1: }| {1:~ }Nvim is open source and freely distributable{1: }|
{1:~ }https://neovim.io/#chat{1: }| {1:~ }https://neovim.io/#chat{1: }|
@ -976,8 +976,8 @@ describe('ui/ext_messages', function()
{1:~ }type :q{5:<Enter>} to exit {1: }| {1:~ }type :q{5:<Enter>} to exit {1: }|
{1:~ }type :help{5:<Enter>} for help {1: }| {1:~ }type :help{5:<Enter>} for help {1: }|
{1:~ }| {1:~ }|
{IGNORE}| {MATCH:.*}|
{IGNORE}| {MATCH:.*}|
{1:~ }| {1:~ }|
{1:~ }| {1:~ }|
{1:~ }| {1:~ }|
@ -1022,7 +1022,7 @@ describe('ui/ext_messages', function()
| |
| |
| |
{IGNORE}| {MATCH:.*}|
| |
Nvim is open source and freely distributable | Nvim is open source and freely distributable |
https://neovim.io/#chat | https://neovim.io/#chat |
@ -1032,8 +1032,8 @@ describe('ui/ext_messages', function()
type :q{5:<Enter>} to exit | type :q{5:<Enter>} to exit |
type :help{5:<Enter>} for help | type :help{5:<Enter>} for help |
| |
{IGNORE}| {MATCH:.*}|
{IGNORE}| {MATCH:.*}|
| |
| |
| |

View File

@ -269,7 +269,7 @@ local ext_keys = {
-- grid: Expected screen state (string). Each line represents a screen -- grid: Expected screen state (string). Each line represents a screen
-- row. Last character of each row (typically "|") is stripped. -- row. Last character of each row (typically "|") is stripped.
-- Common indentation is stripped. -- Common indentation is stripped.
-- Lines containing only "{IGNORE}|" are skipped. -- "{MATCH:x}|" lines are matched against Lua pattern `x`.
-- attr_ids: Expected text attributes. Screen rows are transformed according -- attr_ids: Expected text attributes. Screen rows are transformed according
-- to this table, as follows: each substring S composed of -- to this table, as follows: each substring S composed of
-- characters having the same attributes will be substituted by -- characters having the same attributes will be substituted by
@ -390,11 +390,10 @@ function Screen:expect(expected, attr_ids, ...)
err_msg = "Expected screen height " .. #expected_rows err_msg = "Expected screen height " .. #expected_rows
.. ' differs from actual height ' .. #actual_rows .. '.' .. ' differs from actual height ' .. #actual_rows .. '.'
end end
for i = 1, #expected_rows do for i, row in ipairs(expected_rows) do
msg_expected_rows[i] = expected_rows[i] msg_expected_rows[i] = row
if expected_rows[i] ~= actual_rows[i] and expected_rows[i] ~= "{IGNORE}|" then local m = (row ~= actual_rows[i] and row:match('{MATCH:(.*)}') or nil)
local m = expected_rows[i]:match('{MATCH:(.*)}') if row ~= actual_rows[i] and (not m or not actual_rows[i]:match(m)) then
if not m or not actual_rows[i]:match(m) then
msg_expected_rows[i] = '*' .. msg_expected_rows[i] msg_expected_rows[i] = '*' .. msg_expected_rows[i]
if i <= #actual_rows then if i <= #actual_rows then
actual_rows[i] = '*' .. actual_rows[i] actual_rows[i] = '*' .. actual_rows[i]
@ -404,7 +403,6 @@ function Screen:expect(expected, attr_ids, ...)
end end
end end
end end
end
if err_msg ~= nil then if err_msg ~= nil then
return ( return (
err_msg..'\nExpected:\n |'..table.concat(msg_expected_rows, '\n |')..'\n' err_msg..'\nExpected:\n |'..table.concat(msg_expected_rows, '\n |')..'\n'