aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers/lua/test_helpers.lua
diff options
context:
space:
mode:
authorelky <kylelholzinger@gmail.com>2023-04-05 16:51:51 -0400
committerGitHub <noreply@github.com>2023-04-05 22:51:51 +0200
commit4b9cb43f34f71156a27468d10f5ebf8180ae19af (patch)
treebb002634438c96bd0f3193bfb3b742d0e52768de /tests/helpers/lua/test_helpers.lua
parenttests: fix scheduling (#183) (diff)
downloadmason-lspconfig-4b9cb43f34f71156a27468d10f5ebf8180ae19af.tar
mason-lspconfig-4b9cb43f34f71156a27468d10f5ebf8180ae19af.tar.gz
mason-lspconfig-4b9cb43f34f71156a27468d10f5ebf8180ae19af.tar.bz2
mason-lspconfig-4b9cb43f34f71156a27468d10f5ebf8180ae19af.tar.lz
mason-lspconfig-4b9cb43f34f71156a27468d10f5ebf8180ae19af.tar.xz
mason-lspconfig-4b9cb43f34f71156a27468d10f5ebf8180ae19af.tar.zst
mason-lspconfig-4b9cb43f34f71156a27468d10f5ebf8180ae19af.zip
feat: register package aliases (#182)
Diffstat (limited to 'tests/helpers/lua/test_helpers.lua')
-rw-r--r--tests/helpers/lua/test_helpers.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/helpers/lua/test_helpers.lua b/tests/helpers/lua/test_helpers.lua
index 5e38639..15ccd5e 100644
--- a/tests/helpers/lua/test_helpers.lua
+++ b/tests/helpers/lua/test_helpers.lua
@@ -16,6 +16,25 @@ function async_test(suspend_fn)
end
end
+local TableMock = {}
+TableMock.__index = TableMock
+
+function TableMock.new(tbl, key)
+ return setmetatable({
+ tbl = tbl,
+ key = key,
+ }, TableMock)
+end
+
+function TableMock:apply(value)
+ self.original_value = self.tbl[self.key]
+ self.tbl[self.key] = value
+end
+
+function TableMock:revert()
+ self.tbl[self.key] = self.original_value
+end
+
-- selene: allow(incorrect_standard_library_use)
mockx = {
just_runs = function() end,
@@ -29,6 +48,12 @@ mockx = {
error(exception, 2)
end
end,
+ table = function(tbl, key, new_value)
+ local mock = TableMock.new(tbl, key)
+ mock:apply(new_value)
+ assert:add_spy(mock)
+ return mock
+ end,
}
---@param package_name string