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