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