neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

getcwd_spec.lua (2853B)


      1 -- Tests for getcwd(), haslocaldir(), and :lcd
      2 
      3 local t = require('test.testutil')
      4 local n = require('test.functional.testnvim')()
      5 
      6 local eq, eval, source = t.eq, n.eval, n.source
      7 local call, clear, command = n.call, n.clear, n.command
      8 
      9 describe('getcwd', function()
     10  before_each(clear)
     11 
     12  after_each(function()
     13    n.rmdir('Xtopdir')
     14  end)
     15 
     16  it('is working', function()
     17    source([[
     18      function! GetCwdInfo(win, tab)
     19       let tab_changed = 0
     20       let mod = ":t"
     21       if a:tab > 0 && a:tab != tabpagenr()
     22         let tab_changed = 1
     23         exec "tabnext " . a:tab
     24       endif
     25       let bufname = fnamemodify(bufname(winbufnr(a:win)), mod)
     26       if tab_changed
     27         tabprevious
     28       endif
     29       if a:win == 0 && a:tab == 0
     30         let dirname = fnamemodify(getcwd(), mod)
     31         let lflag = haslocaldir()
     32       elseif a:tab == 0
     33         let dirname = fnamemodify(getcwd(a:win), mod)
     34         let lflag = haslocaldir(a:win)
     35       else
     36         let dirname = fnamemodify(getcwd(a:win, a:tab), mod)
     37         let lflag = haslocaldir(a:win, a:tab)
     38       endif
     39       return bufname . ' ' . dirname . ' ' . lflag
     40      endfunction
     41    ]])
     42    command('new')
     43    command('let cwd=getcwd()')
     44    call('mkdir', 'Xtopdir')
     45    command('silent cd Xtopdir')
     46    call('mkdir', 'Xdir1')
     47    call('mkdir', 'Xdir2')
     48    call('mkdir', 'Xdir3')
     49    command('new a')
     50    command('new b')
     51    command('new c')
     52    command('3wincmd w')
     53    command('silent lcd Xdir1')
     54    eq('a Xdir1 1', eval('GetCwdInfo(0, 0)'))
     55    command('wincmd W')
     56    eq('b Xtopdir 0', eval('GetCwdInfo(0, 0)'))
     57    command('wincmd W')
     58    command('silent lcd Xdir3')
     59    eq('c Xdir3 1', eval('GetCwdInfo(0, 0)'))
     60    eq('a Xdir1 1', eval('GetCwdInfo(bufwinnr("a"), 0)'))
     61    eq('b Xtopdir 0', eval('GetCwdInfo(bufwinnr("b"), 0)'))
     62    eq('c Xdir3 1', eval('GetCwdInfo(bufwinnr("c"), 0)'))
     63    command('wincmd W')
     64    eq('a Xdir1 1', eval('GetCwdInfo(bufwinnr("a"), tabpagenr())'))
     65    eq('b Xtopdir 0', eval('GetCwdInfo(bufwinnr("b"), tabpagenr())'))
     66    eq('c Xdir3 1', eval('GetCwdInfo(bufwinnr("c"), tabpagenr())'))
     67 
     68    command('tabnew x')
     69    command('new y')
     70    command('new z')
     71    command('3wincmd w')
     72    eq('x Xtopdir 0', eval('GetCwdInfo(0, 0)'))
     73    command('wincmd W')
     74    command('silent lcd Xdir2')
     75    eq('y Xdir2 1', eval('GetCwdInfo(0, 0)'))
     76    command('wincmd W')
     77    command('silent lcd Xdir3')
     78    eq('z Xdir3 1', eval('GetCwdInfo(0, 0)'))
     79    eq('x Xtopdir 0', eval('GetCwdInfo(bufwinnr("x"), 0)'))
     80    eq('y Xdir2 1', eval('GetCwdInfo(bufwinnr("y"), 0)'))
     81    eq('z Xdir3 1', eval('GetCwdInfo(bufwinnr("z"), 0)'))
     82    command('let tp_nr = tabpagenr()')
     83    command('tabrewind')
     84    eq('x Xtopdir 0', eval('GetCwdInfo(3, tp_nr)'))
     85    eq('y Xdir2 1', eval('GetCwdInfo(2, tp_nr)'))
     86    eq('z Xdir3 1', eval('GetCwdInfo(1, tp_nr)'))
     87  end)
     88 end)