90 parser := self compileTree: (PPCCharacterNode new character: Character lf; yourself). |
90 parser := self compileTree: (PPCCharacterNode new character: Character lf; yourself). |
91 self assert: parser parse: String lf. |
91 self assert: parser parse: String lf. |
92 ! |
92 ! |
93 |
93 |
94 testCompileChoice |
94 testCompileChoice |
95 tree := PPCChoiceNode new |
95 tree := PPCChoiceNode new |
96 children: { #digit asParser asCompilerNode. #letter asParser asCompilerNode }; |
96 children: { #digit asParser asCompilerNode. #letter asParser asCompilerNode }; |
97 yourself. |
97 yourself. |
98 |
98 |
99 parser := self compileTree: tree. |
99 parser := self compileTree: tree. |
100 |
100 |
101 self assert: parser class methods size = 4. |
101 self assert: parser class methodDictionary size = 4. |
102 |
102 |
103 self assert: parser parse: '1' to: $1. |
103 self assert: parser parse: '1' to: $1. |
104 self assert: parser parse: 'a' to: $a. |
104 self assert: parser parse: 'a' to: $a. |
105 self assert: parser fail: '_'. |
105 self assert: parser fail: '_'. |
|
106 |
|
107 "Modified: / 30-10-2014 / 23:48:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
106 ! |
108 ! |
107 |
109 |
108 testCompileLiteral |
110 testCompileLiteral |
109 tree := PPCLiteralNode new |
111 tree := PPCLiteralNode new |
110 literal: 'foo'; |
112 literal: 'foo'; |
111 yourself. |
113 yourself. |
112 parser := self compileTree: tree. |
114 parser := self compileTree: tree. |
113 |
115 |
114 self assert: parser class methods size = 2. |
116 self assert: parser class methodDictionary size = 2. |
115 self assert: parser parse: 'foo' to: 'foo'. |
117 self assert: parser parse: 'foo' to: 'foo'. |
116 self assert: parser parse: 'foobar' to: 'foo' end: 3. |
118 self assert: parser parse: 'foobar' to: 'foo' end: 3. |
117 self assert: parser fail: 'boo'. |
119 self assert: parser fail: 'boo'. |
|
120 |
|
121 "Modified: / 30-10-2014 / 23:48:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
118 ! |
122 ! |
119 |
123 |
120 testCompileLiteral2 |
124 testCompileLiteral2 |
121 | | |
125 | | |
122 |
126 |
147 self assert: parser fail: '1'. |
151 self assert: parser fail: '1'. |
148 self assert: parser parse: '' to: nil end: 0. |
152 self assert: parser parse: '' to: nil end: 0. |
149 ! |
153 ! |
150 |
154 |
151 testCompileNotCharSetPredicate |
155 testCompileNotCharSetPredicate |
152 tree := PPCNotCharSetPredicateNode new |
156 tree := PPCNotCharSetPredicateNode new |
153 predicate: (PPCharSetPredicate on: [ :e | e = $a ]); |
157 predicate: (PPCharSetPredicate on: [ :e | e = $a ]); |
154 yourself. |
158 yourself. |
155 parser := self compileTree: tree. |
159 parser := self compileTree: tree. |
156 |
160 |
157 self assert: parser class methods size = 2. |
161 self assert: parser class methodDictionary size = 2. |
158 self assert: parser parse: 'b' to: nil end: 0. |
162 self assert: parser parse: 'b' to: nil end: 0. |
159 self assert: context invocationCount = 2. |
163 self assert: context invocationCount = 2. |
160 |
164 |
161 self assert: parser fail: 'a'. |
165 self assert: parser fail: 'a'. |
162 self assert: parser parse: '' to: nil end: 0. |
166 self assert: parser parse: '' to: nil end: 0. |
|
167 |
|
168 "Modified: / 30-10-2014 / 23:49:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
163 ! |
169 ! |
164 |
170 |
165 testCompileNotLiteral |
171 testCompileNotLiteral |
166 tree := PPCNotLiteralNode new |
172 tree := PPCNotLiteralNode new |
167 literal: 'foo'; |
173 literal: 'foo'; |
168 yourself. |
174 yourself. |
169 parser := self compileTree: tree. |
175 parser := self compileTree: tree. |
170 |
176 |
171 self assert: parser class methods size = 2. |
177 self assert: parser class methodDictionary size = 2. |
172 self assert: parser parse: 'bar' to: nil end: 0. |
178 self assert: parser parse: 'bar' to: nil end: 0. |
173 self assert: context invocationCount = 2. |
179 self assert: context invocationCount = 2. |
174 |
180 |
175 self assert: parser fail: 'foo'. |
181 self assert: parser fail: 'foo'. |
176 self assert: parser parse: '' to: nil end: 0. |
182 self assert: parser parse: '' to: nil end: 0. |
|
183 |
|
184 "Modified: / 30-10-2014 / 23:50:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
177 ! |
185 ! |
178 |
186 |
179 testCompileNotMessagePredicate |
187 testCompileNotMessagePredicate |
180 tree := PPCNotMessagePredicateNode new |
188 tree := PPCNotMessagePredicateNode new |
181 message: #isDigit; |
189 message: #isDigit; |
182 yourself. |
190 yourself. |
183 parser := self compileTree: tree. |
191 parser := self compileTree: tree. |
184 |
192 |
185 self assert: parser class methods size = 2. |
193 self assert: parser class methodDictionary size = 2. |
186 self assert: parser parse: 'a' to: nil end: 0. |
194 self assert: parser parse: 'a' to: nil end: 0. |
187 self assert: context invocationCount = 2. |
195 self assert: context invocationCount = 2. |
188 |
196 |
189 self assert: parser fail: '1'. |
197 self assert: parser fail: '1'. |
190 self assert: parser parse: '' to: nil end: 0. |
198 self assert: parser parse: '' to: nil end: 0. |
|
199 |
|
200 "Modified: / 30-10-2014 / 23:50:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
191 ! |
201 ! |
192 |
202 |
193 testCompileOptional |
203 testCompileOptional |
194 tree := PPCOptionalNode new |
204 tree := PPCOptionalNode new |
195 child: ($a asParser asCompilerNode); |
205 child: ($a asParser asCompilerNode); |
253 self assert: parser parse: 'a' to: #($a). |
263 self assert: parser parse: 'a' to: #($a). |
254 self assert: parser parse: '' to: #(). |
264 self assert: parser parse: '' to: #(). |
255 ! |
265 ! |
256 |
266 |
257 testCompileStarCharSetPredicate |
267 testCompileStarCharSetPredicate |
258 tree := PPCStarCharSetPredicateNode new |
268 tree := PPCStarCharSetPredicateNode new |
259 predicate: (PPCharSetPredicate on: [:e | e = $a ]); |
269 predicate: (PPCharSetPredicate on: [:e | e = $a ]); |
260 yourself. |
270 yourself. |
261 parser := self compileTree: tree. |
271 parser := self compileTree: tree. |
262 |
272 |
263 self assert: parser class methods size = 2. |
273 self assert: parser class methodDictionary size = 2. |
264 self assert: parser parse: 'aaa1' to: #( $a $a $a) end: 3. |
274 self assert: parser parse: 'aaa1' to: #( $a $a $a) end: 3. |
265 self assert: context invocationCount = 2. |
275 self assert: context invocationCount = 2. |
266 self assert: parser parse: 'bba' to: #() end: 0. |
276 self assert: parser parse: 'bba' to: #() end: 0. |
267 self assert: context invocationCount = 2. |
277 self assert: context invocationCount = 2. |
268 |
278 |
|
279 "Modified: / 30-10-2014 / 23:50:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
269 ! |
280 ! |
270 |
281 |
271 testCompileStarMessagePredicate |
282 testCompileStarMessagePredicate |
272 tree := PPCStarMessagePredicateNode new |
283 tree := PPCStarMessagePredicateNode new |
273 message: #isLetter; |
284 message: #isLetter; |
274 yourself. |
285 yourself. |
275 parser := self compileTree: tree. |
286 parser := self compileTree: tree. |
276 |
287 |
277 self assert: parser class methods size = 2. |
288 self assert: parser class methodDictionary size = 2. |
278 self assert: parser parse: 'abc1' to: #( $a $b $c) end: 3. |
289 self assert: parser parse: 'abc1' to: #( $a $b $c) end: 3. |
279 self assert: context invocationCount = 2. |
290 self assert: context invocationCount = 2. |
280 |
291 |
281 self assert: parser parse: '123a' to: #() end: 0. |
292 self assert: parser parse: '123a' to: #() end: 0. |
282 self assert: context invocationCount = 2. |
293 self assert: context invocationCount = 2. |
283 |
294 |
|
295 "Modified: / 30-10-2014 / 23:50:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
284 ! |
296 ! |
285 |
297 |
286 testCompileSymbolAction |
298 testCompileSymbolAction |
287 tree := PPCSymbolActionNode new |
299 tree := PPCSymbolActionNode new |
288 block: #second; |
300 block: #second; |
339 self assert: context lwRestoreCount = 1. |
351 self assert: context lwRestoreCount = 1. |
340 |
352 |
341 ! |
353 ! |
342 |
354 |
343 testCompileTokenStarMessagePredicate |
355 testCompileTokenStarMessagePredicate |
344 |
356 |
345 tree := PPCTokenStarMessagePredicateNode new message: #isLetter. |
357 tree := PPCTokenStarMessagePredicateNode new message: #isLetter. |
346 parser := self compileTree: tree params: {#guards -> false}. |
358 parser := self compileTree: tree params: {#guards -> false}. |
347 |
359 |
348 self assert: parser class methods size = 2. |
360 self assert: parser class methodDictionary size = 2. |
349 |
361 |
350 self assert: parser parse: 'foo' to: parser. |
362 self assert: parser parse: 'foo' to: parser. |
351 self assert: context invocationCount = 2. |
363 self assert: context invocationCount = 2. |
352 self assert: context lwRememberCount = 0. |
364 self assert: context lwRememberCount = 0. |
353 self assert: context lwRestoreCount = 0. |
365 self assert: context lwRestoreCount = 0. |
354 self assert: context rememberCount = 0. |
366 self assert: context rememberCount = 0. |
355 |
367 |
356 self assert: parser parse: 'foo123' to: parser end: 3. |
368 self assert: parser parse: 'foo123' to: parser end: 3. |
|
369 |
|
370 "Modified: / 30-10-2014 / 23:50:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
357 ! ! |
371 ! ! |
358 |
372 |
359 !PPCNodeCompilingTest methodsFor:'tests - guard'! |
373 !PPCNodeCompilingTest methodsFor:'tests - guard'! |
360 |
374 |
361 testSequenceTokenGuard |
375 testSequenceTokenGuard |