Skip to content

Commit d11d0d0

Browse files
committed
add parameter-types compatibility tests
1 parent 4a9afab commit d11d0d0

29 files changed

+1024
-549
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "cucumber/messages/group.hpp"
2+
#include "cucumber_cpp/CucumberCpp.hpp"
3+
#include "gmock/gmock.h"
4+
#include <string>
5+
6+
struct Flight
7+
{
8+
std::string from;
9+
std::string to;
10+
};
11+
12+
PARAMETER(Flight, "flight", "([A-Z]{3})-([A-Z]{3})", true)
13+
{
14+
return { group.children[0].value.value(), group.children[1].value.value() };
15+
}
16+
17+
STEP(R"({flight} has been delayed)", (const Flight& flight))
18+
{
19+
EXPECT_THAT(flight.from, testing::StrEq("LHR"));
20+
EXPECT_THAT(flight.to, testing::StrEq("CDG"));
21+
}

cucumber_cpp/CucumberCpp.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#include "cucumber_cpp/library/Application.hpp"
55
#include "cucumber_cpp/library/Context.hpp"
66
#include "cucumber_cpp/library/Hooks.hpp"
7+
#include "cucumber_cpp/library/Parameter.hpp"
78
#include "cucumber_cpp/library/Steps.hpp"
89
#include "cucumber_cpp/library/engine/StringTo.hpp"
10+
#include "library/cucumber_expression/MatchRange.hpp"
911

1012
namespace cucumber_cpp
1113
{

cucumber_cpp/library/Application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace cucumber_cpp::library
156156
return programContextRef;
157157
}
158158

159-
cucumber_expression::ParameterRegistration& Application::ParameterRegistration()
159+
cucumber_expression::ParameterRegistry& Application::ParameterRegistration()
160160
{
161161
return parameterRegistry;
162162
}

cucumber_cpp/library/Application.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace cucumber_cpp::library
4545

4646
CLI::App& CliParser();
4747
Context& ProgramContext();
48-
cucumber_expression::ParameterRegistration& ParameterRegistration();
48+
cucumber_expression::ParameterRegistry& ParameterRegistration();
4949

5050
// void AddReportHandler(const std::string& name, std::unique_ptr<report::ReportHandlerV2>&& reporter);
5151

cucumber_cpp/library/Body.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cucumber_cpp/library/Body.hpp"
22
#include "cucumber/messages/exception.hpp"
3+
#include "cucumber/messages/step_match_arguments_list.hpp"
34
#include "cucumber/messages/test_step_result.hpp"
45
#include "cucumber/messages/test_step_result_status.hpp"
56
#include "cucumber_cpp/library/engine/ExecutionContext.hpp"
@@ -48,7 +49,7 @@ namespace cucumber_cpp::library
4849
cucumber::messages::test_step_result& testStepResult;
4950
};
5051

51-
cucumber::messages::test_step_result Body::ExecuteAndCatchExceptions(const ExecuteArgs& args)
52+
cucumber::messages::test_step_result Body::ExecuteAndCatchExceptions(const cucumber::messages::step_match_arguments_list& args)
5253
{
5354
cucumber::messages::test_step_result testStepResult{ .status = cucumber::messages::test_step_result_status::PASSED };
5455
CucumberResultReporter reportListener{ testStepResult };

cucumber_cpp/library/Body.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CUCUMBER_CPP_BODY_HPP
33

44
#include "cucumber/messages/exception.hpp"
5+
#include "cucumber/messages/step_match_arguments_list.hpp"
56
#include "cucumber/messages/test_step_result.hpp"
67
#include "cucumber/messages/test_step_result_status.hpp"
78
#include <any>
@@ -31,10 +32,10 @@ namespace cucumber_cpp::library
3132
{
3233
virtual ~Body() = default;
3334

34-
cucumber::messages::test_step_result ExecuteAndCatchExceptions(const ExecuteArgs& args = {});
35+
cucumber::messages::test_step_result ExecuteAndCatchExceptions(const cucumber::messages::step_match_arguments_list& args = {});
3536

3637
protected:
37-
virtual void Execute(const ExecuteArgs& args) = 0;
38+
virtual void Execute(const cucumber::messages::step_match_arguments_list& args) = 0;
3839
};
3940

4041
template<typename T>

cucumber_cpp/library/BodyMacro.hpp

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CUCUMBER_CPP_BODYMACRO_HPP
33

44
#include "cucumber_cpp/library/Body.hpp"
5+
#include "cucumber_cpp/library/cucumber_expression/ParameterRegistry.hpp"
56
#include "cucumber_cpp/library/engine/StringTo.hpp"
67
#include <cstddef>
78
#include <gtest/gtest.h>
@@ -14,51 +15,42 @@
1415

1516
#define BODY_STRUCT CONCAT(BodyImpl, __LINE__)
1617

17-
#define BODY(matcher, type, targs, registration, base) \
18-
namespace \
19-
{ \
20-
struct BODY_STRUCT : cucumber_cpp::library::Body \
21-
, base \
22-
{ \
23-
/* Workaround namespaces in `base`. For example `base` = Foo::Bar. */ \
24-
/* Then the result would be Foo::Bar::Foo::Bar which is invalid */ \
25-
using myBase = base; \
26-
using myBase::myBase; \
27-
\
28-
void Execute(const std::variant<std::vector<std::string>, std::vector<std::any>>& args) override \
29-
{ \
30-
cucumber_cpp::library::SetUpTearDownWrapper wrapper{ *this }; \
31-
/* ASSERT_NO_THROW(ExecuteWithArgs(args, static_cast<void(*) targs>(nullptr))); */ \
32-
ExecuteWithArgs(args, static_cast<void(*) targs>(nullptr)); \
33-
} \
34-
\
35-
template<class... TArgs> \
36-
void ExecuteWithArgs(const std::variant<std::vector<std::string>, std::vector<std::any>>& args, void (* /* unused */)(TArgs...)) \
37-
{ \
38-
if (std::holds_alternative<std::vector<std::string>>(args)) \
39-
ExecuteWithArgs<TArgs...>(std::get<std::vector<std::string>>(args), std::make_index_sequence<sizeof...(TArgs)>{}); \
40-
else \
41-
ExecuteWithArgs<TArgs...>(std::get<std::vector<std::any>>(args), std::make_index_sequence<sizeof...(TArgs)>{}); \
42-
} \
43-
\
44-
template<class... TArgs, std::size_t... I> \
45-
void ExecuteWithArgs(const std::vector<std::string>& args, std::index_sequence<I...> /*unused*/) \
46-
{ \
47-
ExecuteWithArgs(cucumber_cpp::library::engine::StringTo<std::remove_cvref_t<TArgs>>(args[I])...); \
48-
} \
49-
\
50-
template<class... TArgs, std::size_t... I> \
51-
void ExecuteWithArgs(const std::vector<std::any>& args, std::index_sequence<I...> /*unused*/) \
52-
{ \
53-
ExecuteWithArgs(std::any_cast<std::remove_cvref_t<TArgs>>(args[I])...); \
54-
} \
55-
\
56-
private: \
57-
void ExecuteWithArgs targs; \
58-
static const std::size_t ID; \
59-
}; \
60-
} \
61-
const std::size_t BODY_STRUCT::ID = registration<BODY_STRUCT>(matcher, type); \
18+
#define BODY(matcher, type, targs, registration, base) \
19+
namespace \
20+
{ \
21+
struct BODY_STRUCT : cucumber_cpp::library::Body \
22+
, base \
23+
{ \
24+
/* Workaround namespaces in `base`. For example `base` = Foo::Bar. */ \
25+
/* Then the result would be Foo::Bar::Foo::Bar which is invalid */ \
26+
using myBase = base; \
27+
using myBase::myBase; \
28+
\
29+
void Execute(const cucumber::messages::step_match_arguments_list& args) override \
30+
{ \
31+
cucumber_cpp::library::SetUpTearDownWrapper wrapper{ *this }; \
32+
/* ASSERT_NO_THROW(ExecuteWithArgs(args, static_cast<void(*) targs>(nullptr))); */ \
33+
ExecuteWithArgs(args, static_cast<void(*) targs>(nullptr)); \
34+
} \
35+
\
36+
template<class... TArgs> \
37+
void ExecuteWithArgs(const cucumber::messages::step_match_arguments_list& args, void (* /* unused */)(TArgs...)) \
38+
{ \
39+
ExecuteWithArgs<TArgs...>(args, std::make_index_sequence<sizeof...(TArgs)>{}); \
40+
} \
41+
\
42+
template<class... TArgs, std::size_t... I> \
43+
void ExecuteWithArgs(const cucumber::messages::step_match_arguments_list& args, std::index_sequence<I...> /*unused*/) \
44+
{ \
45+
ExecuteWithArgs(cucumber_cpp::library::cucumber_expression::ConverterTypeMap<std::remove_cvref_t<TArgs>>::Instance().at(args.step_match_arguments[I].parameter_type_name.value())(args.step_match_arguments[I].group)...); \
46+
} \
47+
\
48+
private: \
49+
void ExecuteWithArgs targs; \
50+
static const std::size_t ID; \
51+
}; \
52+
} \
53+
const std::size_t BODY_STRUCT::ID = registration<BODY_STRUCT>(matcher, type); \
6254
void BODY_STRUCT::ExecuteWithArgs targs
6355

6456
#endif

0 commit comments

Comments
 (0)