1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPAbstractParserTest subclass:#PPCExpressionsVerificationTest |
|
6 instanceVariableNames:'parser result context resource fileResources' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Extras-Tests-Expressions' |
|
10 ! |
|
11 |
|
12 !PPCExpressionsVerificationTest class methodsFor:'as yet unclassified'! |
|
13 |
|
14 isAbstract |
|
15 ^ self name = #PPCExpressionsVerificationTest |
|
16 ! |
|
17 |
|
18 resources |
|
19 ^ (OrderedCollection with: PPCResources) |
|
20 addAll: super resources; |
|
21 yourself |
|
22 ! ! |
|
23 |
|
24 !PPCExpressionsVerificationTest methodsFor:'accessing'! |
|
25 |
|
26 compiledGrammar |
|
27 ^ self compiledGrammarClass new |
|
28 ! |
|
29 |
|
30 compiledGrammarClass |
|
31 self subclassResponsibility |
|
32 ! |
|
33 |
|
34 grammar |
|
35 ^ PPExpressionGrammar new |
|
36 ! ! |
|
37 |
|
38 !PPCExpressionsVerificationTest methodsFor:'setup'! |
|
39 |
|
40 setUp |
|
41 super setUp. |
|
42 fileResources := (self resources detect: [:e | e = PPCResources ]) current. |
|
43 ! |
|
44 |
|
45 tearDown |
|
46 super tearDown. |
|
47 " |
|
48 self compiledSmalltalkGrammarClass isNil ifFalse:[ |
|
49 self compiledSmalltalkGrammarClass removeFromSystem |
|
50 ]. |
|
51 " |
|
52 ! ! |
|
53 |
|
54 !PPCExpressionsVerificationTest methodsFor:'tests'! |
|
55 |
|
56 testExpressions |
|
57 | compiledParser normalParser expected actual | |
|
58 normalParser := self grammar. |
|
59 compiledParser := self compiledGrammar. |
|
60 |
|
61 fileResources expressionSourcesMedium do: [ :source | |
|
62 expected := normalParser parse: source. |
|
63 expected isPetitFailure ifFalse: [ |
|
64 actual := (compiledParser parse: source withContext: self context). |
|
65 self assert: expected equals: actual. |
|
66 ] |
|
67 ]. |
|
68 ! |
|
69 |
|
70 testSanity |
|
71 | compiledParser normalParser source | |
|
72 normalParser := self grammar. |
|
73 compiledParser := self compiledGrammar. |
|
74 |
|
75 source := fileResources expressionOfSize: 100. |
|
76 result := normalParser parse: source. |
|
77 |
|
78 self assert: (((self deepFlattened: result) select: [ :e | e isNumber ]) size) = 100. |
|
79 self assert: (((self deepFlattened: result)select: [ :e | e isNumber ]) size) = 100. |
|
80 ! ! |
|
81 |
|
82 !PPCExpressionsVerificationTest methodsFor:'utilities'! |
|
83 |
|
84 deepFlatten: anObject into: aCollection |
|
85 (anObject isCollection and:[anObject isString not]) ifTrue:[ |
|
86 anObject do:[:each|self deepFlatten: each into: aCollection] |
|
87 ] ifFalse:[ |
|
88 aCollection add: anObject |
|
89 ]. |
|
90 ^aCollection |
|
91 ! |
|
92 |
|
93 deepFlattened: aCollection |
|
94 ^self deepFlatten: aCollection into: OrderedCollection new. |
|
95 ! ! |
|
96 |
|