robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.0 KiB70 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local clear = n.clear
6local command = n.command
7local eq = t.eq
8local eval = n.eval
9local feed = n.feed
10local api = n.api
11local testprg = n.testprg
12local retry = t.retry
13
14describe(':ls', function()
15  before_each(function()
16    clear()
17  end)
18
19  --- @param start_running_term fun()
20  --- @param start_finished_term fun()
21  local function test_ls_terminal_buffer(start_running_term, start_finished_term)
22    command('edit foo')
23    command('set hidden')
24    start_running_term()
25    command('vsplit')
26    start_finished_term()
27
28    retry(nil, 5000, function()
29      local ls_output = eval('execute("ls")')
30      -- Normal buffer.
31      eq('\n  1  h ', string.match(ls_output, '\n *1....'))
32      -- Terminal buffer [R]unning.
33      eq('\n  2 #aR', string.match(ls_output, '\n *2....'))
34      -- Terminal buffer [F]inished.
35      eq('\n  3 %aF', string.match(ls_output, '\n *3....'))
36    end)
37
38    retry(nil, 5000, function()
39      local ls_output = eval('execute("ls R")')
40      -- Just the [R]unning terminal buffer.
41      eq('\n  2 #aR ', string.match(ls_output, '^\n *2 ... '))
42    end)
43
44    retry(nil, 5000, function()
45      local ls_output = eval('execute("ls F")')
46      -- Just the [F]inished terminal buffer.
47      eq('\n  3 %aF ', string.match(ls_output, '^\n *3 ... '))
48    end)
49  end
50
51  describe('R, F for', function()
52    it('terminal buffers', function()
53      api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
54      test_ls_terminal_buffer(function()
55        command('terminal')
56      end, function()
57        command('terminal')
58        feed('iexit<cr>')
59      end)
60    end)
61
62    it('nvim_open_term() buffers', function()
63      test_ls_terminal_buffer(function()
64        command('enew | call nvim_open_term(0, {})')
65      end, function()
66        command('enew | call chanclose(nvim_open_term(0, {}))')
67      end)
68    end)
69  end)
70end)