commit 71ea6565b6acee663aa34db56ff4f4a10c2211ef
parent 7bb5d2a1825bc323afa9e44e727c440dc2573333
Author: Richard Ipsum <richardipsum@fastmail.co.uk>
Date: Mon, 20 May 2019 19:52:42 +0100
Handle multiple matching implementations
Diffstat:
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/tyarn.in b/tyarn.in
@@ -199,15 +199,23 @@ function parse_scenarios(filepath)
end
function find_matching_implementation(implementations, step)
- for patt, impl in pairs(implementations) do
+ -- In the event we have more than one matching implementation
+ -- pick the implementation that has the longest pattern.
+
+ local ret_impl = nil
+ local ret_matches = nil
+ local ret_patt = ""
+ for patt, impl in pairs(implementations) do
matched, matches = tyarn.re_match(step, string.format("^%s$", patt))
- if matched then
- return impl, matches
+ if matched and string.len(patt) > string.len(ret_patt) then
+ ret_impl = impl
+ ret_matches = matches
+ ret_patt = patt
end
end
- return nil, nil
+ return ret_impl, ret_matches
end
function load_shell_library(path)