getcwd_spec.lua 2.8 KB

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