diff options
| author | William Boman <william@redwill.se> | 2023-02-23 07:38:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-23 07:38:08 +0100 |
| commit | 11e34da70dc531e5d917fd4303db2d81258f6ada (patch) | |
| tree | 5f43adfff3d89093174ff7af7e3681992b482d05 /tests | |
| parent | chore: autogenerate (#1022) (diff) | |
| download | mason-11e34da70dc531e5d917fd4303db2d81258f6ada.tar mason-11e34da70dc531e5d917fd4303db2d81258f6ada.tar.gz mason-11e34da70dc531e5d917fd4303db2d81258f6ada.tar.bz2 mason-11e34da70dc531e5d917fd4303db2d81258f6ada.tar.lz mason-11e34da70dc531e5d917fd4303db2d81258f6ada.tar.xz mason-11e34da70dc531e5d917fd4303db2d81258f6ada.tar.zst mason-11e34da70dc531e5d917fd4303db2d81258f6ada.zip | |
tests: add LuaRegistrySource spec (#1027)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-registry/sources/lua_spec.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/mason-registry/sources/lua_spec.lua b/tests/mason-registry/sources/lua_spec.lua new file mode 100644 index 00000000..27a351d7 --- /dev/null +++ b/tests/mason-registry/sources/lua_spec.lua @@ -0,0 +1,50 @@ +local LuaRegistrySource = require "mason-registry.sources.lua" + +describe("Lua registry source", function() + it("should get package", function() + package.loaded["pkg-index"] = { + ["my-pkg"] = "pkg-index.my-pkg", + } + package.loaded["pkg-index.my-pkg"] = {} + local source = LuaRegistrySource.new { + mod = "pkg-index", + } + assert.is_not_nil(source:get_package "my-pkg") + assert.is_nil(source:get_package "non-existent") + end) + + it("should get all package names", function() + package.loaded["pkg-index"] = { + ["my-pkg"] = "pkg-index.my-pkg", + ["rust-analyzer"] = "pkg-index.rust-analyzer", + ["typescript-language-server"] = "pkg-index.typescript-language-server", + } + local source = LuaRegistrySource.new { + mod = "pkg-index", + } + local package_names = source:get_all_package_names() + table.sort(package_names) + assert.same({ + "my-pkg", + "rust-analyzer", + "typescript-language-server", + }, package_names) + end) + + it("should check if is installed", function() + package.loaded["pkg-index"] = {} + local installed_source = LuaRegistrySource.new { + mod = "pkg-index", + } + local uninstalled_source = LuaRegistrySource.new { + mod = "non-existent", + } + + assert.is_true(installed_source:is_installed()) + assert.is_false(uninstalled_source:is_installed()) + end) + + it("should stringify instances", function() + assert.equals("LuaRegistrySource(mod=pkg-index)", tostring(LuaRegistrySource.new { mod = "pkg-index" })) + end) +end) |
