robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
6.9 KiB245 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 = n.clear
7local command = n.command
8local curwin = n.api.nvim_get_current_win
9local eq = t.eq
10local exec_lua = n.exec_lua
11local feed = n.feed
12local fn = n.fn
13local api = n.api
14local is_os = t.is_os
15
16describe('title', function()
17  local screen
18
19  before_each(function()
20    clear()
21    screen = Screen.new()
22  end)
23
24  it('shows "No Name", CWD if the buffer is unnamed', function()
25    local expected = (is_os('win') and '[No Name] (C:/) - Nvim' or '[No Name] (/) - Nvim')
26    command(is_os('win') and 'cd C:\\' or 'cd /')
27    command('set title')
28    screen:expect(function()
29      eq(expected, screen.title)
30    end)
31  end)
32
33  it('shows filename + directory if the buffer name is outside CWD', function()
34    local expected = (is_os('win') and 'myfile (C:/mydir) - Nvim' or 'myfile (/mydir) - Nvim')
35    command('set title')
36    command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
37    screen:expect(function()
38      eq(expected, screen.title)
39    end)
40  end)
41
42  it('shows filename + CWD if the buffer is in CWD', function()
43    local expected = (is_os('win') and 'myfile (C:/) - Nvim' or 'myfile (/) - Nvim')
44    command('set title')
45    command(is_os('win') and 'cd C:\\' or 'cd /')
46    command('file myfile')
47    screen:expect(function()
48      eq(expected, screen.title)
49    end)
50  end)
51
52  it('is updated in Insert mode', function()
53    command(is_os('win') and 'cd C:\\' or 'cd /')
54    api.nvim_set_option_value('title', true, {})
55    screen:expect(function()
56      local expected = (is_os('win') and '[No Name] (C:/) - Nvim' or '[No Name] (/) - Nvim')
57      eq(expected, screen.title)
58    end)
59    feed('ifoo')
60    screen:expect(function()
61      local expected = (is_os('win') and '[No Name] + (C:/) - Nvim' or '[No Name] + (/) - Nvim')
62      eq(expected, screen.title)
63    end)
64    feed('<Esc>')
65    api.nvim_set_option_value('titlestring', '%m %f (%{mode(1)}) | nvim', {})
66    screen:expect(function()
67      eq('[+] [No Name] (n) | nvim', screen.title)
68    end)
69    feed('i')
70    screen:expect(function()
71      eq('[+] [No Name] (i) | nvim', screen.title)
72    end)
73    feed('<Esc>')
74    screen:expect(function()
75      eq('[+] [No Name] (n) | nvim', screen.title)
76    end)
77  end)
78
79  it('is updated in Cmdline mode', function()
80    api.nvim_set_option_value('title', true, {})
81    api.nvim_set_option_value('titlestring', '%f (%{mode(1)}) | nvim', {})
82    screen:expect(function()
83      eq('[No Name] (n) | nvim', screen.title)
84    end)
85    feed(':')
86    screen:expect(function()
87      eq('[No Name] (c) | nvim', screen.title)
88    end)
89    feed('<Esc>')
90    screen:expect(function()
91      eq('[No Name] (n) | nvim', screen.title)
92    end)
93  end)
94
95  it('is updated in Terminal mode', function()
96    api.nvim_set_option_value('title', true, {})
97    api.nvim_set_option_value('titlestring', '%t (%{mode(1)}) | nvim', {})
98    fn.jobstart({ n.testprg('shell-test'), 'INTERACT' }, { term = true })
99    api.nvim_buf_set_name(0, 'shell-test')
100    screen:expect(function()
101      eq('shell-test (nt) | nvim', screen.title)
102    end)
103    feed('i')
104    screen:expect(function()
105      eq('shell-test (t) | nvim', screen.title)
106    end)
107    api.nvim_set_option_value('titlelen', 1, {})
108    screen:expect(function()
109      eq('<t) | nvim', screen.title)
110    end)
111    command('set titlelen&')
112    screen:expect(function()
113      eq('shell-test (t) | nvim', screen.title)
114    end)
115    feed([[<C-\><C-N>]])
116    screen:expect(function()
117      eq('shell-test (nt) | nvim', screen.title)
118    end)
119  end)
120
121  describe('is not changed by', function()
122    local file1 = is_os('win') and 'C:\\mydir\\myfile1' or '/mydir/myfile1'
123    local file2 = is_os('win') and 'C:\\mydir\\myfile2' or '/mydir/myfile2'
124    local expected = (is_os('win') and 'myfile1 (C:/mydir) - Nvim' or 'myfile1 (/mydir) - Nvim')
125    local buf2
126
127    before_each(function()
128      command('edit ' .. file1)
129      buf2 = fn.bufadd(file2)
130      command('set title')
131    end)
132
133    it('calling setbufvar() to set an option in a hidden buffer from i_CTRL-R', function()
134      command([[inoremap <F2> <C-R>=setbufvar(]] .. buf2 .. [[, '&autoindent', 1) ?? ''<CR>]])
135      feed('i<F2><Esc>')
136      command('redraw!')
137      screen:expect(function()
138        eq(expected, screen.title)
139      end)
140    end)
141
142    it('an RPC call to nvim_set_option_value in a hidden buffer', function()
143      api.nvim_set_option_value('autoindent', true, { buf = buf2 })
144      command('redraw!')
145      screen:expect(function()
146        eq(expected, screen.title)
147      end)
148    end)
149
150    it('a Lua callback calling nvim_set_option_value in a hidden buffer', function()
151      exec_lua(string.format(
152        [[
153        vim.schedule(function()
154          vim.api.nvim_set_option_value('autoindent', true, { buf = %d })
155        end)
156      ]],
157        buf2
158      ))
159      command('redraw!')
160      screen:expect(function()
161        eq(expected, screen.title)
162      end)
163    end)
164
165    it('a Lua callback calling vim._with in a hidden buffer', function()
166      exec_lua(string.format(
167        [[
168        vim.schedule(function()
169          vim._with({buf = %d}, function() end)
170        end)
171      ]],
172        buf2
173      ))
174      command('redraw!')
175      screen:expect(function()
176        eq(expected, screen.title)
177      end)
178    end)
179
180    it('setting the buffer of another window using RPC', function()
181      local oldwin = curwin()
182      command('split')
183      api.nvim_win_set_buf(oldwin, buf2)
184      command('redraw!')
185      screen:expect(function()
186        eq(expected, screen.title)
187      end)
188    end)
189
190    it('setting the buffer of another window using Lua callback', function()
191      local oldwin = curwin()
192      command('split')
193      exec_lua(string.format(
194        [[
195        vim.schedule(function()
196          vim.api.nvim_win_set_buf(%d, %d)
197        end)
198      ]],
199        oldwin,
200        buf2
201      ))
202      command('redraw!')
203      screen:expect(function()
204        eq(expected, screen.title)
205      end)
206    end)
207
208    it('creating a floating window using RPC', function()
209      api.nvim_open_win(buf2, false, {
210        relative = 'editor',
211        width = 5,
212        height = 5,
213        row = 0,
214        col = 0,
215      })
216      command('redraw!')
217      screen:expect(function()
218        eq(expected, screen.title)
219      end)
220    end)
221
222    it('creating a floating window using Lua callback', function()
223      exec_lua(string.format(
224        [[
225        vim.api.nvim_open_win(%d, false, {
226          relative = 'editor', width = 5, height = 5, row = 0, col = 0,
227        })
228      ]],
229        buf2
230      ))
231      command('redraw!')
232      screen:expect(function()
233        eq(expected, screen.title)
234      end)
235    end)
236
237    it('changing name of non-current buffer', function()
238      api.nvim_buf_set_name(buf2, 'foo')
239      command('redraw!')
240      screen:expect(function()
241        eq(expected, screen.title)
242      end)
243    end)
244  end)
245end)