Skip to content

Commit

Permalink
Fitnesse Issue unclebob#461 - Have !today option work if arguments fo…
Browse files Browse the repository at this point in the history
…llowed by other text.
  • Loading branch information
mwarhaftig committed Sep 12, 2014
1 parent 6e1f684 commit 0a087d0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions parserTokens.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ http:// and https:// link
| table
} close brace
}}} close preformat
-xml and -t date format option
4 changes: 2 additions & 2 deletions src/fitnesse/wikitext/parser/Include.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public Maybe<Symbol> parse(Symbol current, Parser parser) {

next = parser.moveNext(1);
String option = "";
if (next.isType(SymbolType.Text) && next.getContent().startsWith("-")) {
option = next.getContent();
if ((next.isType(SymbolType.Text) && next.getContent().startsWith("-")) || next.isType(SymbolType.DateFormatOption)) {
option = next.getContent() + (next.isType(SymbolType.DateFormatOption) ? parser.moveNext(1).getContent() : "");
next = parser.moveNext(1);
if (!next.isType(SymbolType.Whitespace)) return Symbol.nothing;
next = parser.moveNext(1);
Expand Down
2 changes: 1 addition & 1 deletion src/fitnesse/wikitext/parser/SymbolProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ See.symbolType, SymbolType.Style, new LastModified(), Image.symbolType,
Evaluator.symbolType, SymbolType.CloseEvaluator, Variable.symbolType, Preformat.symbolType,
SymbolType.ClosePreformat, SymbolType.OpenParenthesis, SymbolType.OpenBrace, SymbolType.OpenBracket, SymbolType.CloseNesting,
SymbolType.CloseParenthesis, SymbolType.CloseBrace, SymbolType.ClosePlainTextTable, SymbolType.CloseBracket, SymbolType.CloseLiteral,
SymbolType.Bold,
SymbolType.Bold, SymbolType.DateFormatOption,
SymbolType.Italic, SymbolType.Strike, new AnchorReference(), WikiWord.symbolType, SymbolType.EMail, SymbolType.Text,
});

Expand Down
3 changes: 3 additions & 0 deletions src/fitnesse/wikitext/parser/SymbolType.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public Maybe<Symbol> parse(Symbol current, Parser parser) {
.wikiMatcher(new Matcher().string(":"));
public static final SymbolType Comma = new SymbolType("Comma")
.wikiMatcher(new Matcher().string(","));
public static final SymbolType DateFormatOption = new SymbolType("DateFormatOption")
.wikiMatcher(new Matcher().string("-xml"))
.wikiMatcher(new Matcher().string("-t"));
public static final SymbolType Delta = new SymbolType("Delta")
.wikiMatcher(new Matcher().string("+").digits())
.wikiMatcher(new Matcher().string("-").digits());
Expand Down
2 changes: 1 addition & 1 deletion src/fitnesse/wikitext/parser/Today.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected Today(String symbolName, String symbolText, int unitForIncrement) {
}

public Maybe<Symbol> parse(Symbol current, Parser parser) {
List<Symbol> lookAhead = parser.peek(new SymbolType[] {SymbolType.Whitespace, SymbolType.Text});
List<Symbol> lookAhead = parser.peek(new SymbolType[] {SymbolType.Whitespace, SymbolType.DateFormatOption});
if (lookAhead.size() != 0 ) {
String option = lookAhead.get(1).getContent();
if (isDateFormatOption(option)) {
Expand Down
4 changes: 3 additions & 1 deletion test/fitnesse/wikitext/parser/TodayExtensionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public void translatesMonthsFromTodays() {
ParserTestHelper.assertTranslatesTo("!monthsFromToday (MMM)", "Mar");
ParserTestHelper.assertTranslatesTo("!monthsFromToday (dd MMM)", "04 Mar");
ParserTestHelper.assertTranslatesTo("!monthsFromToday (dd MMM", "!monthsFromToday (dd MMM");
ParserTestHelper.assertTranslatesTo("!monthsFromToday -t.", "04 Mar, 2003 15:06.");
ParserTestHelper.assertTranslatesTo("!monthsFromToday -xml.", "2003-03-04T15:06:07.");
}

@Test
Expand All @@ -49,7 +51,7 @@ public void translatesWithDayIncrementsAndCustomFormat() {
@Test
public void translatesInTable() {
ParserTestHelper.assertTranslatesTo("|!monthsFromToday (ddMMM)|\n", ParserTestHelper.tableWithCell("04Mar"));
ParserTestHelper.assertTranslatesTo("|!monthsFromToday -t +2|\n", ParserTestHelper.tableWithCell("04 May, 2003 15:06"));
ParserTestHelper.assertTranslatesTo("|!monthsFromToday -t +2.|\n", ParserTestHelper.tableWithCell("04 May, 2003 15:06."));
}

private static class MonthsFromToday extends Today {
Expand Down
4 changes: 3 additions & 1 deletion test/fitnesse/wikitext/parser/TodayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public void translatesTodays() {
ParserTestHelper.assertTranslatesTo("!today (MMM)", "Mar");
ParserTestHelper.assertTranslatesTo("!today (dd MMM)", "04 Mar");
ParserTestHelper.assertTranslatesTo("!today (dd MMM", "!today (dd MMM");
ParserTestHelper.assertTranslatesTo("!today -t.", "04 Mar, 2002 15:06.");
ParserTestHelper.assertTranslatesTo("!today -xml.", "2002-03-04T15:06:07.");
}

@Test
Expand All @@ -46,6 +48,6 @@ public void translatesWithDayIncrementsAndCustomFormat() {
@Test
public void translatesInTable() {
ParserTestHelper.assertTranslatesTo("|!today (ddMMM)|\n", ParserTestHelper.tableWithCell("04Mar"));
ParserTestHelper.assertTranslatesTo("|!today -t|\n", ParserTestHelper.tableWithCell("04 Mar, 2002 15:06"));
ParserTestHelper.assertTranslatesTo("|!today -t.|\n", ParserTestHelper.tableWithCell("04 Mar, 2002 15:06."));
}
}

0 comments on commit 0a087d0

Please sign in to comment.