use of io.cucumber.core.stepexpression.StepExpressionFactory 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.stepexpression.StepExpressionFactory 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.stepexpression.StepExpressionFactory in project cucumber-jvm by cucumber.
the class CachingGlue method prepareGlue.
void prepareGlue(StepTypeRegistry stepTypeRegistry) throws DuplicateStepDefinitionException {
StepExpressionFactory stepExpressionFactory = new StepExpressionFactory(stepTypeRegistry, bus);
// TODO: separate prepared and unprepared glue into different classes
parameterTypeDefinitions.forEach(ptd -> {
ParameterType<?> parameterType = ptd.parameterType();
stepTypeRegistry.defineParameterType(parameterType);
emitParameterTypeDefined(parameterType);
});
dataTableTypeDefinitions.forEach(dtd -> stepTypeRegistry.defineDataTableType(dtd.dataTableType()));
docStringTypeDefinitions.forEach(dtd -> stepTypeRegistry.defineDocStringType(dtd.docStringType()));
if (defaultParameterTransformers.size() == 1) {
DefaultParameterTransformerDefinition definition = defaultParameterTransformers.get(0);
ParameterByTypeTransformer transformer = definition.parameterByTypeTransformer();
stepTypeRegistry.setDefaultParameterTransformer(transformer);
} else if (defaultParameterTransformers.size() > 1) {
throw new DuplicateDefaultParameterTransformers(defaultParameterTransformers);
}
if (defaultDataTableEntryTransformers.size() == 1) {
DefaultDataTableEntryTransformerDefinition definition = defaultDataTableEntryTransformers.get(0);
TableEntryByTypeTransformer transformer = definition.tableEntryByTypeTransformer();
stepTypeRegistry.setDefaultDataTableEntryTransformer(transformer);
} else if (defaultDataTableEntryTransformers.size() > 1) {
throw new DuplicateDefaultDataTableEntryTransformers(defaultDataTableEntryTransformers);
}
if (defaultDataTableCellTransformers.size() == 1) {
DefaultDataTableCellTransformerDefinition definition = defaultDataTableCellTransformers.get(0);
TableCellByTypeTransformer transformer = definition.tableCellByTypeTransformer();
stepTypeRegistry.setDefaultDataTableCellTransformer(transformer);
} else if (defaultDataTableCellTransformers.size() > 1) {
throw new DuplicateDefaultDataTableCellTransformers(defaultDataTableCellTransformers);
}
// TODO: Redefine hooks for each scenario, similar to how we're doing
// for CoreStepDefinition
beforeHooks.forEach(this::emitHook);
beforeStepHooks.forEach(this::emitHook);
stepDefinitions.forEach(stepDefinition -> {
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(bus.generateId(), stepDefinition, expression);
CoreStepDefinition previous = stepDefinitionsByPattern.get(stepDefinition.getPattern());
if (previous != null) {
throw new DuplicateStepDefinitionException(previous, stepDefinition);
}
stepDefinitionsByPattern.put(coreStepDefinition.getExpression().getSource(), coreStepDefinition);
emitStepDefined(coreStepDefinition);
});
afterStepHooks.forEach(this::emitHook);
afterHooks.forEach(this::emitHook);
}
use of io.cucumber.core.stepexpression.StepExpressionFactory in project cucumber-jvm by cucumber.
the class PrettyFormatterTest method should_mark_nested_arguments_as_part_of_enclosing_argument.
@Test
void should_mark_nested_arguments_as_part_of_enclosing_argument() {
Formats formats = ansi();
PrettyFormatter prettyFormatter = new PrettyFormatter(new ByteArrayOutputStream());
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);
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));
}
Aggregations