mkview_spec.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear = n.clear
  4. local command = n.command
  5. local get_pathsep = n.get_pathsep
  6. local eq = t.eq
  7. local fn = n.fn
  8. local rmdir = n.rmdir
  9. local mkdir = t.mkdir
  10. local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec'
  11. describe(':mkview', function()
  12. local tmp_file_base = file_prefix .. '-tmpfile'
  13. local local_dir = file_prefix .. '.d'
  14. local view_dir = file_prefix .. '.view.d'
  15. before_each(function()
  16. clear()
  17. mkdir(view_dir)
  18. mkdir(local_dir)
  19. end)
  20. after_each(function()
  21. -- Remove any views created in the view directory
  22. rmdir(view_dir)
  23. rmdir(local_dir)
  24. end)
  25. it('viewoption curdir restores local current directory', function()
  26. local cwd_dir = fn.getcwd()
  27. local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir
  28. -- By default the local current directory should save
  29. command(set_view_dir_command)
  30. command('edit ' .. tmp_file_base .. '1')
  31. command('lcd ' .. local_dir)
  32. command('mkview')
  33. -- Create a new instance of Nvim to remove the 'lcd'
  34. clear()
  35. -- Disable saving the local current directory for the second view
  36. command(set_view_dir_command)
  37. command('set viewoptions-=curdir')
  38. command('edit ' .. tmp_file_base .. '2')
  39. command('lcd ' .. local_dir)
  40. command('mkview')
  41. -- Create a new instance of Nvim to test saved 'lcd' option
  42. clear()
  43. command(set_view_dir_command)
  44. -- Load the view without a saved local current directory
  45. command('edit ' .. tmp_file_base .. '2')
  46. command('loadview')
  47. -- The view's current directory should not have changed
  48. eq(cwd_dir, fn.getcwd())
  49. -- Load the view with a saved local current directory
  50. command('edit ' .. tmp_file_base .. '1')
  51. command('loadview')
  52. -- The view's local directory should have been saved
  53. eq(cwd_dir .. get_pathsep() .. local_dir, fn.getcwd())
  54. end)
  55. end)