44#include " cucumber/messages/step_match_arguments_list.hpp"
55#include " cucumber/messages/test_case.hpp"
66#include " cucumber_cpp/library/HookRegistry.hpp"
7+ #include " cucumber_cpp/library/StepRegistry.hpp"
78#include " cucumber_cpp/library/assemble/AssembledTestSuite.hpp"
9+ #include " cucumber_cpp/library/cucumber_expression/Argument.hpp"
810#include " cucumber_cpp/library/cucumber_expression/Matcher.hpp"
911#include " cucumber_cpp/library/support/SupportCodeLibrary.hpp"
1012#include " cucumber_cpp/library/support/Types.hpp"
2224
2325namespace cucumber_cpp ::library::assemble
2426{
27+ namespace
28+ {
29+ auto TransformToMatch (const std::string& text)
30+ {
31+ return [&text](const StepRegistry::Definition& definition) -> std::pair<std::string, std::optional<std::vector<cucumber_expression::Argument>>>
32+ {
33+ const auto match = std::visit (cucumber_expression::MatchVisitor{ text }, definition.regex );
34+ return { definition.id , match };
35+ };
36+ }
37+
38+ bool HasMatch (const std::pair<std::string, std::optional<std::vector<cucumber_expression::Argument>>>& pair)
39+ {
40+ return pair.second .has_value ();
41+ }
42+ }
43+
2544 std::vector<AssembledTestSuite> AssembleTestSuites (support::SupportCodeLibrary supportCodeLibrary,
2645 std::string_view testRunStartedId,
2746 util::Broadcaster& broadcaster,
2847 const std::list<support::PickleSource>& sourcedPickles,
2948 cucumber::gherkin::id_generator_ptr idGenerator)
3049 {
31- std::vector <std::string> testUris;
50+ std::list <std::string> testUris;
3251 std::map<std::string, AssembledTestSuite> assembledTestSuiteMap;
3352
3453 for (const auto & pickleSource : sourcedPickles)
@@ -47,30 +66,24 @@ namespace cucumber_cpp::library::assemble
4766
4867 for (const auto & step : pickleSource.pickle ->steps )
4968 {
50- // auto definitions = supportCodeLibrary.stepRegistry.FindDefinitions(step.text);
5169 const auto & stepDefinitions = supportCodeLibrary.stepRegistry .StepDefinitions ();
5270
53- std::vector<std::string> stepDefinitionIds;
54- std::vector<cucumber::messages::step_match_arguments_list> stepMatchArgumentsLists;
55-
56- for (const auto & definition : stepDefinitions)
57- {
58- const auto match = std::visit (cucumber_expression::MatchVisitor{ step.text }, definition.regex );
59- if (match)
60- {
61- stepDefinitionIds.push_back (definition.id );
62- auto & argumentList = stepMatchArgumentsLists.emplace_back ();
63- for (const auto & result : *match)
64- argumentList.step_match_arguments .emplace_back (result.Group (), result.Name ().empty () ? std::nullopt : std::make_optional (result.Name ()));
65- }
66- }
67-
68- testCase.test_steps .emplace_back (
71+ auto & testStep = testCase.test_steps .emplace_back (
6972 std::nullopt ,
7073 idGenerator->next_id (),
7174 step.id ,
72- stepDefinitionIds,
73- stepMatchArgumentsLists);
75+ std::vector<std::string>{},
76+ std::vector<cucumber::messages::step_match_arguments_list>{});
77+
78+ for (const auto & [id, match] : stepDefinitions |
79+ std::views::transform (TransformToMatch (step.text )) |
80+ std::views::filter (HasMatch))
81+ {
82+ testStep.step_definition_ids .value ().push_back (id);
83+ auto & argumentList = testStep.step_match_arguments_lists .value ().emplace_back ();
84+ for (const auto & result : *match)
85+ argumentList.step_match_arguments .emplace_back (result.Group (), result.Name ().empty () ? std::nullopt : std::make_optional (result.Name ()));
86+ }
7487 }
7588
7689 for (const auto & hookId : supportCodeLibrary.hookRegistry .FindIds (HookType::after, pickleSource.pickle ->tags ) | std::views::reverse)
0 commit comments