1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPAbstractParserTest subclass:#PPCNodeCompilingTest |
|
6 instanceVariableNames:'parser context tree result' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Tests-Nodes' |
|
10 ! |
|
11 |
|
12 |
|
13 !PPCNodeCompilingTest methodsFor:'context'! |
|
14 |
|
15 context |
|
16 ^ context := PPCProfilingContext new |
|
17 ! ! |
|
18 |
|
19 !PPCNodeCompilingTest methodsFor:'test support'! |
|
20 |
|
21 assert: whatever parse: input |
|
22 result := super assert: whatever parse: input. |
|
23 ! |
|
24 |
|
25 compileTree: root |
|
26 ^ self compileTree: root arguments: PPCArguments default |
|
27 ! |
|
28 |
|
29 compileTree: root arguments: arguments |
|
30 | configuration | |
|
31 arguments profile: true. |
|
32 |
|
33 configuration := PPCPluggableConfiguration on: [ :_self | |
|
34 _self specialize. |
|
35 _self specialize. |
|
36 _self tokenize. |
|
37 _self inline. |
|
38 _self merge. |
|
39 _self generate. |
|
40 ]. |
|
41 |
|
42 ^ configuration compile: root arguments: arguments. |
|
43 ! |
|
44 |
|
45 tearDown |
|
46 | class | |
|
47 |
|
48 class := (Smalltalk at: #PPGeneratedParser ifAbsent: [nil]). |
|
49 class notNil ifTrue:[ |
|
50 class removeFromSystem |
|
51 ]. |
|
52 ! ! |
|
53 |
|
54 !PPCNodeCompilingTest methodsFor:'tests - guard'! |
|
55 |
|
56 testSequenceTokenGuard |
|
57 |
|
58 tree := PPCSequenceNode new |
|
59 children: { |
|
60 'foo' asParser trimmingToken asCompilerTree optimizeTree. |
|
61 'bar' asParser trimmingToken asCompilerTree optimizeTree. |
|
62 } |
|
63 yourself. |
|
64 parser := self compileTree: tree. |
|
65 |
|
66 self assert: parser parse: 'foobar'. |
|
67 self assert: result first inputValue = 'foo'. |
|
68 self assert: result second inputValue = 'bar'. |
|
69 |
|
70 self assert: parser parse: ' foobar'. |
|
71 self assert: result first inputValue = 'foo'. |
|
72 self assert: result second inputValue = 'bar'. |
|
73 |
|
74 self assert: parser fail: ' foo'. |
|
75 ! |
|
76 |
|
77 testTrimmingTokenGuard |
|
78 |
|
79 tree := PPCChoiceNode new |
|
80 children: { |
|
81 'foo' asParser trimmingToken asCompilerTree optimizeTree. |
|
82 'bar' asParser trimmingToken asCompilerTree optimizeTree |
|
83 } |
|
84 yourself. |
|
85 parser := self compileTree: tree. |
|
86 |
|
87 self assert: parser parse: 'foo'. |
|
88 self assert: result inputValue = 'foo'. |
|
89 |
|
90 self assert: parser parse: 'bar'. |
|
91 self assert: result inputValue = 'bar'. |
|
92 |
|
93 self assert: parser parse: ' foo'. |
|
94 self assert: result inputValue = 'foo'. |
|
95 |
|
96 self assert: parser parse: ' bar'. |
|
97 self assert: result inputValue = 'bar'. |
|
98 |
|
99 self assert: parser fail: 'zorg'. |
|
100 self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'token' ]). |
|
101 ! ! |
|
102 |
|
103 !PPCNodeCompilingTest class methodsFor:'documentation'! |
|
104 |
|
105 version_HG |
|
106 |
|
107 ^ '$Changeset: <not expanded> $' |
|
108 ! ! |
|
109 |
|