robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
5.5 KiB153 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local tt = require('test.functional.testterm')
5local describe, it, before_each = t.describe, t.it, t.before_each
6local assert_alive = n.assert_alive
7local clear = n.clear
8local feed = n.feed
9local command = n.command
10local eq = t.eq
11local eval = n.eval
12local api = n.api
13local sleep = vim.uv.sleep
14local retry = t.retry
15local is_os = t.is_os
16
17describe(':terminal', function()
18  local screen
19
20  before_each(function()
21    clear()
22    -- set the statusline to a constant value because of variables like pid
23    -- and current directory and to improve visibility of splits
24    api.nvim_set_option_value('statusline', '==========', {})
25    screen = tt.setup_screen(3)
26    command('highlight StatusLine NONE')
27    command('highlight StatusLineNC NONE')
28    command('highlight StatusLineTerm NONE')
29    command('highlight StatusLineTermNC NONE')
30    command('highlight VertSplit NONE')
31  end)
32
33  it('next to a closing window', function()
34    command('split')
35    command('terminal')
36    command('vsplit foo')
37    eq(3, eval("winnr('$')"))
38    feed('ZQ') -- Close split, should not crash. #7538
39    assert_alive()
40  end)
41
42  it('does not change size on WinEnter', function()
43    feed('<c-\\><c-n>')
44    feed('k')
45    command('2split')
46    screen:expect([[
47      ^tty ready                                         |
48      rows: 5, cols: 50                                 |
49      ==========                                        |
50      tty ready                                         |
51      rows: 5, cols: 50                                 |
52                                                        |*3
53      ==========                                        |
54                                                        |
55    ]])
56    command('wincmd p')
57    screen:expect([[
58      tty ready                                         |
59      rows: 5, cols: 50                                 |
60      ==========                                        |
61      ^tty ready                                         |
62      rows: 5, cols: 50                                 |
63                                                        |*3
64      ==========                                        |
65                                                        |
66    ]])
67  end)
68
69  it('does not change size if updated when not visible in any window #19665', function()
70    local channel = api.nvim_get_option_value('channel', {})
71    command('enew')
72    sleep(100)
73    api.nvim_chan_send(channel, 'foo')
74    sleep(100)
75    command('bprevious')
76    screen:expect([[
77      tty ready                                         |
78      ^foo                                               |
79                                                        |*8
80    ]])
81  end)
82
83  it('forwards resize request to the program', function()
84    feed([[<C-\><C-N>G]])
85    local w1, h1 = screen._width - 3, screen._height - 2
86    local w2, h2 = w1 - 6, h1 - 3
87
88    if is_os('win') then
89      -- win: SIGWINCH is unreliable, use a weaker test. #7506
90      retry(3, 30000, function()
91        screen:try_resize(w1, h1)
92        screen:expect { any = 'rows: 7, cols: 47' }
93        screen:try_resize(w2, h2)
94        screen:expect { any = 'rows: 4, cols: 41' }
95      end)
96      return
97    end
98
99    screen:try_resize(w1, h1)
100    screen:expect([[
101      tty ready                                      |
102      rows: 7, cols: 47                              |
103                                                     |*4
104      ^                                               |
105                                                     |
106    ]])
107    screen:try_resize(w2, h2)
108    screen:expect([[
109      tty ready                                |
110      rows: 7, cols: 47                        |
111      rows: 4, cols: 41                        |
112      ^                                         |
113                                               |
114    ]])
115  end)
116
117  it('stays in terminal mode with <Cmd>wincmd', function()
118    command('terminal')
119    command('split')
120    command('terminal')
121    feed('a<Cmd>wincmd j<CR>')
122    eq(2, eval('winnr()'))
123    eq('t', eval('mode(1)'))
124  end)
125
126  it("non-terminal opened in Terminal mode applies 'scrolloff' #34447", function()
127    api.nvim_set_option_value('scrolloff', 5, {})
128    api.nvim_set_option_value('showtabline', 0, {})
129    screen:try_resize(78, 10)
130    eq({ mode = 't', blocking = false }, api.nvim_get_mode())
131    n.exec_lua([[
132      vim.api.nvim_create_autocmd({ 'BufEnter' }, {
133        callback = function()
134          vim.schedule(function() vim.fn.line('w0') end)
135        end,
136      })
137    ]])
138    n.add_builddir_to_rtp()
139    n.exec('tab help api-types')
140    screen:expect([[
141                                                                                    |
142      ==============================================================================|
143      API Definitions                                         *api-definitions*     |
144                                                                                    |
145                                                              ^*api-types*           |
146      The Nvim C API defines custom types for all function parameters. Some are just|
147      typedefs around C99 standard types, others are Nvim-defined data structures.  |
148                                                                                    |
149      Basic types ~                                                                 |
150                                                                                    |
151    ]])
152  end)
153end)