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