From c0abaf9ca604485ceee04ae8ca83c11382febc89 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 12 Sep 2019 13:06:34 +0200 Subject: tests: Screen:expect: support "{MATCH:…}" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/functional/ui/screen.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'test/functional/ui') diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 41e022791e..e9583bf805 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -391,14 +391,17 @@ function Screen:expect(expected, attr_ids, ...) .. ' differs from actual height ' .. #actual_rows .. '.' end for i = 1, #expected_rows do - msg_expected_rows[i] = expected_rows[i] + msg_expected_rows[i] = expected_rows[i] if expected_rows[i] ~= actual_rows[i] and expected_rows[i] ~= "{IGNORE}|" then - msg_expected_rows[i] = '*' .. msg_expected_rows[i] - if i <= #actual_rows then - actual_rows[i] = '*' .. actual_rows[i] - end - if err_msg == nil then - err_msg = 'Row ' .. tostring(i) .. ' did not match.' + local m = expected_rows[i]:match('{MATCH:(.*)}') + if not m or not actual_rows[i]:match(m) then + msg_expected_rows[i] = '*' .. msg_expected_rows[i] + if i <= #actual_rows then + actual_rows[i] = '*' .. actual_rows[i] + end + if err_msg == nil then + err_msg = 'Row ' .. tostring(i) .. ' did not match.' + end end end end -- cgit From 4abb67c027e93afac8c2f436d48956fffcd69848 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 9 Nov 2019 22:22:24 -0800 Subject: test/Screen:expect: replace "{IGNORE}" with "{MATCH:…}" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #11004 --- test/functional/ui/messages_spec.lua | 14 +++++++------- test/functional/ui/screen.lua | 24 +++++++++++------------- 2 files changed, 18 insertions(+), 20 deletions(-) (limited to 'test/functional/ui') diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index d16559bab2..8ad3aff21f 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -122,7 +122,7 @@ describe('ui/ext_messages', function() feed('G$x') screen:expect{grid=[[ line 1 | - {IGNORE}| + {MATCH:.*}| {1:~ }| {1:~ }| {1:~ }| @@ -966,7 +966,7 @@ describe('ui/ext_messages', function() {1:~ }| {1:~ }| {1:~ }| - {IGNORE}| + {MATCH:.*}| {1:~ }| {1:~ }Nvim is open source and freely distributable{1: }| {1:~ }https://neovim.io/#chat{1: }| @@ -976,8 +976,8 @@ describe('ui/ext_messages', function() {1:~ }type :q{5:} to exit {1: }| {1:~ }type :help{5:} for help {1: }| {1:~ }| - {IGNORE}| - {IGNORE}| + {MATCH:.*}| + {MATCH:.*}| {1:~ }| {1:~ }| {1:~ }| @@ -1022,7 +1022,7 @@ describe('ui/ext_messages', function() | | | - {IGNORE}| + {MATCH:.*}| | Nvim is open source and freely distributable | https://neovim.io/#chat | @@ -1032,8 +1032,8 @@ describe('ui/ext_messages', function() type :q{5:} to exit | type :help{5:} for help | | - {IGNORE}| - {IGNORE}| + {MATCH:.*}| + {MATCH:.*}| | | | diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index e9583bf805..d3f78bf77b 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -269,7 +269,7 @@ local ext_keys = { -- grid: Expected screen state (string). Each line represents a screen -- row. Last character of each row (typically "|") 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 -- to this table, as follows: each substring S composed of -- characters having the same attributes will be substituted by @@ -390,18 +390,16 @@ function Screen:expect(expected, attr_ids, ...) err_msg = "Expected screen height " .. #expected_rows .. ' differs from actual height ' .. #actual_rows .. '.' end - for i = 1, #expected_rows do - msg_expected_rows[i] = expected_rows[i] - if expected_rows[i] ~= actual_rows[i] and expected_rows[i] ~= "{IGNORE}|" then - local m = expected_rows[i]:match('{MATCH:(.*)}') - if not m or not actual_rows[i]:match(m) then - msg_expected_rows[i] = '*' .. msg_expected_rows[i] - if i <= #actual_rows then - actual_rows[i] = '*' .. actual_rows[i] - end - if err_msg == nil then - err_msg = 'Row ' .. tostring(i) .. ' did not match.' - end + for i, row in ipairs(expected_rows) do + msg_expected_rows[i] = row + local m = (row ~= actual_rows[i] and row:match('{MATCH:(.*)}') or nil) + if row ~= actual_rows[i] and (not m or not actual_rows[i]:match(m)) then + msg_expected_rows[i] = '*' .. msg_expected_rows[i] + if i <= #actual_rows then + actual_rows[i] = '*' .. actual_rows[i] + end + if err_msg == nil then + err_msg = 'Row ' .. tostring(i) .. ' did not match.' end end end -- cgit