Skip to content
Draft
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
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>[19.1.4,29.0.0)</version>
<version>[30.1.1-SNAPSHOT,31.0.0)</version>
</dependency>

<dependency>
Expand Down
18 changes: 9 additions & 9 deletions java/src/main/java/io/cucumber/gherkin/Locations.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class Locations {
* We can't use Long.valueOf() because it caches only the first 128
* values, and typical feature files have much more lines.
*/
private static final Long[] longs = new Long[4096];
private static final Integer[] ints = new Integer[4096];

static {
for (int i = 0; i < longs.length; i++) {
longs[i] = (long) i;
for (int i = 0; i < ints.length; i++) {
ints[i] = i;
}
}

private static Long getLong(int i) {
private static Integer getInteger(int i) {
// JMH benchmark shows that this implementation is the
// fastest when i<4096 (and about 20% slower than
// Long.valueOf() when i>=4096).
Expand All @@ -39,25 +39,25 @@ private static Long getLong(int i) {
// 1024/2048/4096 initial size
// - dynamic lazy initialized cache with 256
// initialized size
if (i >= longs.length) {
return (long) i;
if (i >= ints.length) {
return i;
}
return longs[i];
return ints[i];
}

static Location atColumn(Location location, int column) {
requireNonNull(location);
if (column <= 0) {
throw new IllegalArgumentException("Columns are index-1 based");
}
return new Location(location.getLine(), getLong(column));
return new Location(location.getLine(), getInteger(column));
}

static Location atLine(int line) {
if (line < 0) {
throw new IllegalArgumentException("Lines are index-0 based");
}
return new Location(getLong(line), null);
return new Location(getInteger(line), null);
}

}
4 changes: 2 additions & 2 deletions java/src/main/java/io/cucumber/gherkin/ParserException.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ private static String createMessage(String message, Location location) {
if (location == null) {
return String.format("(-1,0): %s", message);
}
Long line = location.getLine();
Long column = location.getColumn().orElse(0L);
Integer line = location.getLine();
Integer column = location.getColumn().orElse(0);
return String.format("(%s:%s): %s", line, column, message);
}

Expand Down
2 changes: 2 additions & 0 deletions java/src/main/java/io/cucumber/gherkin/PickleCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private void compileScenario(List<Pickle> pickles, Scenario scenario, List<Tag>
Pickle pickle = new Pickle(
idGenerator.newId(),
uri,
scenario.getLocation(),
scenario.getName(),
language,
steps,
Expand Down Expand Up @@ -170,6 +171,7 @@ private void compileScenarioOutline(List<Pickle> pickles, Scenario scenario, Lis
Pickle pickle = new Pickle(
idGenerator.newId(),
uri,
valuesRow.getLocation(),
interpolate(scenario.getName(), variableCells, valueCells),
language,
steps,
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/io/cucumber/gherkin/TokenFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ String formatToken(Token token) {

return String.format("(%s:%s)%s:%s/%s/%s",
toString(token.location.getLine()),
toString(token.location.getColumn().orElse(0L)),
toString(token.location.getColumn().orElse(0)),
toString(token.matchedType),
token.matchedKeyword == null ? "" : String.format("(%s)%s",
toString(token.keywordType),
Expand Down
6 changes: 3 additions & 3 deletions java/src/test/java/io/cucumber/gherkin/LocationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class LocationsTest {
void atLine() {
// random integer conversion that is far after the cache upper bound works
Location location = Locations.atLine(12000);
assertEquals(Long.valueOf(12000L), location.getLine());
assertEquals(Integer.valueOf(12000), location.getLine());
// sequential integer conversion works (the cache has no hole)
for (int i = 0; i < 12000; i++) {
Long expectedLine = (long) i;
Integer expectedLine = i;
Location actual = Locations.atLine(i);
assertEquals(expectedLine, actual.getLine());
}
Expand All @@ -37,7 +37,7 @@ void atLine_multithreaded_does_not_raise_exception() {
for (int i = 0; i < numberOfThreads; i++) {
threads[i] = new Thread(() -> {
for (int j = 500; j < numberOfIterations; j *= 2) {
Long expectedLine = (long) j;
Integer expectedLine = j;
Location actual = Locations.atLine(j);
assertEquals(expectedLine, actual.getLine());
}
Expand Down
4 changes: 2 additions & 2 deletions testdata/good/background.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"pickle":{"astNodeIds":["3"],"id":"8","language":"en","name":"minimalistic","steps":[{"astNodeIds":["0"],"id":"6","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["2"],"id":"7","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/background.feature"}}
{"pickle":{"astNodeIds":["5"],"id":"11","language":"en","name":"also minimalistic","steps":[{"astNodeIds":["0"],"id":"9","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["4"],"id":"10","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/background.feature"}}
{"pickle":{"astNodeIds":["3"],"id":"8","language":"en","location":{"column":3,"line":7},"name":"minimalistic","steps":[{"astNodeIds":["0"],"id":"6","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["2"],"id":"7","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/background.feature"}}
{"pickle":{"astNodeIds":["5"],"id":"11","language":"en","location":{"column":3,"line":10},"name":"also minimalistic","steps":[{"astNodeIds":["0"],"id":"9","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["4"],"id":"10","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/background.feature"}}
8 changes: 4 additions & 4 deletions testdata/good/complex_background.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"pickle":{"astNodeIds":["3"],"id":"17","language":"en","name":"minimalistic","steps":[{"astNodeIds":["0"],"id":"15","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["2"],"id":"16","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/complex_background.feature"}}
{"pickle":{"astNodeIds":["5"],"id":"20","language":"en","name":"also minimalistic","steps":[{"astNodeIds":["0"],"id":"18","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["4"],"id":"19","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/complex_background.feature"}}
{"pickle":{"astNodeIds":["13","10"],"id":"24","language":"en","name":"with examples","steps":[{"astNodeIds":["0"],"id":"21","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["6"],"id":"22","text":"a rule background step","type":"Context"},{"astNodeIds":["8","10"],"id":"23","text":"the 1 minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/complex_background.feature"}}
{"pickle":{"astNodeIds":["13","11"],"id":"28","language":"en","name":"with examples","steps":[{"astNodeIds":["0"],"id":"25","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["6"],"id":"26","text":"a rule background step","type":"Context"},{"astNodeIds":["8","11"],"id":"27","text":"the 2 minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/complex_background.feature"}}
{"pickle":{"astNodeIds":["3"],"id":"17","language":"en","location":{"column":3,"line":7},"name":"minimalistic","steps":[{"astNodeIds":["0"],"id":"15","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["2"],"id":"16","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/complex_background.feature"}}
{"pickle":{"astNodeIds":["5"],"id":"20","language":"en","location":{"column":3,"line":10},"name":"also minimalistic","steps":[{"astNodeIds":["0"],"id":"18","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["4"],"id":"19","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/complex_background.feature"}}
{"pickle":{"astNodeIds":["13","10"],"id":"24","language":"en","location":{"column":7,"line":23},"name":"with examples","steps":[{"astNodeIds":["0"],"id":"21","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["6"],"id":"22","text":"a rule background step","type":"Context"},{"astNodeIds":["8","10"],"id":"23","text":"the 1 minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/complex_background.feature"}}
{"pickle":{"astNodeIds":["13","11"],"id":"28","language":"en","location":{"column":7,"line":24},"name":"with examples","steps":[{"astNodeIds":["0"],"id":"25","text":"the minimalism inside a background","type":"Context"},{"astNodeIds":["6"],"id":"26","text":"a rule background step","type":"Context"},{"astNodeIds":["8","11"],"id":"27","text":"the 2 minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/complex_background.feature"}}
2 changes: 1 addition & 1 deletion testdata/good/datatables.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"pickle":{"astNodeIds":["13"],"id":"19","language":"en","name":"minimalistic","steps":[{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"},{"value":"bar"}]},{"cells":[{"value":"boz"},{"value":"boo"}]}]}},"astNodeIds":["2"],"id":"14","text":"a simple data table","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"}]}]}},"astNodeIds":["4"],"id":"15","text":"a data table with a single cell","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"},{"value":"bar"},{"value":"boz"}]}]}},"astNodeIds":["6"],"id":"16","text":"a data table with different fromatting","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"},{"value":""},{"value":"boz"}]}]}},"astNodeIds":["8"],"id":"17","text":"a data table with an empty cell","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"},{"value":"bar"}]},{"cells":[{"value":"boz"},{"value":"boo"}]},{"cells":[{"value":"boz2"},{"value":"boo2"}]}]}},"astNodeIds":["12"],"id":"18","text":"a data table with comments and newlines inside","type":"Context"}],"tags":[],"uri":"../testdata/good/datatables.feature"}}
{"pickle":{"astNodeIds":["13"],"id":"19","language":"en","location":{"column":3,"line":3},"name":"minimalistic","steps":[{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"},{"value":"bar"}]},{"cells":[{"value":"boz"},{"value":"boo"}]}]}},"astNodeIds":["2"],"id":"14","text":"a simple data table","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"}]}]}},"astNodeIds":["4"],"id":"15","text":"a data table with a single cell","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"},{"value":"bar"},{"value":"boz"}]}]}},"astNodeIds":["6"],"id":"16","text":"a data table with different fromatting","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"},{"value":""},{"value":"boz"}]}]}},"astNodeIds":["8"],"id":"17","text":"a data table with an empty cell","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"foo"},{"value":"bar"}]},{"cells":[{"value":"boz"},{"value":"boo"}]},{"cells":[{"value":"boz2"},{"value":"boo2"}]}]}},"astNodeIds":["12"],"id":"18","text":"a data table with comments and newlines inside","type":"Context"}],"tags":[],"uri":"../testdata/good/datatables.feature"}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"pickle":{"astNodeIds":["4"],"id":"7","language":"en","name":"some whitespace is important","steps":[{"argument":{"dataTable":{"rows":[{"cells":[{"value":"\nraindrops--\nher last kiss\ngoodbye.\n"}]}]}},"astNodeIds":["1"],"id":"5","text":"3 lines of poetry on 5 lines","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"lost i n space"}]}]}},"astNodeIds":["3"],"id":"6","text":"an example of negative space","type":"Context"}],"tags":[],"uri":"../testdata/good/datatables_with_new_lines.feature"}}
{"pickle":{"astNodeIds":["4"],"id":"7","language":"en","location":{"column":3,"line":3},"name":"some whitespace is important","steps":[{"argument":{"dataTable":{"rows":[{"cells":[{"value":"\nraindrops--\nher last kiss\ngoodbye.\n"}]}]}},"astNodeIds":["1"],"id":"5","text":"3 lines of poetry on 5 lines","type":"Context"},{"argument":{"dataTable":{"rows":[{"cells":[{"value":"lost i n space"}]}]}},"astNodeIds":["3"],"id":"6","text":"an example of negative space","type":"Context"}],"tags":[],"uri":"../testdata/good/datatables_with_new_lines.feature"}}
16 changes: 8 additions & 8 deletions testdata/good/descriptions.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{"pickle":{"astNodeIds":["1"],"id":"20","language":"en","name":"two lines","steps":[{"astNodeIds":["0"],"id":"19","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["3"],"id":"22","language":"en","name":"without indentation","steps":[{"astNodeIds":["2"],"id":"21","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["5"],"id":"24","language":"en","name":"empty lines in the middle","steps":[{"astNodeIds":["4"],"id":"23","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["7"],"id":"26","language":"en","name":"empty lines around","steps":[{"astNodeIds":["6"],"id":"25","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["9"],"id":"28","language":"en","name":"comment after description","steps":[{"astNodeIds":["8"],"id":"27","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["11"],"id":"30","language":"en","name":"comment right after description","steps":[{"astNodeIds":["10"],"id":"29","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["13"],"id":"32","language":"en","name":"description with escaped docstring separator","steps":[{"astNodeIds":["12"],"id":"31","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["18","16"],"id":"34","language":"en","name":"scenario outline with a description","steps":[{"astNodeIds":["14","16"],"id":"33","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["1"],"id":"20","language":"en","location":{"column":3,"line":4},"name":"two lines","steps":[{"astNodeIds":["0"],"id":"19","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["3"],"id":"22","language":"en","location":{"column":1,"line":9},"name":"without indentation","steps":[{"astNodeIds":["2"],"id":"21","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["5"],"id":"24","language":"en","location":{"column":3,"line":13},"name":"empty lines in the middle","steps":[{"astNodeIds":["4"],"id":"23","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["7"],"id":"26","language":"en","location":{"column":3,"line":19},"name":"empty lines around","steps":[{"astNodeIds":["6"],"id":"25","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["9"],"id":"28","language":"en","location":{"column":3,"line":26},"name":"comment after description","steps":[{"astNodeIds":["8"],"id":"27","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["11"],"id":"30","language":"en","location":{"column":3,"line":33},"name":"comment right after description","steps":[{"astNodeIds":["10"],"id":"29","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["13"],"id":"32","language":"en","location":{"column":3,"line":40},"name":"description with escaped docstring separator","steps":[{"astNodeIds":["12"],"id":"31","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
{"pickle":{"astNodeIds":["18","16"],"id":"34","language":"en","location":{"column":5,"line":52},"name":"scenario outline with a description","steps":[{"astNodeIds":["14","16"],"id":"33","text":"the minimalism","type":"Context"}],"tags":[],"uri":"../testdata/good/descriptions.feature"}}
Loading