Skip to content

Commit

Permalink
ditto - unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hansonchar committed Jun 18, 2024
1 parent cffef3d commit cef8822
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions doc/generic/pgf/lib/examplesfinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ local I =

local finder = {}

-- local tostring = require "ml".tstring

-- Reorganize the captured result into a nicer form
local function reorg(table, k, v, ...)
if type(k) == "string" then
u.set(table, k, u.strip(v))
Expand All @@ -45,8 +44,7 @@ finder.grammar =
P {
"examples",
examples = SP * "examples" * SP * "=" * SP * "{" * SP * V "content" * SP * "}",
content = Cf(Ct"" * Cg(V("options") ^ -1 * Ct(V("exentry") ^ 1)), reorg),
-- content = Ct(V("options") ^ -1 * V("exentry") ^ 1),
content = Cf(Ct "" * Cg(V("options") ^ -1 * Ct(V("exentry") ^ 1)), reorg),
options = V "optionskv" * P(",") ^ -1,
optionskv = Cg(C("options") * SP * "=" * SP * str),
exentry = SP * "{" * SP * V "excontent" * SP * "}" * P(",") ^ -1,
Expand Down Expand Up @@ -82,7 +80,12 @@ local test_case =
]=]

local matches = finder.grammar:match(test_case)
print(tostring(matches))
-- print(tostring(matches))
assert(matches.options == "top level options")
assert(u.strip(matches[1].options) == "first entry options")
assert(u.strip(matches[1].code) == "first entry code")
assert(not matches[2].options)
assert(u.strip(matches[2].code) == "second entry code")
-- local p = SP * P"examples" * SP * P"=" * SP *
-- P"{" * SP * (P"options" * SP * P"=" * SP * str) ^ -1 * SP * P(",")^-1 * SP * I * P"}"
-- local matches = p:match(test_case)
Expand Down

0 comments on commit cef8822

Please sign in to comment.