diff options
| author | William Boman <william@redwill.se> | 2022-07-16 16:46:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-16 16:46:23 +0200 |
| commit | f887633842d44307f260d6ea4b99c0ae24994cfb (patch) | |
| tree | a6b40aa4cd451b3000a6aea3d4a678857129c7a7 /tests | |
| parent | docs: updates (#83) (diff) | |
| download | mason-f887633842d44307f260d6ea4b99c0ae24994cfb.tar mason-f887633842d44307f260d6ea4b99c0ae24994cfb.tar.gz mason-f887633842d44307f260d6ea4b99c0ae24994cfb.tar.bz2 mason-f887633842d44307f260d6ea4b99c0ae24994cfb.tar.lz mason-f887633842d44307f260d6ea4b99c0ae24994cfb.tar.xz mason-f887633842d44307f260d6ea4b99c0ae24994cfb.tar.zst mason-f887633842d44307f260d6ea4b99c0ae24994cfb.zip | |
feat(mason-lspconfig): add get_installed_servers() method & add more tests (#84)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-lspconfig/api/command_spec.lua | 71 | ||||
| -rw-r--r-- | tests/mason-lspconfig/setup_spec.lua | 45 | ||||
| -rw-r--r-- | tests/mason/setup_spec.lua | 52 | ||||
| -rw-r--r-- | tests/minimal_init.vim | 2 |
4 files changed, 169 insertions, 1 deletions
diff --git a/tests/mason-lspconfig/api/command_spec.lua b/tests/mason-lspconfig/api/command_spec.lua new file mode 100644 index 00000000..0551c777 --- /dev/null +++ b/tests/mason-lspconfig/api/command_spec.lua @@ -0,0 +1,71 @@ +local spy = require "luassert.spy" +local stub = require "luassert.stub" +local match = require "luassert.match" + +local server_mappings = require "mason-lspconfig.mappings.server" +local filetype_mappings = require "mason-lspconfig.mappings.filetype" +local api = require "mason-lspconfig.api.command" +local registry = require "mason-registry" +local Pkg = require "mason-core.package" + +describe(":LspInstall", function() + server_mappings.lspconfig_to_package["dummylsp"] = "dummy" + server_mappings.package_to_lspconfig["dummy"] = "dummylsp" + filetype_mappings.dummylang = { "dummylsp" } + + it("should install the provided servers", function() + local dummy = registry.get_package "dummy" + spy.on(Pkg, "install") + api.LspInstall { "dummylsp@1.0.0" } + assert.spy(Pkg.install).was_called(1) + assert.spy(Pkg.install).was_called_with(match.ref(dummy), { + version = "1.0.0", + }) + end) + + it( + "should prompt user for server to install based on filetype", + async_test(function() + local dummy = registry.get_package "dummy" + spy.on(Pkg, "install") + stub(vim.ui, "select") + vim.ui.select.invokes(function(items, opts, callback) + callback "dummylsp" + end) + vim.cmd [[new | setf dummylang]] + api.LspInstall {} + assert.spy(Pkg.install).was_called(1) + assert.spy(Pkg.install).was_called_with(match.ref(dummy), { + version = nil, + }) + assert.spy(vim.ui.select).was_called(1) + assert.spy(vim.ui.select).was_called_with({ "dummylsp" }, match.is_table(), match.is_function()) + end) + ) + + it( + "should not prompt user for server to install if no filetype match exists", + async_test(function() + spy.on(Pkg, "install") + stub(vim.ui, "select") + vim.cmd [[new | setf nolsplang]] + api.LspInstall {} + assert.spy(Pkg.install).was_called(0) + assert.spy(vim.ui.select).was_called(0) + end) + ) +end) + +describe(":LspUninstall", function() + server_mappings.lspconfig_to_package["dummylsp"] = "dummy" + server_mappings.package_to_lspconfig["dummy"] = "dummylsp" + filetype_mappings.dummylang = { "dummylsp" } + + it("should uninstall the provided servers", function() + local dummy = registry.get_package "dummy" + spy.on(Pkg, "uninstall") + api.LspUninstall { "dummylsp" } + assert.spy(Pkg.uninstall).was_called(1) + assert.spy(Pkg.uninstall).was_called_with(match.ref(dummy)) + end) +end) diff --git a/tests/mason-lspconfig/setup_spec.lua b/tests/mason-lspconfig/setup_spec.lua new file mode 100644 index 00000000..39795be4 --- /dev/null +++ b/tests/mason-lspconfig/setup_spec.lua @@ -0,0 +1,45 @@ +local match = require "luassert.match" +local spy = require "luassert.spy" + +local Pkg = require "mason-core.package" +local mason_lspconfig = require "mason-lspconfig" +local server_mappings = require "mason-lspconfig.mappings.server" +local registry = require "mason-registry" +local filetype_mappings = require "mason-lspconfig.mappings.filetype" + +describe("mason-lspconfig setup", function() + server_mappings.lspconfig_to_package["dummylsp"] = "dummy" + server_mappings.package_to_lspconfig["dummy"] = "dummylsp" + filetype_mappings.dummylang = { "dummylsp" } + + it("should set up user commands", function() + mason_lspconfig.setup() + local user_commands = vim.api.nvim_get_commands {} + + assert.is_true(match.tbl_containing { + bang = false, + bar = false, + nargs = "*", + complete = "custom", + definition = "Install one or more LSP servers.", + }(user_commands["LspInstall"])) + + assert.is_true(match.tbl_containing { + bang = false, + bar = false, + definition = "Uninstall one or more LSP servers.", + nargs = "+", + complete = "custom", + }(user_commands["LspUninstall"])) + end) + + it("should install servers listed in ensure_installed", function() + local dummy = registry.get_package "dummy" + spy.on(Pkg, "install") + mason_lspconfig.setup { ensure_installed = { "dummylsp@1.0.0" } } + assert.spy(Pkg.install).was_called(1) + assert.spy(Pkg.install).was_called_with(match.ref(dummy), { + version = "1.0.0", + }) + end) +end) diff --git a/tests/mason/setup_spec.lua b/tests/mason/setup_spec.lua new file mode 100644 index 00000000..f7abf125 --- /dev/null +++ b/tests/mason/setup_spec.lua @@ -0,0 +1,52 @@ +local match = require "luassert.match" +local mason = require "mason" +local path = require "mason-core.path" + +describe("mason setup", function() + it("should enhance the PATH environment", function() + mason.setup() + assert.is_true(vim.startswith(vim.env.PATH, path.bin_prefix())) + end) + + it("should set up user commands", function() + mason.setup() + local user_commands = vim.api.nvim_get_commands {} + + assert.is_true(match.tbl_containing { + bang = false, + bar = false, + nargs = "0", + definition = "Opens mason's UI window.", + }(user_commands["Mason"])) + + assert.is_true(match.tbl_containing { + bang = false, + bar = false, + definition = "Install one or more packages.", + nargs = "+", + complete = "custom", + }(user_commands["MasonInstall"])) + + assert.is_true(match.tbl_containing { + bang = false, + bar = false, + definition = "Uninstall one or more packages.", + nargs = "+", + complete = "custom", + }(user_commands["MasonUninstall"])) + + assert.is_true(match.tbl_containing { + bang = false, + bar = false, + definition = "Uninstall all packages.", + nargs = "0", + }(user_commands["MasonUninstallAll"])) + + assert.is_true(match.tbl_containing { + bang = false, + bar = false, + definition = "Opens the mason.nvim log.", + nargs = "0", + }(user_commands["MasonLog"])) + end) +end) diff --git a/tests/minimal_init.vim b/tests/minimal_init.vim index 1a4bfb31..a42b6f89 100644 --- a/tests/minimal_init.vim +++ b/tests/minimal_init.vim @@ -21,7 +21,7 @@ index["dummy"] = "dummy_package" index["dummy2"] = "dummy_package" require("mason").setup { - install_root_dir = os.getenv("INSTALL_ROOT_DIR"), + install_root_dir = vim.env.INSTALL_ROOT_DIR, } EOF |
