use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class PrettyFormatterTest method should_mark_nested_argument_as_part_of_full_argument.
@Test
void should_mark_nested_argument_as_part_of_full_argument() {
Formats formats = ansi();
StepTypeRegistry registry = new StepTypeRegistry(Locale.ENGLISH);
StepExpressionFactory stepExpressionFactory = new StepExpressionFactory(registry, bus);
StepDefinition stepDefinition = new StubStepDefinition("^the order is placed( and (not yet )?confirmed)?$", String.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
PrettyFormatter prettyFormatter = new PrettyFormatter(new ByteArrayOutputStream());
String stepText = "the order is placed and not yet confirmed";
String formattedText = prettyFormatter.formatStepText("Given ", stepText, formats.get("passed"), formats.get("passed_arg"), createArguments(expression.match(stepText)));
assertThat(formattedText, equalTo(AnsiEscapes.GREEN + "Given " + AnsiEscapes.RESET + AnsiEscapes.GREEN + "the order is placed" + AnsiEscapes.RESET + AnsiEscapes.GREEN + AnsiEscapes.INTENSITY_BOLD + " and not yet confirmed" + AnsiEscapes.RESET));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class CachingGlueTest method returns_match_from_cache_for_ste_with_doc_string.
@Test
void returns_match_from_cache_for_ste_with_doc_string() throws AmbiguousStepDefinitionsException {
StepDefinition stepDefinition1 = new MockedStepDefinition("^pattern1", String.class);
StepDefinition stepDefinition2 = new MockedStepDefinition("^pattern2", String.class);
glue.addStepDefinition(stepDefinition1);
glue.addStepDefinition(stepDefinition2);
glue.prepareGlue(stepTypeRegistry);
URI uri = URI.create("file:path/to.feature");
String stepText = "pattern1";
Step pickleStep1 = getPickleStepWithDocString(stepText, "doc string 1");
PickleStepDefinitionMatch match1 = glue.stepDefinitionMatch(uri, pickleStep1);
assertThat(((CoreStepDefinition) match1.getStepDefinition()).getStepDefinition(), is(equalTo(stepDefinition1)));
// check cache
assertThat(glue.getStepPatternByStepText().get(stepText), is(equalTo(stepDefinition1.getPattern())));
CoreStepDefinition coreStepDefinition = glue.getStepDefinitionsByPattern().get(stepDefinition1.getPattern());
assertThat(coreStepDefinition.getStepDefinition(), is(equalTo(stepDefinition1)));
// check arguments
assertThat(match1.getArguments().get(0).getValue(), is(equalTo("doc string 1")));
// check second match
Step pickleStep2 = getPickleStepWithDocString(stepText, "doc string 2");
PickleStepDefinitionMatch match2 = glue.stepDefinitionMatch(uri, pickleStep2);
// check arguments
assertThat(match2.getArguments().get(0).getValue(), is(equalTo("doc string 2")));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class CachingGlueTest method returns_no_match_after_evicting_scenario_scoped.
@Test
void returns_no_match_after_evicting_scenario_scoped() throws AmbiguousStepDefinitionsException {
URI uri = URI.create("file:path/to.feature");
String stepText = "pattern1";
Step pickleStep1 = getPickleStep(stepText);
StepDefinition stepDefinition1 = new MockedScenarioScopedStepDefinition("^pattern1");
glue.addStepDefinition(stepDefinition1);
glue.prepareGlue(stepTypeRegistry);
PickleStepDefinitionMatch pickleStepDefinitionMatch = glue.stepDefinitionMatch(uri, pickleStep1);
assertThat(((CoreStepDefinition) pickleStepDefinitionMatch.getStepDefinition()).getStepDefinition(), is(equalTo(stepDefinition1)));
glue.removeScenarioScopedGlue();
glue.prepareGlue(stepTypeRegistry);
PickleStepDefinitionMatch pickleStepDefinitionMatch2 = glue.stepDefinitionMatch(uri, pickleStep1);
assertThat(pickleStepDefinitionMatch2, nullValue());
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class PrettyFormatterTest method should_mark_subsequent_arguments_in_steps.
@Test
void should_mark_subsequent_arguments_in_steps() {
Formats formats = ansi();
StepTypeRegistry registry = new StepTypeRegistry(Locale.ENGLISH);
StepExpressionFactory stepExpressionFactory = new StepExpressionFactory(registry, bus);
StepDefinition stepDefinition = new StubStepDefinition("text {string} text {string}", String.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
PrettyFormatter prettyFormatter = new PrettyFormatter(new ByteArrayOutputStream());
String stepText = "text 'arg1' text 'arg2'";
String formattedText = prettyFormatter.formatStepText("Given ", stepText, formats.get("passed"), formats.get("passed_arg"), createArguments(expression.match(stepText)));
assertThat(formattedText, equalTo(AnsiEscapes.GREEN + "Given " + AnsiEscapes.RESET + AnsiEscapes.GREEN + "text " + AnsiEscapes.RESET + AnsiEscapes.GREEN + AnsiEscapes.INTENSITY_BOLD + "'arg1'" + AnsiEscapes.RESET + AnsiEscapes.GREEN + " text " + AnsiEscapes.RESET + AnsiEscapes.GREEN + AnsiEscapes.INTENSITY_BOLD + "'arg2'" + AnsiEscapes.RESET));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method table_expression_with_list_type_creates_list_of_ingredients_from_table.
@SuppressWarnings("unchecked")
@Test
void table_expression_with_list_type_creates_list_of_ingredients_from_table() {
registry.defineDataTableType(new DataTableType(Ingredient.class, listBeanMapper(registry)));
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", getTypeFromStepDefinition());
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", table);
List<Ingredient> ingredients = (List<Ingredient>) match.get(0).getValue();
Ingredient ingredient = ingredients.get(0);
assertThat(ingredient.amount, is(equalTo(2)));
}
Aggregations