diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-02-18 09:27:10 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-02-18 10:44:35 +0800 |
commit | 9b9f8dfcc41ceb80d3970eb58af8ee350b57dc7f (patch) | |
tree | c0347335374e363432711ad9f0ba02badefb300b /test/functional/ui | |
parent | bb369a14f3e948c8efa3709d95e4dc2098b2de6a (diff) | |
download | rneovim-9b9f8dfcc41ceb80d3970eb58af8ee350b57dc7f.tar.gz rneovim-9b9f8dfcc41ceb80d3970eb58af8ee350b57dc7f.tar.bz2 rneovim-9b9f8dfcc41ceb80d3970eb58af8ee350b57dc7f.zip |
test: make {MATCH:} behave less unexpectedly in screen:expect()
Include the rest of the line and allow multiple {MATCH:} patterns.
Diffstat (limited to 'test/functional/ui')
-rw-r--r-- | test/functional/ui/bufhl_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ui/messages_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 19 |
3 files changed, 19 insertions, 6 deletions
diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua index 418294ac07..adec0770de 100644 --- a/test/functional/ui/bufhl_spec.lua +++ b/test/functional/ui/bufhl_spec.lua @@ -303,7 +303,7 @@ describe('Buffer highlighting', function() {1:~ }| {1:~ }| {1:~ }| - 2 change3; before #3 {MATCH:.*}| + 2 changes; before #3 {MATCH:.*}| ]]} command('undo') diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 3052a74f38..212d3aee7d 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -1322,7 +1322,7 @@ describe('ui/ext_messages', function() {1:~ }type :q{5:<Enter>} to exit {1: }| {1:~ }type :help{5:<Enter>} for help {1: }| {1:~ }| - {1:~ }type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+}| + {1:~{MATCH: +}}type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+}{1:{MATCH: +}}| {1:~ }| {MATCH:.*}| {MATCH:.*}| @@ -1378,7 +1378,7 @@ describe('ui/ext_messages', function() type :q{5:<Enter>} to exit | type :help{5:<Enter>} for help | | - type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+}| + {MATCH: +}type :help news{5:<Enter>} to see changes in v{MATCH:%d+%.%d+ +}| | {MATCH:.*}| {MATCH:.*}| diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 7760f26fca..14ce050578 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -75,6 +75,7 @@ local busted = require('busted') local deepcopy = helpers.deepcopy local shallowcopy = helpers.shallowcopy local concat_tables = helpers.concat_tables +local pesc = helpers.pesc local run_session = helpers.run_session local eq = helpers.eq local dedent = helpers.dedent @@ -257,7 +258,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. --- "{MATCH:x}|" lines are matched against Lua pattern `x`. +-- "{MATCH:x}" in a line is 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 @@ -382,8 +383,20 @@ function Screen:expect(expected, attr_ids, ...) 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] and actual_rows[i]:match(m))) then + local pat = nil + if actual_rows[i] and row ~= actual_rows[i] then + local after = row + while true do + local s, e, m = after:find('{MATCH:(.-)}') + if not s then + pat = pat and (pat .. pesc(after)) + break + end + pat = (pat or '') .. pesc(after:sub(1, s - 1)) .. m + after = after:sub(e + 1) + end + end + if row ~= actual_rows[i] and (not pat or not actual_rows[i]:match(pat)) then msg_expected_rows[i] = '*' .. msg_expected_rows[i] if i <= #actual_rows then actual_rows[i] = '*' .. actual_rows[i] |