01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import fitnesse.wiki.InMemoryPage;
06: import fitnesse.wiki.PageCrawler;
07: import fitnesse.wiki.PathParser;
08: import fitnesse.wiki.WikiPage;
09:
10: public class SuiteWidgetTest extends AbstractWidget {
11: private WikiPage root;
12:
13: private WikiPage parent;
14:
15: private PageCrawler crawler;
16:
17: public void setUp() throws Exception {
18: root = InMemoryPage.makeRoot("RooT");
19: crawler = root.getPageCrawler();
20: parent = crawler.addPage(root, PathParser.parse("ParenT"),
21: "parent");
22: crawler.addPage(root, PathParser.parse("ParentTwo"),
23: "parent two");
24: crawler
25: .addPage(parent, PathParser.parse("ChildOne"),
26: "content");
27: crawler
28: .addPage(parent, PathParser.parse("ChildTwo"),
29: "content");
30: }
31:
32: public void testMatch() throws Exception {
33: // Well formed
34: assertMatchEquals("!" + SuiteWidget.WIDGET_NAME, "!"
35: + SuiteWidget.WIDGET_NAME);
36: assertMatchEquals("!" + SuiteWidget.WIDGET_NAME + "\n", "!"
37: + SuiteWidget.WIDGET_NAME);
38: assertMatchEquals("!" + SuiteWidget.WIDGET_NAME + " -R\n", "!"
39: + SuiteWidget.WIDGET_NAME + " -R");
40: assertMatchEquals("!" + SuiteWidget.WIDGET_NAME + "\r", "!"
41: + SuiteWidget.WIDGET_NAME);
42: assertMatchEquals("!" + SuiteWidget.WIDGET_NAME + " -R\r", "!"
43: + SuiteWidget.WIDGET_NAME + " -R");
44: assertMatchEquals("!" + SuiteWidget.WIDGET_NAME + " \n", "!"
45: + SuiteWidget.WIDGET_NAME + " ");
46:
47: // No whitespace on the left
48: assertMatchEquals(" !" + SuiteWidget.WIDGET_NAME + "\n", null);
49: assertMatchEquals(" !" + SuiteWidget.WIDGET_NAME + " -R\n",
50: null);
51:
52: // Don't render the widget if anything follows the name
53: assertMatchEquals("!" + SuiteWidget.WIDGET_NAME + " zap\n",
54: null);
55: }
56:
57: public void testIsNotHierarchical() throws Exception {
58: assertFalse(new SuiteWidget(new WidgetRoot(parent), "!"
59: + SuiteWidget.WIDGET_NAME + "\n").isRecursive());
60: }
61:
62: public void testIsHierarchical() throws Exception {
63: assertTrue(new SuiteWidget(new WidgetRoot(parent), "!"
64: + SuiteWidget.WIDGET_NAME + " -R\n").isRecursive());
65: }
66:
67: protected String getRegexp() {
68: return SuiteWidget.REGEXP;
69: }
70: }
|