From a5634616e022f5923614f35729585aac19a5a543 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 15 Feb 2024 23:44:34 +0100 Subject: Packages now reference bases for missing simple fields Extending composite value from base in a package propagates the change to the base because there is no special handling for it yet. --- srcinfo.lua | 9 ++++- srcinfo_spec.lua | 107 +++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 105 insertions(+), 11 deletions(-) diff --git a/srcinfo.lua b/srcinfo.lua index ef40cd9..855502a 100644 --- a/srcinfo.lua +++ b/srcinfo.lua @@ -6,8 +6,15 @@ local modes = { [PKGBASE] = PKGBASE, [PKGNAME] = PKGNAME, } +local package_mt = {} +function package_mt:__index (key) + return self.base[key] +end + + +local function apply (state, method, ...) if state[method] then return state[method](state, ...) @@ -51,7 +58,7 @@ function srcinfo (text, options) self.current = {name=value} if self.mode == PKGNAME then self.current.base = self.base - return self.current + return setmetatable(self.current, package_mt) else table.insert(self.base.packages, self.current) end diff --git a/srcinfo_spec.lua b/srcinfo_spec.lua index acc32df..3f6eee8 100644 --- a/srcinfo_spec.lua +++ b/srcinfo_spec.lua @@ -74,16 +74,18 @@ describe("Parses name-only .SRCINFO in", function() end) -it("Default mode is pkgname", function() - local default = srcinfo(stx.dedent[[ - pkgbase = example - pkgname = example - ]]) - local explicit = srcinfo(stx.dedent[[ - pkgbase = example - pkgname = example - ]], {mode="pkgname"}) - assert.are.same(default, explicit) +describe("Default mode is", function() + it("pkgname", function() + local default = srcinfo(stx.dedent[[ + pkgbase = example + pkgname = example + ]]) + local explicit = srcinfo(stx.dedent[[ + pkgbase = example + pkgname = example + ]], {mode="pkgname"}) + assert.are.same(default, explicit) + end) end) @@ -186,3 +188,88 @@ describe("Comments", function() assert.are.same("I like #hiking", pkgs[1].base.pkgdesc) end) end) + + +describe("Fields are parsed into", function() + it("simple values", function() + local pkgs = srcinfo(stx.dedent[[ + pkgbase = example + pkgdesc = Example package + pkgver = 1.0.0 + pkgrel = 1 + arch = any + + pkgname = example + ]]) + assert.are.same("example", pkgs[1].base.name) + assert.are.same("Example package", pkgs[1].base.pkgdesc) + assert.are.same("1.0.0", pkgs[1].base.pkgver) + assert.are.same("1", pkgs[1].base.pkgrel) + assert.are.same("any", pkgs[1].base.arch) + end) + + it("composite values", function() + local pkgs = srcinfo(stx.dedent[[ + pkgbase = example + depends = library + depends = utility + + pkgname = example + ]]) + assert.are.same({"library", "utility"}, pkgs[1].base.depends) + end) +end) + + +describe("Packages can access base", function() + it("simple value fields", function() + local pkgs = srcinfo(stx.dedent[[ + pkgbase = example + arch = any + pkgname = example + ]]) + assert.are.same("any", pkgs[1].arch) + end) + + it("composite value fields", function() + local pkgs = srcinfo(stx.dedent[[ + pkgbase = example + depends = library + depends = utility + pkgname = example + ]]) + assert.are.same({"library", "utility"}, pkgs[1].depends) + end) +end) + + +describe("Composite fields are", function() + it("extended", function() + local pkgs = srcinfo(stx.dedent[[ + pkgbase = example + depends = library + pkgname = example + depends = utility + pkgname = example-b + depends = special + ]]) + assert.are.same("library", pkgs[1].base.depends) + assert.are.same({"library", "utility"}, pkgs[1].depends) + assert.are.same({"library", "special"}, pkgs[2].depends) + end) + + it("separeted", function() + local pkgs = srcinfo(stx.dedent[[ + pkgbase = example + depends = library + depends = module + pkgname = example + depends = utility + pkgname = example-b + depends = special + ]]) + assert.are.same({"library", "module"}, pkgs[1].base.depends) + assert.are.same({"library", "module", "utility"}, pkgs[1].depends) + assert.are.same({"library", "module", "special"}, pkgs[2].depends) + end) +end) -- cgit v1.1