Skip to content

Commit

Permalink
Add support for output parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fhoeben committed Jan 24, 2015
1 parent fde7420 commit 7d29a5b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>nl.hsac</groupId>
<artifactId>hsac-fitnesse-plugin</artifactId>
<version>1.8.0</version>
<version>1.8.1</version>
<packaging>jar</packaging>
<url>https://github.com/fhoeben/hsac-fitnesse-plugin</url>

Expand Down
21 changes: 17 additions & 4 deletions src/main/java/nl/hsac/fitnesse/slim/AutoArgScenarioTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@
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<String> inputs;
private Set<String> outputs;

public AutoArgScenarioTable(Table table, String tableId, SlimTestContext testContext) {
super(table, tableId, testContext);
}

@Override
public List<SlimAssertion> getAssertions() throws SyntaxError {
inputs = findInputs();
inputs = findArguments(ARG_PATTERN);
outputs = findArguments(OUT_PATTERN);
return super.getAssertions();
}

Expand All @@ -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<String> findInputs() {
private Set<String> findArguments(Pattern pattern) {
Set<String> found = new LinkedHashSet<String>();
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);
Expand Down

0 comments on commit 7d29a5b

Please sign in to comment.