Search in sources :

Example 1 with Argument

use of io.cucumber.plugin.event.Argument in project cucumber-jvm by cucumber.

the class JsonFormatter method createMatchMap.

private Map<String, Object> createMatchMap(TestStep step, Result result) {
    Map<String, Object> matchMap = new HashMap<>();
    if (step instanceof PickleStepTestStep) {
        PickleStepTestStep testStep = (PickleStepTestStep) step;
        if (!testStep.getDefinitionArgument().isEmpty()) {
            List<Map<String, Object>> argumentList = new ArrayList<>();
            for (Argument argument : testStep.getDefinitionArgument()) {
                Map<String, Object> argumentMap = new HashMap<>();
                if (argument.getValue() != null) {
                    argumentMap.put("val", argument.getValue());
                    argumentMap.put("offset", argument.getStart());
                }
                argumentList.add(argumentMap);
            }
            matchMap.put("arguments", argumentList);
        }
    }
    if (!result.getStatus().is(Status.UNDEFINED)) {
        matchMap.put("location", step.getCodeLocation());
    }
    return matchMap;
}
Also used : PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) DocStringArgument(io.cucumber.plugin.event.DocStringArgument) StepArgument(io.cucumber.plugin.event.StepArgument) Argument(io.cucumber.plugin.event.Argument) DataTableArgument(io.cucumber.plugin.event.DataTableArgument) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with Argument

use of io.cucumber.plugin.event.Argument in project syndesis-qe by syndesisio.

the class PrettyFormatter method formatStepText.

String formatStepText(String keyword, String stepText, Format textFormat, Format argFormat, List<Argument> arguments) {
    int beginIndex = 0;
    StringBuilder result = new StringBuilder(textFormat.text(keyword));
    for (Argument argument : arguments) {
        // can be null if the argument is missing.
        if (argument.getValue() != null) {
            int argumentOffset = argument.getStart();
            // ignore it when formatting
            if (argumentOffset < beginIndex) {
                continue;
            }
            String text = stepText.substring(beginIndex, argumentOffset);
            result.append(textFormat.text(text));
        }
        if (argument.getValue() != null) {
            String text = stepText.substring(argument.getStart(), argument.getEnd());
            result.append(argFormat.text(text));
            // set beginIndex to end of argument
            beginIndex = argument.getEnd();
        }
    }
    if (beginIndex != stepText.length()) {
        String text = stepText.substring(beginIndex);
        result.append(textFormat.text(text));
    }
    return result.toString();
}
Also used : Argument(io.cucumber.plugin.event.Argument)

Example 3 with Argument

use of io.cucumber.plugin.event.Argument in project cucumber-jvm by cucumber.

the class PrettyFormatter method formatStepText.

String formatStepText(String keyword, String stepText, Format textFormat, Format argFormat, List<Argument> arguments) {
    int beginIndex = 0;
    StringBuilder result = new StringBuilder(textFormat.text(keyword));
    for (Argument argument : arguments) {
        // can be null if the argument is missing.
        if (argument.getValue() != null) {
            int argumentOffset = argument.getStart();
            // ignore it when formatting
            if (argumentOffset < beginIndex) {
                continue;
            }
            String text = stepText.substring(beginIndex, argumentOffset);
            result.append(textFormat.text(text));
        }
        // @And("(it )?has something")
        if (argument.getValue() != null) {
            String text = stepText.substring(argument.getStart(), argument.getEnd());
            result.append(argFormat.text(text));
            // set beginIndex to end of argument
            beginIndex = argument.getEnd();
        }
    }
    if (beginIndex != stepText.length()) {
        String text = stepText.substring(beginIndex);
        result.append(textFormat.text(text));
    }
    return result.toString();
}
Also used : StepArgument(io.cucumber.plugin.event.StepArgument) Argument(io.cucumber.plugin.event.Argument) DataTableArgument(io.cucumber.core.gherkin.DataTableArgument)

Example 4 with Argument

use of io.cucumber.plugin.event.Argument in project cucumber-jvm by cucumber.

the class DefinitionArgument method createArguments.

static List<Argument> createArguments(List<io.cucumber.core.stepexpression.Argument> match) {
    List<Argument> args = new ArrayList<>();
    for (io.cucumber.core.stepexpression.Argument argument : match) {
        if (argument instanceof ExpressionArgument) {
            ExpressionArgument expressionArgument = (ExpressionArgument) argument;
            args.add(new DefinitionArgument(expressionArgument));
        }
    }
    return args;
}
Also used : ExpressionArgument(io.cucumber.core.stepexpression.ExpressionArgument) Argument(io.cucumber.plugin.event.Argument) ArrayList(java.util.ArrayList) ExpressionArgument(io.cucumber.core.stepexpression.ExpressionArgument)

Aggregations

Argument (io.cucumber.plugin.event.Argument)4 StepArgument (io.cucumber.plugin.event.StepArgument)2 ArrayList (java.util.ArrayList)2 DataTableArgument (io.cucumber.core.gherkin.DataTableArgument)1 ExpressionArgument (io.cucumber.core.stepexpression.ExpressionArgument)1 DataTableArgument (io.cucumber.plugin.event.DataTableArgument)1 DocStringArgument (io.cucumber.plugin.event.DocStringArgument)1 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1