From 365d15a36deb20452e9deca69de1537032f04732 Mon Sep 17 00:00:00 2001 From: tris203 Date: Sat, 6 Jan 2024 13:34:23 +0000 Subject: [PATCH] better? --- tests/hawtkeys/e2e_spec.lua | 64 +++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/tests/hawtkeys/e2e_spec.lua b/tests/hawtkeys/e2e_spec.lua index 0162d32..2a3b29e 100644 --- a/tests/hawtkeys/e2e_spec.lua +++ b/tests/hawtkeys/e2e_spec.lua @@ -1,6 +1,5 @@ ---@diagnostic disable-next-line: undefined-field local eq = assert.are.same -local truthy = assert.is_true local ts = require("hawtkeys.ts") local function copy_configs_to_stdpath_config() @@ -19,30 +18,55 @@ describe("file searching", function() end) it("can detect a Vim Default Keymap", function() + local notMatch = 0 local keymaps = ts.get_all_keymaps() - print(vim.inspect(keymaps)) - truthy(vim.tbl_contains(keymaps, function(v) - return vim.deep_equal(v, { - from_file = "Vim Defaults", - lhs = "Y", - mode = "n", - rhs = "y$", - }) - end, { predicate = true })) + for _, v in ipairs(keymaps) do + if + vim.deep_equal(v, { + from_file = "Vim Defaults", + lhs = "Y", + mode = "n", + rhs = "y$", + }) + then + eq(v, { + from_file = "Vim Defaults", + lhs = "Y", + mode = "n", + rhs = "y$", + }) + else + notMatch = notMatch + 1 + end + end + eq(vim.tbl_count(keymaps), notMatch + 1) end) it("can detect a keymap from a file", function() + local notMatch = 0 local keymaps = ts.get_all_keymaps() - print(vim.fn.stdpath("config")) - print(vim.inspect(keymaps)) - truthy(vim.tbl_contains(keymaps, function(v) - return vim.deep_equal(v, { - from_file = vim.fn.stdpath("config") .. "/e2e_config.lua", - lhs = "example", - mode = "n", - rhs = "echo 'Example'", - }) - end, { predicate = true })) + + for _, v in ipairs(keymaps) do + if + vim.deep_equal(v, { + from_file = vim.fn.stdpath("config") .. "/e2e_config.lua", + lhs = "example", + mode = "n", + rhs = "echo 'Example'", + }) + then + eq(v, { + from_file = vim.fn.stdpath("config") .. "/e2e_config.lua", + lhs = "example", + mode = "n", + rhs = "echo 'Example'", + }) + else + notMatch = notMatch + 1 + end + end + + eq(vim.tbl_count(keymaps), notMatch + 1) end) it("should find a file in stdpath('config')", function()