use of gherkin.formatter.Argument in project cucumber-jvm by cucumber.
the class JdkPatternArgumentMatcher method argumentsFrom.
public List<Argument> argumentsFrom(String stepName) {
Matcher matcher = pattern.matcher(stepName);
if (matcher.lookingAt()) {
List<Argument> arguments = new ArrayList<Argument>(matcher.groupCount());
for (int i = 1; i <= matcher.groupCount(); i++) {
int startIndex = matcher.start(i);
arguments.add(new Argument(startIndex == -1 ? null : startIndex, matcher.group(i)));
}
return arguments;
} else {
return null;
}
}
use of gherkin.formatter.Argument in project cucumber-jvm by cucumber.
the class StepDefinitionMatch method createArgumentsForErrorMessage.
private List<Argument> createArgumentsForErrorMessage(Step step) {
List<Argument> arguments = new ArrayList<Argument>(getArguments());
if (step.getDocString() != null) {
arguments.add(new Argument(-1, "DocString:" + step.getDocString().getValue()));
}
if (step.getRows() != null) {
List<List<String>> rows = map(step.getRows(), new Mapper<DataTableRow, List<String>>() {
@Override
public List<String> map(DataTableRow row) {
return row.getCells();
}
});
arguments.add(new Argument(-1, "Table:" + rows.toString()));
}
return arguments;
}
use of gherkin.formatter.Argument in project cucumber-jvm by cucumber.
the class StepdefGenerator method generate.
public List<MetaStepdef> generate(Collection<StepDefinition> stepDefinitions, List<CucumberFeature> features) {
List<MetaStepdef> result = new ArrayList<MetaStepdef>();
List<StepDefinition> sortedStepdefs = new ArrayList<StepDefinition>();
sortedStepdefs.addAll(stepDefinitions);
Collections.sort(sortedStepdefs, STEP_DEFINITION_COMPARATOR);
for (StepDefinition stepDefinition : sortedStepdefs) {
MetaStepdef metaStepdef = new MetaStepdef();
metaStepdef.source = stepDefinition.getPattern();
// TODO = get the flags too
metaStepdef.flags = "";
for (CucumberFeature feature : features) {
List<CucumberTagStatement> cucumberTagStatements = feature.getFeatureElements();
for (CucumberTagStatement tagStatement : cucumberTagStatements) {
List<Step> steps = tagStatement.getSteps();
for (Step step : steps) {
List<Argument> arguments = stepDefinition.matchedArguments(step);
if (arguments != null) {
MetaStepdef.MetaStep ms = new MetaStepdef.MetaStep();
ms.name = step.getName();
for (Argument argument : arguments) {
MetaStepdef.MetaArgument ma = new MetaStepdef.MetaArgument();
ma.offset = argument.getOffset();
ma.val = argument.getVal();
ms.args.add(ma);
}
metaStepdef.steps.add(ms);
}
}
}
Collections.sort(cucumberTagStatements, CUCUMBER_TAG_STATEMENT_COMPARATOR);
}
result.add(metaStepdef);
}
return result;
}
use of gherkin.formatter.Argument in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments.
@Test
public void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments() throws Throwable {
Step step = new Step(null, "Given ", "I have 4 cukes in my belly", 1, null, null);
StepDefinition stepDefinition = new StubStepDefinition(new Object(), Object.class.getMethod("toString"), "some pattern");
StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(asList(new Argument(7, "4")), stepDefinition, null, step, new LocalizedXStreams(getClass().getClassLoader()));
try {
stepDefinitionMatch.runStep(new I18n("en"));
fail();
} catch (CucumberException expected) {
assertEquals("Arity mismatch: Step Definition 'toString' with pattern [some pattern] is declared with 0 parameters. However, the gherkin step has 1 arguments [4]. \n" + "Step: Given I have 4 cukes in my belly", expected.getMessage());
}
}
use of gherkin.formatter.Argument in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments.
@Test
public void throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments() throws Throwable {
Step step = new Step(null, "Given ", "I have 4 cukes in my belly", 1, new ArrayList<DataTableRow>(), null);
StepDefinition stepDefinition = new StubStepDefinition(new Object(), WithTwoParams.class.getMethod("withTwoParams", Integer.TYPE, Short.TYPE, List.class), "some pattern");
StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(asList(new Argument(7, "4")), stepDefinition, null, step, new LocalizedXStreams(getClass().getClassLoader()));
try {
stepDefinitionMatch.runStep(new I18n("en"));
fail();
} catch (CucumberException expected) {
assertEquals("Arity mismatch: Step Definition 'withTwoParams' with pattern [some pattern] is declared with 3 parameters. However, the gherkin step has 2 arguments [4, Table:[]]. \n" + "Step: Given I have 4 cukes in my belly", expected.getMessage());
}
}
Aggregations