Skip to content

Commit c7e247a

Browse files
authored
Tags with special characters (#123)
* updated scanner::tag with a whitelist of characters * udpated CHANGELOG
1 parent f0de58f commit c7e247a

4 files changed

Lines changed: 58 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Fixed
1111

1212
- Tags with hyphens are not parsed correctly ([111](https://github.com/ThoSe1990/cwt-cucumber/pull/111))
13+
- Tags with dots are not parsed correctly ([123](https://github.com/ThoSe1990/cwt-cucumber/pull/123))
1314
- Removed Cucumber prints to `stdout` when using `--report-json`, only JSON report is printed to stdout. No prints when printing JSON results to a file ([108](https://github.com/ThoSe1990/cwt-cucumber/pull/108))
1415
- Parser fails with empty table cells in data tables or Scenario Outlines ([116](https://github.com/ThoSe1990/cwt-cucumber/pull/116))
1516

gtest/run_scenarios_tags.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,27 @@ TEST_F(run_scenarios_special_tags, ignore_2)
483483
EXPECT_EQ(cuke::results::test_results().scenarios_skipped(), 0);
484484
EXPECT_FALSE(cuke::internal::get_runtime_options().ignore_scenario());
485485
}
486+
TEST_F(run_scenarios_special_tags, tag_with_special_chars)
487+
{
488+
const char* script = R"*(
489+
Feature: a feature
490+
@$*./<>::'|%^&!?_-#
491+
Scenario: a scenario
492+
Given a step
493+
494+
@my.tag.with.dots
495+
Scenario: this runs
496+
Given a step
497+
)*";
498+
cuke::parser p;
499+
p.parse_script(script);
500+
make_args("@$*./<>::'|%^&!?_-# or @my.tag.with.dots");
501+
502+
cuke::test_runner runner;
503+
p.for_each_scenario(runner);
504+
505+
ASSERT_EQ(cuke::results::test_results().scenarios_count(), 2);
506+
EXPECT_EQ(cuke::results::test_results().scenarios_passed(), 2);
507+
EXPECT_EQ(cuke::results::test_results().scenarios_skipped(), 0);
508+
EXPECT_FALSE(cuke::internal::get_runtime_options().ignore_scenario());
509+
}

gtest/tags.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ TEST(tag_expression, tag_with_hyphen)
233233
ASSERT_EQ(tc.size(), 1);
234234
EXPECT_EQ(tc[0].value, "@my-tag");
235235
}
236+
TEST(tag_expression, tag_with_dots)
237+
{
238+
cuke::internal::tag_expression tc("@my.tag");
239+
ASSERT_EQ(tc.size(), 1);
240+
EXPECT_EQ(tc[0].value, "@my.tag");
241+
}
242+
TEST(tag_expression, tag_with_special_chars)
243+
{
244+
cuke::internal::tag_expression tc("@$*./<>::'|%^&!?_-#");
245+
ASSERT_EQ(tc.size(), 1);
246+
EXPECT_EQ(tc[0].value, "@$*./<>::'|%^&!?_-#");
247+
}
236248
TEST(tag_expression, tag_with_hyphen_and_operator)
237249
{
238250
cuke::internal::tag_expression tc("@my-tag and @other-tag");
@@ -475,3 +487,15 @@ TEST(tag_evaluation, hyphenated_tag_and)
475487
cuke::internal::tag_expression tc("@tag-1 and @tag-2");
476488
EXPECT_TRUE(tc.evaluate(tags));
477489
}
490+
TEST(tag_evaluation, tags_with_dots)
491+
{
492+
std::vector<std::string> tags{std::string("@tag.1"), std::string("@tag.2")};
493+
cuke::internal::tag_expression tc("@tag.1 and @tag.2");
494+
EXPECT_TRUE(tc.evaluate(tags));
495+
}
496+
TEST(tag_evaluation, tags_with_special_char)
497+
{
498+
std::vector<std::string> tags{std::string("@$*./<>::'|%^&!?_-#")};
499+
cuke::internal::tag_expression tc("@$*./<>::'|%^&!?_-#");
500+
EXPECT_TRUE(tc.evaluate(tags));
501+
}

src/scanner.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ static bool is_alpha(char c)
1313

1414
static bool is_digit(char c) { return c >= '0' && c <= '9'; }
1515

16+
static bool is_tag_char(char c)
17+
{
18+
return is_alpha(c) || is_digit(c) || c == '-' || c == '.' || c == '#' ||
19+
c == '/' || c == ':' || c == '$' || c == '*' || c == '<' || c == '>' ||
20+
c == '\'' || c == '|' || c == '%' || c == '^' || c == '&' ||
21+
c == '!' || c == '?';
22+
}
23+
1624
scanner::scanner(std::string_view source) : m_source(source)
1725
{
1826
find_language();
@@ -224,7 +232,7 @@ token scanner::number()
224232

225233
token scanner::tag()
226234
{
227-
while (is_alpha(peek()) || is_digit(peek()) || peek() == '-')
235+
while (is_tag_char(peek()))
228236
{
229237
advance();
230238
}

0 commit comments

Comments
 (0)