commit 2cf0679dded121c834a95a1b67f7d5a94b670ed6
parent 52a1d4fbaa57cc65718de28ab456fdbccfd03f82
Author: Richard Ipsum <richardipsum@vx21.xyz>
Date: Sun, 17 Nov 2019 21:46:31 +0000
Ignore whitespace between keyword and description
Diffstat:
M | tyarn.in | | | 34 | ++++++++++++++++++++++++++++------ |
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/tyarn.in b/tyarn.in
@@ -34,6 +34,11 @@ function lstrip(s)
return string.gsub(s, '%s+', '', 1)
end
+function normalise_scenario_line(str, step_type)
+ normalised, _ = string.gsub(str, '^' .. step_type .. '%s+', step_type .. ' ', 1)
+ return normalised
+end
+
function parse_implementations(filepath)
implementations = {}
@@ -49,8 +54,25 @@ function parse_implementations(filepath)
line = lstrip(line)
if matched then
- if string.find(line, "IMPLEMENTS") then
+ if string.find(line, "IMPLEMENTS GIVEN") then
+ key = string.gsub(line, "IMPLEMENTS%s+", "")
+ key = normalise_scenario_line(key, "GIVEN")
+ implementations[key] = {}
+ elseif string.find(line, "IMPLEMENTS WHEN") then
+ key = string.gsub(line, "IMPLEMENTS%s+", "")
+ key = normalise_scenario_line(key, "WHEN")
+ implementations[key] = {}
+ elseif string.find(line, "IMPLEMENTS THEN") then
+ key = string.gsub(line, "IMPLEMENTS%s+", "")
+ key = normalise_scenario_line(key, "THEN")
+ implementations[key] = {}
+ elseif string.find(line, "IMPLEMENTS ASSUMING") then
+ key = string.gsub(line, "IMPLEMENTS%s+", "")
+ key = normalise_scenario_line(key, "ASSUMING")
+ implementations[key] = {}
+ elseif string.find(line, "IMPLEMENTS FINALLY") then
key = string.gsub(line, "IMPLEMENTS%s+", "")
+ key = normalise_scenario_line(key, "FINALLY")
implementations[key] = {}
elseif key ~= nil then
-- in the middle of a step's implementation
@@ -82,19 +104,19 @@ function parse_scenario_line(scenario, scenario_name, steps_seen,
stripped_line = lstrip(line)
if tyarn.re_match(line, "^( )[ \t]*GIVEN") then
- table.insert(scenario, stripped_line)
+ table.insert(scenario, normalise_scenario_line(stripped_line, "GIVEN"))
last_step_type = "GIVEN"
steps_seen["GIVEN"] = true
elseif tyarn.re_match(line, "^( )[ \t]*WHEN") then
- table.insert(scenario, stripped_line)
+ table.insert(scenario, normalise_scenario_line(stripped_line, "WHEN"))
last_step_type = "WHEN"
steps_seen["WHEN"] = true
elseif tyarn.re_match(line, "^( )[ \t]*THEN") then
- table.insert(scenario, stripped_line)
+ table.insert(scenario, normalise_scenario_line(stripped_line, "THEN"))
last_step_type = "THEN"
steps_seen["THEN"] = true
elseif tyarn.re_match(line, "^( )[ \t]*ASSUMING") then
- table.insert(scenario, stripped_line)
+ table.insert(scenario, normalise_scenario_line(stripped_line, "ASSUMING"))
last_step_type = "ASSUMING"
steps_seen["ASSUMING"] = true
elseif tyarn.re_match(line, "^( )[ \t]*AND") then
@@ -115,7 +137,7 @@ function parse_scenario_line(scenario, scenario_name, steps_seen,
elseif tyarn.re_match(line, "^( )[ \t]*FINALLY") then
last_step_type = "FINALLY"
steps_seen["FINALLY"] = true
- table.insert(scenario["FINALLY"], stripped_line)
+ table.insert(scenario["FINALLY"], normalise_scenario_line(stripped_line, "FINALLY"))
end
return last_step_type