@Test public void testArgumentAtEnd() { String stepName = "1A"; Argument[] arguments = { new Argument("1", 0) }; String simulatedStepDefinition = StepDefinitionUtil.simulateMatchingStepDefinition(stepName, arguments); assertThat(simulatedStepDefinition).isEqualTo("^(\\d+)A$"); }
public static String simulateMatchingStepDefinition(String stepName, Argument[] arguments) { StringBuilder builder = new StringBuilder(); builder.append("^"); int lastIndex = 0; for (Argument argument : arguments) { if (argument.getOffset() > lastIndex) { builder.append(escapeRegularExpression(stepName.substring(lastIndex, argument.getOffset()))); } boolean isNumeric = StringUtils.isNotEmpty(argument.getVal()) && StringUtils.isNumeric(argument.getVal()); if (isNumeric && argument.getOffset() > 0 && stepName.charAt(argument.getOffset() - 1) == '"') { isNumeric = false; } if (isNumeric) { builder.append("(\\d+)"); } else { builder.append("([^\"]*)"); } lastIndex = argument.getOffset() + argument.getVal().length(); } if (lastIndex < stepName.length()) { builder.append(escapeRegularExpression(stepName.substring(lastIndex))); } builder.append("$"); return builder.toString(); }
StepDefinitionUtil { public static String simulateMatchingStepDefinition(String stepName, Argument[] arguments) { StringBuilder builder = new StringBuilder(); builder.append("^"); int lastIndex = 0; for (Argument argument : arguments) { if (argument.getOffset() > lastIndex) { builder.append(escapeRegularExpression(stepName.substring(lastIndex, argument.getOffset()))); } boolean isNumeric = StringUtils.isNotEmpty(argument.getVal()) && StringUtils.isNumeric(argument.getVal()); if (isNumeric && argument.getOffset() > 0 && stepName.charAt(argument.getOffset() - 1) == '"') { isNumeric = false; } if (isNumeric) { builder.append("(\\d+)"); } else { builder.append("([^\"]*)"); } lastIndex = argument.getOffset() + argument.getVal().length(); } if (lastIndex < stepName.length()) { builder.append(escapeRegularExpression(stepName.substring(lastIndex))); } builder.append("$"); return builder.toString(); } }
StepDefinitionUtil { public static String simulateMatchingStepDefinition(String stepName, Argument[] arguments) { StringBuilder builder = new StringBuilder(); builder.append("^"); int lastIndex = 0; for (Argument argument : arguments) { if (argument.getOffset() > lastIndex) { builder.append(escapeRegularExpression(stepName.substring(lastIndex, argument.getOffset()))); } boolean isNumeric = StringUtils.isNotEmpty(argument.getVal()) && StringUtils.isNumeric(argument.getVal()); if (isNumeric && argument.getOffset() > 0 && stepName.charAt(argument.getOffset() - 1) == '"') { isNumeric = false; } if (isNumeric) { builder.append("(\\d+)"); } else { builder.append("([^\"]*)"); } lastIndex = argument.getOffset() + argument.getVal().length(); } if (lastIndex < stepName.length()) { builder.append(escapeRegularExpression(stepName.substring(lastIndex))); } builder.append("$"); return builder.toString(); }  }
StepDefinitionUtil { public static String simulateMatchingStepDefinition(String stepName, Argument[] arguments) { StringBuilder builder = new StringBuilder(); builder.append("^"); int lastIndex = 0; for (Argument argument : arguments) { if (argument.getOffset() > lastIndex) { builder.append(escapeRegularExpression(stepName.substring(lastIndex, argument.getOffset()))); } boolean isNumeric = StringUtils.isNotEmpty(argument.getVal()) && StringUtils.isNumeric(argument.getVal()); if (isNumeric && argument.getOffset() > 0 && stepName.charAt(argument.getOffset() - 1) == '"') { isNumeric = false; } if (isNumeric) { builder.append("(\\d+)"); } else { builder.append("([^\"]*)"); } lastIndex = argument.getOffset() + argument.getVal().length(); } if (lastIndex < stepName.length()) { builder.append(escapeRegularExpression(stepName.substring(lastIndex))); } builder.append("$"); return builder.toString(); }  static List<String> parseStepDefinitionsJson(String stepDefinitionsJson); static String extractStepDefinition(ResultsWithMatch stepOrHook, String hookName, List<String> stepDefinitions); static String simulateMatchingStepDefinition(String stepName, Argument[] arguments); }
StepDefinitionUtil { public static String simulateMatchingStepDefinition(String stepName, Argument[] arguments) { StringBuilder builder = new StringBuilder(); builder.append("^"); int lastIndex = 0; for (Argument argument : arguments) { if (argument.getOffset() > lastIndex) { builder.append(escapeRegularExpression(stepName.substring(lastIndex, argument.getOffset()))); } boolean isNumeric = StringUtils.isNotEmpty(argument.getVal()) && StringUtils.isNumeric(argument.getVal()); if (isNumeric && argument.getOffset() > 0 && stepName.charAt(argument.getOffset() - 1) == '"') { isNumeric = false; } if (isNumeric) { builder.append("(\\d+)"); } else { builder.append("([^\"]*)"); } lastIndex = argument.getOffset() + argument.getVal().length(); } if (lastIndex < stepName.length()) { builder.append(escapeRegularExpression(stepName.substring(lastIndex))); } builder.append("$"); return builder.toString(); }  static List<String> parseStepDefinitionsJson(String stepDefinitionsJson); static String extractStepDefinition(ResultsWithMatch stepOrHook, String hookName, List<String> stepDefinitions); static String simulateMatchingStepDefinition(String stepName, Argument[] arguments);  }