Skip to content

Commit

Permalink
Use test data_dir:path()
Browse files Browse the repository at this point in the history
  • Loading branch information
notomo committed Jun 26, 2023
1 parent f1f8071 commit 2fb5b73
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lua/waitevent/vendor/misclib/test/data_dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ function M.setup(root_path, opts)
opts = opts or {}
local base_dir = opts.base_dir or "test_data/"
local base_path = vim.fs.joinpath(root_path, base_dir)
local relative_path = base_dir .. math.random(1, 2 ^ 30) .. "/"
local relative_path = vim.fs.joinpath(base_dir, math.random(1, 2 ^ 30))
local full_path = vim.fs.joinpath(root_path, relative_path)
local tbl = {
relative_path = relative_path,
full_path = full_path,
_relative_path = relative_path,
_base_path = base_path,
}
local self = setmetatable(tbl, M)
Expand Down Expand Up @@ -41,6 +41,14 @@ function M.create_dir(self, path)
return dir_path
end

function M.path(self, path)
return vim.fs.joinpath(self.full_path, path)
end

function M.relative_path(self, path)
return vim.fs.joinpath(self._relative_path, path)
end

function M.cd(self, path)
local dir_path = vim.fs.joinpath(self.full_path, path)
vim.api.nvim_set_current_dir(dir_path)
Expand Down

0 comments on commit 2fb5b73

Please sign in to comment.