From 4b9cb43f34f71156a27468d10f5ebf8180ae19af Mon Sep 17 00:00:00 2001 From: elky Date: Wed, 5 Apr 2023 16:51:51 -0400 Subject: feat: register package aliases (#182) --- tests/helpers/lua/test_helpers.lua | 25 +++++++++++++++++++++++++ tests/mason-lspconfig/setup_spec.lua | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'tests') 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 diff --git a/tests/mason-lspconfig/setup_spec.lua b/tests/mason-lspconfig/setup_spec.lua index 9bb5edf..6c8f293 100644 --- a/tests/mason-lspconfig/setup_spec.lua +++ b/tests/mason-lspconfig/setup_spec.lua @@ -225,6 +225,24 @@ describe("mason-lspconfig setup", function() assert.same({ name = "dummylsp", cmd = { "user-cmd" } }, config) end) + + it("should set up package aliases", function() + stub(registry, "register_package_aliases") + + local mapping_mock = mockx.table(require "mason-lspconfig.mappings.server", "package_to_lspconfig", { + ["rust-analyzer"] = "rust_analyzer", + ["typescript-language-server"] = "tsserver", + }) + + mason_lspconfig.setup {} + + assert.spy(registry.register_package_aliases).was_called(1) + assert.spy(registry.register_package_aliases).was_called_with { + ["rust-analyzer"] = { "rust_analyzer" }, + ["typescript-language-server"] = { "tsserver" }, + } + mapping_mock:revert() + end) end) describe("mason-lspconfig setup_handlers", function() -- cgit v1.2.3-70-g09d2