|
1 "{ Encoding: utf8 }" |
|
2 |
|
3 "{ Package: 'stx:goodies/petitparser/parsers/java' }" |
|
4 |
|
5 "{ NameSpace: Smalltalk }" |
|
6 |
|
7 PPCompositeParserTest subclass:#PPJavaLexiconTest |
|
8 instanceVariableNames:'' |
|
9 classVariableNames:'' |
|
10 poolDictionaries:'' |
|
11 category:'PetitJava-Tests' |
|
12 ! |
|
13 |
|
14 PPJavaLexiconTest comment:'' |
|
15 ! |
|
16 |
|
17 !PPJavaLexiconTest methodsFor:'accessing'! |
|
18 |
|
19 parserClass |
|
20 ^ PPJavaLexicon |
|
21 ! ! |
|
22 |
|
23 !PPJavaLexiconTest methodsFor:'testing'! |
|
24 |
|
25 testIdentifier6 |
|
26 |
|
27 self |
|
28 fail: 'super' |
|
29 rule: #identifier |
|
30 ! ! |
|
31 |
|
32 !PPJavaLexiconTest methodsFor:'testing-comments'! |
|
33 |
|
34 testComment1 |
|
35 |
|
36 self |
|
37 parse: '//' |
|
38 rule: #comment |
|
39 ! |
|
40 |
|
41 testComment2 |
|
42 |
|
43 self |
|
44 parse: '//comment' |
|
45 rule: #comment |
|
46 ! |
|
47 |
|
48 testComment3 |
|
49 |
|
50 self |
|
51 parse: '// comment' |
|
52 rule: #comment |
|
53 ! |
|
54 |
|
55 testComment4 |
|
56 |
|
57 self |
|
58 parse: '/* comment */' |
|
59 rule: #comment |
|
60 ! |
|
61 |
|
62 testComment5 |
|
63 |
|
64 self |
|
65 fail: '/* comment ' |
|
66 rule: #comment |
|
67 ! |
|
68 |
|
69 testComment6 |
|
70 |
|
71 self |
|
72 parse: '/* this comment /* // /** ends here: */' |
|
73 rule: #comment |
|
74 ! |
|
75 |
|
76 testComment7 |
|
77 |
|
78 self |
|
79 parse: '/** |
|
80 * @param args |
|
81 * @return void |
|
82 */' |
|
83 rule: #comment |
|
84 ! |
|
85 |
|
86 testTraditionalComment1 |
|
87 |
|
88 self |
|
89 parse: '/* this comment */' |
|
90 rule: #traditionalComment |
|
91 ! |
|
92 |
|
93 testTraditionalComment2 |
|
94 |
|
95 self |
|
96 parse: '/* this comment / */' |
|
97 rule: #comment |
|
98 ! ! |
|
99 |
|
100 !PPJavaLexiconTest methodsFor:'testing-identifiers'! |
|
101 |
|
102 testIdentifier1 |
|
103 |
|
104 self |
|
105 parse: 'String' |
|
106 rule: #identifier |
|
107 ! |
|
108 |
|
109 testIdentifier2 |
|
110 |
|
111 self |
|
112 parse: 'i3' |
|
113 rule: #identifier |
|
114 ! |
|
115 |
|
116 testIdentifier3 |
|
117 |
|
118 self |
|
119 parse: 'αρετη' |
|
120 rule: #identifier |
|
121 ! |
|
122 |
|
123 testIdentifier4 |
|
124 |
|
125 self |
|
126 parse: 'MAX_VALUE' |
|
127 rule: #identifier |
|
128 ! |
|
129 |
|
130 testIdentifier5 |
|
131 |
|
132 self |
|
133 parse: 'isLetterOrDigit' |
|
134 rule: #identifier |
|
135 ! ! |
|
136 |
|
137 !PPJavaLexiconTest methodsFor:'testing-input'! |
|
138 |
|
139 testInput1 |
|
140 |
|
141 self parse: 'package testPackage; |
|
142 class Test { |
|
143 public static void main(String[] args) { |
|
144 String hello = "Hello", lo = "lo"; |
|
145 System.out.print((hello == "Hello") + " "); |
|
146 System.out.print((Other.hello == hello) + " "); |
|
147 System.out.print((other.Other.hello == hello) + " "); |
|
148 System.out.print((hello == ("Hel"+"lo")) + " "); |
|
149 System.out.print((hello == ("Hel"+lo)) + " "); |
|
150 System.out.println(hello == ("Hel"+lo).intern()); |
|
151 } |
|
152 } |
|
153 class Other { static String hello = "Hello"; }' |
|
154 rule: #input |
|
155 ! |
|
156 |
|
157 testInput2 |
|
158 |
|
159 self parse: 'package other; |
|
160 public class Other { static String hello = "Hello"; }' |
|
161 rule: #input |
|
162 ! |
|
163 |
|
164 testInput3 |
|
165 |
|
166 self parse: 'class Value { int val; } |
|
167 class Test { |
|
168 public static void main(String[] args) { |
|
169 int i1 = 3; |
|
170 int i2 = i1; |
|
171 i2 = 4; |
|
172 System.out.print("i1==" + i1); |
|
173 System.out.println(" but i2==" + i2); |
|
174 Value v1 = new Value(); |
|
175 v1.val = 5; |
|
176 Value v2 = v1; |
|
177 v2.val = 6; |
|
178 System.out.print("v1.val==" + v1.val); |
|
179 System.out.println(" and v2.val==" + v2.val); |
|
180 } |
|
181 }' |
|
182 rule: #input |
|
183 ! ! |
|
184 |
|
185 !PPJavaLexiconTest methodsFor:'testing-lineTerminators'! |
|
186 |
|
187 testInputCharacter1 |
|
188 |
|
189 self |
|
190 parse: '\' |
|
191 rule: #inputCharacter |
|
192 ! |
|
193 |
|
194 testInputCharacter2 |
|
195 |
|
196 self |
|
197 fail: (Character cr asString) |
|
198 rule: #inputCharacter |
|
199 ! |
|
200 |
|
201 testInputCharacter3 |
|
202 |
|
203 self |
|
204 fail: (Character lf asString) |
|
205 rule: #inputCharacter |
|
206 ! |
|
207 |
|
208 testLineTerminator1 |
|
209 |
|
210 self |
|
211 parse: (Character lf asString) |
|
212 rule: #lineTerminator |
|
213 ! |
|
214 |
|
215 testLineTerminator2 |
|
216 |
|
217 self |
|
218 parse: (Character cr asString) |
|
219 rule: #lineTerminator |
|
220 ! |
|
221 |
|
222 testLineTerminator3 |
|
223 |
|
224 self |
|
225 parse: (Character cr asString , Character lf asString) |
|
226 rule: #lineTerminator |
|
227 ! |
|
228 |
|
229 testLineTerminator4 |
|
230 |
|
231 self |
|
232 fail: (Character space asString) |
|
233 rule: #lineTerminator |
|
234 ! |
|
235 |
|
236 testLineTerminator5 |
|
237 |
|
238 self |
|
239 fail: ('a' asString) |
|
240 rule: #lineTerminator |
|
241 ! ! |
|
242 |
|
243 !PPJavaLexiconTest methodsFor:'testing-literal-float'! |
|
244 |
|
245 testFloatLiteral1 |
|
246 self |
|
247 parse: '1e1f' |
|
248 rule: #floatingPointLiteral |
|
249 ! |
|
250 |
|
251 testFloatLiteral10 |
|
252 self |
|
253 parse: '0.0' |
|
254 rule: #floatingPointLiteral |
|
255 ! |
|
256 |
|
257 testFloatLiteral11 |
|
258 self |
|
259 parse: '3.14' |
|
260 rule: #floatingPointLiteral |
|
261 ! |
|
262 |
|
263 testFloatLiteral12 |
|
264 self |
|
265 parse: '1e-9d' |
|
266 rule: #floatingPointLiteral |
|
267 ! |
|
268 |
|
269 testFloatLiteral13 |
|
270 self |
|
271 parse: '1e137' |
|
272 rule: #floatingPointLiteral |
|
273 ! |
|
274 |
|
275 testFloatLiteral2 |
|
276 self |
|
277 parse: '2.f' |
|
278 rule: #floatingPointLiteral |
|
279 ! |
|
280 |
|
281 testFloatLiteral3 |
|
282 self |
|
283 parse: '.3f' |
|
284 rule: #floatingPointLiteral |
|
285 ! |
|
286 |
|
287 testFloatLiteral4 |
|
288 self |
|
289 parse: '0f' |
|
290 rule: #floatingPointLiteral |
|
291 ! |
|
292 |
|
293 testFloatLiteral5 |
|
294 self |
|
295 parse: '3.14f' |
|
296 rule: #floatingPointLiteral |
|
297 ! |
|
298 |
|
299 testFloatLiteral6 |
|
300 self |
|
301 parse: '6.022137e+23f' |
|
302 rule: #floatingPointLiteral |
|
303 ! |
|
304 |
|
305 testFloatLiteral7 |
|
306 self |
|
307 parse: '1e1' |
|
308 rule: #floatingPointLiteral |
|
309 ! |
|
310 |
|
311 testFloatLiteral8 |
|
312 self |
|
313 parse: '2.' |
|
314 rule: #floatingPointLiteral |
|
315 ! |
|
316 |
|
317 testFloatLiteral9 |
|
318 self |
|
319 parse: '.3' |
|
320 rule: #floatingPointLiteral |
|
321 ! ! |
|
322 |
|
323 !PPJavaLexiconTest methodsFor:'testing-literals'! |
|
324 |
|
325 testBooleanLiteral1 |
|
326 self |
|
327 parse: 'true' |
|
328 rule: #booleanLiteral |
|
329 ! |
|
330 |
|
331 testBooleanLiteral2 |
|
332 self |
|
333 parse: 'false' |
|
334 rule: #booleanLiteral |
|
335 ! |
|
336 |
|
337 testLiteral1 |
|
338 |
|
339 self |
|
340 parse: 'null' |
|
341 rule: #literal |
|
342 ! |
|
343 |
|
344 testLiteral10 |
|
345 |
|
346 self |
|
347 fail: '0777 L' |
|
348 rule: #literal |
|
349 ! |
|
350 |
|
351 testLiteral11 |
|
352 |
|
353 self |
|
354 fail: '0777 0' |
|
355 rule: #literal |
|
356 ! |
|
357 |
|
358 testLiteral12 |
|
359 |
|
360 self |
|
361 fail: '0 x' |
|
362 rule: #literal |
|
363 ! |
|
364 |
|
365 testLiteral13 |
|
366 |
|
367 self |
|
368 parse: '"This is a Java string"' |
|
369 rule: #literal |
|
370 ! |
|
371 |
|
372 testLiteral2 |
|
373 |
|
374 self |
|
375 parse: 'false' |
|
376 rule: #literal |
|
377 ! |
|
378 |
|
379 testLiteral3 |
|
380 |
|
381 self |
|
382 parse: '6.022137e+23f' |
|
383 rule: #literal |
|
384 ! |
|
385 |
|
386 testLiteral4 |
|
387 |
|
388 self |
|
389 parse: '1e1' |
|
390 rule: #literal |
|
391 ! |
|
392 |
|
393 testLiteral5 |
|
394 |
|
395 self |
|
396 parse: '0x100000000L' |
|
397 rule: #literal |
|
398 ! |
|
399 |
|
400 testLiteral6 |
|
401 |
|
402 self |
|
403 parse: '0372' |
|
404 rule: #literal |
|
405 ! |
|
406 |
|
407 testLiteral7 |
|
408 |
|
409 self |
|
410 parse: '0xDadaCafe' |
|
411 rule: #literal |
|
412 ! |
|
413 |
|
414 testLiteral8 |
|
415 |
|
416 self |
|
417 parse: '0x00FF00FF' |
|
418 rule: #literal |
|
419 ! |
|
420 |
|
421 testLiteral9 |
|
422 |
|
423 self |
|
424 parse: '0777L' |
|
425 rule: #literal |
|
426 ! |
|
427 |
|
428 testNullLiteral1 |
|
429 |
|
430 self |
|
431 parse: 'null' |
|
432 rule: #nullLiteral |
|
433 ! |
|
434 |
|
435 testStringLiteral1 |
|
436 |
|
437 self |
|
438 parse: '""' |
|
439 rule: #stringLiteral |
|
440 ! |
|
441 |
|
442 testStringLiteral10 |
|
443 |
|
444 self |
|
445 fail: '"This is a \\ |
|
446 two lines Java string"' |
|
447 rule: #stringLiteral |
|
448 ! |
|
449 |
|
450 testStringLiteral11 |
|
451 |
|
452 self |
|
453 parse: '"null"' |
|
454 rule: #stringLiteral |
|
455 ! |
|
456 |
|
457 testStringLiteral2 |
|
458 |
|
459 self |
|
460 parse: '"\""' |
|
461 rule: #stringLiteral |
|
462 ! |
|
463 |
|
464 testStringLiteral3 |
|
465 |
|
466 self |
|
467 parse: '"This is a Java string"' |
|
468 rule: #stringLiteral |
|
469 ! |
|
470 |
|
471 testStringLiteral4 |
|
472 |
|
473 self |
|
474 fail: '"This is a |
|
475 two lines Java string"' |
|
476 rule: #stringLiteral |
|
477 ! |
|
478 |
|
479 testStringLiteral5 |
|
480 |
|
481 self |
|
482 fail: '"This is a \b |
|
483 two lines Java string"' |
|
484 rule: #stringLiteral |
|
485 ! |
|
486 |
|
487 testStringLiteral6 |
|
488 |
|
489 self |
|
490 fail: '"This is a \t |
|
491 two lines Java string"' |
|
492 rule: #stringLiteral |
|
493 ! |
|
494 |
|
495 testStringLiteral7 |
|
496 |
|
497 self |
|
498 fail: '"This is a \n |
|
499 two lines Java string"' |
|
500 rule: #stringLiteral |
|
501 ! |
|
502 |
|
503 testStringLiteral8 |
|
504 |
|
505 self |
|
506 fail: '"This is a \f |
|
507 two lines Java string"' |
|
508 rule: #stringLiteral |
|
509 ! |
|
510 |
|
511 testStringLiteral9 |
|
512 |
|
513 self |
|
514 fail: '"This is a \r |
|
515 two lines Java string"' |
|
516 rule: #stringLiteral |
|
517 ! ! |
|
518 |
|
519 !PPJavaLexiconTest methodsFor:'testing-literals-characters'! |
|
520 |
|
521 testCharacterLiteral1 |
|
522 self |
|
523 parse: '''a''' |
|
524 rule: #characterLiteral |
|
525 ! |
|
526 |
|
527 testCharacterLiteral2 |
|
528 self |
|
529 parse: '''%''' |
|
530 rule: #characterLiteral |
|
531 ! |
|
532 |
|
533 testCharacterLiteral3 |
|
534 self |
|
535 parse: '''\t''' |
|
536 rule: #characterLiteral |
|
537 ! |
|
538 |
|
539 testCharacterLiteral4 |
|
540 self |
|
541 parse: '''\\''' |
|
542 rule: #characterLiteral |
|
543 ! |
|
544 |
|
545 testCharacterLiteral5 |
|
546 self |
|
547 parse: '''\''''' |
|
548 rule: #characterLiteral |
|
549 ! |
|
550 |
|
551 testCharacterLiteral6 |
|
552 "not clear how this must be supported |
|
553 (see http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.6)" |
|
554 |
|
555 "self |
|
556 parse: '''\u03a9''' |
|
557 rule: #characterLiteral" |
|
558 ! |
|
559 |
|
560 testCharacterLiteral7 |
|
561 "not clear how this must be supported |
|
562 (see http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.6)" |
|
563 " |
|
564 self |
|
565 parse: '''\uFFFF''' |
|
566 rule: #characterLiteral" |
|
567 ! |
|
568 |
|
569 testCharacterLiteral8 |
|
570 self |
|
571 parse: '''\177''' |
|
572 rule: #characterLiteral |
|
573 ! |
|
574 |
|
575 testSeparator1 |
|
576 self |
|
577 parse: '{' |
|
578 rule: #separator |
|
579 ! ! |
|
580 |
|
581 !PPJavaLexiconTest methodsFor:'testing-literals-integer'! |
|
582 |
|
583 testHexIntegerLiteral1 |
|
584 self |
|
585 parse: '0xC0B0L' |
|
586 rule: #hexIntegerLiteral |
|
587 ! |
|
588 |
|
589 testIntegerLiteral1 |
|
590 self |
|
591 parse: '0' |
|
592 rule: #integerLiteral |
|
593 ! |
|
594 |
|
595 testIntegerLiteral10 |
|
596 self |
|
597 parse: '1996' |
|
598 rule: #integerLiteral |
|
599 ! |
|
600 |
|
601 testIntegerLiteral11 |
|
602 self |
|
603 parse: '0x00FF00FF' |
|
604 rule: #integerLiteral |
|
605 ! |
|
606 |
|
607 testIntegerLiteral2 |
|
608 self |
|
609 parse: '0l' |
|
610 rule: #integerLiteral |
|
611 ! |
|
612 |
|
613 testIntegerLiteral3 |
|
614 self |
|
615 parse: '0777L' |
|
616 rule: #integerLiteral |
|
617 ! |
|
618 |
|
619 testIntegerLiteral4 |
|
620 self |
|
621 parse: '0x100000000L' |
|
622 rule: #integerLiteral |
|
623 ! |
|
624 |
|
625 testIntegerLiteral5 |
|
626 self |
|
627 parse: '2147483648L' |
|
628 rule: #integerLiteral |
|
629 ! |
|
630 |
|
631 testIntegerLiteral6 |
|
632 self |
|
633 parse: '0xC0B0L' |
|
634 rule: #integerLiteral |
|
635 ! |
|
636 |
|
637 testIntegerLiteral7 |
|
638 self |
|
639 parse: '2' |
|
640 rule: #integerLiteral |
|
641 ! |
|
642 |
|
643 testIntegerLiteral8 |
|
644 self |
|
645 parse: '0372' |
|
646 rule: #integerLiteral |
|
647 ! |
|
648 |
|
649 testIntegerLiteral9 |
|
650 self |
|
651 parse: '0xDadaCafe' |
|
652 rule: #integerLiteral |
|
653 ! |
|
654 |
|
655 testOctalIntegerLiteral1 |
|
656 self |
|
657 parse: '0777L' |
|
658 rule: #octalIntegerLiteral |
|
659 ! |
|
660 |
|
661 testOperator |
|
662 self |
|
663 parse: '>' |
|
664 rule: #operator |
|
665 ! ! |
|
666 |
|
667 !PPJavaLexiconTest methodsFor:'testing-unicode'! |
|
668 |
|
669 testUnicodeEscape1 |
|
670 |
|
671 self |
|
672 parse: '\u0000' |
|
673 rule: #unicodeEscape |
|
674 ! |
|
675 |
|
676 testUnicodeEscape2 |
|
677 |
|
678 self |
|
679 fail: '\u000' |
|
680 rule: #unicodeEscape |
|
681 ! |
|
682 |
|
683 testUnicodeEscape3 |
|
684 |
|
685 self |
|
686 fail: '\u00000' |
|
687 rule: #unicodeEscape |
|
688 ! |
|
689 |
|
690 testUnicodeInputCharacter1 |
|
691 |
|
692 self |
|
693 parse: '\u0000' |
|
694 rule: #unicodeInputCharacter |
|
695 ! |
|
696 |
|
697 testUnicodeInputCharacter2 |
|
698 |
|
699 self |
|
700 parse: '\' |
|
701 rule: #unicodeInputCharacter |
|
702 ! |
|
703 |
|
704 testUnicodeInputCharacter3 |
|
705 |
|
706 self |
|
707 parse: 'µ' |
|
708 rule: #unicodeInputCharacter |
|
709 ! |
|
710 |
|
711 testUnicodeInputCharacter4 |
|
712 |
|
713 self |
|
714 fail: '\\' |
|
715 rule: #unicodeInputCharacter |
|
716 ! |
|
717 |
|
718 testUnicodeInputCharacter5 |
|
719 self |
|
720 parse: '\u2297' |
|
721 rule: #unicodeInputCharacter |
|
722 ! |
|
723 |
|
724 testUnicodeInputCharacter6 |
|
725 self |
|
726 fail: '\u2H97' |
|
727 rule: #unicodeInputCharacter |
|
728 ! |
|
729 |
|
730 testUnicodeInputCharacter7 |
|
731 "unicode value for \" |
|
732 self |
|
733 parse: '\u005a' |
|
734 rule: #unicodeInputCharacter |
|
735 ! |
|
736 |
|
737 testWhiteSpace1 |
|
738 "Testing whiteSpace parser" |
|
739 self |
|
740 parse: (Character value: 12) asString |
|
741 rule: #whiteSpace |
|
742 ! |
|
743 |
|
744 testWhiteSpace2 |
|
745 "Testing whiteSpace parser" |
|
746 self |
|
747 fail: 'WhiteSpace testing' |
|
748 rule: #whiteSpace |
|
749 ! ! |
|
750 |