test_autochdir.vim 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. " Test 'autochdir' behavior
  2. source check.vim
  3. CheckOption autochdir
  4. func Test_set_filename()
  5. CheckFunction test_autochdir
  6. let cwd = getcwd()
  7. call test_autochdir()
  8. set acd
  9. let s:li = []
  10. autocmd DirChanged auto call add(s:li, "autocd")
  11. autocmd DirChanged auto call add(s:li, expand("<afile>"))
  12. new
  13. w samples/Xtest
  14. call assert_equal("Xtest", expand('%'))
  15. call assert_equal("samples", substitute(getcwd(), '.*/\(\k*\)', '\1', ''))
  16. call assert_equal(["autocd", getcwd()], s:li)
  17. bwipe!
  18. au! DirChanged
  19. set noacd
  20. call chdir(cwd)
  21. call delete('samples/Xtest')
  22. endfunc
  23. func Test_set_filename_other_window()
  24. CheckFunction test_autochdir
  25. let cwd = getcwd()
  26. call test_autochdir()
  27. call mkdir('Xa', 'R')
  28. call mkdir('Xb', 'R')
  29. call mkdir('Xc', 'R')
  30. try
  31. args Xa/aaa.txt Xb/bbb.txt
  32. set acd
  33. let winid = win_getid()
  34. snext
  35. call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
  36. call win_execute(winid, 'file ' .. cwd .. '/Xc/ccc.txt')
  37. call assert_equal('Xb', substitute(getcwd(), '.*/\([^/]*\)$', '\1', ''))
  38. finally
  39. set noacd
  40. call chdir(cwd)
  41. bwipe! aaa.txt
  42. bwipe! bbb.txt
  43. bwipe! ccc.txt
  44. endtry
  45. endfunc
  46. func Test_acd_win_execute()
  47. CheckFunction test_autochdir
  48. let cwd = getcwd()
  49. set acd
  50. call test_autochdir()
  51. call mkdir('XacdDir', 'R')
  52. let winid = win_getid()
  53. new XacdDir/file
  54. call assert_match('testdir.XacdDir$', getcwd())
  55. cd ..
  56. call assert_match('testdir$', getcwd())
  57. call win_execute(winid, 'echo')
  58. call assert_match('testdir$', getcwd())
  59. bwipe!
  60. set noacd
  61. call chdir(cwd)
  62. endfunc
  63. func Test_verbose_pwd()
  64. CheckFunction test_autochdir
  65. let cwd = getcwd()
  66. call test_autochdir()
  67. edit global.txt
  68. call assert_match('\[global\].*testdir$', execute('verbose pwd'))
  69. call mkdir('Xautodir', 'R')
  70. split Xautodir/local.txt
  71. lcd Xautodir
  72. call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
  73. set acd
  74. wincmd w
  75. call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
  76. execute 'tcd' cwd
  77. call assert_match('\[tabpage\].*testdir$', execute('verbose pwd'))
  78. execute 'cd' cwd
  79. call assert_match('\[global\].*testdir$', execute('verbose pwd'))
  80. execute 'lcd' cwd
  81. call assert_match('\[window\].*testdir$', execute('verbose pwd'))
  82. edit
  83. call assert_match('\[autochdir\].*testdir$', execute('verbose pwd'))
  84. enew
  85. wincmd w
  86. call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
  87. wincmd w
  88. call assert_match('\[window\].*testdir$', execute('verbose pwd'))
  89. wincmd w
  90. call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
  91. set noacd
  92. call assert_match('\[autochdir\].*testdir[/\\]Xautodir', execute('verbose pwd'))
  93. wincmd w
  94. call assert_match('\[window\].*testdir$', execute('verbose pwd'))
  95. execute 'cd' cwd
  96. call assert_match('\[global\].*testdir$', execute('verbose pwd'))
  97. wincmd w
  98. call assert_match('\[window\].*testdir[/\\]Xautodir', execute('verbose pwd'))
  99. bwipe!
  100. call chdir(cwd)
  101. endfunc
  102. func Test_multibyte()
  103. " using an invalid character should not cause a crash
  104. set wic
  105. call assert_fails('tc űŤŤŤ¦*', has('win32') ? 'E480:' : 'E344:')
  106. set nowic
  107. endfunc
  108. " vim: shiftwidth=2 sts=2 expandtab