diff options
author | Aki <please@ignore.pl> | 2024-02-15 01:40:42 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-02-15 01:40:42 +0100 |
commit | add28ed158e7f6992ad94b946e96ca44c36fbe2d (patch) | |
tree | d3a8ae6292011506d25d65c56a91576da31eed68 /srcinfo_spec.lua | |
parent | edf34ef94eb35988833e21bd0a0287405d509434 (diff) | |
download | lua-srcinfo-add28ed158e7f6992ad94b946e96ca44c36fbe2d.zip lua-srcinfo-add28ed158e7f6992ad94b946e96ca44c36fbe2d.tar.gz lua-srcinfo-add28ed158e7f6992ad94b946e96ca44c36fbe2d.tar.bz2 |
Comments may now be preceded by whitespace and not followed by one
Diffstat (limited to 'srcinfo_spec.lua')
-rw-r--r-- | srcinfo_spec.lua | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/srcinfo_spec.lua b/srcinfo_spec.lua new file mode 100644 index 0000000..acc32df --- /dev/null +++ b/srcinfo_spec.lua @@ -0,0 +1,188 @@ +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) + + +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) +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) |