Commit f56bc258 authored by Jamie A. Jennings's avatar Jamie A. Jennings

Fixed more subtle issues in trace.lua. The next significant release will have...

Fixed more subtle issues in trace.lua.  The next significant release will have to address the fact that tracing is unable to leverage much of the lpeg functionality, so it is "simulated".  Doing this faithfully is challenging, much like keeping an interpreter in sync with a compiler -- you do not want to do this if it can be avoided!  And we will avoid it in the next significant release.
parent f1c06eed
Pipeline #120034370 passed with stage
in 1 minute and 11 seconds
This diff is collapsed.
......@@ -27,7 +27,9 @@ function check_trace(exp, input, expectation, expected_nextpos, expected_content
if not rplx then
error("this expression failed to compile: " .. exp, 2)
end
local t = trace.internal(rplx, input)
local ok, t = pcall(trace.internal, rplx, input)
check(ok, "trace failed with an error", 1)
if not ok then return end
lasttrace = t -- GLOBAL
check(( (expectation and t.match) or ((not expectation) and (not t.match)) ),
(expectation and
......@@ -95,7 +97,7 @@ function check_structure(arg1, arg2, arg3)
local max = #subs_representation
for i = 1, max do
local sub_rep = subs_representation[i]
if not tr.subs[i] then
if (not tr.subs) or (not tr.subs[i]) then
check(false, "expected sub #" .. tostring(i) .. " but received no value", 1)
else
local actual = ast.tostring(tr.subs[i].ast)
......@@ -463,4 +465,59 @@ check_trace('foo+', "xyzg", true, 4) -- g prohibited
check_trace('foo+', "xyzh", true, 5) -- h allowed
check_trace('foo+', "xyzcd", true, 4) -- "cd" matched
check_trace('{.* !<[b-d]}', "xyz", true, 4)
check_trace('{.* !<[b-d]}', "xyb", false)
check_trace('[b-d]', "xyz", false)
check_trace('![b-d]', "xyz", true, 1)
check_trace('>[b-d]', "xyz", false)
check_trace('!>[b-d]', "xyz", true, 1)
check_trace('>![b-d]', "xyz", true, 1)
check_trace('[^b-d]', "xyz", true, 2)
check_trace('![^b-d]', "xyz", false)
check_trace('>[^b-d]', "xyz", true, 1)
check_trace('!>[^b-d]', "xyz", false)
check_trace('>![^b-d]', "xyz", false)
check_trace('[b-d]', "cxyz", true, 2)
check_trace('![b-d]', "cxyz", false)
check_trace('>[b-d]', "cxyz", true, 1)
check_trace('!>[b-d]', "cxyz", false)
check_trace('>![b-d]', "cxyz", false)
check_trace('[^b-d]', "cxyz", false)
check_trace('![^b-d]', "cxyz", true, 1)
check_trace('>[^b-d]', "cxyz", false)
check_trace('!>[^b-d]', "cxyz", true, 1)
check_trace('>![^b-d]', "cxyz", true, 1)
check_trace('[b-d]', "", false)
check_trace('![b-d]', "", true, 1)
check_trace('>[b-d]', "", false)
check_trace('!>[b-d]', "", true, 1)
check_trace('>![b-d]', "", true, 1)
check_trace('[^b-d]', "", false)
check_trace('![^b-d]', "", true, 1)
check_trace('>[^b-d]', "", false)
check_trace('!>[^b-d]', "", true, 1)
check_trace('>![^b-d]', "", true, 1)
check_trace('<[b-d]', "", false)
check_trace('!<[b-d]', "", true, 1)
check_trace('<![b-d]', "", true, 1)
local rplx, errs = e:compile('<[^b-d]')
check(not rplx, "expected an error because <X compiles to .&-X, and dot has variable length")
local rplx, errs = e:compile('!<[^b-d]')
check(not rplx, "expected an error because <X compiles to .&-X, and dot has variable length")
local rplx, errs = e:compile('<![^b-d]')
check(rplx, "should compile because <! is equivalent to !")
check_trace('![^b-d]', "", true, 1)
check_trace('![^b-d]', "c", true, 1)
check_trace('![^b-d]', "b", true, 1)
check_trace('![^b-d]', "X", false)
return test.finish()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment