-
-
Notifications
You must be signed in to change notification settings - Fork 694
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
gherkin: Commented Cucumber tags still being picked up in getTags() #721
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs. |
Can confirm this bug is still present in Gherkin 8/9. Basically any line staringt with a |
And that is exactly what happens.
A feature header has a language definition, tags, feature line and description helper.
The tags are defined as a tag line. @Override
public boolean match_TagLine(Token token) {
if (token.line.startsWith(GherkinLanguageConstants.TAG_PREFIX)) {
setTokenMatched(token, TokenType.TagLine, null, null, null, token.line.getTags());
return true;
}
return false;
} @Override
public List<GherkinLineSpan> getTags() {
return getSpans("\\s+");
} Which is then matched and split on whitespace. |
The go implementation is definitely different. Tokens that don't start with func (m *matcher) MatchTagLine(line *Line) (ok bool, token *Token, err error) {
if line.StartsWith(TAG_PREFIX) {
var tags []*LineSpan
var column = line.Indent()
splits := strings.Split(line.TrimmedLineText, TAG_PREFIX)
for i := range splits {
txt := strings.Trim(splits[i], " ")
if txt != "" {
tags = append(tags, &LineSpan{column, TAG_PREFIX + txt})
}
column = column + utf8.RuneCountInString(splits[i]) + 1
}
token, ok = m.newTokenAtLocation(line.LineNumber, line.Indent()), true
token.Type = TokenTypeTagLine
token.Items = tags
}
return
} |
Javascript does the same as go. public getTags() {
let column = this.indent + 1
const items = this.trimmedLineText.trim().split('@')
items.shift()
return items.map(function(item) {
const length = item.length
const span = { column, text: '@' + item.trim() }
column += length + 1
return span
})
} |
@property
def tags(self):
column = self.indent + 1
items = self._trimmed_line_text.strip().split('@')
tags = []
for item in items[1:]:
tags.append({'column': column, 'text': '@' + item.strip()})
column += len(item) + 1
return tags Same for python. So I'm confident in saying that the Java implementation of Gherkin is splitting the tags incorrectly. However Gherkin also doesn't support comments anywhere but at the start of the line. It is not possible to comment tags inline. So the syntax highlighting in IDEA is incorrect. The alternative would be to use one line per tag. @Tag one
#@Commented tag two
Scenario: Some scenario |
I can take a look at this in a week or so Rien for Ruby unless you're comfortable fixing it yourself. Let me know. |
I just got started but you're welcome to help! In pseudo code I think the solution to should be
And I'm not sure if this the right solution. We may as well throw a parse error if we encounter whitespace in a tag. |
Sorry I am late to the party here. I don't think we should allow spaces in tags. Gherkin only allows comments if they are preceded by zero or more whitespace, and I don't think we should make an exception for lines with tags. So these lines should all cause parse errors:
This should be treated as a regular comment (everything on the line is ignores)
|
IDEA, Eclipse and this syntax highlighter on Github all disagree. Feature: example
@Tag #comment
Scenario: example Sensibly so (at least for java) because |
I think I found were this went wrong. The example below also works in IDEA, Eclipse and Github. Feature: example
@Tag#comment
Scenario: example People have read this as |
I think we should throw a parse error if a We need a few more files in
The algorithm: If a line matches
|
I'm not sure about that. Fixing individual feature files is easy sure. However IDEs and syntax highlighters update on a much slower cycle. And most Cucumber users will depend on their IDE to tell them if their feature file is valid or not. This inconsistency will cause allot of confusion for a long time. While IDEs are updating we'll also see them supporting different Gherkin versions. So depending on the editor a feature file may or may not look valid. Again this adds to the confusion. It is also not a major new feature like rules so there is a good chance it won't be fixed pro-actively either if at all. So overall this will be quite hurtful to the ecosystem. Implementation wise, both parsing and rejecting the line have comparable complexity. So I don't see a reason not to parse. |
Fair points about IDEs. We can allow comments after the initial
WDYT? |
Agreed. They're functionally not usable and IDEs don't accept them either. |
What about this though:
Does that become |
Here is another one:
Parse error? |
This looks okay: Feature: example
@Tag#comment @Tag@Tag
Scenario: example If we use
We don't need to worry about lines with only comments as they're handled by the parser already.
|
Got a good solution for Java in #880. Also got rid of the scanner so it should be easier to port to other languages. There is some extra character counting going on but we can ignore that in other languages. |
Summary
Commenting out a single tag above a scenario (leaving the first tag uncommented). The Scenario object still picks up the commented tag using getTags()
Expected Behavior
The expected behaviour can be seen if you comment out the entire line of tags. In this case, none of the tags are picked up by getTags()
Current Behavior
Commenting a tag at the end of a list of tags on a scenario, and checking the getTags() values. The uncommented tag(s) are visible (expected), but the commented out tag(s) are also visible. It should be noted that where the comment starts, it is added to the corresponding tag value (e.g. instead of @exampleTag, it's now #@exampleTag)
Your Environment
The text was updated successfully, but these errors were encountered: