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 AnchorDeclarationWidgetTest extends AbstractWidget {
08: public void testRegularExpressionToMatch() throws Exception {
09: assertTrue("Match 1", Pattern.matches(
10: AnchorDeclarationWidget.REGEXP, "!anchor name"));
11: assertTrue("Match 2", Pattern.matches(
12: AnchorDeclarationWidget.REGEXP, "!anchor 1234"));
13: assertFalse("Match 3", Pattern.matches(
14: AnchorDeclarationWidget.REGEXP, "!anchor @#$@#%"));
15: assertFalse("Match 4", Pattern.matches(
16: AnchorDeclarationWidget.REGEXP, "! anchor name"));
17: assertFalse("Match 5", Pattern.matches(
18: AnchorDeclarationWidget.REGEXP,
19: "!anchor name other stuff"));
20: assertFalse("Match 6", Pattern.matches(
21: AnchorDeclarationWidget.REGEXP, "!anchor name "));
22: }
23:
24: public void testRendering() throws Exception {
25: AnchorDeclarationWidget declarationWidget = new AnchorDeclarationWidget(
26: null, "!anchor name");
27: assertEquals("<a name=\"name\"/>", declarationWidget.render()
28: .trim());
29: }
30:
31: public void testRenderingManyWordMatch() throws Exception {
32: AnchorDeclarationWidget declarationWidget = new AnchorDeclarationWidget(
33: null, "!anchor name some other stuff");
34: assertEquals("<a name=\"name\"/>", declarationWidget.render()
35: .trim());
36: }
37:
38: public void testRenderingTextBefore() throws Exception {
39: AnchorDeclarationWidget declarationWidget = new AnchorDeclarationWidget(
40: null, "stuff!anchor name some other stuff");
41: assertEquals("<a name=\"name\"/>", declarationWidget.render()
42: .trim());
43: }
44:
45: public void testRenderingTextBeforeWithSpace() throws Exception {
46: AnchorDeclarationWidget declarationWidget = new AnchorDeclarationWidget(
47: null, "stuff !anchor name some other stuff");
48: assertEquals("<a name=\"name\"/>", declarationWidget.render()
49: .trim());
50: }
51:
52: protected String getRegexp() {
53: return AnchorDeclarationWidget.REGEXP;
54: }
55: }
|