Skip to content

Commit c889667

Browse files
committed
test(files): improve window title mocking to account for Nightly changes
Details: - Nightly (after PR number 28387 in neovim/neovim) started to truncate window titles from the left (instead of from the right). This is a good change, but it didn't work well with screenshot testing of 'mini.files'. Those tests mock window title by replacing variable starting part of the path with a known one ("MOCK_ROOT"). As mocking was not very advanced, it started to result on Nightly in screenshots with floating window titles that get truncated from the left **after** mocking. The solution is to make mocking a bit more advanced: replace exactly the number of characters from "MOCK_ROOT" that are in visible part of path start.
1 parent b5143e5 commit c889667

22 files changed

+30
-23
lines changed

tests/dir-files/mock-win-functions.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
local mock_title = function(x)
22
if type(x) ~= 'string' then return x end
3-
-- Make sure that full path title is same on any machine
4-
return x:gsub('^.*/tests/dir%-files', 'MOCK_ROOT/tests/dir-files')
3+
-- Make sure that full path title is the same on any machine
4+
return x:gsub('^(.+)/tests/dir%-files', function(m)
5+
-- Account for possible title truncation.
6+
-- NOTE: This will also remove the intentional truncation with '…' prefix.
7+
-- There should be dedicated tests for this truncation that are not
8+
-- affected by this mock.
9+
local mocked_root = string.sub('MOCK_ROOT', -vim.fn.strdisplaywidth(m))
10+
return mocked_root .. '/tests/dir-files'
11+
end)
512
end
613

714
_G.nvim_open_win_orig = vim.api.nvim_open_win

tests/screenshots/tests-test_files.lua---Preview---does-not-highlight-big-files

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ big.lua ────────────────┐
2+
01|┌OCK_ROOT/tests/dir-files ┐┌ big.lua ────────────────┐
33
02|│ common ││local a = "aaaaaaaaaaaaaa│
44
03|│ lua │└─────────────────────────┘
55
04|│ nested │

tests/screenshots/tests-test_files.lua---Preview---previews-only-one-level-deep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ dir-1 ──────────────────┐
2+
01|┌T/tests/dir-files/nested ┐┌ dir-1 ──────────────────┐
33
02|│ dir-1 ││ dir-11 │
44
03|└─────────────────────────┘│ dir-12 │
55
04|~ └─────────────────────────┘

tests/screenshots/tests-test_files.lua---Preview---works-for-directories

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ .a-dir ─────────────────┐
2+
01|┌T/tests/dir-files/common ┐┌ .a-dir ─────────────────┐
33
02|│ .a-dir ││ aa-file │
44
03|│ a-dir ││ ab-file │
55
04|│ b-dir │└─────────────────────────┘

tests/screenshots/tests-test_files.lua---Preview---works-for-directories-002

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ a-dir ──────────────────┐
2+
01|┌T/tests/dir-files/common ┐┌ a-dir ──────────────────┐
33
02|│ .a-dir ││ aa-dir │
44
03|│ a-dir ││ aa-file │
55
04|│ b-dir ││ ab-file │

tests/screenshots/tests-test_files.lua---Preview---works-for-files

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ a.lua ──────────────────┐
2+
01|┌OOT/tests/dir-files/real ┐┌ a.lua ──────────────────┐
33
02|│ a.lua ││local a = 1 │
44
03|│ b.txt ││local t = { │
55
04|│ c.gif ││ x = math.max(1, 2), │

tests/screenshots/tests-test_files.lua---Preview---works-for-files-002

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ b.txt ──────────────────┐
2+
01|┌OOT/tests/dir-files/real ┐┌ b.txt ──────────────────┐
33
02|│ a.lua ││Line 1 │
44
03|│ b.txt ││Line 2 │
55
04|│ c.gif ││Line 3 │

tests/screenshots/tests-test_files.lua---Preview---works-for-files-003

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ c.gif ──────────────────┐
2+
01|┌OOT/tests/dir-files/real ┐┌ c.gif ──────────────────┐
33
02|│ a.lua ││-Non-text-file-----------│
44
03|│ b.txt │└─────────────────────────┘
55
04|│ c.gif │

tests/screenshots/tests-test_files.lua---Preview---works-for-files-004

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ LICENSE ────────────────┐
2+
01|┌OOT/tests/dir-files/real ┐┌ LICENSE ────────────────┐
33
02|│ a.lua ││ │
44
03|│ b.txt │└─────────────────────────┘
55
04|│ c.gif │

tests/screenshots/tests-test_files.lua---Preview---works-for-files-005

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--|---------|---------|---------|---------|---------|---------|---------|---------|
2-
01|┌MOCK_ROOT/tests/dir-files┐┌ Makefile ───────────────┐
2+
01|┌OOT/tests/dir-files/real ┐┌ Makefile ───────────────┐
33
02|│ a.lua ││VAR ?= 1 │
44
03|│ b.txt ││ │
55
04|│ c.gif ││all: test │

0 commit comments

Comments
 (0)