435
|
1 |
"{ Package: 'stx:goodies/petitparser/parsers/java' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
PPJavaLexiconTest subclass:#PPJavaSyntaxTest
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'PetitJava-Tests'
|
|
10 |
!
|
|
11 |
|
|
12 |
!PPJavaSyntaxTest methodsFor:'accessing'!
|
|
13 |
|
|
14 |
parserClass
|
|
15 |
^ PPJavaSyntax
|
|
16 |
! !
|
|
17 |
|
|
18 |
!PPJavaSyntaxTest methodsFor:'testing'!
|
|
19 |
|
|
20 |
testAdditiveExpression1
|
|
21 |
|
|
22 |
self parse: 'true'
|
|
23 |
rule: #additiveExpression
|
|
24 |
!
|
|
25 |
|
|
26 |
testAdditiveExpression2
|
|
27 |
|
|
28 |
self parse: '3 + 5'
|
|
29 |
rule: #additiveExpression
|
|
30 |
!
|
|
31 |
|
|
32 |
testAdditiveExpression3
|
|
33 |
|
|
34 |
self parse: '4 + 8 - 2 + 9'
|
|
35 |
rule: #additiveExpression
|
|
36 |
!
|
|
37 |
|
|
38 |
testAndExpression1
|
|
39 |
|
|
40 |
self parse: 'true'
|
|
41 |
rule: #andExpression
|
|
42 |
!
|
|
43 |
|
|
44 |
testBlock1
|
|
45 |
|
|
46 |
self parse: '{ }'
|
|
47 |
rule: #block
|
|
48 |
!
|
|
49 |
|
|
50 |
testBlock2
|
|
51 |
|
|
52 |
self
|
|
53 |
parse:
|
|
54 |
'{
|
|
55 |
System.out.println("Hello World!!");
|
|
56 |
System.out.println("Hello World!!");
|
|
57 |
}'
|
|
58 |
rule: #block
|
|
59 |
!
|
|
60 |
|
|
61 |
testCompilationUnit1
|
|
62 |
|
|
63 |
self parse: 'package foo;
|
|
64 |
public class CU1 {}'
|
|
65 |
rule: #compilationUnit
|
|
66 |
!
|
|
67 |
|
|
68 |
testCompilationUnit2
|
|
69 |
|
|
70 |
self parse: 'package foo;
|
|
71 |
import foo.Bar;
|
|
72 |
public class CU2 {
|
|
73 |
}'
|
|
74 |
rule: #compilationUnit
|
|
75 |
!
|
|
76 |
|
|
77 |
testCompilationUnit3
|
|
78 |
|
|
79 |
self parse: 'class myfirstjavaprog
|
|
80 |
{
|
|
81 |
public static void main(String args[])
|
|
82 |
{
|
|
83 |
System.out.println("Hello World!!");
|
|
84 |
}
|
|
85 |
}'
|
|
86 |
rule: #compilationUnit
|
|
87 |
!
|
|
88 |
|
|
89 |
testCompilationUnit4
|
|
90 |
|
|
91 |
self parse: '
|
|
92 |
public class OddEven {
|
|
93 |
private int input;
|
|
94 |
public static void main(String[] args) {
|
|
95 |
OddEven number = new OddEven();
|
|
96 |
number.showDialog(); }
|
|
97 |
public void showDialog() {
|
|
98 |
|
|
99 |
try {
|
|
100 |
|
|
101 |
input = Integer.parseInt(JOptionPane.showInputDialog("Please Enter A Number"));
|
|
102 |
calculate();
|
|
103 |
} catch (NumberFormatException e) {
|
|
104 |
|
|
105 |
System.err.println("ERROR: Invalid input. Please type in a numerical value.");
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
private void calculate() {
|
|
110 |
if (input % 2 == 0) {
|
|
111 |
System.out.println("Even");
|
|
112 |
} else {
|
|
113 |
System.out.println("Odd");
|
|
114 |
}
|
|
115 |
}
|
|
116 |
}'
|
|
117 |
rule: #compilationUnit
|
|
118 |
!
|
|
119 |
|
|
120 |
testCompilationUnit5
|
|
121 |
|
|
122 |
self parse: 'class myfirstjavaprog
|
|
123 |
{
|
|
124 |
|
|
125 |
public myfirstjavaprog() {
|
|
126 |
|
|
127 |
}
|
|
128 |
|
|
129 |
public static void main(String args[])
|
|
130 |
{
|
|
131 |
System.out.println("Hello World!!");
|
|
132 |
}
|
|
133 |
}'
|
|
134 |
rule: #compilationUnit
|
|
135 |
!
|
|
136 |
|
|
137 |
testConditionalAndExpression1
|
|
138 |
|
|
139 |
self parse: 'true'
|
|
140 |
rule: #conditionalAndExpression
|
|
141 |
!
|
|
142 |
|
|
143 |
testConditionalOrExpression1
|
|
144 |
|
|
145 |
self parse: 'true'
|
|
146 |
rule: #conditionalOrExpression
|
|
147 |
!
|
|
148 |
|
|
149 |
testEqualityExpression1
|
|
150 |
|
|
151 |
self
|
|
152 |
parse: 'true'
|
|
153 |
rule: #equalityExpression
|
|
154 |
!
|
|
155 |
|
|
156 |
testExclusiveOrExpression1
|
|
157 |
|
|
158 |
self parse: 'true'
|
|
159 |
rule: #exclusiveOrExpression
|
|
160 |
!
|
|
161 |
|
|
162 |
testExpression1
|
|
163 |
|
|
164 |
self parse: '1 + 2'
|
|
165 |
rule: #expression
|
|
166 |
!
|
|
167 |
|
|
168 |
testExpression2
|
|
169 |
|
|
170 |
self parse: 'true'
|
|
171 |
rule: #expression
|
|
172 |
!
|
|
173 |
|
|
174 |
testExpression3
|
|
175 |
|
|
176 |
self parse: 'a.method()'
|
|
177 |
rule: #expression
|
|
178 |
!
|
|
179 |
|
|
180 |
testExpression4
|
|
181 |
|
|
182 |
self parse: 'a'
|
|
183 |
rule: #expression
|
|
184 |
!
|
|
185 |
|
|
186 |
testExpression5
|
|
187 |
|
|
188 |
self parse: 'a += 5'
|
|
189 |
rule: #expression
|
|
190 |
!
|
|
191 |
|
|
192 |
testFormalParameters1
|
|
193 |
|
|
194 |
self
|
|
195 |
parse: '
|
|
196 |
(String s, Object parameterType)
|
|
197 |
'
|
|
198 |
rule: #formalParameters
|
|
199 |
!
|
|
200 |
|
|
201 |
testFormalParameters2
|
|
202 |
|
|
203 |
self
|
|
204 |
parse: '
|
|
205 |
(Object ... parameterType)
|
|
206 |
'
|
|
207 |
rule: #formalParameters
|
|
208 |
!
|
|
209 |
|
|
210 |
testFormalParameters3
|
|
211 |
|
|
212 |
self
|
|
213 |
parse: '(String name, Class<?>... parameterTypes)
|
|
214 |
'
|
|
215 |
rule: #formalParameters
|
|
216 |
!
|
|
217 |
|
|
218 |
testFormalParameters4
|
|
219 |
|
|
220 |
self
|
|
221 |
parse: '(int one, int two, int three, int four)'
|
|
222 |
rule: #formalParameters
|
|
223 |
!
|
|
224 |
|
|
225 |
testFormalParameters5
|
|
226 |
|
|
227 |
self
|
|
228 |
parse: '()'
|
|
229 |
rule: #formalParameters
|
|
230 |
!
|
|
231 |
|
|
232 |
testIfStatement1
|
|
233 |
|
|
234 |
self parse: 'if (true) {}'
|
|
235 |
rule: #ifStatement
|
|
236 |
!
|
|
237 |
|
|
238 |
testIfStatement2
|
|
239 |
|
|
240 |
self parse: 'if (true) {} else {}'
|
|
241 |
rule: #ifStatement
|
|
242 |
!
|
|
243 |
|
|
244 |
testIfStatement3
|
|
245 |
|
|
246 |
self parse: '
|
|
247 |
if (true)
|
|
248 |
{int a = 0; a = 1;}
|
|
249 |
else
|
|
250 |
{return false;}'
|
|
251 |
rule: #ifStatement
|
|
252 |
!
|
|
253 |
|
|
254 |
testIfStatement4
|
|
255 |
|
|
256 |
self parse: 'if (true) a = 0;'
|
|
257 |
rule: #ifStatement
|
|
258 |
!
|
|
259 |
|
|
260 |
testIfStatement5
|
|
261 |
|
|
262 |
self parse: 'if (a < 4) {}'
|
|
263 |
rule: #ifStatement
|
|
264 |
!
|
|
265 |
|
|
266 |
testImportDeclaration1
|
|
267 |
|
|
268 |
self parse: 'import foo.Top;'
|
|
269 |
rule: #importDeclaration
|
|
270 |
!
|
|
271 |
|
|
272 |
testImportDeclaration2
|
|
273 |
|
|
274 |
self parse: 'import foo.Top2.*;'
|
|
275 |
rule: #importDeclaration
|
|
276 |
!
|
|
277 |
|
|
278 |
testInclusiveOrExpression1
|
|
279 |
|
|
280 |
self parse: 'true'
|
|
281 |
rule: #inclusiveOrExpression
|
|
282 |
!
|
|
283 |
|
|
284 |
testInstanceofExpression1
|
|
285 |
|
|
286 |
self
|
|
287 |
parse: 'true'
|
|
288 |
rule: #instanceofExpression
|
|
289 |
!
|
|
290 |
|
|
291 |
testLocalVariableDeclaration1
|
|
292 |
|
|
293 |
self parse: 'Type name'
|
|
294 |
rule: #localVariableDeclaration
|
|
295 |
!
|
|
296 |
|
|
297 |
testLocalVariableDeclaration2
|
|
298 |
|
|
299 |
self parse: 'Type name = value, name2'
|
|
300 |
rule: #localVariableDeclaration
|
|
301 |
!
|
|
302 |
|
|
303 |
testLocalVariableDeclarationStatement1
|
|
304 |
|
|
305 |
self parse: 'int i = 5;'
|
|
306 |
rule: #localVariableDeclarationStatement
|
|
307 |
!
|
|
308 |
|
|
309 |
testLocalVariableDeclarationStatement2
|
|
310 |
|
|
311 |
self parse: 'int i, j = 6;'
|
|
312 |
rule: #localVariableDeclarationStatement
|
|
313 |
!
|
|
314 |
|
|
315 |
testLocalVariableDeclarationStatement3
|
|
316 |
|
|
317 |
self parse: 'Srting str, in, g;'
|
|
318 |
rule: #localVariableDeclarationStatement
|
|
319 |
!
|
|
320 |
|
|
321 |
testMethodDeclaration3
|
|
322 |
|
|
323 |
self
|
|
324 |
parse: '
|
|
325 |
public void getMethod(String s, Object ... parameterType)
|
|
326 |
{
|
|
327 |
}
|
|
328 |
'
|
|
329 |
rule: #methodDeclaration
|
|
330 |
!
|
|
331 |
|
|
332 |
testMethodDeclaration4
|
|
333 |
|
|
334 |
self
|
|
335 |
parse: '
|
|
336 |
public void getMethod(String s, int o)
|
|
337 |
{
|
|
338 |
}
|
|
339 |
'
|
|
340 |
rule: #methodDeclaration
|
|
341 |
!
|
|
342 |
|
|
343 |
testMultiplicativeExpression1
|
|
344 |
|
|
345 |
self parse: 'true'
|
|
346 |
rule: #multiplicativeExpression
|
|
347 |
!
|
|
348 |
|
|
349 |
testMultiplicativeExpression2
|
|
350 |
|
|
351 |
self parse: '3 * 5'
|
|
352 |
rule: #multiplicativeExpression
|
|
353 |
!
|
|
354 |
|
|
355 |
testMultiplicativeExpression3
|
|
356 |
|
|
357 |
self parse: '4 * 8 / 2 * 9'
|
|
358 |
rule: #multiplicativeExpression
|
|
359 |
!
|
|
360 |
|
|
361 |
testNormalParameterDecl1
|
|
362 |
|
|
363 |
self parse: 'final int integers[]'
|
|
364 |
rule: #normalParameterDecl
|
|
365 |
!
|
|
366 |
|
|
367 |
testNormalParameterDecl2
|
|
368 |
|
|
369 |
self parse: 'String str'
|
|
370 |
rule: #normalParameterDecl
|
|
371 |
!
|
|
372 |
|
|
373 |
testPackageDeclaration1
|
|
374 |
|
|
375 |
self parse: 'package foo;'
|
|
376 |
rule: #packageDeclaration
|
|
377 |
!
|
|
378 |
|
|
379 |
testPackageDeclaration2
|
|
380 |
|
|
381 |
self parse: 'package foo.Bar;'
|
|
382 |
rule: #packageDeclaration
|
|
383 |
!
|
|
384 |
|
|
385 |
testPackageDeclaration3
|
|
386 |
|
|
387 |
self fail: 'package ;'
|
|
388 |
rule: #packageDeclaration
|
|
389 |
!
|
|
390 |
|
|
391 |
testPrimary1
|
|
392 |
|
|
393 |
self
|
|
394 |
parse: 'true'
|
|
395 |
rule: #primary
|
|
396 |
!
|
|
397 |
|
|
398 |
testPrimary2
|
|
399 |
|
|
400 |
self
|
|
401 |
parse: '"Java string"'
|
|
402 |
rule: #primary
|
|
403 |
!
|
|
404 |
|
|
405 |
testPrimaryWithselectors1
|
|
406 |
|
|
407 |
self
|
|
408 |
parse: 'true'
|
|
409 |
rule: #primaryWithselectors
|
|
410 |
!
|
|
411 |
|
|
412 |
testPrimaryWithselectors2
|
|
413 |
|
|
414 |
self
|
|
415 |
parse: 'foo().bar()'
|
|
416 |
rule: #primaryWithselectors
|
|
417 |
!
|
|
418 |
|
|
419 |
testQualifiedName1
|
|
420 |
|
|
421 |
self parse: 'a.a'
|
|
422 |
rule: #qualifiedName
|
|
423 |
!
|
|
424 |
|
|
425 |
testRelationalExpression1
|
|
426 |
|
|
427 |
self parse: 'true'
|
|
428 |
rule: #relationalExpression
|
|
429 |
!
|
|
430 |
|
|
431 |
testRelationalExpression2
|
|
432 |
|
|
433 |
self parse: '3 > 5'
|
|
434 |
rule: #relationalExpression
|
|
435 |
!
|
|
436 |
|
|
437 |
testReturnStatement1
|
|
438 |
|
|
439 |
self parse: 'return true;'
|
|
440 |
rule: #returnStatement
|
|
441 |
!
|
|
442 |
|
|
443 |
testReturnStatement2
|
|
444 |
|
|
445 |
self parse: 'return;'
|
|
446 |
rule: #returnStatement
|
|
447 |
!
|
|
448 |
|
|
449 |
testShiftExpression1
|
|
450 |
|
|
451 |
self parse: 'true'
|
|
452 |
rule: #shiftExpression
|
|
453 |
!
|
|
454 |
|
|
455 |
testStatement1
|
|
456 |
|
|
457 |
self parse: 'System.out.println("Hello World!!");'
|
|
458 |
rule: #statement
|
|
459 |
!
|
|
460 |
|
|
461 |
testStatement2
|
|
462 |
|
|
463 |
self parse: 'return true;'
|
|
464 |
rule: #statement
|
|
465 |
!
|
|
466 |
|
|
467 |
testStatement3
|
|
468 |
|
|
469 |
self parse: '{}'
|
|
470 |
rule: #statement
|
|
471 |
!
|
|
472 |
|
|
473 |
testUnaryExpression1
|
|
474 |
|
|
475 |
self parse: 'a'
|
|
476 |
rule: #unaryExpression
|
|
477 |
!
|
|
478 |
|
|
479 |
testUnaryExpression2
|
|
480 |
|
|
481 |
self parse: 'true'
|
|
482 |
rule: #unaryExpression
|
|
483 |
!
|
|
484 |
|
|
485 |
testUnaryExpressionNotPlusMinus1
|
|
486 |
|
|
487 |
self
|
|
488 |
parse: 'true'
|
|
489 |
rule: #unaryExpressionNotPlusMinus
|
|
490 |
!
|
|
491 |
|
|
492 |
testVariableDeclarator1
|
|
493 |
|
|
494 |
self parse: 'var'
|
|
495 |
rule: #variableDeclarator
|
|
496 |
!
|
|
497 |
|
|
498 |
testVariableDeclarator2
|
|
499 |
|
|
500 |
self parse: 'var[][]'
|
|
501 |
rule: #variableDeclarator
|
|
502 |
!
|
|
503 |
|
|
504 |
testVariableDeclarator3
|
|
505 |
|
|
506 |
self parse: 'var = a.methd()'
|
|
507 |
rule: #variableDeclarator
|
|
508 |
!
|
|
509 |
|
|
510 |
testWhileStatement1
|
|
511 |
|
|
512 |
self parse: 'while (true) object.executeMethod();'
|
|
513 |
rule: #whileStatement
|
|
514 |
!
|
|
515 |
|
|
516 |
testWhileStatement2
|
|
517 |
|
|
518 |
self parse: 'while (3>2) {block; of; statements;}'
|
|
519 |
rule: #whileStatement
|
|
520 |
! !
|
|
521 |
|
|
522 |
!PPJavaSyntaxTest methodsFor:'testing-classes'!
|
|
523 |
|
|
524 |
testClassDeclaration1
|
|
525 |
|
|
526 |
self parse: '//comment
|
|
527 |
class myfirstjavaprog
|
|
528 |
{
|
|
529 |
public static void main(String args[])
|
|
530 |
{
|
|
531 |
System.out.println("Hello World!!");
|
|
532 |
}
|
|
533 |
}'
|
|
534 |
rule: #classDeclaration
|
|
535 |
!
|
|
536 |
|
|
537 |
testMethodDeclaration1
|
|
538 |
|
|
539 |
self
|
|
540 |
parse: 'public void aMethod() { }'
|
|
541 |
rule: #methodDeclaration
|
|
542 |
!
|
|
543 |
|
|
544 |
testMethodDeclaration2
|
|
545 |
|
|
546 |
self
|
|
547 |
parse: 'public aMethod() { }'
|
|
548 |
rule: #methodDeclaration
|
|
549 |
! !
|
|
550 |
|