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 java.util.regex.Pattern;
06: import fitnesse.wikitext.WidgetBuilder;
07: import fitnesse.wiki.MockWikiPage;
08: import fitnesse.testutil.AbstractRegex;
09:
10: public class PreformattedWidgetTest extends AbstractRegex {
11: public void testRegexp() throws Exception {
12: Pattern pattern = Pattern.compile(PreformattedWidget.REGEXP,
13: Pattern.DOTALL);
14: assertTrue("match1", pattern.matcher("{{{preformatted}}}")
15: .matches());
16: assertTrue("match2", pattern.matcher("{{{{preformatted}}}}")
17: .matches());
18: assertFalse("match3", pattern
19: .matcher("{{ {not preformatted}}}").matches());
20: assertTrue("match4", pattern.matcher("{{{\npreformatted\n}}}")
21: .matches());
22: }
23:
24: public void testHtml() throws Exception {
25: PreformattedWidget widget = new PreformattedWidget(
26: new MockWidgetRoot(), "{{{preformatted text}}}");
27: assertEquals("<pre>preformatted text</pre>", widget.render());
28: }
29:
30: public void testMultiLine() throws Exception {
31: PreformattedWidget widget = new PreformattedWidget(
32: new MockWidgetRoot(), "{{{\npreformatted text\n}}}");
33: assertEquals("<pre>\npreformatted text\n</pre>", widget
34: .render());
35: }
36:
37: public void testAsWikiText() throws Exception {
38: PreformattedWidget widget = new PreformattedWidget(
39: new MockWidgetRoot(), "{{{preformatted text}}}");
40: assertEquals("{{{preformatted text}}}", widget.asWikiText());
41: }
42:
43: public void testThatLiteralsWorkInPreformattedText()
44: throws Exception {
45: WidgetRoot root = new WidgetRoot("{{{abc !-123-! xyz}}}",
46: new MockWikiPage(), WidgetBuilder.htmlWidgetBuilder);
47: String text = root.render();
48: assertEquals("<pre>abc 123 xyz</pre>", text);
49: }
50:
51: public void testThatVariablesWorkInPreformattedText()
52: throws Exception {
53: WidgetRoot root = new WidgetRoot(
54: "!define X {123}\n{{{abc ${X} xyz}}}",
55: new MockWikiPage(), WidgetBuilder.htmlWidgetBuilder);
56: String text = root.render();
57: assertSubString("<pre>abc 123 xyz</pre>", text);
58: }
59: }
|