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.testutil.AbstractRegex;
07: import junit.swingui.TestRunner;
08:
09: public class TableCellWidgetTest extends AbstractRegex {
10: public TableRowWidget row;
11:
12: private TableWidget table;
13:
14: public static void main(String[] args) {
15: TestRunner
16: .main(new String[] { "fitnesse.wikitext.widgets.TableCellWidgetTest" });
17: }
18:
19: public void setUp() throws Exception {
20: table = new TableWidget(new MockWidgetRoot(), "");
21: row = new TableRowWidget(table, "", false);
22: }
23:
24: public void testSimpleCell() throws Exception {
25: TableCellWidget cell = new TableCellWidget(row, "a", false);
26: assertEquals(1, cell.numberOfChildren());
27: WikiWidget child = cell.nextChild();
28: assertEquals(TextWidget.class, child.getClass());
29: assertEquals("a", ((TextWidget) child).getText());
30: }
31:
32: public void testTrimsWhiteSpace() throws Exception {
33: TableCellWidget cell = new TableCellWidget(row, " 1 item ",
34: false);
35: assertEquals(1, cell.numberOfChildren());
36: WikiWidget child = cell.nextChild();
37: assertEquals(TextWidget.class, child.getClass());
38: assertEquals("1 item", ((TextWidget) child).getText());
39: }
40:
41: public void testLiteralCell() throws Exception {
42: TableCellWidget cell = new TableCellWidget(row,
43: "''italic'' '''bold''", true);
44: assertEquals(1, cell.numberOfChildren());
45: assertSubString("''italic'' '''bold''", cell.render());
46: }
47:
48: public void testLiteralInLiteralCell() throws Exception {
49: WidgetRoot root = new MockWidgetRoot();
50: root.defineLiteral("blah");
51: table = new TableWidget(root, "");
52: row = new TableRowWidget(table, "", true);
53: TableCellWidget cell = new TableCellWidget(row, "''!lit(0)''",
54: true);
55: assertSubString("''blah''", cell.render());
56: }
57:
58: public void testVariableInLiteralCell() throws Exception {
59: WidgetRoot root = new MockWidgetRoot();
60: root.addVariable("X", "abc");
61: table = new TableWidget(root, "");
62: row = new TableRowWidget(table, "", true);
63: TableCellWidget cell = new TableCellWidget(row, "''${X}''",
64: true);
65: assertSubString("''abc''", cell.render());
66: }
67: }
|