|
1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPCAbstractParserTest subclass:#PPCExpressionGrammarVerificationTest |
|
6 instanceVariableNames:'parser result context resource fileResources' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Extras-Tests-Expressions' |
|
10 ! |
|
11 |
|
12 !PPCExpressionGrammarVerificationTest class methodsFor:'accessing'! |
|
13 |
|
14 resources |
|
15 ^ (OrderedCollection with: PPCResources) |
|
16 addAll: super resources; |
|
17 yourself |
|
18 ! ! |
|
19 |
|
20 !PPCExpressionGrammarVerificationTest class methodsFor:'testing'! |
|
21 |
|
22 isAbstract |
|
23 ^ self == PPCExpressionGrammarVerificationTest |
|
24 |
|
25 "Modified: / 29-07-2015 / 18:50:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
26 ! ! |
|
27 |
|
28 !PPCExpressionGrammarVerificationTest methodsFor:'accessing'! |
|
29 |
|
30 petitParserClass |
|
31 "Return the name of the petit parser to compile" |
|
32 |
|
33 ^ PPExpressionGrammar |
|
34 |
|
35 "Modified: / 29-07-2015 / 17:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
36 ! ! |
|
37 |
|
38 !PPCExpressionGrammarVerificationTest 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 !PPCExpressionGrammarVerificationTest methodsFor:'tests'! |
|
55 |
|
56 testExpressions |
|
57 | compiledParser petitParser expected actual | |
|
58 petitParser := self petitParser. |
|
59 compiledParser := self compiledParser. |
|
60 |
|
61 fileResources expressionSourcesMedium do: [ :source | |
|
62 expected := petitParser parse: source. |
|
63 expected isPetitFailure ifFalse: [ |
|
64 actual := (compiledParser parse: source withContext: self context). |
|
65 self assert: expected equals: actual. |
|
66 ] |
|
67 ]. |
|
68 |
|
69 "Modified: / 29-07-2015 / 17:03:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
70 ! |
|
71 |
|
72 testSanity |
|
73 | compiledParser petitParser source | |
|
74 petitParser := self petitParser. |
|
75 compiledParser := self compiledParser. |
|
76 |
|
77 source := fileResources expressionOfSize: 100. |
|
78 result := petitParser parse: source. |
|
79 |
|
80 self assert: (((self deepFlattened: result) select: [ :e | e isNumber ]) size) = 100. |
|
81 self assert: (((self deepFlattened: result)select: [ :e | e isNumber ]) size) = 100. |
|
82 |
|
83 "Modified: / 29-07-2015 / 17:03:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
84 ! ! |
|
85 |
|
86 !PPCExpressionGrammarVerificationTest methodsFor:'utilities'! |
|
87 |
|
88 deepFlatten: anObject into: aCollection |
|
89 (anObject isCollection and:[anObject isString not]) ifTrue:[ |
|
90 anObject do:[:each|self deepFlatten: each into: aCollection] |
|
91 ] ifFalse:[ |
|
92 aCollection add: anObject |
|
93 ]. |
|
94 ^aCollection |
|
95 ! |
|
96 |
|
97 deepFlattened: aCollection |
|
98 ^self deepFlatten: aCollection into: OrderedCollection new. |
|
99 ! ! |
|
100 |