diff --git a/lua/cmdbuf/test/helper.lua b/lua/cmdbuf/test/helper.lua index 1ff41a1..8124b2a 100644 --- a/lua/cmdbuf/test/helper.lua +++ b/lua/cmdbuf/test/helper.lua @@ -2,6 +2,9 @@ local helper = require("vusted.helper") local plugin_name = helper.get_module_root(...) helper.root = helper.find_plugin_root(plugin_name) +vim.opt.packpath:prepend(vim.fs.joinpath(helper.root, "spec/.shared/packages")) +require("assertlib").register(require("vusted.assert").register) + helper.cleanup() function helper.before_each() end @@ -31,8 +34,4 @@ function helper.search(pattern) return result end -local asserts = require("vusted.assert").asserts -local asserters = require(plugin_name .. ".vendor.assertlib").list() -require(plugin_name .. ".vendor.misclib.test.assert").register(asserts.create, asserters) - return helper diff --git a/lua/cmdbuf/vendor/assertlib/asserter.lua b/lua/cmdbuf/vendor/assertlib/asserter.lua deleted file mode 100644 index 49f1e9d..0000000 --- a/lua/cmdbuf/vendor/assertlib/asserter.lua +++ /dev/null @@ -1,62 +0,0 @@ -local M = {} - -function M.new(name, attributes) - vim.validate({ - name = { name, "string" }, - 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_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) - local expected = vim.inspect(result.expected) - local actual = vim.inspect(result.actual) - return vim.deep_equal(expected, actual) - end, - positive_message = attributes.positive_message or function(result) - return ("%s should be %s, but actual: %s"):format(result.name, result.expected, result.actual) - end, - negative_message = attributes.negative_message or function(result) - return ("%s should not be %s, but actual: %s"):format(result.name, result.expected, result.actual) - end, - } -end - -function M.from(module) - local asserters = {} - for name, fn_or_table in pairs(module) do - local atributes - if type(fn_or_table) == "function" then - atributes = { get_actual = fn_or_table } - else - atributes = fn_or_table - end - table.insert(asserters, M.new(name, atributes)) - end - return asserters -end - -return M diff --git a/lua/cmdbuf/vendor/assertlib/function/buffer.lua b/lua/cmdbuf/vendor/assertlib/function/buffer.lua deleted file mode 100644 index 6c50359..0000000 --- a/lua/cmdbuf/vendor/assertlib/function/buffer.lua +++ /dev/null @@ -1,55 +0,0 @@ -local M = {} - -function M.current_line() - return vim.api.nvim_get_current_line() -end - -function M.filetype() - return vim.bo.filetype -end - -function M.buffer_full_name() - return vim.api.nvim_buf_get_name(0) -end - -function M.buffer_name_tail() - local full_name = vim.api.nvim_buf_get_name(0) - return vim.fn.fnamemodify(full_name, ":t") -end - -function M.buffer_number() - return vim.api.nvim_get_current_buf() -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) - 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 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 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: -%s]]):format(result.expected, content) - end, -} - -return M diff --git a/lua/cmdbuf/vendor/assertlib/function/cursor.lua b/lua/cmdbuf/vendor/assertlib/function/cursor.lua deleted file mode 100644 index cb92aa1..0000000 --- a/lua/cmdbuf/vendor/assertlib/function/cursor.lua +++ /dev/null @@ -1,19 +0,0 @@ -local M = {} - -function M.cursor_row() - return vim.fn.line(".") -end - -function M.cursor_column() - return vim.fn.col(".") -end - -function M.cursor_position() - return vim.api.nvim_win_get_cursor(0) -end - -function M.cursor_word() - return vim.fn.expand("") -end - -return M diff --git a/lua/cmdbuf/vendor/assertlib/function/list.lua b/lua/cmdbuf/vendor/assertlib/function/list.lua deleted file mode 100644 index 9e5fc4b..0000000 --- a/lua/cmdbuf/vendor/assertlib/function/list.lua +++ /dev/null @@ -1,7 +0,0 @@ -local M = {} - -function M.list_length(list) - return #list -end - -return M diff --git a/lua/cmdbuf/vendor/assertlib/function/message.lua b/lua/cmdbuf/vendor/assertlib/function/message.lua deleted file mode 100644 index 9bbfd6c..0000000 --- a/lua/cmdbuf/vendor/assertlib/function/message.lua +++ /dev/null @@ -1,36 +0,0 @@ -local M = {} - -local tail_messages = function(messages) - local limit = 100 - local length = #messages - local tail = table.concat(vim.list_slice(messages, length - limit, length), "\n") - return tail, limit -end - -M.exists_message = { - get_actual = function() - return vim.split(vim.api.nvim_exec2("messages", { output = true }).output, "\n", { plain = true }) - end, - is_ok = function(result) - for _, msg in ipairs(result.actual) do - if msg:match(result.expected) then - return true - end - end - return false - end, - positive_message = function(result) - local actual, limit = tail_messages(result.actual) - return ([[`%s` not found message -Actual messages tail (max: %d): -%s]]):format(result.expected, limit, actual) - end, - negative_message = function(result) - local actual, limit = tail_messages(result.actual) - return ([[`%s` found message -Actual messages tail (max: %d): -%s]]):format(result.expected, limit, actual) - end, -} - -return M diff --git a/lua/cmdbuf/vendor/assertlib/function/mode.lua b/lua/cmdbuf/vendor/assertlib/function/mode.lua deleted file mode 100644 index 662a44a..0000000 --- a/lua/cmdbuf/vendor/assertlib/function/mode.lua +++ /dev/null @@ -1,7 +0,0 @@ -local M = {} - -function M.mode() - return vim.api.nvim_get_mode().mode -end - -return M diff --git a/lua/cmdbuf/vendor/assertlib/function/tab.lua b/lua/cmdbuf/vendor/assertlib/function/tab.lua deleted file mode 100644 index 7865720..0000000 --- a/lua/cmdbuf/vendor/assertlib/function/tab.lua +++ /dev/null @@ -1,11 +0,0 @@ -local M = {} - -function M.tab_count() - return vim.fn.tabpagenr("$") -end - -function M.tab_number() - return vim.fn.tabpagenr() -end - -return M diff --git a/lua/cmdbuf/vendor/assertlib/function/window.lua b/lua/cmdbuf/vendor/assertlib/function/window.lua deleted file mode 100644 index 74a27bc..0000000 --- a/lua/cmdbuf/vendor/assertlib/function/window.lua +++ /dev/null @@ -1,11 +0,0 @@ -local M = {} - -function M.window_count() - return vim.fn.tabpagewinnr(vim.fn.tabpagenr(), "$") -end - -function M.window_id() - return vim.api.nvim_get_current_win() -end - -return M diff --git a/lua/cmdbuf/vendor/assertlib/init.lua b/lua/cmdbuf/vendor/assertlib/init.lua deleted file mode 100644 index 51764dd..0000000 --- a/lua/cmdbuf/vendor/assertlib/init.lua +++ /dev/null @@ -1,34 +0,0 @@ -local M = {} - -local dir_parts = vim.split((...):gsub("/", "."), ".", { plain = true }) -function M.list() - local base_index = vim.fn.index(dir_parts, "assertlib") - local base_parts = vim.list_slice(dir_parts, 1, base_index + 1) - local base_path = table.concat(base_parts, "/") - - local function_pattern = ("lua/%s/function/*.lua"):format(base_path) - local module_paths = vim.api.nvim_get_runtime_file(function_pattern, true) - local module_names = vim.tbl_map(function(path) - path = path:gsub("\\", "/") - local splitted = vim.split(path, "/", { plain = true }) - local file_name = splitted[#splitted] - local name = file_name:sub(1, #file_name - 4) - return name - end, module_paths) - - local all = {} - local base_module_path = table.concat(base_parts, ".") - for _, module_name in ipairs(module_names) do - local module = require(base_module_path .. ".function." .. module_name) - local asserters = require(base_module_path .. ".asserter").from(module) - vim.list_extend(all, asserters) - end - - table.sort(all, function(a, b) - return a.name > b.name - end) - - return all -end - -return M diff --git a/lua/cmdbuf/vendor/misclib/test/assert.lua b/lua/cmdbuf/vendor/misclib/test/assert.lua deleted file mode 100644 index 790661b..0000000 --- a/lua/cmdbuf/vendor/misclib/test/assert.lua +++ /dev/null @@ -1,16 +0,0 @@ -local M = {} - -function M.register(create_assert, asserters) - for _, asserter in ipairs(asserters) do - create_assert(asserter.name):register(function(self) - return function(_, args) - local result = asserter.get_result(args) - self:set_positive(asserter.positive_message(result)) - self:set_negative(asserter.negative_message(result)) - return asserter.is_ok(result) - end - end) - end -end - -return M diff --git a/spec/lua/cmdbuf/vendorlib.lua b/spec/lua/cmdbuf/vendorlib.lua index 758785c..c704308 100644 --- a/spec/lua/cmdbuf/vendorlib.lua +++ b/spec/lua/cmdbuf/vendorlib.lua @@ -1,15 +1,5 @@ return { - "notomo/assertlib.nvim/lua/assertlib/asserter.lua", - "notomo/assertlib.nvim/lua/assertlib/function/buffer.lua", - "notomo/assertlib.nvim/lua/assertlib/function/cursor.lua", - "notomo/assertlib.nvim/lua/assertlib/function/list.lua", - "notomo/assertlib.nvim/lua/assertlib/function/message.lua", - "notomo/assertlib.nvim/lua/assertlib/function/mode.lua", - "notomo/assertlib.nvim/lua/assertlib/function/tab.lua", - "notomo/assertlib.nvim/lua/assertlib/function/window.lua", - "notomo/assertlib.nvim/lua/assertlib/init.lua", "notomo/misclib.nvim/lua/misclib/cursor.lua", "notomo/misclib.nvim/lua/misclib/message.lua", "notomo/misclib.nvim/lua/misclib/module.lua", - "notomo/misclib.nvim/lua/misclib/test/assert.lua", }