Search in sources :

Example 1 with Expression

use of io.cucumber.cucumberexpressions.Expression in project cucumber-jvm by cucumber.

the class StepTypeRegistryTest method should_define_parameter_type.

@Test
void should_define_parameter_type() {
    ParameterType<Object> expected = new ParameterType<>("example", ".*", Object.class, (String s) -> null);
    registry.defineParameterType(expected);
    Expression expresion = expressionFactory.createExpression("{example}");
    assertThat(expresion.getRegexp().pattern(), is("^(.*)$"));
}
Also used : ParameterType(io.cucumber.cucumberexpressions.ParameterType) Expression(io.cucumber.cucumberexpressions.Expression) Test(org.junit.jupiter.api.Test)

Example 2 with Expression

use of io.cucumber.cucumberexpressions.Expression in project cucumber-jvm by cucumber.

the class JavaParameterTypeDefinitionTest method converter_may_have_non_generic_return_type.

@Test
void converter_may_have_non_generic_return_type() throws NoSuchMethodException {
    Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_capture_group_to_optional_string", String.class);
    JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", "(.*)", method, false, false, false, lookup);
    registry.defineParameterType(definition.parameterType());
    Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_capture_group_to_optional_string}");
    List<Argument<?>> args = cucumberExpression.match("convert_capture_group_to_optional_string");
    assertThat(args.get(0).getValue(), is(Optional.of("convert_capture_group_to_optional_string")));
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 3 with Expression

use of io.cucumber.cucumberexpressions.Expression in project cucumber-jvm by cucumber.

the class JavaParameterTypeDefinitionTest method can_define_parameter_type_converters_with_two_capture_groups.

@Test
void can_define_parameter_type_converters_with_two_capture_groups() throws NoSuchMethodException {
    Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_two_capture_group_to_string", String.class, String.class);
    JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", "([^ ]*) ([^ ]*)", method, false, false, false, lookup);
    registry.defineParameterType(definition.parameterType());
    Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_two_capture_group_to_string}");
    List<Argument<?>> test = cucumberExpression.match("test test");
    assertThat(test.get(0).getValue(), equalTo("convert_two_capture_group_to_string"));
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 4 with Expression

use of io.cucumber.cucumberexpressions.Expression in project cucumber-jvm by cucumber.

the class JavaParameterTypeDefinitionTest method can_define_parameter_type_converters_with_one_capture_group.

@Test
void can_define_parameter_type_converters_with_one_capture_group() throws NoSuchMethodException {
    Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_one_capture_group_to_string", String.class);
    JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", "(.*)", method, false, false, false, lookup);
    registry.defineParameterType(definition.parameterType());
    Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_one_capture_group_to_string}");
    List<Argument<?>> test = cucumberExpression.match("test");
    assertThat(test.get(0).getValue(), equalTo("convert_one_capture_group_to_string"));
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 5 with Expression

use of io.cucumber.cucumberexpressions.Expression in project cucumber-jvm by cucumber.

the class JavaParameterTypeDefinitionTest method can_define_parameter_type_converters_with_var_args.

@Test
void can_define_parameter_type_converters_with_var_args() throws NoSuchMethodException {
    Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_varargs_capture_group_to_string", String[].class);
    JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", "([^ ]*) ([^ ]*)", method, false, false, false, lookup);
    registry.defineParameterType(definition.parameterType());
    Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_varargs_capture_group_to_string}");
    List<Argument<?>> test = cucumberExpression.match("test test");
    assertThat(test.get(0).getValue(), equalTo("convert_varargs_capture_group_to_string"));
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Aggregations

Expression (io.cucumber.cucumberexpressions.Expression)7 ExpressionFactory (io.cucumber.cucumberexpressions.ExpressionFactory)6 Test (org.junit.jupiter.api.Test)6 Argument (io.cucumber.cucumberexpressions.Argument)5 Method (java.lang.reflect.Method)5 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1 StepDefinition (io.cucumber.core.backend.StepDefinition)1 EventBus (io.cucumber.core.eventbus.EventBus)1 CucumberException (io.cucumber.core.exception.CucumberException)1 ParameterType (io.cucumber.cucumberexpressions.ParameterType)1 UndefinedParameterTypeException (io.cucumber.cucumberexpressions.UndefinedParameterTypeException)1 DataTable (io.cucumber.datatable.DataTable)1 DataTableTypeRegistryTableConverter (io.cucumber.datatable.DataTableTypeRegistryTableConverter)1 DocString (io.cucumber.docstring.DocString)1 DocStringTypeRegistryDocStringConverter (io.cucumber.docstring.DocStringTypeRegistryDocStringConverter)1 Envelope (io.cucumber.messages.types.Envelope)1 UndefinedParameterType (io.cucumber.messages.types.UndefinedParameterType)1 String.format (java.lang.String.format)1 Type (java.lang.reflect.Type)1 List (java.util.List)1