diff options
author | Asbjørn Sloth Tønnesen <ast@2e8.dk> | 2019-07-17 17:22:35 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <ast@2e8.dk> | 2019-07-17 17:22:35 +0000 |
commit | 7d02dd60c0d6d106919ad3a021a6f98445daea78 (patch) | |
tree | 7eff0e9ed2ab3cbf154f5c4defc7eb275bb5b77a | |
parent | 5dbfa921c8df2f5fe518886dc25eb1c44d8c99a7 (diff) | |
download | lua-inet-7d02dd60c0d6d106919ad3a021a6f98445daea78.tar.gz lua-inet-7d02dd60c0d6d106919ad3a021a6f98445daea78.tar.xz lua-inet-7d02dd60c0d6d106919ad3a021a6f98445daea78.zip |
tests: readme: strengthen parser
Signed-off-by: Asbjørn Sloth Tønnesen <ast@2e8.dk>
-rw-r--r-- | README.rst | 4 | ||||
-rw-r--r-- | test/readme.lua | 23 |
2 files changed, 18 insertions, 9 deletions
@@ -152,7 +152,7 @@ Addition inet('2001:db8::/64') + 5 -- returns inet('2001:db8::5/64') - inet('::ffff:0.0.0.0/96') + inet('192.0.2.24') -- XXXreturns inet('192.0.2.24') + --inet('::ffff:0.0.0.0/96') + inet('192.0.2.24') -- returns inet('192.0.2.24') ``foo - bar`` ~~~~~~~~~~~~~ @@ -163,7 +163,7 @@ Subtract inet('2001:db8::5/64') - 5 -- returns inet('2001:db8::/64') - inet('2001:db8::5/64') - inet('2001:db8::') -- XXXreturns 5 + --inet('2001:db8::5/64') - inet('2001:db8::') -- returns 5 ``foo / bar`` ~~~~~~~~~~~~~ diff --git a/test/readme.lua b/test/readme.lua index 17f8312..9de3ae2 100644 --- a/test/readme.lua +++ b/test/readme.lua @@ -16,17 +16,23 @@ do local sp = P(' ') local eq = P('=') local nl = P('\n') - local div = P(' -- returns ') local non_nl = P(1)-nl + local rest_of_line = non_nl^0 - local example = Ct(Cc('example') * C(((P(1)-(div+nl))^1)) * div * C(non_nl^1)) - local assign_left = P('local ')^-1 * C(((P(1)-((sp^0 * eq)+nl))^1)) + local div = sp^1 * P('-- returns ') local assign_mid = sp^1 * eq * sp^1 - local assign_right = C(non_nl^1) + + local not_str = (sp^0 * nl) + div + assign_mid + local str = C((P(1)-not_str)^1) + local example = Ct(Cc('example') * str * div * sp^0 * str) + local assign_left = P('local ')^-1 * str + local assign_right = str local assignment = Ct(Cc('assignment') * assign_left * assign_mid * assign_right) - local indented_line = sp^2 * (example + assignment) - local anyline = non_nl^0 - local line = indented_line + anyline + local comment = P('--') * rest_of_line + local indented_line = sp^2 * (comment + example + assignment) * sp^0 + local anyline = rest_of_line - (sp * rest_of_line) + local non_match = Ct(Cc('unable to parse line') * C(rest_of_line)) + local line = indented_line + anyline + non_match readme_parser = Ct((line * nl)^0 * line^-1 * -1) end @@ -109,6 +115,9 @@ local function readme_test() local line = lines[i] local kind = line[1] local handler = handlers[kind] + if not handler then + print('unknown handler', kind, line[2]) + end handler(line) end end |