Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix supported characters in Tags #30

Merged
merged 6 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ All user visible changes to `gherkin` crate will be documented in this file. Thi



## [0.11.1] · ???
[0.11.1]: /../../tree/v0.11.1

[Diff](/../../compare/v0.11.0...v0.11.1)

### Fixed

- Allowed keywords in `Feature`s `Description`. ([#30], [cucumber#175])
- Allowed characters in `Tag`s. ([#30], [cucumber#174])
- Comments on the same line with `Tag`s. ([#30])
- `Tag`s requiring whitespaces between them. ([#30])

[#30]: /../../pull/30
[cucumber#174]: https://github.com/cucumber-rs/cucumber/issues/174
[cucumber#175]: https://github.com/cucumber-rs/cucumber/issues/175




## [0.11.0] · 2021-12-06
[0.11.0]: /../../tree/v0.11.0

Expand Down
30 changes: 23 additions & 7 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::ops::Deref;

#[derive(Debug, Clone)]
pub(crate) struct Keywords<'a> {
pub feature: &'a [&'a str],
Expand Down Expand Up @@ -36,14 +38,11 @@ impl<'a> Keywords<'a> {
}

pub fn all(&self) -> Vec<&'a str> {
let mut v = vec![];

for x in [
let mut v = [
self.feature,
self.background,
self.rule,
self.scenario,
self.rule,
self.scenario_outline,
self.examples,
self.given,
Expand All @@ -53,9 +52,26 @@ impl<'a> Keywords<'a> {
self.but,
]
.iter()
{
v.append(&mut x.to_vec());
}
.flat_map(|s| s.iter().map(Deref::deref))
.collect::<Vec<_>>();

v.sort_unstable();

v
}

pub fn exclude_in_description(&self) -> Vec<&'a str> {
let mut v = [
self.feature,
self.background,
self.rule,
self.scenario,
self.scenario_outline,
self.examples,
]
.iter()
.flat_map(|s| s.iter().map(Deref::deref))
.collect::<Vec<_>>();

v.sort_unstable();

Expand Down
12 changes: 9 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,12 @@ rule any_directive() -> &'static str
}

rule description_line() -> &'input str
= _ !"@" !any_directive() _ n:not_nl() nl_eof() { n }
= _
!"@" !keyword((&*env.keywords().exclude_in_description()))
_ n:not_nl() nl_eof()
{
n
}

rule description() -> Option<String>
= d:(description_line() ** _) {
Expand Down Expand Up @@ -415,7 +420,8 @@ rule scenario() -> Scenario
rule tag_char() -> &'input str
= s:$([_]) {?
let x = s.chars().next().unwrap();
if x.is_alphanumeric() || x == '_' || x == '-' {
// `)` isn't allowed, as it would collide with TagExpression.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see in reference implemetation, we should support it.

Maybe this should be resolved by escaping in TagExpression?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyranron somewhere buried in separate github repo, there is mentioning of escaping https://github.com/cucumber/tag-expressions#escaping

if !x.is_whitespace() && !"\r\n@)".contains(x) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\r, \n and even \t are covered by .is_whitespace() already.

Ok(s)
} else {
Err("tag character")
Expand All @@ -426,7 +432,7 @@ pub(crate) rule tag() -> String
= "@" s:tag_char()+ { s.join("") }

pub(crate) rule tags() -> Vec<String>
= t:(tag() ** ([' ']+)) _ nl() { t }
= t:(tag() ** _) _ nl()* { t }
/ { vec![] }

rule rule_() -> Rule
Expand Down
15 changes: 12 additions & 3 deletions tests/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
@feature-tag
Feature: This is a feature file

For all queries, parameters will not be set for default values as defined by:
* Numeric inputs: 0
* String inputs: ""
But list isn't exhaustive


# Surprise comment
Background:
Expand All @@ -19,7 +24,11 @@ Background:
And then it was fun
| value1 | value2 |

@tag1 @tag2 @tag-life_woo
#comment
@tag1 @tag2 @tag-life_woo @tag.with#more.chars #comment


#comment
Scenario: A second scenario test
Given I have not been testing much
Then I should probably start doing it
Expand All @@ -29,8 +38,8 @@ Scenario: A second scenario test
Given I am lightly tabbed
Then handle how tabbed I am

@taglife
Scenario Outline: eating
@taglife@with_joined_tags
Scenario Outline: eating <eat> cucumbers
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Expand Down