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("^(.*)$"));
}
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")));
}
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"));
}
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"));
}
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"));
}
Aggregations