local srcinfo = require "srcinfo" local stx = require "pl.stringx" describe("Parses empty content in", function() it("pkgname mode (default)", function() local pkgs = srcinfo"" assert.are.same({}, pkgs) end) it("pkgbase mode", function() local bases = srcinfo("", {mode="pkgbase"}) assert.are.same({}, bases) end) end) describe("Parses name-only .SRCINFO in", function() describe("pkgname mode (default) with", function() it("one package", function() local pkgs = srcinfo(stx.dedent[[ pkgbase = example pkgname = example ]]) assert.are.same("example", pkgs[1].name) assert.are.same("example", pkgs[1].base.name) assert.is_nil(pkgs[2]) end) it("multiple packages", function() local pkgs = srcinfo(stx.dedent[[ pkgbase = example pkgname = example pkgname = example-b pkgname = example-c ]]) assert.are.same("example", pkgs[1].name) assert.are.same("example-b", pkgs[2].name) assert.are.same("example-c", pkgs[3].name) assert.are.same("example", pkgs[1].base.name) assert.are.equal(pkgs[1].base, pkgs[2].base) assert.are.equal(pkgs[1].base, pkgs[3].base) assert.is_nil(pkgs[4]) end) end) describe("pkgbase mode with", function() it("one package", function() local bases = srcinfo(stx.dedent[[ pkgbase = example pkgname = example ]], {mode="pkgbase"}) assert.are.same("example", bases[1].name) assert.are.same("example", bases[1].packages[1].name) assert.is_nil(bases[2]) assert.is_nil(bases[1].packages[2]) end) it("multiple packages", function() local bases = srcinfo(stx.dedent[[ pkgbase = example pkgname = example pkgname = example-b pkgname = example-c ]], {mode="pkgbase"}) assert.are.same("example", bases[1].name) assert.are.same("example", bases[1].packages[1].name) assert.are.same("example-b", bases[1].packages[2].name) assert.are.same("example-c", bases[1].packages[3].name) assert.is_nil(bases[2]) assert.is_nil(bases[1].packages[4]) end) end) end) 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) describe("Indentation does not matter", function() local conventional = srcinfo(stx.dedent[[ pkgbase = example pkgdesc = Example package pkgver = 1.0.0 pkgrel = 1 arch = any license = BSD-3 pkgname = example pkgname = example-bonus depends = lua ]]) it("for fields", function() assert.are.same(conventional, srcinfo(stx.dedent[[ pkgbase = example pkgdesc = Example package pkgver = 1.0.0 pkgrel = 1 arch = any license = BSD-3 pkgname = example pkgname = example-bonus depends = lua ]])) end) it("between sections", function() assert.are.same(conventional, srcinfo(stx.dedent[[ pkgbase = example pkgdesc = Example package pkgver = 1.0.0 pkgrel = 1 arch = any license = BSD-3 pkgname = example pkgname = example-bonus depends = lua ]])) end) end) describe("Parses multiple .SRCINFO in the same context in", function() it("pkgname mode (default)", function() local pkgs = srcinfo(stx.dedent[[ pkgbase = example pkgname = example pkgbase = sample pkgname = sample ]]) assert.are.same("example", pkgs[1].name) assert.are.same("example", pkgs[1].base.name) assert.are.same("sample", pkgs[2].name) assert.are.same("sample", pkgs[2].base.name) end) it("pkgbase mode", function() local bases = srcinfo(stx.dedent[[ pkgbase = example pkgname = example pkgbase = sample pkgname = sample ]], {mode="pkgbase"}) assert.are.same("example", bases[1].name) assert.are.same("example", bases[1].packages[1].name) assert.are.same("sample", bases[2].name) assert.are.same("sample", bases[2].packages[1].name) end) end) describe("Comments", function() it("are ignored", function() local pkgs = srcinfo(stx.dedent[[ pkgbase = example #arch = any pkgname = example # pkgname = sample ]]) assert.are.same("example", pkgs[1].name) assert.is_nil(pkgs[1].base.arch) assert.is_nil(pkgs[2]) end) it("work only if they are the first thing in the line", function() local pkgs = srcinfo(stx.dedent[[ pkgbase = example pkgdesc = I like #hiking pkgname = example ]]) 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)