diff --git a/lua/waitevent/vendor/assertlib/asserter.lua b/lua/waitevent/vendor/assertlib/asserter.lua index 4268578..49f1e9d 100644 --- a/lua/waitevent/vendor/assertlib/asserter.lua +++ b/lua/waitevent/vendor/assertlib/asserter.lua @@ -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) diff --git a/lua/waitevent/vendor/assertlib/function/buffer.lua b/lua/waitevent/vendor/assertlib/function/buffer.lua index 7107b9f..6c50359 100644 --- a/lua/waitevent/vendor/assertlib/function/buffer.lua +++ b/lua/waitevent/vendor/assertlib/function/buffer.lua @@ -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: diff --git a/lua/waitevent/vendor/misclib/test/data_dir.lua b/lua/waitevent/vendor/misclib/test/data_dir.lua index be401ad..d298d98 100644 --- a/lua/waitevent/vendor/misclib/test/data_dir.lua +++ b/lua/waitevent/vendor/misclib/test/data_dir.lua @@ -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, @@ -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) @@ -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) @@ -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