aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mason-core')
-rw-r--r--tests/mason-core/installer/installer_spec.lua5
-rw-r--r--tests/mason-core/receipt_spec.lua86
2 files changed, 88 insertions, 3 deletions
diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua
index 04de82ba..3e291308 100644
--- a/tests/mason-core/installer/installer_spec.lua
+++ b/tests/mason-core/installer/installer_spec.lua
@@ -87,12 +87,11 @@ describe("installer", function()
local receipt = vim.json.decode(arg)
assert.is_true(match.tbl_containing {
name = "dummy",
- primary_source = match.same {
+ source = match.same {
type = handle.package.spec.schema,
id = handle.package.spec.source.id,
},
- secondary_sources = match.same {},
- schema_version = "1.1",
+ schema_version = "1.2",
metrics = match.is_table(),
links = match.same {
bin = { executable = "target" },
diff --git a/tests/mason-core/receipt_spec.lua b/tests/mason-core/receipt_spec.lua
new file mode 100644
index 00000000..05ce1439
--- /dev/null
+++ b/tests/mason-core/receipt_spec.lua
@@ -0,0 +1,86 @@
+local InstallReceipt = require("mason-core.receipt").InstallReceipt
+local fs = require "mason-core.fs"
+
+local function fixture(file)
+ return vim.json.decode(fs.sync.read_file(("./tests/fixtures/receipts/%s"):format(file)))
+end
+
+describe("receipt ::", function()
+ it("should parse 1.0 structures", function()
+ local receipt = InstallReceipt.new(fixture "1.0.json")
+
+ assert.equals("angular-language-server", receipt:get_name())
+ assert.equals("1.0", receipt:get_schema_version())
+ assert.same({ type = "npm", package = "@angular/language-server" }, receipt:get_source())
+ assert.same({
+ bin = {
+ ngserver = "node_modules/.bin/ngserver",
+ },
+ }, receipt:get_links())
+ assert.is_true(receipt:is_schema_min "1.0")
+ end)
+
+ it("should parse 1.1 structures", function()
+ local receipt = InstallReceipt.new(fixture "1.1.json")
+
+ assert.equals("angular-language-server", receipt:get_name())
+ assert.equals("1.1", receipt:get_schema_version())
+ assert.same({
+ type = "registry+v1",
+ id = "pkg:npm/%40angular/language-server@16.1.8",
+
+ source = {
+ extra_packages = { "typescript@5.1.3" },
+ version = "16.1.8",
+ package = "@angular/language-server",
+ },
+ }, receipt:get_source())
+ assert.same({
+ bin = {
+ ngserver = "node_modules/.bin/ngserver",
+ },
+ opt = {},
+ share = {},
+ }, receipt:get_links())
+ assert.is_true(receipt:is_schema_min "1.1")
+ end)
+
+ it("should parse 1.2 structures", function()
+ local receipt = InstallReceipt.new(fixture "1.2.json")
+
+ assert.equals("angular-language-server", receipt:get_name())
+ assert.equals("1.2", receipt:get_schema_version())
+ assert.same({
+ type = "registry+v1",
+ id = "pkg:npm/%40angular/language-server@16.1.8",
+ }, receipt:get_source())
+ assert.same({
+ bin = {
+ ngserver = "node_modules/.bin/ngserver",
+ },
+ opt = {},
+ share = {},
+ }, receipt:get_links())
+ assert.is_true(receipt:is_schema_min "1.2")
+ end)
+
+ describe("schema versions ::", function()
+ it("should check minimum compatibility", function()
+ local receipt_1_0 = InstallReceipt.new { schema_version = "1.0" }
+ local receipt_1_1 = InstallReceipt.new { schema_version = "1.1" }
+ local receipt_1_2 = InstallReceipt.new { schema_version = "1.2" }
+
+ assert.is_true(receipt_1_0:is_schema_min "1.0")
+ assert.is_true(receipt_1_1:is_schema_min "1.0")
+ assert.is_true(receipt_1_2:is_schema_min "1.0")
+
+ assert.is_false(receipt_1_0:is_schema_min "1.1")
+ assert.is_true(receipt_1_1:is_schema_min "1.1")
+ assert.is_true(receipt_1_2:is_schema_min "1.1")
+
+ assert.is_false(receipt_1_0:is_schema_min "1.2")
+ assert.is_false(receipt_1_1:is_schema_min "1.2")
+ assert.is_true(receipt_1_2:is_schema_min "1.2")
+ end)
+ end)
+end)