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:
07: public class AnchorMarkerWidgetTest extends AbstractWidget {
08: public void testRegularExpression() throws Exception {
09: assertTrue("Match 1", Pattern.matches(
10: AnchorMarkerWidget.REGEXP, ".#anchorName"));
11: assertFalse("Match 2", Pattern.matches(
12: AnchorMarkerWidget.REGEXP, ".# anchorName"));
13: assertFalse("Match 3", Pattern.matches(
14: AnchorMarkerWidget.REGEXP, ".#anchor Name"));
15: assertFalse("Match 4", Pattern.matches(
16: AnchorMarkerWidget.REGEXP, "blah.#anchorName"));
17: }
18:
19: public void testRender() throws Exception {
20: AnchorMarkerWidget widget = new AnchorMarkerWidget(null,
21: ".#anchorName");
22: assertEquals("<a href=\"#anchorName\">.#anchorName</a>", widget
23: .render().trim());
24: }
25:
26: public void testRenderWithSpaces() throws Exception {
27: AnchorMarkerWidget widget = new AnchorMarkerWidget(null,
28: ".#anchorName and some other stuff");
29: assertEquals("<a href=\"#anchorName\">.#anchorName</a>", widget
30: .render().trim());
31: }
32:
33: public void testRenderBefore() throws Exception {
34: AnchorMarkerWidget widget = new AnchorMarkerWidget(null,
35: "stuffbefore.#anchorName and some other stuff");
36: assertEquals("<a href=\"#anchorName\">.#anchorName</a>", widget
37: .render().trim());
38: }
39:
40: public void testRenderWithNewline() throws Exception {
41: AnchorMarkerWidget widget = new AnchorMarkerWidget(null,
42: "stuffbefore\r\n.#anchorName and some other stuff");
43: assertEquals("<a href=\"#anchorName\">.#anchorName</a>", widget
44: .render().trim());
45: }
46:
47: protected String getRegexp() {
48: return AnchorMarkerWidget.REGEXP;
49: }
50: }
|