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

Fixed issue #113

parent 168a0233
Pipeline #140397871 passed with stage
in 58 seconds
1.2.2-dev-5
1.2.2-dev-6
......@@ -29,16 +29,25 @@ tc = {[:upper:] [:lower:]*} -- title case
-- Quoted strings, using single or double quote.
-- Within a string, the quote character can be escaped using a backslash.
local alias backslash = { [\\] [\\] } -- \\
local alias dquote = ["] -- "
local alias escaped_dquote = { [\\] dquote }
local alias escaped_dquote = { [\\] dquote } -- \"
local alias squote = ['] -- '
local alias escaped_squote = { [\\] squote }
local alias escaped_squote = { [\\] squote } -- \'
sq = {squote {escaped_squote / {!squote .}}* squote}
dq = {dquote {escaped_dquote / {!dquote .}}* dquote}
sq = {squote {escaped_squote / backslash / {!squote .}}* squote}
dq = {dquote {escaped_dquote / backslash / {!dquote .}}* dquote}
-- word.q is a quoted word, with either single or double quotes
q = sq / dq
-- test sq accepts "''", "'abc 92'", "'abc \\'def\\' ghi'"
-- test dq accepts "\"\"", "\"abc 92\"", "\"abc \\\"def\\\"\""
-- Escape characters are not a great technique, but it is commonly known. Even so, the tests below
-- are quite hard to understand. We have options for how we might do better, and we need to balance
-- the clarity that would come from having an additional syntax for literals with the complexity of
-- having an additional syntax in RPL.
-- test dq accepts "\"\\\\\"" -- two backslashes inside double quotes, i.e. "\\"
-- test dq rejects "\"\\\"" -- one backslash inside double quotes, i.e. "\"
......@@ -165,6 +165,15 @@ function unittest.extract_tests_from_file(filename)
return test_lines, line_numbers
end
local left_delim = utf8.char(0x300A)
local right_delim = utf8.char(0x300B)
-- This replaces ustring.requote() so that the user can see exactly what is the
-- Rosie interpretation of the string they are unit testing.
local function printable(str)
return left_delim .. str .. right_delim
end
-- Do tests of inclusion/exclusion
function unittest.do_include_test(rplx, testIdentifier, testInfo, input)
assert(testInfo.subs and testInfo.subs[1] and testInfo.subs[1].type=="includesKeyword")
......@@ -179,11 +188,11 @@ function unittest.do_include_test(rplx, testIdentifier, testInfo, input)
end
status, msg = test_includes(rplx, teststr, containedIdentifier)
if status=="error" then
return 0, 0, 1, 0, "BLOCKED: " .. testIdentifier .. " did not accept " .. ustring.requote(teststr)
return 0, 0, 1, 0, "BLOCKED: " .. testIdentifier .. " did not accept " .. printable(teststr)
elseif status==false then
if (not testing_excludes) then
msg = testIdentifier .. " did not include " .. containedIdentifier ..
" with input " .. ustring.requote(teststr)
" with input " .. printable(teststr)
return 0, 1, 0, 0, "FAILED: " .. msg
else
return 0, 0, 0, 1, nil -- pass
......@@ -191,7 +200,7 @@ function unittest.do_include_test(rplx, testIdentifier, testInfo, input)
elseif status==true then
if testing_excludes then
msg = testIdentifier .. " did not exclude " .. containedIdentifier ..
" with input " .. ustring.requote(teststr)
" with input " .. printable(teststr)
return 0, 1, 0, 0, "FAILED: " .. msg
else
return 0, 0, 0, 1, nil -- pass
......@@ -219,7 +228,7 @@ function unittest.do_match_test(rplx, testIdentifier, testInfo, input)
return 0, 0, 0, 1, nil -- pass
else
msg = "FAILED: " .. testIdentifier .. " did not "
.. testInfo.data:sub(1,-2).. " ".. ustring.requote(teststr)
.. testInfo.data:sub(1,-2).. " ".. printable(teststr)
return 0, 1, 0, 0, msg -- fail
end
end -- if teststr is a valid Rosie string
......
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