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.wiki;
04:
05: import junit.framework.TestCase;
06:
07: public class PathParserTest extends TestCase {
08: public WikiPagePath path;
09:
10: private WikiPagePath makePath(String pathName) {
11: WikiPagePath path = PathParser.parse(pathName);
12: return path;
13: }
14:
15: public void testSimpleName() throws Exception {
16: path = makePath("ParentPage");
17: assertEquals("ParentPage", path.getFirst());
18: assertTrue(path.getRest().isEmpty());
19: }
20:
21: public void testTwoComponentName() throws Exception {
22: path = makePath("ParentPage.ChildPage");
23: assertEquals("ParentPage", path.getFirst());
24: assertEquals("ChildPage", path.getRest().getFirst());
25: assertTrue(path.getRest().getRest().isEmpty());
26: }
27:
28: public void testAbsolutePath() throws Exception {
29: path = makePath(".ParentPage.ChildPage");
30: assertEquals(WikiPagePath.ROOT, path.getFirst());
31: assertEquals("ParentPage", path.getRest().getFirst());
32: assertEquals("ChildPage", path.getRest().getRest().getFirst());
33: assertTrue(path.getRest().getRest().getRest().isEmpty());
34: }
35:
36: public void testRoot() throws Exception {
37: path = makePath("root");
38: assertEquals(WikiPagePath.ROOT, path.getFirst());
39: assertTrue(path.getRest().isEmpty());
40: }
41:
42: public void testDot() throws Exception {
43: path = makePath(".");
44: assertEquals(WikiPagePath.ROOT, path.getFirst());
45: assertTrue(path.getRest().isEmpty());
46: }
47:
48: public void testEmptyString() throws Exception {
49: path = makePath("");
50: assertTrue(path.isEmpty());
51: }
52:
53: public void testInvalidNames() throws Exception {
54: assertNull(makePath("bob"));
55: assertNull(makePath("bobMartin"));
56: assertNull(makePath("_root"));
57: }
58:
59: public void testRender() throws Exception {
60: assertEquals("MyPage", PathParser.render(makePath("MyPage")));
61: assertEquals(".MyPage", PathParser.render(makePath(".MyPage")));
62:
63: WikiPagePath p = PathParser.parse(".MyPage");
64: p.makeAbsolute();
65: assertEquals(".MyPage", PathParser.render(p));
66:
67: assertEquals(".", PathParser.render(PathParser.parse(".")));
68: // todo RCM 2/7/05 More tests here.
69: }
70: }
|