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.wikitext.WikiWidget;
06: import fitnesse.html.HtmlElement;
07: import junit.swingui.TestRunner;
08:
09: public class TableWidgetTest extends AbstractWidget {
10: public static void main(String[] args) {
11: TestRunner
12: .main(new String[] { "fitnesse.wikitext.widgets.TableWidgetTest" });
13: }
14:
15: protected String getRegexp() {
16: return TableWidget.REGEXP;
17: }
18:
19: public void setUp() throws Exception {
20: }
21:
22: public void tearDown() throws Exception {
23: }
24:
25: public void testRegexp() throws Exception {
26: assertMatches("|a|\n");
27: assertMatches("|a|b|\n");
28: assertMatches("|a|b|\n|c|\n");
29: assertMatches("|a|\n|b|\n|c|\n");
30: assertNoMatch("|abc\n|\n");
31: assertNoMatch(" |a|b|c|\n"); // leading space is illegal
32: assertMatches("|a|b|c| \t\n"); // trailing space is legal
33: assertMatches("| a | b | c |\n"); // inline space is legal
34: }
35:
36: public void testRegexpForLiteralTable() throws Exception {
37: assertMatches("!|a|\n");
38: assertMatches("!|a|\n|b|\n");
39: assertNoMatch(" !|a|\n");
40: }
41:
42: public void testSimpleTable() throws Exception {
43: TableWidget table = new TableWidget(new MockWidgetRoot(),
44: "|a|\n");
45: assertEquals(1, table.numberOfChildren());
46: assertEquals(1, table.getColumns());
47: WikiWidget child = table.nextChild();
48: assertEquals(TableRowWidget.class, child.getClass());
49: TableRowWidget row = (TableRowWidget) child;
50: assertEquals(1, row.numberOfChildren());
51: child = row.nextChild();
52: assertEquals(TableCellWidget.class, child.getClass());
53: TableCellWidget cell = (TableCellWidget) child;
54: assertEquals(1, cell.numberOfChildren());
55: child = cell.nextChild();
56: assertEquals(TextWidget.class, child.getClass());
57: assertEquals("a", ((TextWidget) child).getText());
58: }
59:
60: public void testBiggerTable() throws Exception {
61: TableWidget table = new TableWidget(new MockWidgetRoot(),
62: "|a|b|c|\n|d|\n|e|f|\n");
63: assertEquals(3, table.numberOfChildren());
64: assertEquals(3, table.getColumns());
65: }
66:
67: public void testHtml() throws Exception {
68: TableWidget table = new TableWidget(new MockWidgetRoot(),
69: "|a|\n");
70: String expected = "<table border=\"1\" cellspacing=\"0\" class=\"table-widget\">\n"
71: + "<colgroup>\n<col class=\"col-single\" />\n</colgroup>\n"
72: + "<tr><td class=\"column1\">a</td>"
73: + HtmlElement.endl
74: + "</tr>\n</table>\n";
75: assertEquals(expected, table.render());
76: }
77:
78: public void testBiggerHtml() throws Exception {
79: TableWidget table = new TableWidget(new MockWidgetRoot(),
80: "|a|\n|b|c|\n");
81: String expected = "<table border=\"1\" cellspacing=\"0\" class=\"table-widget\">\n"
82: + "<colgroup>\n<col class=\"col-1\" />\n<col class=\"col-2\" />\n</colgroup>\n"
83: + "<tr><td colspan=\"2\" class=\"column1\">a</td>"
84: + HtmlElement.endl
85: + "</tr>\n<tr><td class=\"column1\">b</td>"
86: + HtmlElement.endl
87: + "<td class=\"column2\">c</td>"
88: + HtmlElement.endl + "</tr>\n</table>\n";
89: assertEquals(expected, table.render());
90: }
91:
92: public void testTestTable() throws Exception {
93: TableWidget table = new TableWidget(new MockWidgetRoot(),
94: "!|'''bold text'''|\n");
95: assertTrue(table.isTestTable);
96: assertSubString("'''bold text'''", table.render());
97: }
98:
99: }
|