Skip to content

Commit 604b85d

Browse files
authored
fix: tag expression parsing for scenarios with no tags (#65)
1 parent 849f5e9 commit 604b85d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

cucumber-cpp/TagExpression.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ namespace cucumber_cpp
2626
return true;
2727
}
2828

29-
if (tags.empty())
30-
{
31-
return false;
32-
}
33-
3429
std::string eval = tagExpr;
3530

3631
for (std::smatch matches; std::regex_search(eval, matches, std::regex(R"((@[^ \)]+))"));)

cucumber-cpp/test/TestTagExpression.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "cucumber-cpp/TagExpression.hpp"
22
#include "gmock/gmock.h"
3-
#include <iomanip>
43

54
namespace cucumber_cpp
65
{
76
struct TestTagExpression : testing::Test
87
{
98
std::set<std::string, std::less<>> inputTags = { "@abc", "@def", "@efg" };
109
std::set<std::string, std::less<>> noTags = {};
10+
std::set<std::string, std::less<>> ignoredTags = { "@abc", "@def", "@efg", "@ignore" };
1111
};
1212

1313
TEST_F(TestTagExpression, EmptyTagExpression)
@@ -26,32 +26,55 @@ namespace cucumber_cpp
2626
{
2727
EXPECT_THAT(IsTagExprSelected("@abc", noTags), testing::IsFalse());
2828
EXPECT_THAT(IsTagExprSelected("@abc", inputTags), testing::IsTrue());
29+
EXPECT_THAT(IsTagExprSelected("@abc", ignoredTags), testing::IsTrue());
2930

3031
EXPECT_THAT(IsTagExprSelected("@foo", inputTags), testing::IsFalse());
32+
EXPECT_THAT(IsTagExprSelected("@foo", ignoredTags), testing::IsFalse());
3133
}
3234

3335
TEST_F(TestTagExpression, AndTag)
3436
{
3537
EXPECT_THAT(IsTagExprSelected("@abc and @def", noTags), testing::IsFalse());
3638
EXPECT_THAT(IsTagExprSelected("@abc and @def", inputTags), testing::IsTrue());
39+
EXPECT_THAT(IsTagExprSelected("@abc and @def", ignoredTags), testing::IsTrue());
3740

3841
EXPECT_THAT(IsTagExprSelected("@abc and @foo", inputTags), testing::IsFalse());
42+
EXPECT_THAT(IsTagExprSelected("@abc and @foo", ignoredTags), testing::IsFalse());
3943
}
4044

4145
TEST_F(TestTagExpression, OrTag)
4246
{
4347
EXPECT_THAT(IsTagExprSelected("@foo or @def", noTags), testing::IsFalse());
4448
EXPECT_THAT(IsTagExprSelected("@abc or @foo", inputTags), testing::IsTrue());
49+
EXPECT_THAT(IsTagExprSelected("@abc or @foo", ignoredTags), testing::IsTrue());
4550

4651
EXPECT_THAT(IsTagExprSelected("@fez or @foo", inputTags), testing::IsFalse());
52+
EXPECT_THAT(IsTagExprSelected("@fez or @foo", ignoredTags), testing::IsFalse());
4753
}
4854

4955
TEST_F(TestTagExpression, AndOrGroupedTag)
5056
{
5157
EXPECT_THAT(IsTagExprSelected("@abc and (@def or @efg)", noTags), testing::IsFalse());
5258
EXPECT_THAT(IsTagExprSelected("@abc and (@def or @efg)", inputTags), testing::IsTrue());
59+
EXPECT_THAT(IsTagExprSelected("@abc and (@def or @efg)", ignoredTags), testing::IsTrue());
5360

5461
EXPECT_THAT(IsTagExprSelected("@fez and (@def or @efg)", inputTags), testing::IsFalse());
62+
EXPECT_THAT(IsTagExprSelected("@fez and (@def or @efg)", ignoredTags), testing::IsFalse());
5563
EXPECT_THAT(IsTagExprSelected("@abc and (@fez or @bar)", inputTags), testing::IsFalse());
64+
EXPECT_THAT(IsTagExprSelected("@abc and (@fez or @bar)", ignoredTags), testing::IsFalse());
65+
}
66+
67+
TEST_F(TestTagExpression, Negating)
68+
{
69+
EXPECT_THAT(IsTagExprSelected("not @ignore", noTags), testing::IsTrue());
70+
EXPECT_THAT(IsTagExprSelected("not @ignore", inputTags), testing::IsTrue());
71+
EXPECT_THAT(IsTagExprSelected("not @ignore", ignoredTags), testing::IsFalse());
72+
}
73+
74+
TEST_F(TestTagExpression, WithTagNegating)
75+
{
76+
EXPECT_THAT(IsTagExprSelected("@abc and not @ignore", noTags), testing::IsFalse());
77+
EXPECT_THAT(IsTagExprSelected("@abc and not @ignore", inputTags), testing::IsTrue());
78+
EXPECT_THAT(IsTagExprSelected("@abc and not @ignore", ignoredTags), testing::IsFalse());
5679
}
5780
}

0 commit comments

Comments
 (0)