Skip to content

Commit

Permalink
Update vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
notomo committed Jun 10, 2023
1 parent a1bf89b commit f1f8071
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
15 changes: 13 additions & 2 deletions lua/waitevent/vendor/assertlib/asserter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@ function M.new(name, attributes)
attributes = { attributes, "table" },
})
attributes.get_actual = attributes.get_actual or function() end
attributes.get_actual_args = attributes.get_actual_args
or function(args)
return { unpack(args, 1, #args - 1) }
end
attributes.get_expected = attributes.get_expected or function(...)
return ...
end
attributes.get_expected_args = attributes.get_expected_args or function(args)
return { args[#args] }
end
return {
name = name,
get_result = function(args)
local expected = attributes.get_expected(args[#args])
local actual = attributes.get_actual(unpack(args, 1, #args - 1))
local expected_args = attributes.get_expected_args(args)
local expected = attributes.get_expected(unpack(expected_args))
local actual_args = attributes.get_actual_args(args)
local actual = attributes.get_actual(unpack(actual_args))
return {
name = name,
expected = expected,
expected_args = expected_args,
actual = actual,
actual_args = actual_args,
}
end,
is_ok = attributes.is_ok or function(result)
Expand Down
14 changes: 11 additions & 3 deletions lua/waitevent/vendor/assertlib/function/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ function M.buffer_number()
end

M.exists_pattern = {
get_expected_args = function(args)
return args
end,
get_expected = function(pattern)
return pattern:gsub("\n", "\\n")
end,
is_ok = function(result)
return vim.fn.search(result.expected, "n") ~= 0
local bufnr = result.expected_args[2] or 0
return vim.api.nvim_buf_call(bufnr, function()
return vim.fn.search(result.expected, "n") ~= 0
end)
end,
positive_message = function(result)
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
local bufnr = result.expected_args[2] or 0
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
local content = table.concat(lines, "\n")
return ([[`%s` not found
Actual lines:
%s]]):format(result.expected, content)
end,
negative_message = function(result)
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
local bufnr = result.expected_args[2] or 0
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
local content = table.concat(lines, "\n")
return ([[`%s` found
Actual lines:
Expand Down
13 changes: 7 additions & 6 deletions lua/waitevent/vendor/misclib/test/data_dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ M.__index = M
function M.setup(root_path, opts)
opts = opts or {}
local base_dir = opts.base_dir or "test_data/"
local base_path = root_path .. "/" .. base_dir
local base_path = vim.fs.joinpath(root_path, base_dir)
local relative_path = base_dir .. math.random(1, 2 ^ 30) .. "/"
local full_path = root_path .. "/" .. relative_path
local full_path = vim.fs.joinpath(root_path, relative_path)
local tbl = {
relative_path = relative_path,
full_path = full_path,
Expand All @@ -22,7 +22,7 @@ end
function M.create_file(self, path, content)
self:create_dir(vim.fs.dirname(path))

local file_path = self.full_path .. path
local file_path = vim.fs.joinpath(self.full_path, path)
local f = io.open(file_path, "w")
if not f then
error("cannot open: " .. file_path)
Expand All @@ -36,13 +36,14 @@ function M.create_file(self, path, content)
end

function M.create_dir(self, path)
local dir_path = self.full_path .. path
local dir_path = vim.fs.joinpath(self.full_path, path)
vim.fn.mkdir(dir_path, "p")
return dir_path
end

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

local delete = function(target_path)
Expand All @@ -53,7 +54,7 @@ local delete = function(target_path)
end

function M.delete(self, path)
local target_path = self.full_path .. path
local target_path = vim.fs.joinpath(self.full_path, path)
delete(target_path)
end

Expand Down

0 comments on commit f1f8071

Please sign in to comment.