aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/window_split_tab_spec.lua
blob: c102b1f1335b4f1ca963a66afca181dccd3ed0a4 (plain) (blame)
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
local helpers = require('test.functional.helpers')
local thelpers = require('test.functional.terminal.helpers')
local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf
local feed, nvim = helpers.feed, helpers.nvim
local feed_data = thelpers.feed_data

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
    nvim('set_option', 'statusline', '==========')
    nvim('command', 'highlight StatusLine cterm=NONE')
    nvim('command', 'highlight StatusLineNC cterm=NONE')
    nvim('command', 'highlight VertSplit cterm=NONE')
    screen = thelpers.screen_setup(3)
  end)

  after_each(function()
    screen:detach()
  end)

  describe('when the screen is resized', function()
    it('will forward a resize request to the program', function()
      screen:try_resize(screen._width + 3, screen._height + 5)
      screen:expect([[
        tty ready                                            |
        rows: 14, cols: 53                                   |
        {1: }                                                    |
                                                             |
                                                             |
                                                             |
                                                             |
                                                             |
                                                             |
                                                             |
                                                             |
                                                             |
                                                             |
                                                             |
        -- TERMINAL --                                       |
      ]])
      screen:try_resize(screen._width - 6, screen._height - 10)
      screen:expect([[
        tty ready                                      |
        rows: 14, cols: 53                             |
        rows: 4, cols: 47                              |
        {1: }                                              |
        -- TERMINAL --                                 |
      ]])
    end)
  end)

  describe('split horizontally', function()
    before_each(function()
      nvim('command', 'sp')
    end)

    local function reduce_height()
      screen:expect([[
        tty ready                                         |
        rows: 3, cols: 50                                 |
        {1: }                                                 |
        ~                                                 |
        ==========                                        |
        tty ready                                         |
        rows: 3, cols: 50                                 |
        {2: }                                                 |
        ==========                                        |
        -- TERMINAL --                                    |
      ]])
    end

    it('uses the minimum height of all window displaying it', reduce_height)

    describe('and then vertically', function()
      before_each(function()
        reduce_height()
        nvim('command', 'vsp')
      end)

      local function reduce_width()
        screen:expect([[
          rows: 3, cols: 50        |rows: 3, cols: 50       |
          rows: 3, cols: 24        |rows: 3, cols: 24       |
          {1: }                        |{2: }                       |
          ~                        |~                       |
          ==========                ==========              |
          rows: 3, cols: 50                                 |
          rows: 3, cols: 24                                 |
          {2: }                                                 |
          ==========                                        |
          -- TERMINAL --                                    |
        ]])
        feed('<c-\\><c-n>gg')
        screen:expect([[
          ^tty ready                |rows: 3, cols: 50       |
          rows: 3, cols: 50        |rows: 3, cols: 24       |
          rows: 3, cols: 24        |{2: }                       |
          {2: }                        |~                       |
          ==========                ==========              |
          rows: 3, cols: 50                                 |
          rows: 3, cols: 24                                 |
          {2: }                                                 |
          ==========                                        |
                                                            |
        ]])
      end

      it('uses the minimum width of all window displaying it', reduce_width)

      describe('and then closes one of the vertical splits with q:', function()
        before_each(function()
          reduce_width()
          nvim('command', 'q')
          feed('<c-w>ja')
        end)

        it('will restore the width', function()
          screen:expect([[
            rows: 3, cols: 24                                 |
            rows: 3, cols: 50                                 |
            {2: }                                                 |
            ~                                                 |
            ==========                                        |
            rows: 3, cols: 24                                 |
            rows: 3, cols: 50                                 |
            {1: }                                                 |
            ==========                                        |
            -- TERMINAL --                                    |
          ]])
        end)
      end)
    end)
  end)
end)