test: only trim trailing spaces in swapfile tests (#25341)

This commit is contained in:
zeertzjq 2023-09-24 22:03:54 +08:00 committed by GitHub
parent 9637b7dae4
commit ed0d6536e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 23 deletions

View File

@ -17,14 +17,13 @@ local pesc = helpers.pesc
local os_kill = helpers.os_kill local os_kill = helpers.os_kill
local set_session = helpers.set_session local set_session = helpers.set_session
local spawn = helpers.spawn local spawn = helpers.spawn
local nvim_async = helpers.nvim_async local async_meths = helpers.async_meths
local expect_msg_seq = helpers.expect_msg_seq local expect_msg_seq = helpers.expect_msg_seq
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local meths = helpers.meths local meths = helpers.meths
local retry = helpers.retry local retry = helpers.retry
local trim = helpers.trim
local write_file = helpers.write_file local write_file = helpers.write_file
describe(':recover', function() describe(':recover', function()
@ -113,17 +112,17 @@ describe("preserve and (R)ecover with custom 'directory'", function()
it('killing TUI process without :preserve #22096', function() it('killing TUI process without :preserve #22096', function()
helpers.skip(helpers.is_os('win')) helpers.skip(helpers.is_os('win'))
local screen = Screen.new() local screen0 = Screen.new()
screen:attach() screen0:attach()
local child_server = new_pipename() local child_server = new_pipename()
funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server}) funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server})
screen:expect({any = pesc('[No Name]')}) -- Wait for the child process to start. screen0:expect({any = pesc('[No Name]')}) -- Wait for the child process to start.
local child_session = helpers.connect(child_server) local child_session = helpers.connect(child_server)
set_session(child_session) set_session(child_session)
local swappath1 = setup_swapname() local swappath1 = setup_swapname()
set_session(nvim0) set_session(nvim0)
command('call chanclose(&channel)') -- Kill the child process. command('call chanclose(&channel)') -- Kill the child process.
screen:expect({any = pesc('[Process exited 1]')}) -- Wait for the child process to stop. screen0:expect({any = pesc('[Process exited 1]')}) -- Wait for the child process to stop.
test_recover(swappath1) test_recover(swappath1)
end) end)
@ -204,7 +203,7 @@ describe('swapfile detection', function()
screen2:expect(expected_no_dialog) screen2:expect(expected_no_dialog)
-- With API call and shortmess+=F -- With API call and shortmess+=F
nvim_async('command', 'edit %') async_meths.command('edit %')
screen2:expect{any=[[Found a swap file by the name ".*]] screen2:expect{any=[[Found a swap file by the name ".*]]
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]} ..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
feed('e') -- Chose "Edit" at the swap dialog. feed('e') -- Chose "Edit" at the swap dialog.
@ -415,13 +414,13 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
'--cmd', init_dir, '--cmd', init_set, '--cmd', init_dir, '--cmd', init_set,
testfile}) testfile})
retry(nil, nil, function() retry(nil, nil, function()
eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', trim(funcs.getline('$'))) eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
eval("getline('$')->trim(' ', 2)"))
end) end)
meths.chan_send(chan, 'q') meths.chan_send(chan, 'q')
retry(nil, nil, function() retry(nil, nil, function()
eq({'', '[Process exited 1]', ''}, { eq({'', '[Process exited 1]', ''},
trim(funcs.getline(1)), trim(funcs.getline(2)), trim(funcs.getline('$')), eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
})
end) end)
end) end)
@ -430,13 +429,13 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
'--cmd', init_dir, '--cmd', init_set, '--cmd', init_dir, '--cmd', init_set,
'-p', otherfile, testfile}) '-p', otherfile, testfile})
retry(nil, nil, function() retry(nil, nil, function()
eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', trim(funcs.getline('$'))) eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
eval("getline('$')->trim(' ', 2)"))
end) end)
meths.chan_send(chan, 'a') meths.chan_send(chan, 'a')
retry(nil, nil, function() retry(nil, nil, function()
eq({'', '[Process exited 1]', ''}, { eq({'', '[Process exited 1]', ''},
trim(funcs.getline(1)), trim(funcs.getline(2)), trim(funcs.getline('$')), eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
})
end) end)
end) end)
@ -450,17 +449,18 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
'--cmd', init_dir, '--cmd', init_set, '--cmd', init_dir, '--cmd', init_set,
'--cmd', 'set tags='..otherfile, '-tsecond'}) '--cmd', 'set tags='..otherfile, '-tsecond'})
retry(nil, nil, function() retry(nil, nil, function()
eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', trim(funcs.getline('$'))) eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:',
eval("getline('$')->trim(' ', 2)"))
end) end)
meths.chan_send(chan, 'q') meths.chan_send(chan, 'q')
retry(nil, nil, function() retry(nil, nil, function()
eq('Press ENTER or type command to continue', trim(funcs.getline('$'))) eq('Press ENTER or type command to continue',
eval("getline('$')->trim(' ', 2)"))
end) end)
meths.chan_send(chan, '\r') meths.chan_send(chan, '\r')
retry(nil, nil, function() retry(nil, nil, function()
eq({'', '[Process exited 1]', ''}, { eq({'', '[Process exited 1]', ''},
trim(funcs.getline(1)), trim(funcs.getline(2)), trim(funcs.getline('$')), eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})"))
})
end) end)
end) end)
end) end)

View File

@ -5,7 +5,6 @@ local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf
local feed, testprg = helpers.feed, helpers.testprg local feed, testprg = helpers.feed, helpers.testprg
local eval = helpers.eval local eval = helpers.eval
local command = helpers.command local command = helpers.command
local matches = helpers.matches
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local retry = helpers.retry local retry = helpers.retry
local meths = helpers.meths local meths = helpers.meths
@ -457,8 +456,8 @@ describe("'scrollback' option", function()
expect_lines(58) expect_lines(58)
-- Verify off-screen state -- Verify off-screen state
matches((is_os('win') and '^36: line[ ]*$' or '^35: line[ ]*$'), eval("getline(line('w0') - 1)")) eq((is_os('win') and '36: line' or '35: line'), eval("getline(line('w0') - 1)->trim(' ', 2)"))
matches((is_os('win') and '^27: line[ ]*$' or '^26: line[ ]*$'), eval("getline(line('w0') - 10)")) eq((is_os('win') and '27: line' or '26: line'), eval("getline(line('w0') - 10)->trim(' ', 2)"))
end) end)
it('deletes extra lines immediately', function() it('deletes extra lines immediately', function()