author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 24 Nov 2014 11:38:11 +0000 | |
changeset 423 | f3b99c7c1b20 |
parent 377 | 6112a403a52d |
child 454 | a9cd5ea7cc36 |
permissions | -rw-r--r-- |
158 | 1 |
"{ Package: 'stx:goodies/petitparser/tests' }" |
2 |
||
3 |
PPAbstractParserTest subclass:#PPCompositeParserTest |
|
4 |
instanceVariableNames:'parser result' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'PetitTests-Core' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!PPCompositeParserTest class methodsFor:'accessing'! |
|
12 |
||
13 |
resources |
|
14 |
^ Array with: PPParserResource |
|
15 |
! ! |
|
16 |
||
17 |
!PPCompositeParserTest class methodsFor:'testing'! |
|
18 |
||
19 |
isAbstract |
|
20 |
^ self name = #PPCompositeParserTest |
|
21 |
! ! |
|
22 |
||
23 |
!PPCompositeParserTest methodsFor:'accessing'! |
|
24 |
||
25 |
parserClass |
|
26 |
self subclassResponsibility |
|
27 |
! |
|
28 |
||
29 |
parserInstance |
|
30 |
^ PPParserResource current parserAt: self parserClass |
|
31 |
! |
|
32 |
||
33 |
parserInstanceFor: aSymbol |
|
34 |
^ aSymbol = #start |
|
35 |
ifTrue: [ self parserInstance ] |
|
36 |
ifFalse: [ |
|
37 |
self parserInstance |
|
38 |
productionAt: aSymbol |
|
39 |
ifAbsent: [ self error: 'Production ' , self parserClass name , '>>' , aSymbol printString , ' not found.' ] ] |
|
40 |
! ! |
|
41 |
||
42 |
!PPCompositeParserTest methodsFor:'parsing'! |
|
43 |
||
44 |
fail: aString rule: aSymbol |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
45 |
| production context | |
158 | 46 |
production := self parserInstanceFor: aSymbol. |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
47 |
context := self context. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
48 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
49 |
result := production end parse: aString withContext: context. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
50 |
|
158 | 51 |
self |
52 |
assert: result isPetitFailure |
|
53 |
description: 'Able to parse ' , aString printString. |
|
54 |
^ result |
|
55 |
! |
|
56 |
||
57 |
parse: aString |
|
58 |
^ self parse: aString rule: #start |
|
59 |
! |
|
60 |
||
61 |
parse: aString rule: aSymbol |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
62 |
| production context | |
158 | 63 |
production := self parserInstanceFor: aSymbol. |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
64 |
context := self context. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
65 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
66 |
result := production end parse: aString withContext: context. |
158 | 67 |
self |
68 |
deny: result isPetitFailure |
|
69 |
description: 'Unable to parse ' , aString printString. |
|
70 |
^ result |
|
71 |
! ! |
|
72 |
||
73 |
!PPCompositeParserTest methodsFor:'running'! |
|
74 |
||
75 |
setUp |
|
76 |
super setUp. |
|
77 |
parser := self parserInstance |
|
78 |
! |
|
79 |
||
80 |
tearDown |
|
81 |
super tearDown. |
|
82 |
parser := result := nil |
|
83 |
! ! |
|
84 |
||
85 |
!PPCompositeParserTest methodsFor:'utilities'! |
|
86 |
||
87 |
assert: aCollection is: anObject |
|
88 |
self parse: aCollection. |
|
89 |
self |
|
90 |
assert: result = anObject |
|
91 |
description: 'Got: ' , result printString , '; Expected: ' , anObject printString |
|
92 |
resumable: true |
|
93 |
! ! |
|
94 |
||
95 |
!PPCompositeParserTest class methodsFor:'documentation'! |
|
96 |
||
97 |
version |
|
317 | 98 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/tests/PPCompositeParserTest.st,v 1.2 2014-03-04 20:31:51 cg Exp $' |
158 | 99 |
! |
100 |
||
101 |
version_CVS |
|
317 | 102 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/tests/PPCompositeParserTest.st,v 1.2 2014-03-04 20:31:51 cg Exp $' |
158 | 103 |
! |
104 |
||
376
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
317
diff
changeset
|
105 |
version_HG |
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
317
diff
changeset
|
106 |
|
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
317
diff
changeset
|
107 |
^ '$Changeset: <not expanded> $' |
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
317
diff
changeset
|
108 |
! |
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
317
diff
changeset
|
109 |
|
158 | 110 |
version_SVN |
317 | 111 |
^ '$Id: PPCompositeParserTest.st,v 1.2 2014-03-04 20:31:51 cg Exp $' |
158 | 112 |
! ! |
113 |