source: trunk/testsrc/ws/fugue88/jpath/PathTest.java

Last change on this file was 6, checked in by dsowen, 21 years ago

Split out the access stuff into accesslib.
New Creator interface off-loads object creation to user.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1/*
2 * Created on Aug 2, 2005
3 *
4 * $Log$
5 * Revision 1.2  2005/09/21 22:00:46  dsowen
6 * Split out the access stuff into accesslib.
7 * New Creator interface off-loads object creation to user.
8 *
9 * Revision 1.1  2005/08/03 00:35:29  dsowen
10 * Initial commit.
11 *
12 */
13package ws.fugue88.jpath;
14
15import java.util.Iterator;
16
17import junit.framework.TestCase;
18
19/**
20 * @author dsowen
21 */
22public class PathTest extends TestCase {
23
24        public void testQuote()
25        {
26                assertEquals("test", PathParser.quote("test"));
27                assertEquals("te\\'st", PathParser.quote("te'st"));
28        }
29
30        public void testIdentifier() throws Exception
31        {
32                Path path = new SimplePathParser().parse("/test");
33                Iterator i = path.iterator();
34                PathPart part = (PathPart)i.next();
35                assertTrue(part instanceof Identifier);
36                assertEquals("test", ((Identifier)part).getName());
37                assertFalse(i.hasNext());
38        }
39
40        public void testNumberSelector() throws Exception
41        {
42                Path path = new SimplePathParser().parse("[0]");
43                Iterator i = path.iterator();
44                PathPart part = (PathPart)i.next();
45                assertTrue(part instanceof NumberSelector);
46                assertEquals(0, ((NumberSelector)part).getIndex());
47                assertFalse(i.hasNext());
48        }
49
50        public void testStringSelectorSimple() throws Exception
51        {
52                Path path = new SimplePathParser().parse("['test']");
53                Iterator i = path.iterator();
54                PathPart part = (PathPart)i.next();
55                assertTrue(part instanceof StringSelector);
56                assertEquals("test", ((StringSelector)part).getKey());
57                assertFalse(i.hasNext());
58        }
59
60        public void testStringSelectorQuoted() throws Exception
61        {
62                Path path = new SimplePathParser().parse("['te\\'st']");
63                Iterator i = path.iterator();
64                PathPart part = (PathPart)i.next();
65                assertTrue(part instanceof StringSelector);
66                assertEquals("te'st", ((StringSelector)part).getKey());
67                assertFalse(i.hasNext());
68        }
69
70        public void testCompound1() throws Exception
71        {
72                Path path = new SimplePathParser().parse("/a/b");
73                Iterator i = path.iterator();
74                PathPart part = (PathPart)i.next();
75                assertTrue(part instanceof Identifier);
76                assertEquals("a", ((Identifier)part).getName());
77                part = (PathPart)i.next();
78                assertTrue(part instanceof Identifier);
79                assertEquals("b", ((Identifier)part).getName());
80                assertFalse(i.hasNext());
81        }
82}
Note: See TracBrowser for help on using the repository browser.