Skip to content

Commit

Permalink
fix: variable reusing and minor rewrite for #361
Browse files Browse the repository at this point in the history
  • Loading branch information
U117293 authored and U117293 committed Feb 27, 2025
1 parent 6e0de0d commit 17f35df
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions java/src/main/java/io/cucumber/gherkin/PickleCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
import io.cucumber.messages.types.Tag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -107,8 +105,9 @@ private void compileScenario(List<Pickle> pickles, Scenario scenario, List<Tag>

StepKeywordType lastKeywordType = StepKeywordType.UNKNOWN;
for (Step step : allSteps) {
if (step.getKeywordType().get() != StepKeywordType.CONJUNCTION)
lastKeywordType = step.getKeywordType().get();
StepKeywordType stepKeywordType = step.getKeywordType().get();
if (stepKeywordType != StepKeywordType.CONJUNCTION)
lastKeywordType = stepKeywordType;

steps.add(pickleStep(step, lastKeywordType));
}
Expand Down Expand Up @@ -144,8 +143,9 @@ private void compileScenarioOutline(List<Pickle> pickles, Scenario scenario, Lis

if (!scenario.getSteps().isEmpty())
for (Step step : backgroundSteps) {
if (step.getKeywordType().get() != StepKeywordType.CONJUNCTION)
lastKeywordType = step.getKeywordType().get();
StepKeywordType stepKeywordType = step.getKeywordType().get();
if (stepKeywordType != StepKeywordType.CONJUNCTION)
lastKeywordType = stepKeywordType;

steps.add(pickleStep(step, lastKeywordType));
}
Expand All @@ -157,8 +157,9 @@ private void compileScenarioOutline(List<Pickle> pickles, Scenario scenario, Lis
tags.addAll(examples.getTags());

for (Step scenarioOutlineStep : scenario.getSteps()) {
if (scenarioOutlineStep.getKeywordType().get() != StepKeywordType.CONJUNCTION)
lastKeywordType = scenarioOutlineStep.getKeywordType().get();
StepKeywordType stepKeywordType = scenarioOutlineStep.getKeywordType().get();
if (stepKeywordType != StepKeywordType.CONJUNCTION)
lastKeywordType = stepKeywordType;

PickleStep pickleStep = pickleStep(scenarioOutlineStep, variableCells, valuesRow, lastKeywordType);

Expand Down Expand Up @@ -220,17 +221,14 @@ private PickleStep pickleStep(Step step, List<TableCell> variableCells, TableRow
if (step.getDataTable().isPresent()) {
argument = new PickleStepArgument(null, pickleDataTable(step.getDataTable().get(), variableCells, valueCells));
}

if (step.getDocString().isPresent()) {
argument = new PickleStepArgument(pickleDocString(step.getDocString().get(), variableCells, valueCells), null);
}


List<String> astNodeIds;
if (valuesRow != null) {
astNodeIds = Stream.of(singletonList(step.getId()), singletonList(valuesRow.getId()))
.flatMap(Collection::stream)
.collect(Collectors.toList());
astNodeIds = Arrays.asList(step.getId(), valuesRow.getId());

} else {
astNodeIds = singletonList(step.getId());
Expand Down Expand Up @@ -261,6 +259,9 @@ private String interpolate(String name, List<TableCell> variableCells, List<Tabl
}

private List<PickleTag> pickleTags(List<Tag> tags) {
if (tags.isEmpty()) {
return Collections.emptyList();
}
List<PickleTag> result = new ArrayList<>();
for (Tag tag : tags) {
result.add(pickleTag(tag));
Expand Down

0 comments on commit 17f35df

Please sign in to comment.