mkview_spec.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear = helpers.clear
  3. local command = helpers.command
  4. local get_pathsep = helpers.get_pathsep
  5. local eq = helpers.eq
  6. local funcs = helpers.funcs
  7. local rmdir = helpers.rmdir
  8. local mkdir = helpers.mkdir
  9. local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec'
  10. describe(':mkview', function()
  11. local tmp_file_base = file_prefix .. '-tmpfile'
  12. local local_dir = file_prefix .. '.d'
  13. local view_dir = file_prefix .. '.view.d'
  14. before_each(function()
  15. clear()
  16. mkdir(view_dir)
  17. mkdir(local_dir)
  18. end)
  19. after_each(function()
  20. -- Remove any views created in the view directory
  21. rmdir(view_dir)
  22. rmdir(local_dir)
  23. end)
  24. it('viewoption curdir restores local current directory', function()
  25. local cwd_dir = funcs.getcwd()
  26. local set_view_dir_command = 'set viewdir=' .. cwd_dir ..
  27. 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, funcs.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, funcs.getcwd())
  54. end)
  55. end)