summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/terminal/window_split_tab_spec.lua
blob: 0c3da5b3a5bde6708323bf7e92a4a69091592d96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
local t = require('test.testutil')
local n = require('test.functional.testnvim')()

local tt = require('test.functional.testterm')
local assert_alive = n.assert_alive
local clear = n.clear
local feed = n.feed
local command = n.command
local eq = t.eq
local eval = n.eval
local api = n.api
local sleep = vim.uv.sleep
local retry = t.retry
local is_os = t.is_os

describe(':terminal', function()
  local screen

  before_each(function()
    clear()
    -- set the statusline to a constant value because of variables like pid
    -- and current directory and to improve visibility of splits
    api.nvim_set_option_value('statusline', '==========', {})
    screen = tt.setup_screen(3)
    command('highlight StatusLine NONE')
    command('highlight StatusLineNC NONE')
    command('highlight StatusLineTerm NONE')
    command('highlight StatusLineTermNC NONE')
    command('highlight VertSplit NONE')
  end)

  it('next to a closing window', function()
    command('split')
    command('terminal')
    command('vsplit foo')
    eq(3, eval("winnr('$')"))
    feed('ZQ') -- Close split, should not crash. #7538
    assert_alive()
  end)

  it('does not change size on WinEnter', function()
    feed('<c-\\><c-n>')
    feed('k')
    command('2split')
    screen:expect([[
      ^tty ready                                         |
      rows: 5, cols: 50                                 |
      ==========                                        |
      tty ready                                         |
      rows: 5, cols: 50                                 |
                                                        |*3
      ==========                                        |
                                                        |
    ]])
    command('wincmd p')
    screen:expect([[
      tty ready                                         |
      rows: 5, cols: 50                                 |
      ==========                                        |
      ^tty ready                                         |
      rows: 5, cols: 50                                 |
                                                        |*3
      ==========                                        |
                                                        |
    ]])
  end)

  it('does not change size if updated when not visible in any window #19665', function()
    local channel = api.nvim_get_option_value('channel', {})
    command('enew')
    sleep(100)
    api.nvim_chan_send(channel, 'foo')
    sleep(100)
    command('bprevious')
    screen:expect([[
      tty ready                                         |
      ^foo                                               |
                                                        |*8
    ]])
  end)

  it('forwards resize request to the program', function()
    feed([[<C-\><C-N>G]])
    local w1, h1 = screen._width - 3, screen._height - 2
    local w2, h2 = w1 - 6, h1 - 3

    if is_os('win') then
      -- win: SIGWINCH is unreliable, use a weaker test. #7506
      retry(3, 30000, function()
        screen:try_resize(w1, h1)
        screen:expect { any = 'rows: 7, cols: 47' }
        screen:try_resize(w2, h2)
        screen:expect { any = 'rows: 4, cols: 41' }
      end)
      return
    end

    screen:try_resize(w1, h1)
    screen:expect([[
      tty ready                                      |
      rows: 7, cols: 47                              |
                                                     |*4
      ^                                               |
                                                     |
    ]])
    screen:try_resize(w2, h2)
    screen:expect([[
      tty ready                                |
      rows: 7, cols: 47                        |
      rows: 4, cols: 41                        |
      ^                                         |
                                               |
    ]])
  end)

  it('stays in terminal mode with <Cmd>wincmd', function()
    command('terminal')
    command('split')
    command('terminal')
    feed('a<Cmd>wincmd j<CR>')
    eq(2, eval('winnr()'))
    eq('t', eval('mode(1)'))
  end)

  it("non-terminal opened in Terminal mode applies 'scrolloff' #34447", function()
    api.nvim_set_option_value('scrolloff', 5, {})
    api.nvim_set_option_value('showtabline', 0, {})
    screen:try_resize(78, 10)
    eq({ mode = 't', blocking = false }, api.nvim_get_mode())
    n.exec_lua([[
      vim.api.nvim_create_autocmd({ 'BufEnter' }, {
        callback = function()
          vim.schedule(function() vim.fn.line('w0') end)
        end,
      })
    ]])
    n.add_builddir_to_rtp()
    n.exec('tab help api-types')
    screen:expect([[
                                                                                    |
      ==============================================================================|
      API Definitions                                         *api-definitions*     |
                                                                                    |
                                                              ^*api-types*           |
      The Nvim C API defines custom types for all function parameters. Some are just|
      typedefs around C99 standard types, others are Nvim-defined data structures.  |
                                                                                    |
      Basic types ~                                                                 |
                                                                                    |
    ]])
  end)
end)