From 7d29a5b1392a315831e2db0debbc165fd7d939a5 Mon Sep 17 00:00:00 2001 From: Fried Hoeben Date: Sat, 24 Jan 2015 13:01:05 +0100 Subject: [PATCH] Add support for output parameters --- pom.xml | 2 +- .../fitnesse/slim/AutoArgScenarioTable.java | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 8936151..9f214c5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ nl.hsac hsac-fitnesse-plugin - 1.8.0 + 1.8.1 jar https://github.com/fhoeben/hsac-fitnesse-plugin diff --git a/src/main/java/nl/hsac/fitnesse/slim/AutoArgScenarioTable.java b/src/main/java/nl/hsac/fitnesse/slim/AutoArgScenarioTable.java index be8c478..9676730 100644 --- a/src/main/java/nl/hsac/fitnesse/slim/AutoArgScenarioTable.java +++ b/src/main/java/nl/hsac/fitnesse/slim/AutoArgScenarioTable.java @@ -13,13 +13,15 @@ import java.util.regex.Pattern; /** - * ScenarioTable that looks for input parameters in all its rows, without the + * ScenarioTable that looks for in- and output parameters in all its rows, without the * parameters having to be specified in the first row also. */ public class AutoArgScenarioTable extends ScenarioTable { private final static Pattern ARG_PATTERN = Pattern.compile("@\\{(.+?)\\}"); + private static final Pattern OUT_PATTERN = Pattern.compile("\\$(.+?)="); private Set inputs; + private Set outputs; public AutoArgScenarioTable(Table table, String tableId, SlimTestContext testContext) { super(table, tableId, testContext); @@ -27,7 +29,8 @@ public AutoArgScenarioTable(Table table, String tableId, SlimTestContext testCon @Override public List getAssertions() throws SyntaxError { - inputs = findInputs(); + inputs = findArguments(ARG_PATTERN); + outputs = findArguments(OUT_PATTERN); return super.getAssertions(); } @@ -41,16 +44,26 @@ protected void getScenarioArguments() { for (String input : inputs) { addInput(input); } + for (String output : outputs) { + addOutput(output); + } + } + + private void addOutput(String argument) { + // if my pull request (https://github.com/unclebob/fitnesse/pull/592) gets + // merged output adding will have to be done that same as for input + // then this method can be deleted in this class + getOutputs().add(argument); } - private Set findInputs() { + private Set findArguments(Pattern pattern) { Set found = new LinkedHashSet(); int rowCount = table.getRowCount(); for (int row = 0; row < rowCount; row++) { int columnCount = table.getColumnCountInRow(row); for (int column = 0; column < columnCount; column++) { String cellContent = table.getCellContents(column, row); - Matcher m = ARG_PATTERN.matcher(cellContent); + Matcher m = pattern.matcher(cellContent); while (m.find()) { String input = m.group(1); found.add(input);