Skip to content

Commit

Permalink
Refined reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Oct 13, 2018
1 parent dbfd476 commit 2e33342
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private List<CucumberFeature> loadCucumberFeatures(MultiLoader multiLoader, List
Object featureLoader = featureLoaderClass.getConstructor(ResourceLoader.class).newInstance(multiLoader);
return (List<CucumberFeature>)load.invoke(featureLoader, listOfFiles);
} catch(ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException cucumber4Exception) {
LOGGER.info("Found no Cucumber 4.x.x class " + CUCUMBER_4_FEATURE_LOADER + " try Cucumber 2.x.x ");
LOGGER.debug("Found no Cucumber 4.x.x class " + CUCUMBER_4_FEATURE_LOADER + " try Cucumber 2.x.x ");
try {
Class<?> featureLoaderClass = CucumberParser.class.getClassLoader().loadClass(CUCUMBER_2_FEATURE_LOADER);
Method load = featureLoaderClass.getMethod("load", ResourceLoader.class,List.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Optional<String> asGivenWhenThen(ScenarioDisplayOption displayOption) {
suffix = resultToken();
}
renderedDescription += scenarioDefinition.getSteps().stream()
.map(step -> " > " + RenderCucumber.step(step) + " ")
.map(step -> RenderCucumber.step(step) + " ")
.collect(Collectors.joining(lineSeparator())) + suffix;

renderedDescription += System.lineSeparator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RenderMarkdown {
private final String originalText;
private final List<String> lines;

private final static Pattern DATA_TABLE_LINE = Pattern.compile("\\|.*\\|");
private final static Pattern DATA_TABLE_LINE = Pattern.compile("\\s*\\|.*\\|\\s*");
private final static Pattern SEPARATOR_LINE = Pattern.compile("\\|(-|\\s|\\|)+\\|");

private final static Pattern INLINED_TABLE = Pattern.compile("[^\\r\\n\\t\\f\\v\\|](\\r?\\n)\\|");
Expand All @@ -31,11 +31,31 @@ public static String convertEmbeddedTablesIn(String text) {
}

public static String preprocessMarkdownTables(String text) {
if (!INLINED_TABLE.matcher(text).find()) {
return text;

return new RenderMarkdown(text).injectNewLineBeforeTables();


// if (!INLINED_TABLE.matcher(text).find()) {
// return text;
// }
//
// return INLINED_TABLE.matcher(text).replaceFirst(System.lineSeparator() + System.lineSeparator() + "|");
}

private String injectNewLineBeforeTables() {
List<NarrativeBlock> blocks = convertToBlocks(lines);
List<String> spacedLines = new ArrayList<>();

for(NarrativeBlock block: blocks) {
if (block.isTable()) {
spacedLines.add(System.lineSeparator());
spacedLines.addAll(block.lines);
} else {
spacedLines.addAll(block.lines);
}
}

return INLINED_TABLE.matcher(text).replaceFirst(System.lineSeparator() + System.lineSeparator() + "|");
return spacedLines.stream().collect(Collectors.joining(System.lineSeparator()));
}

private String convertTables() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ private String convertTablesToMarkdown(String text) {

public String renderDescriptionWithEmbeddedResults(final String text, RequirementsOutcomes requirementsOutcomes) {

String textWithResults = textWithEmbeddedExampleResults(textWithEmbeddedResults(text, requirementsOutcomes), requirementsOutcomes);
String textWithResults = RenderMarkdown.preprocessMarkdownTables(
textWithEmbeddedExampleResults(textWithEmbeddedResults(text, requirementsOutcomes), requirementsOutcomes));
return wrapTablesInDivs(renderDescription(textWithResults),"example-table example-table-in-summary");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,20 @@ public void formatter_should_prepare_tables_for_markdown() {
assertThat(formatter.renderHtmlEscapedDescription(description), containsString("<table"));
}

@Test
public void formatter_should_inject_lines_before() {
String description = "Given a business with the following details:\n" +
"| Name | Category |\n" +
"|---|---|\n" +
"| ACME | Casino |\n";

assertThat(RenderMarkdown.preprocessMarkdownTables(description), equalTo(
"Given a business with the following details:\n\n\n" +
"| Name | Category |\n" +
"|---|---|\n" +
"| ACME | Casino |"));
}

@Test
public void should_split_up_given_when_then_statements() {
String statement = "Given a calculator\n" +
Expand Down

0 comments on commit 2e33342

Please sign in to comment.