robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
7.5 KiB257 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear, command, eq = n.clear, n.command, t.eq
7local insert = n.insert
8local api = n.api
9local assert_alive = n.assert_alive
10
11describe('ui/ext_tabline', function()
12  local screen
13  local event_tabs, event_curtab, event_curbuf, event_buffers
14
15  before_each(function()
16    clear()
17    screen = Screen.new(25, 5, { rgb = true, ext_tabline = true })
18    function screen:_handle_tabline_update(curtab, tabs, curbuf, buffers)
19      event_curtab = curtab
20      event_tabs = tabs
21      event_curbuf = curbuf
22      event_buffers = buffers
23    end
24  end)
25
26  it('publishes UI events', function()
27    command('tabedit another-tab')
28
29    local expected_tabs = {
30      { tab = 1, name = '[No Name]' },
31      { tab = 2, name = 'another-tab' },
32    }
33    screen:expect {
34      grid = [[
35      ^                         |
36      {1:~                        }|*3
37                               |
38    ]],
39      condition = function()
40        eq(2, event_curtab)
41        eq(expected_tabs, event_tabs)
42      end,
43    }
44
45    command('tabNext')
46    screen:expect {
47      grid = [[
48      ^                         |
49      {1:~                        }|*3
50                               |
51    ]],
52      condition = function()
53        eq(1, event_curtab)
54        eq(expected_tabs, event_tabs)
55      end,
56    }
57  end)
58
59  it('buffer UI events', function()
60    local expected_buffers_initial = {
61      { buffer = 1, name = '[No Name]' },
62    }
63
64    screen:expect {
65      grid = [[
66      ^                         |
67      {1:~                        }|*3
68                               |
69    ]],
70      condition = function()
71        eq(1, event_curbuf)
72        eq(expected_buffers_initial, event_buffers)
73      end,
74    }
75
76    command('badd another-buffer')
77    command('bnext')
78
79    local expected_buffers = {
80      { buffer = 1, name = '[No Name]' },
81      { buffer = 2, name = 'another-buffer' },
82    }
83    screen:expect {
84      grid = [[
85      ^                         |
86      {1:~                        }|*3
87                               |
88    ]],
89      condition = function()
90        eq(2, event_curbuf)
91        eq(expected_buffers, event_buffers)
92      end,
93    }
94  end)
95end)
96
97describe('tabline', function()
98  local screen
99
100  before_each(function()
101    clear()
102    screen = Screen.new(42, 5)
103  end)
104
105  it('redraws when tabline option is set', function()
106    command('set tabline=asdf')
107    command('set showtabline=2')
108    screen:expect {
109      grid = [[
110      {2:asdf                                      }|
111      ^                                          |
112      {1:~                                         }|*2
113                                                |
114    ]],
115    }
116    command('set tabline=jkl')
117    screen:expect {
118      grid = [[
119      {2:jkl                                       }|
120      ^                                          |
121      {1:~                                         }|*2
122                                                |
123    ]],
124    }
125  end)
126
127  it('combines highlight attributes', function()
128    screen:set_default_attr_ids({
129      [1] = { foreground = Screen.colors.Blue1, bold = true }, -- StatusLine
130      [2] = { bold = true, italic = true }, -- StatusLine
131      [3] = { bold = true, italic = true, foreground = Screen.colors.Red }, -- NonText combined with StatusLine
132    })
133    command('hi TabLineFill gui=bold,italic')
134    command('hi Identifier guifg=red')
135    command('set tabline=Test%#Identifier#here')
136    command('set showtabline=2')
137    screen:expect {
138      grid = [[
139      {2:Test}{3:here                                  }|
140      ^                                          |
141      {1:~                                         }|*2
142                                                |
143    ]],
144    }
145  end)
146
147  it('click definitions do not leak memory #21765', function()
148    command('set tabline=%@MyClickFunc@MyClickText%T')
149    command('set showtabline=2')
150    command('redrawtabline')
151  end)
152
153  it('clicks work with truncated double-width label #24187', function()
154    insert('tab1')
155    command('tabnew')
156    insert('tab2')
157    command('tabprev')
158    api.nvim_set_option_value('tabline', '%1T口口%2Ta' .. ('b'):rep(38) .. '%999Xc', {})
159    screen:expect {
160      grid = [[
161      {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
162      tab^1                                      |
163      {1:~                                         }|*2
164                                                |
165    ]],
166    }
167    assert_alive()
168    api.nvim_input_mouse('left', 'press', '', 0, 0, 1)
169    screen:expect {
170      grid = [[
171      {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
172      tab^2                                      |
173      {1:~                                         }|*2
174                                                |
175    ]],
176    }
177    api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
178    screen:expect {
179      grid = [[
180      {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
181      tab^1                                      |
182      {1:~                                         }|*2
183                                                |
184    ]],
185    }
186    api.nvim_input_mouse('left', 'press', '', 0, 0, 39)
187    screen:expect {
188      grid = [[
189      {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
190      tab^2                                      |
191      {1:~                                         }|*2
192                                                |
193    ]],
194    }
195    api.nvim_input_mouse('left', 'press', '', 0, 0, 40)
196    screen:expect {
197      grid = [[
198      tab^1                                      |
199      {1:~                                         }|*3
200                                                |
201    ]],
202    }
203  end)
204
205  it('middle-click closes tab', function()
206    command('tabnew')
207    command('tabnew')
208    command('tabnew')
209    command('tabprev')
210    eq({ 3, 4 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
211    api.nvim_input_mouse('middle', 'press', '', 0, 0, 1)
212    eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
213    api.nvim_input_mouse('middle', 'press', '', 0, 0, 20)
214    eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
215    api.nvim_input_mouse('middle', 'press', '', 0, 0, 1)
216    eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
217  end)
218
219  it('does not show floats with focusable=false', function()
220    screen:set_default_attr_ids({
221      [1] = { background = Screen.colors.Plum1 },
222      [2] = { underline = true, background = Screen.colors.LightGrey },
223      [3] = { bold = true },
224      [4] = { reverse = true },
225      [5] = { bold = true, foreground = Screen.colors.Blue1 },
226      [6] = { foreground = Screen.colors.Fuchsia, bold = true },
227      [7] = { foreground = Screen.colors.SeaGreen, bold = true },
228    })
229    command('tabnew')
230    api.nvim_open_win(0, false, {
231      focusable = false,
232      relative = 'editor',
233      height = 1,
234      width = 1,
235      row = 0,
236      col = 0,
237    })
238    screen:expect {
239      grid = [[
240      {1: }{2:[No Name] }{3: [No Name] }{4:                   }{2:X}|
241      ^                                          |
242      {5:~                                         }|*2
243                                                |
244    ]],
245    }
246    command('tabs')
247    screen:expect {
248      grid = [[
249      {6:Tab page 1}                                |
250      #   [No Name]                             |
251      {6:Tab page 2}                                |
252      >   [No Name]                             |
253      {7:Press ENTER or type command to continue}^   |
254    ]],
255    }
256  end)
257end)