Skip to content

Commit 91d7d85

Browse files
committed
feat: follow the Gherkin standard by not differentiating between step types
1 parent 552df48 commit 91d7d85

File tree

5 files changed

+20
-45
lines changed

5 files changed

+20
-45
lines changed

cucumber_cpp/acceptance_test/features/test_scenarios.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ Feature: Simple feature file
2020
Scenario: A scenario with undefined step
2121
Given a given step
2222
When a when step
23-
Then a when step
23+
Then a missing step
2424
Then a then step

cucumber_cpp/library/StepRegistry.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include "cucumber_cpp/library/cucumber_expression/RegularExpression.hpp"
88
#include "cucumber_cpp/library/engine/StepType.hpp"
99
#include "cucumber_cpp/library/engine/Table.hpp"
10-
#include <algorithm>
1110
#include <cstddef>
1211
#include <memory>
13-
#include <ranges>
1412
#include <span>
1513
#include <string>
1614
#include <utility>
@@ -19,29 +17,18 @@
1917

2018
namespace cucumber_cpp::library
2119
{
22-
namespace
23-
{
24-
auto TypeFilter(engine::StepType stepType)
25-
{
26-
return [stepType](const StepRegistry::Entry& entry)
27-
{
28-
return entry.type == stepType || entry.type == engine::StepType::any;
29-
};
30-
};
31-
}
32-
3320
StepRegistry::StepRegistry(cucumber_expression::ParameterRegistry& parameterRegistry)
3421
: parameterRegistry{ parameterRegistry }
3522
{
3623
for (const auto& matcher : StepStringRegistration::Instance().GetEntries())
3724
Register(matcher.regex, matcher.type, matcher.factory);
3825
}
3926

40-
StepMatch StepRegistry::Query(engine::StepType stepType, const std::string& expression)
27+
StepMatch StepRegistry::Query(const std::string& expression)
4128
{
4229
std::vector<StepMatch> matches;
4330

44-
for (Entry& entry : registry | std::views::filter(TypeFilter(stepType)))
31+
for (Entry& entry : registry)
4532
{
4633
auto match = std::visit(cucumber_expression::MatchVisitor{ expression }, entry.regex);
4734
if (match)
@@ -65,11 +52,6 @@ namespace cucumber_cpp::library
6552
return registry.size();
6653
}
6754

68-
std::size_t StepRegistry::Size(engine::StepType stepType) const
69-
{
70-
return std::ranges::count(registry, stepType, &Entry::type);
71-
}
72-
7355
std::vector<StepRegistry::EntryView> StepRegistry::List() const
7456
{
7557
std::vector<StepRegistry::EntryView> list;

cucumber_cpp/library/StepRegistry.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ namespace cucumber_cpp::library
8484

8585
explicit StepRegistry(cucumber_expression::ParameterRegistry& parameterRegistry);
8686

87-
[[nodiscard]] StepMatch Query(engine::StepType stepType, const std::string& expression);
87+
[[nodiscard]] StepMatch Query(const std::string& expression);
8888

8989
[[nodiscard]] std::size_t Size() const;
90-
[[nodiscard]] std::size_t Size(engine::StepType stepType) const;
9190

9291
[[nodiscard]] std::vector<EntryView> List() const;
9392

cucumber_cpp/library/engine/FeatureFactory.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ namespace cucumber_cpp::library::engine
158158
}
159159
catch (const std::out_of_range&)
160160
{
161-
162161
throw UnsupportedAsteriskError{ std::format("{}:{}: * steps are not supported", scenarioInfo.FeatureInfo().Path().string(), step.location.line) };
163162
}
164163
}
@@ -292,7 +291,7 @@ namespace cucumber_cpp::library::engine
292291
{
293292
try
294293
{
295-
auto stepMatch = stepRegistry.Query(stepType, stepText);
294+
auto stepMatch = stepRegistry.Query(stepText);
296295
return std::make_unique<StepInfo>(scenarioInfo, std::move(stepText), stepType, line, column, std::move(table), std::move(stepMatch));
297296
}
298297
catch (const StepRegistry::StepNotFoundError&)

cucumber_cpp/library/test/TestSteps.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "cucumber_cpp/library/Context.hpp"
22
#include "cucumber_cpp/library/StepRegistry.hpp"
33
#include "cucumber_cpp/library/cucumber_expression/ParameterRegistry.hpp"
4-
#include "cucumber_cpp/library/engine/StepType.hpp"
54
#include "gtest/gtest.h"
65
#include <cstdint>
76
#include <gmock/gmock.h>
@@ -22,43 +21,39 @@ namespace cucumber_cpp::library
2221
TEST_F(TestSteps, RegisterThroughPreregistration)
2322
{
2423
EXPECT_THAT(stepRegistry.Size(), testing::Ge(1));
25-
EXPECT_THAT(stepRegistry.Size(engine::StepType::given), testing::Ge(1));
26-
EXPECT_THAT(stepRegistry.Size(engine::StepType::when), testing::Ge(1));
27-
EXPECT_THAT(stepRegistry.Size(engine::StepType::then), testing::Ge(1));
28-
EXPECT_THAT(stepRegistry.Size(engine::StepType::any), testing::Ge(1));
2924
}
3025

3126
TEST_F(TestSteps, GetGivenStep)
3227
{
33-
const auto matches = stepRegistry.Query(engine::StepType::given, "This is a GIVEN step");
28+
const auto matches = stepRegistry.Query("This is a GIVEN step");
3429

3530
EXPECT_THAT(matches.stepRegexStr, testing::StrEq("^This is a GIVEN step$"));
3631
}
3732

3833
TEST_F(TestSteps, GetWhenStep)
3934
{
40-
const auto matches = stepRegistry.Query(engine::StepType::when, "This is a WHEN step");
35+
const auto matches = stepRegistry.Query("This is a WHEN step");
4136

4237
EXPECT_THAT(matches.stepRegexStr, testing::StrEq("^This is a WHEN step$"));
4338
}
4439

4540
TEST_F(TestSteps, GetThenStep)
4641
{
47-
const auto matches = stepRegistry.Query(engine::StepType::then, "This is a THEN step");
42+
const auto matches = stepRegistry.Query("This is a THEN step");
4843

4944
EXPECT_THAT(matches.stepRegexStr, testing::StrEq("^This is a THEN step$"));
5045
}
5146

5247
TEST_F(TestSteps, GetAnyStep)
5348
{
54-
const auto matches = stepRegistry.Query(engine::StepType::given, "This is a STEP step");
49+
const auto matches = stepRegistry.Query("This is a STEP step");
5550

5651
EXPECT_THAT(matches.stepRegexStr, testing::StrEq("^This is a STEP step$"));
5752
}
5853

5954
TEST_F(TestSteps, GetStepWithMatches)
6055
{
61-
const auto matches = stepRegistry.Query(engine::StepType::when, "This is a step with a 10s delay");
56+
const auto matches = stepRegistry.Query("This is a step with a 10s delay");
6257

6358
EXPECT_THAT(matches.stepRegexStr, testing::StrEq("^This is a step with a ([0-9]+)s delay$"));
6459

@@ -68,20 +63,20 @@ namespace cucumber_cpp::library
6863

6964
TEST_F(TestSteps, GetInvalidStep)
7065
{
71-
EXPECT_THROW((void)stepRegistry.Query(engine::StepType::when, "This step does not exist"), StepRegistry::StepNotFoundError);
66+
EXPECT_THROW((void)stepRegistry.Query("This step does not exist"), StepRegistry::StepNotFoundError);
7267
}
7368

7469
TEST_F(TestSteps, GetAmbiguousStep)
7570
{
76-
EXPECT_NO_THROW((void)stepRegistry.Query(engine::StepType::given, "an ambiguous step"));
77-
EXPECT_NO_THROW((void)stepRegistry.Query(engine::StepType::when, "an ambiguous step"));
71+
EXPECT_NO_THROW((void)stepRegistry.Query("an ambiguous step"));
72+
EXPECT_NO_THROW((void)stepRegistry.Query("an ambiguous step"));
7873

79-
EXPECT_THROW((void)stepRegistry.Query(engine::StepType::then, "an ambiguous step"), StepRegistry::AmbiguousStepError);
74+
EXPECT_THROW((void)stepRegistry.Query("an ambiguous step"), StepRegistry::AmbiguousStepError);
8075
}
8176

8277
TEST_F(TestSteps, InvokeTestWithCucumberExpressions)
8378
{
84-
const auto matches = stepRegistry.Query(engine::StepType::when, R"(Step with cucumber expression syntax 1.5 "abcdef" 10)");
79+
const auto matches = stepRegistry.Query(R"(Step with cucumber expression syntax 1.5 "abcdef" 10)");
8580

8681
auto contextStorage{ std::make_shared<ContextStorageFactoryImpl>() };
8782
Context context{ contextStorage };
@@ -99,16 +94,16 @@ namespace cucumber_cpp::library
9994

10095
TEST_F(TestSteps, EscapedCucumberExpression)
10196
{
102-
const auto matchesParens = stepRegistry.Query(engine::StepType::then, R"(An expression with (parenthesis) should remain as is)");
97+
const auto matchesParens = stepRegistry.Query(R"(An expression with (parenthesis) should remain as is)");
10398
EXPECT_THAT(matchesParens.stepRegexStr, testing::StrEq(R"(^An expression with \(parenthesis\) should remain as is$)"));
10499

105-
const auto matchesBrace = stepRegistry.Query(engine::StepType::then, R"(An expression with {braces} should remain as is)");
100+
const auto matchesBrace = stepRegistry.Query(R"(An expression with {braces} should remain as is)");
106101
EXPECT_THAT(matchesBrace.stepRegexStr, testing::StrEq(R"(^An expression with \{braces\} should remain as is$)"));
107102
}
108103

109104
TEST_F(TestSteps, FunctionLikeStep)
110105
{
111-
const auto matches = stepRegistry.Query(engine::StepType::then, R"(An expression that looks like a function func(1, 2) should keep its parameters)");
106+
const auto matches = stepRegistry.Query(R"(An expression that looks like a function func(1, 2) should keep its parameters)");
112107

113108
auto contextStorage{ std::make_shared<ContextStorageFactoryImpl>() };
114109
Context context{ contextStorage };
@@ -118,7 +113,7 @@ namespace cucumber_cpp::library
118113

119114
TEST_F(TestSteps, EscapedParenthesis)
120115
{
121-
const auto matches1 = stepRegistry.Query(engine::StepType::then, R"(An expression with \(escaped parenthesis\) should keep the slash)");
122-
const auto matches2 = stepRegistry.Query(engine::StepType::then, R"(An expression with \{escaped braces\} should keep the slash)");
116+
const auto matches1 = stepRegistry.Query(R"(An expression with \(escaped parenthesis\) should keep the slash)");
117+
const auto matches2 = stepRegistry.Query(R"(An expression with \{escaped braces\} should keep the slash)");
123118
}
124119
}

0 commit comments

Comments
 (0)