Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Comment columns for slim decision and query tables #401

Merged
merged 3 commits into from

2 participants

@mbarchfe

This enhancement has been discussed before on pivotal as id 3562479 and topic "ignored columns"
It was rated as nice, but not necessary. Comment columns are marked by starting the header with #. This is in conformance to comments used within slim script tables.

Unfortunately, I was not aware of the comment cells mentioned there when I started to implement this feature. Nonetheless, comment columns are more useful than comment cells in my current use case, since I generate wiki pages from Excel sheets.

If there were not much more effort to implement the feature than to pull in the two commits here I would be happy to see this feature in fitness in the future.

Thanks
Markus

commentcolumnquerytable

@amolenaar
Collaborator

If you can update the SliM tables documentation, that would be awesome.

@amolenaar amolenaar added this to the Next release milestone
@mbarchfe

I have updated the wiki documentation in the commented column branch of my fork.

However, what seems odd to me is that fitness.slim.test.ShouldIBuyMilk was removed in November with commit 86acfa3. The wiki page FitNesseRoot/FitNesse/UserGuide/SliM/DecisionTable/content.txt did not work anymore because of that missing class. I have therefore re-added it.

@amolenaar amolenaar merged commit 52c0643 into from
@amolenaar
Collaborator

I think I was I bit rigorous in cleaning up some apparently unused stuff.

It's in. Thanks!

@mbarchfe mbarchfe deleted the branch
@mbarchfe

Thanks for adding the feature. One question concerning the broken user guide. In order to avoid similar problems in the future: Could a check of the status quo of the tests within the user guide be a part of the acceptance test suite?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 5, 2014
  1. @mbarchfe
  2. @mbarchfe
Commits on Feb 9, 2014
  1. @mbarchfe
This page is out of date. Refresh to see the latest.
View
16 FitNesseRoot/FitNesse/UserGuide/SliM/DecisionTable/content.txt
@@ -94,3 +94,19 @@ When exceptions occur in a decision table, they're displayed in line.
| foo | bar | baz? |
| - | | / |
| | * | |
+
+!4 Documentation
+
+If you want to document the data given in a particular row you can just add an extra cell to the right.
+
+| should I buy milk |
+| cash in wallet | credit card | pints of milk remaining | go to store? |
+| 0 | no | 0 | no |
+| 10 | no | 0 | yes | plenty of money but no need for a pint |
+
+For more detailed documentation you can add designated comment columns anywhere. Just prefix the header with a hash symbol.
+
+| should I buy milk |
+| cash in wallet | # comment | credit card | pints of milk remaining | go to store? |
+| -2 | we actually allow negative amounts, meaning debt | no | 0 | no |
+| 1 | must have at least 2 euros | no | 0 | no |
View
7 FitNesseRoot/FitNesse/UserGuide/SliM/QueryTable/content.txt
@@ -58,3 +58,10 @@ The first thing to notice is the ''Query:'' in the first cell of the table. Thi
Each row in the table is checked to see if there is a match in the query response. The fields are matched left to right. If the leftmost field matches, then the row is considered to be "found". Fields that don't matche are marked in error as in the 10-Oct-1974 field above. A cell that is left blank in the table will be filled in from the result and counted as ignored. If the first cell of a row cannot be matched, then the row is considered ''missing''. If there is an unmatched row remaining in the query response, it is added to the table and marked ''surplus''. The order of the rows is irrelevant.
If a !style_code(table) method is declared in the fixture it will be called before the !style_code(query) function is called. It will be passed a list of rows which are themselves lists of cells. The rows and cells represent the all but the first row of the table. This is the same format at the !style_code(doTable) method of Table table, and the !style_code(table) method of Decision table.
+
+In analogy to decision tables you can define comment columns by prefixing the header with the hash symbol.
+
+|Query:employees hired before|10-Dec-1980 |
+|last name|hire date|# comment|
+|Grenning | ||
+|Martin | |we hired him first|
View
38 src/fitnesse/slim/test/ShouldIBuyMilk.java
@@ -0,0 +1,38 @@
+package fitnesse.slim.test;
+
+//Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
+//Released under the terms of the CPL Common Public License version 1.0.
+
+import java.util.List;
+
+public class ShouldIBuyMilk {
+ private int dollars;
+ private int pints;
+ private boolean creditCard;
+
+ public void setCashInWallet(int dollars) {
+ this.dollars = dollars;
+ }
+
+ public void setPintsOfMilkRemaining(int pints) {
+ this.pints = pints;
+ }
+
+ public void setCreditCard(String valid) {
+ creditCard = "yes".equals(valid);
+ }
+
+ public String goToStore() {
+ if (pints == 0 && (dollars > 2 || creditCard))
+ return "yes";
+ else
+ return "no";
+ }
+
+ public void execute() {
+
+ }
+
+ public void table(List<List<String>> table) {
+ }
+}
View
12 src/fitnesse/testsystems/slim/tables/DecisionTable.java
@@ -100,11 +100,13 @@ protected void gatherFunctionsAndVariablesFromColumnHeader() {
private void putColumnHeaderInFunctionOrVariableList(int col) {
String cell = table.getCellContents(col, 1);
- if (cell.endsWith("?") || cell.endsWith("!")) {
- String funcName = cell.substring(0, cell.length() - 1);
- funcStore.add(funcName, col);
- } else {
- varStore.add(cell, col);
+ if (!cell.startsWith("#")) {
+ if (cell.endsWith("?") || cell.endsWith("!")) {
+ String funcName = cell.substring(0, cell.length() - 1);
+ funcStore.add(funcName, col);
+ } else {
+ varStore.add(cell, col);
+ }
}
}
View
15 src/fitnesse/testsystems/slim/tables/QueryTable.java
@@ -14,10 +14,10 @@
import fitnesse.testsystems.slim.Table;
import fitnesse.testsystems.slim.results.SlimExceptionResult;
import fitnesse.testsystems.slim.results.SlimTestResult;
-
import static util.ListUtility.list;
public class QueryTable extends SlimTable {
+ private static final String COMMENT_COLUMN_MARKER = "#";
protected List<String> fieldNames = new ArrayList<String>();
private String queryId;
@@ -165,7 +165,10 @@ protected TestResult markField(int tableRow, int matchedRow, int col, QueryResul
String actualValue = queryResults.getCell(fieldName, matchedRow);
String expectedValue = table.getCellContents(col, tableRow);
SlimTestResult testResult;
- if (actualValue == null)
+ if (fieldName.startsWith(COMMENT_COLUMN_MARKER)) {
+ testResult = SlimTestResult.plain();
+ }
+ else if (actualValue == null)
testResult = SlimTestResult.fail(String.format("field %s not present", fieldName), expectedValue);
else if (expectedValue == null || expectedValue.length() == 0)
testResult = SlimTestResult.ignore(actualValue);
@@ -259,9 +262,11 @@ public int findBestMatch(int tableRow) {
private void eliminateRowsThatDontMatchField() {
String fieldName = fieldNames.get(fieldIndex);
- Iterator<Integer> rowIterator = matchCandidates.iterator();
- while (rowIterator.hasNext())
- eliminateUnmatchingRow(rowIterator, fieldName);
+ if (!fieldName.startsWith(COMMENT_COLUMN_MARKER)) {
+ Iterator<Integer> rowIterator = matchCandidates.iterator();
+ while (rowIterator.hasNext())
+ eliminateUnmatchingRow(rowIterator, fieldName);
+ }
}
private void eliminateUnmatchingRow(Iterator<Integer> rowIterator, String fieldName) {
View
40 test/fitnesse/testsystems/slim/tables/DecisionTableTest.java
@@ -341,6 +341,46 @@ public void translatesTestTablesIntoLiteralTables() throws Exception {
"]";
assertEquals(expectedColorizedTable, colorizedTable);
}
+
+ @Test
+ public void commentColumn() throws Exception {
+ // TODO: a lot of copy and paste from the previous test
+ String decisionTableWithComment =
+ "|DT:fixture|argument||\n" +
+ "|var|func?|#comment|\n" +
+ "|3|5|comment|\n" +
+ "|7|9||\n";
+ DecisionTable dt = makeDecisionTableAndBuildInstructions(decisionTableWithComment);
+ int n=0;
+ Map<String, Object> pseudoResults = SlimCommandRunningClient.resultToMap(
+ list(
+ list(id(n++), "OK"),
+ list(id(n++), VoidConverter.VOID_TAG),
+ list(id(n++), VoidConverter.VOID_TAG), //beginTable
+ list(id(n++), VoidConverter.VOID_TAG), //reset
+ list(id(n++), VoidConverter.VOID_TAG), //set
+ list(id(n++), VoidConverter.VOID_TAG), //execute
+ list(id(n++), "5"),
+ list(id(n++), VoidConverter.VOID_TAG),
+ list(id(n++), VoidConverter.VOID_TAG),
+ list(id(n++), VoidConverter.VOID_TAG),
+ list(id(n++), "5"),
+ list(id(n++), VoidConverter.VOID_TAG) //endTable
+ )
+ );
+ SlimAssertion.evaluateExpectations(assertions, pseudoResults);
+
+ String colorizedTable = dt.getTable().toString();
+ String expectedColorizedTable =
+ "[" +
+ "[pass(DT:fixture), argument, ], " +
+ "[var, func?, #comment], " +
+ "[3, pass(5), comment], " +
+ "[7, fail(a=5;e=9), ]" +
+ "]";
+ assertEquals(expectedColorizedTable, colorizedTable);
+ }
+
@Test
public void canEvaluateReturnValuesAndColorizeTableForMultipleCallsToSameFunction() throws Exception {
View
27 test/fitnesse/testsystems/slim/tables/QueryTableTestBase.java
@@ -283,6 +283,33 @@ public void variablesAreReplacedInMatch() throws Exception {
}
@Test
+ public void commentColumn() throws Exception {
+ queryTableHeader =
+ "|" + tableType() + ":fixture|argument|\n" +
+ "|#comment1|n|#comment2|\n";
+
+
+ assertQueryResults(
+ "|first|1|comment|\n"+
+ "|second|2||\n" ,
+ ListUtility.<Object>list(
+ // trying to ensure that the comment field does not participate in
+ // row matching
+ // if comments were not ignored, the best match would be set from the comment fields
+ list(list("#comment1", "second"), list("n", "1"), list("#comment2", "")),
+ list(list("#comment1", "first"), list("n", "2"), list("#comment2", "comment"))
+ ),
+ "[" +
+ headRow +
+ "[#comment1, n, #comment2], " +
+ "[first, pass(1), comment], " +
+ "[second, pass(2), ]" +
+ "]"
+ );
+
+ }
+
+ @Test
public void variablesAreReplacedInExpected() throws Exception {
makeQueryTableAndBuildInstructions(queryTableHeader + "|2|$V|\n");
qt.setSymbol("V", "5");
Something went wrong with that request. Please try again.