01: package jimm.datavision.test;
02:
03: import jimm.datavision.source.sql.ParserHelper;
04: import junit.framework.TestCase;
05: import junit.framework.TestSuite;
06: import junit.framework.Test;
07:
08: /**
09: * Tests {@link ParserHelper}.
10: *
11: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
12: */
13: public class ParserHelperTest extends TestCase {
14:
15: public static Test suite() {
16: return new TestSuite(ParserHelperTest.class);
17: }
18:
19: public ParserHelperTest(String name) {
20: super (name);
21: }
22:
23: public void testParamEqString() {
24: ParserHelper ph = new ParserHelper("{?1} = 'foo'", 0);
25: assertEquals("", ph.getPrevToken());
26: assertEquals(0, ph.getPrevTokenStartPos());
27: assertEquals(0, ph.getEndBeforeToken());
28: }
29:
30: public void testColEqParam() {
31: ParserHelper ph = new ParserHelper("{office.name} = {?1}", 16);
32: assertEquals("=", ph.getPrevToken());
33: assertEquals(14, ph.getPrevTokenStartPos());
34: assertEquals(13, ph.getEndBeforeToken());
35: }
36:
37: public void testColEqParamNoSpaces() {
38: ParserHelper ph = new ParserHelper("{office.name}={?1}", 14);
39: assertEquals("=", ph.getPrevToken());
40: assertEquals(13, ph.getPrevTokenStartPos());
41: assertEquals(13, ph.getEndBeforeToken());
42: }
43:
44: public void testColNeqParam() {
45: ParserHelper ph = new ParserHelper("{office.name}!={?1}", 15);
46: assertEquals("!=", ph.getPrevToken());
47: assertEquals(13, ph.getPrevTokenStartPos());
48: assertEquals(13, ph.getEndBeforeToken());
49: }
50:
51: public void testColIsParam() {
52: ParserHelper ph = new ParserHelper("{office.name}is{?1}", 15);
53: assertEquals("is", ph.getPrevToken());
54: assertEquals(13, ph.getPrevTokenStartPos());
55: assertEquals(13, ph.getEndBeforeToken());
56: }
57:
58: public void testColIsSpaceAfterParam() {
59: ParserHelper ph = new ParserHelper("{office.name}is {?1}", 16);
60: assertEquals("is", ph.getPrevToken());
61: assertEquals(13, ph.getPrevTokenStartPos());
62: assertEquals(13, ph.getEndBeforeToken());
63: }
64:
65: public void testColIsSpaceBeforeParam() {
66: ParserHelper ph = new ParserHelper("{office.name} is{?1}", 16);
67: assertEquals("is", ph.getPrevToken());
68: assertEquals(14, ph.getPrevTokenStartPos());
69: assertEquals(13, ph.getEndBeforeToken());
70: }
71:
72: public void testColIsNotParam() {
73: ParserHelper ph = new ParserHelper("{office.name} is not {?1}",
74: 21);
75: assertEquals("not", ph.getPrevToken());
76: assertEquals(17, ph.getPrevTokenStartPos());
77: assertEquals(16, ph.getEndBeforeToken());
78: }
79:
80: public static void main(String[] args) {
81: junit.textui.TestRunner.run(suite());
82: System.exit(0);
83: }
84:
85: }
|