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

gherkin/java:Support unicode colon as separator. #223

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package gherkin;

import java.util.regex.Pattern;

public interface GherkinLanguageConstants {
String TAG_PREFIX = "@";
String COMMENT_PREFIX = "#";
String TITLE_KEYWORD_SEPARATOR = ":";
Pattern TITLE_KEYWORD_SEPARATOR = Pattern.compile(":|:");
String TABLE_CELL_SEPARATOR = "|";
String DOCSTRING_SEPARATOR = "\"\"\"";
String DOCSTRING_ALTERNATIVE_SEPARATOR = "```";


}
13 changes: 9 additions & 4 deletions gherkin/java/src/main/java/gherkin/GherkinLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;

import static gherkin.StringUtils.ltrim;
import static gherkin.SymbolCounter.countSymbols;
Expand Down Expand Up @@ -56,10 +57,14 @@ public List<GherkinLineSpan> getTags() {
@Override
public boolean startsWithTitleKeyword(String text) {
int textLength = text.length();
return trimmedLineText.length() > textLength &&
trimmedLineText.startsWith(text) &&
trimmedLineText.substring(textLength, textLength + GherkinLanguageConstants.TITLE_KEYWORD_SEPARATOR.length())
.equals(GherkinLanguageConstants.TITLE_KEYWORD_SEPARATOR);
if (trimmedLineText.length() > textLength && trimmedLineText.startsWith(text)) {
String rest = trimmedLineText.substring(textLength);
Matcher matcher = GherkinLanguageConstants.TITLE_KEYWORD_SEPARATOR.matcher(rest);
if(matcher.find() && matcher.start() == 0){
return true;
}
}
return false;
// TODO aslak: extract startsWithFrom method for clarity
}

Expand Down
2 changes: 1 addition & 1 deletion gherkin/java/src/main/java/gherkin/TokenMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public boolean match_ExamplesLine(Token token) {
private boolean matchTitleLine(Token token, TokenType tokenType, List<String> keywords) {
for (String keyword : keywords) {
if (token.line.startsWithTitleKeyword(keyword)) {
String title = token.line.getRestTrimmed(keyword.length() + GherkinLanguageConstants.TITLE_KEYWORD_SEPARATOR.length());
String title = token.line.getRestTrimmed(keyword.length() + 1);
setTokenMatched(token, tokenType, title, keyword, null, null);
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions gherkin/java/testdata/good/i18n_zh-cn.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#language: zh-CN
功能:汉语解析

场景:冒号可以用在功能和场景中
* 冒号
42 changes: 42 additions & 0 deletions gherkin/java/testdata/good/i18n_zh-cn.feature.ast.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"document": {
"comments": [],
"feature": {
"children": [
{
"keyword": "场景",
"location": {
"column": 3,
"line": 4
},
"name": "冒号可以用在功能和场景中",
"steps": [
{
"keyword": "* ",
"location": {
"column": 5,
"line": 5
},
"text": "冒号",
"type": "Step"
}
],
"tags": [],
"type": "Scenario"
}
],
"keyword": "功能",
"language": "zh-CN",
"location": {
"column": 1,
"line": 2
},
"name": "汉语解析",
"tags": [],
"type": "Feature"
},
"type": "GherkinDocument"
},
"type": "gherkin-document",
"uri": "testdata/good/i18n_zh-cn.feature"
}
27 changes: 27 additions & 0 deletions gherkin/java/testdata/good/i18n_zh-cn.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"pickle": {
"language": "zh-CN",
"locations": [
{
"column": 3,
"line": 4
}
],
"name": "冒号可以用在功能和场景中",
"steps": [
{
"arguments": [],
"locations": [
{
"column": 7,
"line": 5
}
],
"text": "冒号"
}
],
"tags": []
},
"type": "pickle",
"uri": "testdata/good/i18n_zh-cn.feature"
}
9 changes: 9 additions & 0 deletions gherkin/java/testdata/good/i18n_zh-cn.feature.source.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"data": "#language: zh-CN\n功能:汉语解析\n\n 场景:冒号可以用在功能和场景中\n * 冒号\n",
"media": {
"encoding": "utf-8",
"type": "text/vnd.cucumber.gherkin+plain"
},
"type": "source",
"uri": "testdata/good/i18n_zh-cn.feature"
}
6 changes: 6 additions & 0 deletions gherkin/java/testdata/good/i18n_zh-cn.feature.tokens
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(1:1)Language:/zh-CN/
(2:1)FeatureLine:功能/汉语解析/
(3:1)Empty://
(4:3)ScenarioLine:场景/冒号可以用在功能和场景中/
(5:5)StepLine:* /冒号/
EOF