From b0ce639a2eb1bc4ce827abee2df6a59a1a7bb87c Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Thu, 21 Dec 2023 12:59:10 -0800 Subject: [PATCH] fix(tests): export default config via metatable --- lua/hawtkeys/init.lua | 9 +++++++++ tests/hawtkeys/init_spec.lua | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lua/hawtkeys/init.lua b/lua/hawtkeys/init.lua index fdfa2f9..8e48fad 100644 --- a/lua/hawtkeys/init.lua +++ b/lua/hawtkeys/init.lua @@ -1,5 +1,6 @@ ---@class Hawtkeys ---@field config HawtKeyConfig +---@field package defaultConfig HawtKeyConfig local M = {} ---@alias HawtKeySupportedKeyboardLayouts "qwerty" | "dvorak" @@ -128,4 +129,12 @@ function M.setup(config) ) end +setmetatable(M, { + __index = function(_, k) + if k == "defaultConfig" then + return vim.deepcopy(defaultConfig) + end + end, +}) + return M diff --git a/tests/hawtkeys/init_spec.lua b/tests/hawtkeys/init_spec.lua index 6856aee..c6cd05b 100644 --- a/tests/hawtkeys/init_spec.lua +++ b/tests/hawtkeys/init_spec.lua @@ -18,6 +18,7 @@ describe("set up function", function() end) it("should set up the default config", function() hawtkeys.setup({}) + ---@diagnostic disable-next-line: invisible eq(hawtkeys.defaultConfig, hawtkeys.config) end) @@ -39,6 +40,7 @@ describe("set up function", function() hawtkeys.config.highlights.HawtkeysMatchGreat.link ) eq( + ---@diagnostic disable-next-line: invisible hawtkeys.defaultConfig.highlights.HawtkeysMatchGood, hawtkeys.config.highlights.HawtkeysMatchGood ) @@ -56,7 +58,10 @@ describe("set up function", function() }, }, }) - eq("dot_index_expression", hawtkeys.config.keyMapSet["custom.map"].method) + eq( + "dot_index_expression", + hawtkeys.config.keyMapSet["custom.map"].method + ) eq(1, hawtkeys.config.keyMapSet["custom.map"].lhsIndex) eq(2, hawtkeys.config.keyMapSet["custom.map"].rhsIndex) eq("n", hawtkeys.config.keyMapSet["custom.map"].modeIndex)