1 /***
2 * LexerTest.java
3 *
4 * $Author: mballesteros $
5 * $Date: 2003/11/28 19:18:03 $
6 * $Revision: 1.1 $
7 */
8 package net.sf.jec;
9
10 import junit.framework.TestCase;
11
12 /***
13 * @author mballesteros
14 */
15 public class LexerTest extends TestCase {
16
17 /***
18 * Constructor for LexerTest.
19 * @param arg0
20 */
21 public LexerTest(String arg0) {
22 super(arg0);
23 }
24
25 Lexer lexer;
26
27 /*
28 * @see TestCase#setUp()
29 */
30 protected void setUp() throws Exception {
31 super.setUp();
32 }
33
34 public void testAccessorsAndIndexers() {
35 lexer = new Lexer("book");
36 assertEquals("book", lexer.getToken());
37 assertTrue(!lexer.next());
38
39 lexer = new Lexer("book.pages");
40 assertEquals("book", lexer.getToken());
41 assertTrue(lexer.next());
42 assertEquals(".", lexer.getToken());
43 assertTrue(lexer.next());
44 assertEquals("pages", lexer.getToken());
45 assertTrue(!lexer.next());
46
47 lexer = new Lexer("pages[34].size");
48 assertEquals("pages", lexer.getToken());
49 assertTrue(lexer.next());
50 assertEquals("[", lexer.getToken());
51 assertTrue(lexer.next());
52 assertEquals("34", lexer.getToken());
53 assertTrue(lexer.next());
54 assertEquals("]", lexer.getToken());
55 assertTrue(lexer.next());
56 assertEquals(".", lexer.getToken());
57 assertTrue(lexer.next());
58 assertEquals("size", lexer.getToken());
59 assertTrue(!lexer.next());
60 }
61
62 public void testFunctions() {
63 lexer = new Lexer("date ( pages . size(), _book._setText('Hello, <>&world!', 56))");
64 assertEquals("date", lexer.getToken());
65 assertTrue(lexer.next());
66 assertEquals("(", lexer.getToken());
67 assertTrue(lexer.next());
68 assertEquals("pages", lexer.getToken());
69 assertTrue(lexer.next());
70 assertEquals(".", lexer.getToken());
71 assertTrue(lexer.next());
72 assertEquals("size", lexer.getToken());
73 assertTrue(lexer.next());
74 assertEquals("(", lexer.getToken());
75 assertTrue(lexer.next());
76 assertEquals(")", lexer.getToken());
77 assertTrue(lexer.next());
78 assertEquals(",", lexer.getToken());
79 assertTrue(lexer.next());
80 assertEquals("_book", lexer.getToken());
81 assertTrue(lexer.next());
82 assertEquals(".", lexer.getToken());
83 assertTrue(lexer.next());
84 assertEquals("_setText", lexer.getToken());
85 assertTrue(lexer.next());
86 assertEquals("(", lexer.getToken());
87 assertTrue(lexer.next());
88 assertEquals("'", lexer.getToken());
89 assertTrue(lexer.next());
90 assertEquals("Hello, <>&world!", lexer.getToken());
91 assertTrue(lexer.next());
92 assertEquals("'", lexer.getToken());
93 assertTrue(lexer.next());
94 assertEquals(",", lexer.getToken());
95 assertTrue(lexer.next());
96 assertEquals("56", lexer.getToken());
97 assertTrue(lexer.next());
98 assertEquals(")", lexer.getToken());
99 assertTrue(lexer.next());
100 assertEquals(")", lexer.getToken());
101 assertTrue(!lexer.next());
102 }
103
104
105 public void testOthers() {
106 lexer = new Lexer("(100>1.34)&&(15||3)*6+78-15==49");
107 assertEquals("(", lexer.getToken());
108 assertTrue(lexer.next());
109 assertEquals("100", lexer.getToken());
110 assertTrue(lexer.next());
111 assertEquals(">", lexer.getToken());
112 assertTrue(lexer.next());
113 assertEquals("1.34", lexer.getToken());
114 assertTrue(lexer.next());
115 assertEquals(")", lexer.getToken());
116 assertTrue(lexer.next());
117 assertEquals("&&", lexer.getToken());
118 assertTrue(lexer.next());
119 assertEquals("(", lexer.getToken());
120 assertTrue(lexer.next());
121 assertEquals("15", lexer.getToken());
122 assertTrue(lexer.next());
123 assertEquals("||", lexer.getToken());
124 assertTrue(lexer.next());
125 assertEquals("3", lexer.getToken());
126 assertTrue(lexer.next());
127 assertEquals(")", lexer.getToken());
128 assertTrue(lexer.next());
129 assertEquals("*", lexer.getToken());
130 assertTrue(lexer.next());
131 assertEquals("6", lexer.getToken());
132 assertTrue(lexer.next());
133 assertEquals("+", lexer.getToken());
134 assertTrue(lexer.next());
135 assertEquals("78", lexer.getToken());
136 assertTrue(lexer.next());
137 assertEquals("-", lexer.getToken());
138 assertTrue(lexer.next());
139 assertEquals("15", lexer.getToken());
140 assertTrue(lexer.next());
141 assertEquals("==", lexer.getToken());
142 assertTrue(lexer.next());
143 assertEquals("49", lexer.getToken());
144 assertTrue(!lexer.next());
145 }
146
147
148 public void testConstants() {
149 lexer = new Lexer("10.987 + 'pep\"e\"' + \"Man'ol'o\"");
150 assertEquals("10.987", lexer.getToken());
151 assertTrue(lexer.next());
152 assertEquals("+", lexer.getToken());
153 assertTrue(lexer.next());
154 assertEquals("'", lexer.getToken());
155 assertTrue(lexer.next());
156 assertEquals("pep\"e\"", lexer.getToken());
157 assertTrue(lexer.next());
158 assertEquals("'", lexer.getToken());
159 assertTrue(lexer.next());
160 assertEquals("+", lexer.getToken());
161 assertTrue(lexer.next());
162 assertEquals("\"", lexer.getToken());
163 assertTrue(lexer.next());
164 assertEquals("Man'ol'o", lexer.getToken());
165 assertTrue(lexer.next());
166 assertEquals("\"", lexer.getToken());
167 assertTrue(!lexer.next());
168 }
169 }
This page was automatically generated by Maven