fix: #146 better handling for empty tables

PR (#152)
main
Mike Iversen 2024-08-30 09:14:00 -05:00 committed by GitHub
parent 53ee4a4df8
commit c9c11ee71f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View File

@ -190,14 +190,11 @@ end
---@param opts? {dir?: string}
---@return boolean
function M.allowed_dir(opts)
if next(config.allowed_dirs) == nil and next(config.ignored_dirs) == nil then
return true
end
opts = opts or {}
local dir = opts.dir or vim.fn.getcwd()
return utils.dirs_match(dir, config.allowed_dirs) and not utils.dirs_match(dir, config.ignored_dirs)
return (next(config.allowed_dirs) and utils.dirs_match(dir, config.allowed_dirs) or true)
and not (next(config.ignored_dirs) and utils.dirs_match(dir, config.ignored_dirs) or false)
end
---Get an ordered list of sessions, sorted by modified time

View File

@ -25,4 +25,18 @@ describe("Directory utilities:", function()
match = utils.dirs_match(cwd, allowed_dirs)
assert.equals(true, match)
end)
it("can handle only ignore directories", function()
local cwd = "~/Code/Neovim/persisted.nvim"
local allowed_dirs = {}
local ignored_dirs = { { "/tmp" } }
local allowed_match = utils.dirs_match(cwd, allowed_dirs)
local ignored_match = utils.dirs_match(cwd, ignored_dirs)
-- This looks weird, I know. That is because we expect dirs_match to return
-- false for allowed_dirs since allowed dirs is empty.
-- Therefore this is actually testing to ensure we are getting false and false
-- This test specifically addresses the change added in
-- https://github.com/olimorris/persisted.nvim/pull/152
assert.equals(true, not allowed_match and not ignored_match)
end)
end)