From 868a808d2a9624df12555af8313995f86102a4c4 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 16 Feb 2024 15:59:40 +0100 Subject: Parser now handles trailing whitespace without newline --- srcinfo.lua | 2 +- srcinfo_spec.lua | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/srcinfo.lua b/srcinfo.lua index 058b9c6..c038641 100644 --- a/srcinfo.lua +++ b/srcinfo.lua @@ -43,7 +43,7 @@ local comment = lpeg.Cc"comment" * whitespace * lpeg.P"#" * lpeg.C(rest) local empty = lpeg.Cc"empty" * whitespace local invalid = lpeg.Cc"invalid" * lpeg.C(rest) local line = lpeg.Carg(1) * (definition + comment + empty + invalid) / apply * newline -local capture = lpeg.Ct(line^0) * -lpeg.P(1) +local capture = lpeg.Ct(line^0) * whitespace * -lpeg.P(1) local diff --git a/srcinfo_spec.lua b/srcinfo_spec.lua index b0b574b..2312905 100644 --- a/srcinfo_spec.lua +++ b/srcinfo_spec.lua @@ -2,15 +2,23 @@ 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) +describe("Empty strings ared parsed successfully in", function() + it("pkgname mode", function() + assert.are.same({}, srcinfo"") + assert.are.same({}, srcinfo"\n") + assert.are.same({}, srcinfo" ") + assert.are.same({}, srcinfo"\n ") + assert.are.same({}, srcinfo" \n") + assert.are.same({}, srcinfo" \n ") end) it("pkgbase mode", function() - local bases = srcinfo("", {mode="pkgbase"}) - assert.are.same({}, bases) + assert.are.same({}, srcinfo("", {mode="pkgbase"})) + assert.are.same({}, srcinfo("\n", {mode="pkgbase"})) + assert.are.same({}, srcinfo(" ", {mode="pkgbase"})) + assert.are.same({}, srcinfo("\n ", {mode="pkgbase"})) + assert.are.same({}, srcinfo(" \n", {mode="pkgbase"})) + assert.are.same({}, srcinfo(" \n ", {mode="pkgbase"})) end) end) -- cgit v1.1