Skip to content

Commit 6977af0

Browse files
committed
test(misc): cleanup setup_termbg_sync() tests
Details: - Use single `MiniTest.skip()` in a test set hook, since it started to work after these tests were written. - Uniformly use `\027` to indicate escape sequence (instead of `\27`).
1 parent 5e94a68 commit 6977af0

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

tests/test_misc.lua

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ local child = helpers.new_child_neovim()
44
local expect, eq = helpers.expect, helpers.expect.equality
55
local new_set = MiniTest.new_set
66

7-
local skip_if_no_010 = function()
8-
if child.fn.has('nvim-0.10') == 0 then MiniTest.skip('`setup_termbg_sync()` works only on Neovim>=0.10') end
9-
end
10-
117
local project_root = vim.fs.normalize(vim.fn.fnamemodify(vim.fn.getcwd(), ':p'))
128
local dir_misc_path = project_root .. '/tests/dir-misc'
139

@@ -662,6 +658,8 @@ end
662658
T['setup_termbg_sync()'] = new_set({
663659
hooks = {
664660
pre_case = function()
661+
if child.fn.has('nvim-0.10') == 0 then MiniTest.skip('`setup_termbg_sync()` works only on Neovim>=0.10') end
662+
665663
child.lua([[
666664
-- Mock `io.stdout:write` used to send control sequences to terminal emulator
667665
_G.log = {}
@@ -682,11 +680,9 @@ end
682680
T['setup_termbg_sync()']['works'] = new_set(
683681
-- Neovim=0.10 uses string sequence as response, while Neovim>=0.11 sets it
684682
-- in `sequence` table field
685-
{ parametrize = { { '\27]11;rgb:1111/2626/2d2d' }, { { sequence = '\27]11;rgb:1111/2626/2d2d' } } } },
683+
{ parametrize = { { '\027]11;rgb:1111/2626/2d2d' }, { { sequence = '\027]11;rgb:1111/2626/2d2d' } } } },
686684
{
687685
test = function(response_data)
688-
skip_if_no_010()
689-
690686
local eq_log = function(ref_log)
691687
eq(child.lua_get('_G.log'), ref_log)
692688
child.lua('_G.log = {}')
@@ -718,18 +714,16 @@ T['setup_termbg_sync()']['works'] = new_set(
718714
)
719715

720716
T['setup_termbg_sync()']['can be called multiple times'] = function()
721-
skip_if_no_010()
722-
723717
child.cmd('hi Normal guifg=#222222 guibg=#dddddd')
724718
child.lua('MiniMisc.setup_termbg_sync()')
725-
child.api.nvim_exec_autocmds('TermResponse', { data = '\27]11;rgb:1111/2626/2d2d' })
726-
eq(child.lua_get('_G.log'), { { '\27]11;?\a' }, { '\27]11;#dddddd\a' } })
719+
child.api.nvim_exec_autocmds('TermResponse', { data = '\027]11;rgb:1111/2626/2d2d' })
720+
eq(child.lua_get('_G.log'), { { '\027]11;?\a' }, { '\027]11;#dddddd\a' } })
727721
child.lua('_G.log = {}')
728722

729723
-- If called second time, the terminal background color is already synced
730724
child.lua('MiniMisc.setup_termbg_sync()')
731-
child.api.nvim_exec_autocmds('TermResponse', { data = '\27]11;rgb:dddd/dddd/dddd' })
732-
eq(child.lua_get('_G.log'), { { '\27]11;?\a' }, { '\27]11;#dddddd\a' } })
725+
child.api.nvim_exec_autocmds('TermResponse', { data = '\027]11;rgb:dddd/dddd/dddd' })
726+
eq(child.lua_get('_G.log'), { { '\027]11;?\a' }, { '\027]11;#dddddd\a' } })
733727
child.lua('_G.log = {}')
734728

735729
-- Should reset to the color from the very first call
@@ -738,8 +732,6 @@ T['setup_termbg_sync()']['can be called multiple times'] = function()
738732
end
739733

740734
T['setup_termbg_sync()']['does nothing if there is no proper stdout'] = function()
741-
skip_if_no_010()
742-
743735
local validate = function()
744736
child.lua('MiniMisc.setup_termbg_sync()')
745737
child.api.nvim_create_augroup('MiniMiscTermbgSync', { clear = false })
@@ -756,8 +748,6 @@ T['setup_termbg_sync()']['does nothing if there is no proper stdout'] = function
756748
end
757749

758750
T['setup_termbg_sync()']['handles no response from terminal emulator'] = function()
759-
skip_if_no_010()
760-
761751
child.lua('_G.notify_log = {}; vim.notify = function(...) table.insert(_G.notify_log, { ... }) end')
762752
child.lua('MiniMisc.setup_termbg_sync()')
763753
validate_termbg_augroup(true)
@@ -775,8 +765,6 @@ T['setup_termbg_sync()']['handles no response from terminal emulator'] = functio
775765
end
776766

777767
T['setup_termbg_sync()']['handles bad response from terminal emulator'] = function()
778-
skip_if_no_010()
779-
780768
child.lua('_G.notify_log = {}; vim.notify = function(...) table.insert(_G.notify_log, { ... }) end')
781769
child.lua('MiniMisc.setup_termbg_sync()')
782770

@@ -802,8 +790,6 @@ T['setup_termbg_sync()']['handles bad response from terminal emulator'] = functi
802790
end
803791

804792
T['setup_termbg_sync()']['handles parallel unrelated `TermResponse` events'] = function()
805-
skip_if_no_010()
806-
807793
child.lua('_G.notify_log = {}; vim.notify = function(...) table.insert(_G.notify_log, { ... }) end')
808794
child.lua('MiniMisc.setup_termbg_sync()')
809795

@@ -819,7 +805,7 @@ T['setup_termbg_sync()']['handles parallel unrelated `TermResponse` events'] = f
819805

820806
-- After receiving proper response should immediately stop waiting for it and
821807
-- set up proper `termbg` autocommands
822-
local seq = '\27]11;rgb:1111/2626/2d2d'
808+
local seq = '\027]11;rgb:1111/2626/2d2d'
823809
local data = child.fn.has('nvim-0.11') == 1 and { sequence = seq } or seq
824810
child.api.nvim_exec_autocmds('TermResponse', { data = data })
825811
validate_termbg_augroup(true)
@@ -829,13 +815,11 @@ T['setup_termbg_sync()']['handles parallel unrelated `TermResponse` events'] = f
829815
end
830816

831817
T['setup_termbg_sync()']['handles different color formats'] = function()
832-
skip_if_no_010()
833-
834818
local validate = function(term_response_color)
835819
-- Mock clean start to overcome that color is parsed only once per session
836820
child.lua('package.loaded["mini.misc"] = nil')
837821
child.lua('require("mini.misc").setup_termbg_sync()')
838-
child.api.nvim_exec_autocmds('TermResponse', { data = '\27]11;' .. term_response_color })
822+
child.api.nvim_exec_autocmds('TermResponse', { data = '\027]11;' .. term_response_color })
839823

840824
-- Should properly parse initial background and use it to reset on exit
841825
child.lua('_G.log = {}')
@@ -861,11 +845,9 @@ T['setup_termbg_sync()']['handles different color formats'] = function()
861845
end
862846

863847
T['setup_termbg_sync()']['handles transparent `Normal` background'] = function()
864-
skip_if_no_010()
865-
866848
child.cmd('hi Normal guifg=#222222 guibg=#dddddd')
867849
child.lua('MiniMisc.setup_termbg_sync()')
868-
child.api.nvim_exec_autocmds('TermResponse', { data = '\27]11;rgb:1111/2626/2d2d' })
850+
child.api.nvim_exec_autocmds('TermResponse', { data = '\027]11;rgb:1111/2626/2d2d' })
869851
child.lua('_G.log = {}')
870852

871853
-- When syncing with "transparent" `Normal`, should restore the original
@@ -876,8 +858,6 @@ T['setup_termbg_sync()']['handles transparent `Normal` background'] = function()
876858
end
877859

878860
T['setup_termbg_sync()']['respects `opts.explicit_reset`'] = function()
879-
skip_if_no_010()
880-
881861
child.cmd('hi Normal guifg=#222222 guibg=#dddddd')
882862
child.lua('MiniMisc.setup_termbg_sync({ explicit_reset = true })')
883863
child.api.nvim_exec_autocmds('TermResponse', { data = '\027]11;rgb:1111/2626/2d2d' })

0 commit comments

Comments
 (0)