fix: follow_cwd option (#132)
* fix: TestFollowCwd * fix: follow_cwd not actually working cause: `follow_cwd and nil or session` always use `session` because the `true and nil` expression is evaluated to falsemain
parent
b77d244a77
commit
2b4f192aca
1
Makefile
1
Makefile
|
|
@ -34,6 +34,7 @@ test: $(PLENARY_DIR)
|
||||||
nvim --headless --noplugin -u tests/minimal.vim +Setup
|
nvim --headless --noplugin -u tests/minimal.vim +Setup
|
||||||
# nvim --headless --noplugin -u tests/minimal.vim +TestAutoloading
|
# nvim --headless --noplugin -u tests/minimal.vim +TestAutoloading
|
||||||
nvim --headless --noplugin -u tests/minimal.vim +TestGitBranching
|
nvim --headless --noplugin -u tests/minimal.vim +TestGitBranching
|
||||||
|
nvim --headless --noplugin -u tests/minimal.vim +TestFollowCwd
|
||||||
nvim --headless --noplugin -u tests/minimal.vim +TestDefaults
|
nvim --headless --noplugin -u tests/minimal.vim +TestDefaults
|
||||||
nvim --headless --noplugin -u tests/minimal.vim +TearDown
|
nvim --headless --noplugin -u tests/minimal.vim +TearDown
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ function M.load(opt, dir)
|
||||||
|
|
||||||
if session then
|
if session then
|
||||||
if session_exists then
|
if session_exists then
|
||||||
vim.g.persisting_session = config.options.follow_cwd and nil or session
|
vim.g.persisting_session = not config.options.follow_cwd and session or nil
|
||||||
utils.load_session(session, config.options.silent)
|
utils.load_session(session, config.options.silent)
|
||||||
elseif type(config.options.on_autoload_no_session) == "function" then
|
elseif type(config.options.on_autoload_no_session) == "function" then
|
||||||
config.options.on_autoload_no_session()
|
config.options.on_autoload_no_session()
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,14 @@ describe("Follow cwd change", function()
|
||||||
vim.cmd(":bdelete")
|
vim.cmd(":bdelete")
|
||||||
end)
|
end)
|
||||||
it("ensures both sessions were created", function()
|
it("ensures both sessions were created", function()
|
||||||
|
require("persisted").load()
|
||||||
|
|
||||||
local pattern = "/"
|
local pattern = "/"
|
||||||
local name1 = vim.fn.getcwd():gsub(pattern, "%%") .. require("persisted").get_branch() .. ".vim"
|
local branch1 = require("persisted").get_branch()
|
||||||
|
local name1 = vim.fn.getcwd():gsub(pattern, "%%") .. (branch1 or "") .. ".vim"
|
||||||
vim.cmd(":cd ../..")
|
vim.cmd(":cd ../..")
|
||||||
local name2 = vim.fn.getcwd():gsub(pattern, "%%") .. require("persisted").get_branch() .. ".vim"
|
local branch2 = require("persisted").get_branch()
|
||||||
|
local name2 = vim.fn.getcwd():gsub(pattern, "%%") .. (branch2 or "") .. ".vim"
|
||||||
|
|
||||||
local sessions = vim.fn.readdir(session_dir)
|
local sessions = vim.fn.readdir(session_dir)
|
||||||
assert.equals(sessions[1], name1)
|
assert.equals(sessions[1], name1)
|
||||||
|
|
@ -52,7 +56,8 @@ describe("Don't follow cwd change", function()
|
||||||
it("ensures only one session was created", function()
|
it("ensures only one session was created", function()
|
||||||
local pattern = "/"
|
local pattern = "/"
|
||||||
vim.cmd(":cd ../..")
|
vim.cmd(":cd ../..")
|
||||||
local name = vim.fn.getcwd():gsub(pattern, "%%") .. require("persisted").get_branch() .. ".vim"
|
local branch = require("persisted").get_branch()
|
||||||
|
local name = vim.fn.getcwd():gsub(pattern, "%%") .. (branch or "") .. ".vim"
|
||||||
|
|
||||||
local sessions = vim.fn.readdir(session_dir)
|
local sessions = vim.fn.readdir(session_dir)
|
||||||
assert.equals(#sessions, 1)
|
assert.equals(#sessions, 1)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ runtime! plugin/plenary.vim
|
||||||
command Setup PlenaryBustedDirectory tests/setup {minimal_init = 'tests/minimal.vim'}
|
command Setup PlenaryBustedDirectory tests/setup {minimal_init = 'tests/minimal.vim'}
|
||||||
command TestAutoloading PlenaryBustedDirectory tests/autoload {minimal_init = 'tests/minimal.vim'}
|
command TestAutoloading PlenaryBustedDirectory tests/autoload {minimal_init = 'tests/minimal.vim'}
|
||||||
command TestGitBranching PlenaryBustedDirectory tests/git_branching {minimal_init = 'tests/minimal.vim'}
|
command TestGitBranching PlenaryBustedDirectory tests/git_branching {minimal_init = 'tests/minimal.vim'}
|
||||||
command TestFollowCwd PlenaryBustedDirectory tests/follow_cwd/follow_cwd.lua {minimal_init = 'tests/minimal.vim'}
|
command TestFollowCwd PlenaryBustedDirectory tests/follow_cwd {minimal_init = 'tests/minimal.vim'}
|
||||||
command TestDefaults PlenaryBustedFile tests/default_settings_spec.lua
|
command TestDefaults PlenaryBustedFile tests/default_settings_spec.lua
|
||||||
command TearDown PlenaryBustedFile tests/teardown/clean_up_dirs.lua
|
command TearDown PlenaryBustedFile tests/teardown/clean_up_dirs.lua
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue