diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:18 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:29 +0100 |
commit | 04f2f864e270e772c6326cefdf24947f0130e492 (patch) | |
tree | 46f83f909b888a66c741032ab955afc6eab84292 /test/functional/terminal/channel_spec.lua | |
parent | 59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff) | |
download | rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2 rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip |
refactor: format test/*
Diffstat (limited to 'test/functional/terminal/channel_spec.lua')
-rw-r--r-- | test/functional/terminal/channel_spec.lua | 136 |
1 files changed, 84 insertions, 52 deletions
diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua index cb63c35deb..b2553bf2e0 100644 --- a/test/functional/terminal/channel_spec.lua +++ b/test/functional/terminal/channel_spec.lua @@ -26,9 +26,11 @@ describe('terminal channel is closed and later released if', function() command([[let id = nvim_open_term(0, {})]]) local chans = eval('len(nvim_list_chans())') -- channel hasn't been released yet - eq("Vim(call):Can't send data to closed stream", - pcall_err(command, [[bdelete! | call chansend(id, 'test')]])) - feed('<Ignore>') -- add input to separate two RPC requests + eq( + "Vim(call):Can't send data to closed stream", + pcall_err(command, [[bdelete! | call chansend(id, 'test')]]) + ) + feed('<Ignore>') -- add input to separate two RPC requests -- channel has been released after one main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) @@ -37,15 +39,17 @@ describe('terminal channel is closed and later released if', function() command('let id = nvim_open_term(0, {})') local chans = eval('len(nvim_list_chans())') -- channel has been closed but not released - eq("Vim(call):Can't send data to closed stream", - pcall_err(command, [[call chanclose(id) | call chansend(id, 'test')]])) - screen:expect({any='%[Terminal closed%]'}) + eq( + "Vim(call):Can't send data to closed stream", + pcall_err(command, [[call chanclose(id) | call chansend(id, 'test')]]) + ) + screen:expect({ any = '%[Terminal closed%]' }) eq(chans, eval('len(nvim_list_chans())')) -- delete terminal feed('i<CR>') -- need to first process input poke_eventloop() - feed('<Ignore>') -- add input to separate two RPC requests + feed('<Ignore>') -- add input to separate two RPC requests -- channel has been released after another main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) @@ -54,14 +58,18 @@ describe('terminal channel is closed and later released if', function() command('let id = nvim_open_term(0, {})') local chans = eval('len(nvim_list_chans())') -- channel has been closed but not released - eq("Vim(call):Can't send data to closed stream", - pcall_err(command, [[call chanclose(id) | call chansend(id, 'test')]])) - screen:expect({any='%[Terminal closed%]'}) + eq( + "Vim(call):Can't send data to closed stream", + pcall_err(command, [[call chanclose(id) | call chansend(id, 'test')]]) + ) + screen:expect({ any = '%[Terminal closed%]' }) eq(chans, eval('len(nvim_list_chans())')) -- channel still hasn't been released yet - eq("Vim(call):Can't send data to closed stream", - pcall_err(command, [[bdelete | call chansend(id, 'test')]])) - feed('<Ignore>') -- add input to separate two RPC requests + eq( + "Vim(call):Can't send data to closed stream", + pcall_err(command, [[bdelete | call chansend(id, 'test')]]) + ) + feed('<Ignore>') -- add input to separate two RPC requests -- channel has been released after one main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) @@ -70,16 +78,18 @@ describe('terminal channel is closed and later released if', function() command([[let id = termopen('echo')]]) local chans = eval('len(nvim_list_chans())') -- wait for process to exit - screen:expect({any='%[Process exited 0%]'}) + screen:expect({ any = '%[Process exited 0%]' }) -- process has exited but channel has't been released - eq("Vim(call):Can't send data to closed stream", - pcall_err(command, [[call chansend(id, 'test')]])) + eq( + "Vim(call):Can't send data to closed stream", + pcall_err(command, [[call chansend(id, 'test')]]) + ) eq(chans, eval('len(nvim_list_chans())')) -- delete terminal feed('i<CR>') -- need to first process input poke_eventloop() - feed('<Ignore>') -- add input to separate two RPC requests + feed('<Ignore>') -- add input to separate two RPC requests -- channel has been released after another main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) @@ -89,34 +99,38 @@ describe('terminal channel is closed and later released if', function() command([[let id = termopen('echo')]]) local chans = eval('len(nvim_list_chans())') -- wait for process to exit - screen:expect({any='%[Process exited 0%]'}) + screen:expect({ any = '%[Process exited 0%]' }) -- process has exited but channel hasn't been released - eq("Vim(call):Can't send data to closed stream", - pcall_err(command, [[call chansend(id, 'test')]])) + eq( + "Vim(call):Can't send data to closed stream", + pcall_err(command, [[call chansend(id, 'test')]]) + ) eq(chans, eval('len(nvim_list_chans())')) -- channel still hasn't been released yet - eq("Vim(call):Can't send data to closed stream", - pcall_err(command, [[bdelete | call chansend(id, 'test')]])) - feed('<Ignore>') -- add input to separate two RPC requests + eq( + "Vim(call):Can't send data to closed stream", + pcall_err(command, [[bdelete | call chansend(id, 'test')]]) + ) + feed('<Ignore>') -- add input to separate two RPC requests -- channel has been released after one main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) end) it('chansend sends lines to terminal channel in proper order', function() - clear({args = {'--cmd', 'set laststatus=2'}}) + clear({ args = { '--cmd', 'set laststatus=2' } }) local screen = Screen.new(100, 20) screen:attach() - local shells = is_os('win') and {'cmd.exe', 'pwsh.exe -nop', 'powershell.exe -nop'} or {'sh'} + local shells = is_os('win') and { 'cmd.exe', 'pwsh.exe -nop', 'powershell.exe -nop' } or { 'sh' } for _, sh in ipairs(shells) do command([[let id = termopen(']] .. sh .. [[')]]) command([[call chansend(id, ['echo "hello"', 'echo "world"', ''])]]) - screen:expect{ - any=[[echo "hello".*echo "world"]] + screen:expect { + any = [[echo "hello".*echo "world"]], } command('bdelete!') - screen:expect{ - any='%[No Name%]' + screen:expect { + any = '%[No Name%]', } end end) @@ -130,7 +144,7 @@ describe('no crash when TermOpen autocommand', function() command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') screen = Screen.new(60, 4) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}; + [0] = { bold = true, foreground = Screen.colors.Blue }, }) screen:attach() end) @@ -138,58 +152,72 @@ describe('no crash when TermOpen autocommand', function() it('processes job exit event when using termopen()', function() command([[autocmd TermOpen * call input('')]]) async_meths.command('terminal foobar') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*2 ^ | - ]]} + ]], + } feed('<CR>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ready $ foobar | | [Process exited 0] | | - ]]} + ]], + } feed('i<CR>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {0:~ }|*2 | - ]]} + ]], + } assert_alive() end) it('wipes buffer and processes events when using termopen()', function() command([[autocmd TermOpen * bwipe! | call input('')]]) async_meths.command('terminal foobar') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*2 ^ | - ]]} + ]], + } feed('<CR>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {0:~ }|*2 | - ]]} + ]], + } assert_alive() end) it('wipes buffer and processes events when using nvim_open_term()', function() command([[autocmd TermOpen * bwipe! | call input('')]]) async_meths.open_term(0, {}) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*2 ^ | - ]]} + ]], + } feed('<CR>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {0:~ }|*2 | - ]]} + ]], + } assert_alive() end) end) @@ -206,10 +234,11 @@ describe('nvim_open_term', function() it('with force_crlf=true converts newlines', function() local win = meths.get_current_win() local buf = meths.create_buf(false, true) - local term = meths.open_term(buf, {force_crlf = true}) + local term = meths.open_term(buf, { force_crlf = true }) meths.win_set_buf(win, buf) meths.chan_send(term, 'here\nthere\nfoo\r\nbar\n\ntest') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^here | there | foo | @@ -217,9 +246,11 @@ describe('nvim_open_term', function() | test | |*4 - ]]} + ]], + } meths.chan_send(term, '\nfirst') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^here | there | foo | @@ -228,19 +259,20 @@ describe('nvim_open_term', function() test | first | |*3 - ]]} + ]], + } end) it('with force_crlf=false does not convert newlines', function() local win = meths.get_current_win() local buf = meths.create_buf(false, true) - local term = meths.open_term(buf, {force_crlf = false}) + local term = meths.open_term(buf, { force_crlf = false }) meths.win_set_buf(win, buf) meths.chan_send(term, 'here\nthere') - screen:expect{grid=[[ + screen:expect { grid = [[ ^here | there | |*8 - ]]} + ]] } end) end) |