|
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 |
|
13 !PPCExpressionGrammarVerificationTest class methodsFor:'accessing'! |
|
14 |
|
15 resources |
|
16 ^ (OrderedCollection with: PPCResources) |
|
17 addAll: super resources; |
|
18 yourself |
|
19 ! ! |
|
20 |
|
21 !PPCExpressionGrammarVerificationTest class methodsFor:'testing'! |
|
22 |
|
23 isAbstract |
|
24 ^ self == PPCExpressionGrammarVerificationTest |
|
25 |
|
26 "Modified: / 29-07-2015 / 18:50:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
27 ! ! |
|
28 |
|
29 !PPCExpressionGrammarVerificationTest methodsFor:'accessing'! |
|
30 |
|
31 petitParserClass |
|
32 "Return the name of the petit parser to compile" |
|
33 |
|
34 ^ PPExpressionGrammar |
|
35 |
|
36 "Modified: / 29-07-2015 / 17:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
37 ! ! |
|
38 |
|
39 !PPCExpressionGrammarVerificationTest methodsFor:'setup'! |
|
40 |
|
41 setUp |
|
42 super setUp. |
|
43 fileResources := (self resources detect: [:e | e = PPCResources ]) current. |
|
44 ! |
|
45 |
|
46 tearDown |
|
47 super tearDown. |
|
48 " |
|
49 self compiledSmalltalkGrammarClass isNil ifFalse:[ |
|
50 self compiledSmalltalkGrammarClass removeFromSystem |
|
51 ]. |
|
52 " |
|
53 ! ! |
|
54 |
|
55 !PPCExpressionGrammarVerificationTest methodsFor:'tests'! |
|
56 |
|
57 testExpressions |
|
58 | compiledParser petitParser expected actual | |
|
59 petitParser := self petitParser. |
|
60 compiledParser := self compiledParser. |
|
61 |
|
62 fileResources expressionSourcesMedium do: [ :source | |
|
63 expected := petitParser parse: source. |
|
64 expected isPetitFailure ifFalse: [ |
|
65 actual := (compiledParser parse: source withContext: self context). |
|
66 self assert: expected equals: actual. |
|
67 ] |
|
68 ]. |
|
69 |
|
70 "Modified: / 29-07-2015 / 17:03:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
71 ! |
|
72 |
|
73 testSanity |
|
74 | compiledParser petitParser source | |
|
75 petitParser := self petitParser. |
|
76 compiledParser := self compiledParser. |
|
77 |
|
78 source := fileResources expressionOfSize: 100. |
|
79 result := petitParser parse: source. |
|
80 |
|
81 self assert: (((self deepFlattened: result) select: [ :e | e isNumber ]) size) = 100. |
|
82 self assert: (((self deepFlattened: result)select: [ :e | e isNumber ]) size) = 100. |
|
83 |
|
84 "Modified: / 29-07-2015 / 17:03:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
85 ! ! |
|
86 |
|
87 !PPCExpressionGrammarVerificationTest methodsFor:'utilities'! |
|
88 |
|
89 deepFlatten: anObject into: aCollection |
|
90 (anObject isCollection and:[anObject isString not]) ifTrue:[ |
|
91 anObject do:[:each|self deepFlatten: each into: aCollection] |
|
92 ] ifFalse:[ |
|
93 aCollection add: anObject |
|
94 ]. |
|
95 ^aCollection |
|
96 ! |
|
97 |
|
98 deepFlattened: aCollection |
|
99 ^self deepFlatten: aCollection into: OrderedCollection new. |
|
100 ! ! |
|
101 |
|
102 !PPCExpressionGrammarVerificationTest class methodsFor:'documentation'! |
|
103 |
|
104 version |
|
105 ^ 'Path: stx/goodies/petitparser/compiler/tests/extras/PPCExpressionsVerificationTest.st, Version: 1.0, User: jv, Time: 2015-07-29T18:56:55.770+01' |
|
106 ! |
|
107 |
|
108 version_HG |
|
109 ^ 'Path: stx/goodies/petitparser/compiler/tests/extras/PPCExpressionsVerificationTest.st, Version: 1.0, User: jv, Time: 2015-07-29T18:56:55.770+01' |
|
110 ! ! |
|
111 |