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.html.HtmlUtil;
06: import fitnesse.wiki.*;
07: import fitnesse.wikitext.WikiWidget;
08:
09: public class VariableDefinitionWidgetTest extends AbstractWidget {
10: public WikiPage root;
11:
12: private PageCrawler crawler;
13:
14: private WidgetRoot widgetRoot;
15:
16: protected String getRegexp() {
17: return VariableDefinitionWidget.REGEXP;
18: }
19:
20: public void setUp() throws Exception {
21: root = InMemoryPage.makeRoot("RooT");
22: crawler = root.getPageCrawler();
23: }
24:
25: public void tearDown() throws Exception {
26: }
27:
28: public void testRegexp() throws Exception {
29: assertMatches("!define xyz {\n123\r\n456\r\n}");
30: assertMatches("!define abc {1}");
31: assertMatches("!define abc (1)");
32: assertNoMatch("!define");
33: assertNoMatch("!define x");
34: assertNoMatch(" !define x {1}");
35: assertMatches("!define x (!define y {123})");
36: }
37:
38: public void testHtml() throws Exception {
39: WikiPage page = crawler.addPage(root, PathParser
40: .parse("MyPage"), "content");
41: WikiPage page2 = crawler.addPage(root, PathParser
42: .parse("SecondPage"), "content");
43:
44: widgetRoot = new WidgetRoot(page);
45: VariableDefinitionWidget widget = new VariableDefinitionWidget(
46: widgetRoot, "!define x {1}\n");
47: assertEquals("<span class=\"meta\">"
48: + VariableDefinitionWidget.defineLabel + "x=1</span>",
49: widget.render());
50: assertEquals("1", widgetRoot.getVariable("x"));
51:
52: widgetRoot = new WidgetRoot(page2);
53: widget = new VariableDefinitionWidget(widgetRoot,
54: "!define xyzzy (\nbird\n)\n");
55: widget.render();
56: assertEquals("\nbird\n", widgetRoot.getVariable("xyzzy"));
57: }
58:
59: public void testRenderedText() throws Exception {
60: WikiWidget widget = new VariableDefinitionWidget(
61: new WidgetRoot(root), "!define x (1)\n");
62: String renderedText = widget.render();
63: assertSubString("x", renderedText);
64: assertSubString("1", renderedText);
65: }
66:
67: public void testDefinePrecedingClasspath() throws Exception {
68: WikiPage root = InMemoryPage.makeRoot("RooT");
69: PageData data = root.getData();
70: String content = "!define SOME_VARIABLE {Variable #1}\n!path c:\\dotnet\\*.dll";
71: data.setContent(content);
72: root.commit(data);
73: assertEquals("Variable #1", data.getVariable("SOME_VARIABLE"));
74: assertEquals(1, data.getClasspaths().size());
75: assertEquals("c:\\dotnet\\*.dll", data.getClasspaths().get(0));
76: }
77:
78: public void testNoExtraLineBreakInHtml() throws Exception {
79: WikiPage root = InMemoryPage.makeRoot("RooT");
80: PageData data = root.getData();
81: String content = "!define SOME_VARIABLE {Variable #1}\n!define ANOTHER_VARIABLE {Variable #2}";
82: data.setContent(content);
83: assertSubString("SOME_VARIABLE=Variable #1</span>"
84: + HtmlUtil.BR + "<span", data.getHtml());
85: assertNotSubString("SOME_VARIABLE=Variable #1</span>"
86: + HtmlUtil.BR + "" + HtmlUtil.BR + "<span", data
87: .getHtml());
88: }
89:
90: public void testAsWikiText() throws Exception {
91: VariableDefinitionWidget widget = new VariableDefinitionWidget(
92: new MockWidgetRoot(), "!define x {1}\n");
93: assertEquals("!define x {1}", widget.asWikiText());
94: widget = new VariableDefinitionWidget(new MockWidgetRoot(),
95: "!define x ({1})\n");
96: assertEquals("!define x ({1})", widget.asWikiText());
97: }
98: }
|