author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 01 Nov 2014 00:12:10 +0000 | |
changeset 402 | 1d7503124bc8 |
parent 210 | d9e67752b114 |
child 425 | 0a5c4929af56 |
permissions | -rw-r--r-- |
210 | 1 |
"{ Package: 'stx:goodies/petitparser/analyzer/tests' }" |
2 |
||
3 |
PPAbstractParserTest subclass:#PPSearcherTest |
|
4 |
instanceVariableNames:'searcher' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'PetitAnalyzer-Tests' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!PPSearcherTest methodsFor:'running'! |
|
12 |
||
13 |
setUp |
|
14 |
searcher := PPSearcher new |
|
15 |
! ! |
|
16 |
||
17 |
!PPSearcherTest methodsFor:'testing'! |
|
18 |
||
19 |
testAnyPattern |
|
20 |
| result | |
|
21 |
searcher |
|
22 |
matches: PPPattern any |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
23 |
do: [ :parser :answer | |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
24 |
answer |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
25 |
add: parser; |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
26 |
yourself ]. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
27 |
result := searcher execute: $a asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
28 |
self assert: result size equals: 1. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
29 |
result := searcher execute: $a asParser star initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
30 |
self assert: result size equals: 2. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
31 |
result := searcher execute: $a asParser , $b asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
32 |
self assert: result size equals: 3 |
210 | 33 |
! |
34 |
||
35 |
testClassPattern |
|
36 |
| result | |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
37 |
searcher |
210 | 38 |
matches: (PPPattern class: PPLiteralObjectParser) |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
39 |
do: [ :parser :answer | |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
40 |
answer |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
41 |
add: parser; |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
42 |
yourself ]. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
43 |
result := searcher execute: $a asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
44 |
self assert: result size equals: 1. |
210 | 45 |
self assert: (result allSatisfy: [ :each | each class = PPLiteralObjectParser ]). |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
46 |
result := searcher execute: 'abc' asParser initialAnswer: OrderedCollection new. |
210 | 47 |
self assert: result isEmpty. |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
48 |
result := searcher execute: #any asParser initialAnswer: OrderedCollection new. |
210 | 49 |
self assert: result isEmpty. |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
50 |
result := searcher execute: $a asParser / #any asParser , $b asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
51 |
self assert: result size equals: 2. |
210 | 52 |
self assert: (result allSatisfy: [ :each | each class = PPLiteralObjectParser ]) |
53 |
! |
|
54 |
||
55 |
testKindPattern |
|
56 |
| result | |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
57 |
searcher |
210 | 58 |
matches: (PPPattern kind: PPLiteralParser) |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
59 |
do: [ :parser :answer | |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
60 |
answer |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
61 |
add: parser; |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
62 |
yourself ]. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
63 |
result := searcher execute: $a asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
64 |
self assert: result size equals: 1. |
210 | 65 |
self assert: (result allSatisfy: [ :each | each class = PPLiteralObjectParser ]). |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
66 |
result := searcher execute: 'abc' asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
67 |
self assert: result size equals: 1. |
210 | 68 |
self assert: (result allSatisfy: [ :each | each class = PPLiteralSequenceParser ]). |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
69 |
result := searcher execute: #any asParser initialAnswer: OrderedCollection new. |
210 | 70 |
self assert: result isEmpty. |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
71 |
result := searcher execute: $a asParser / #any asParser , $b asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
72 |
self assert: result size equals: 2. |
210 | 73 |
self assert: (result allSatisfy: [ :each | each class = PPLiteralObjectParser ]) |
74 |
! |
|
75 |
||
76 |
testMatchesAny |
|
77 |
| result | |
|
78 |
searcher |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
79 |
matchesAnyOf: (Array with: $a asParser with: $b asParser) |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
80 |
do: [ :parser :answer | |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
81 |
answer |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
82 |
add: parser; |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
83 |
yourself ]. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
84 |
result := searcher execute: $a asParser , $b asParser , $c asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
85 |
self assert: result size equals: 2. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
86 |
self assert: result first literal equals: $a. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
87 |
self assert: result last literal equals: $b |
210 | 88 |
! |
89 |
||
90 |
testMultiplePattern |
|
91 |
| result | |
|
92 |
searcher |
|
93 |
matches: $a asParser |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
94 |
do: [ :parser :answer | |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
95 |
answer first add: parser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
96 |
answer ]. |
210 | 97 |
searcher |
98 |
matches: PPPattern any |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
99 |
do: [ :parser :answer | |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
100 |
answer second add: parser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
101 |
answer ]. |
210 | 102 |
result := searcher |
103 |
execute: $a asParser , $a asParser , $b asParser |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
104 |
initialAnswer: (Array with: OrderedCollection new with: OrderedCollection new). |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
105 |
self assert: result first size equals: 2. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
106 |
self assert: result first first literal equals: $a. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
107 |
self assert: result first last literal equals: $a. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
108 |
self assert: result last size equals: 2. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
109 |
self assert: result last first class equals: PPSequenceParser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
110 |
self assert: result last last literal equals: $b |
210 | 111 |
! |
112 |
||
113 |
testNamePattern |
|
114 |
| result | |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
115 |
searcher |
210 | 116 |
matches: (PPPattern name: 'foo') |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
117 |
do: [ :parser :answer | |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
118 |
answer |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
119 |
add: parser; |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
120 |
yourself ]. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
121 |
result := searcher execute: $a asParser initialAnswer: OrderedCollection new. |
210 | 122 |
self assert: result isEmpty. |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
123 |
result := searcher execute: ($a asParser name: 'foo') initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
124 |
self assert: result size equals: 1. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
125 |
self assert: result first name equals: 'foo'. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
126 |
result := searcher execute: ($a asParser name: 'bar') , ($b asParser name: 'foo') initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
127 |
self assert: result size equals: 1. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
128 |
self assert: result first name equals: 'foo' |
210 | 129 |
! |
130 |
||
131 |
testNewPattern |
|
132 |
self |
|
133 |
should: [ PPPattern new ] |
|
134 |
raise: Error |
|
135 |
! |
|
136 |
||
137 |
testRecursivePattern |
|
138 |
| recursive | |
|
139 |
recursive := PPDelegateParser new. |
|
140 |
recursive setParser: recursive. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
141 |
searcher matches: recursive do: [ :parser :answer | parser ]. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
142 |
self assert: (searcher execute: recursive) equals: recursive. |
210 | 143 |
self assert: (searcher execute: $a asParser) isNil. |
144 |
self assert: (searcher execute: $a asParser / $b asParser star) isNil |
|
145 |
! |
|
146 |
||
147 |
testRepeatedPattern |
|
148 |
| pattern result | |
|
149 |
searcher |
|
150 |
matches: (pattern := PPPattern any) , pattern |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
151 |
do: [ :parser :answer | |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
152 |
answer |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
153 |
add: parser; |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
154 |
yourself ]. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
155 |
result := searcher execute: $a asParser , $b asParser initialAnswer: OrderedCollection new. |
210 | 156 |
self assert: result isEmpty. |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
157 |
result := searcher execute: $a asParser , $a asParser initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
158 |
self assert: result size equals: 1. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
159 |
result := searcher execute: $a asParser , ($a asParser , $b asParser) initialAnswer: OrderedCollection new. |
210 | 160 |
self assert: result isEmpty. |
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
161 |
result := searcher execute: $b asParser , ($a asParser , $a asParser) initialAnswer: OrderedCollection new. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
162 |
self assert: result size equals: 1 |
210 | 163 |
! ! |
164 |
||
165 |
!PPSearcherTest methodsFor:'testing-copy'! |
|
166 |
||
167 |
testCopyMatchAction |
|
168 |
| old new | |
|
169 |
old := $a asParser ==> [ :token | $b ]. |
|
170 |
new := old copyInContext: Dictionary new. |
|
171 |
self assert: (old match: old inContext: Dictionary new). |
|
172 |
self assert: (old match: new inContext: Dictionary new). |
|
173 |
self deny: (old == new). |
|
174 |
! |
|
175 |
||
176 |
testCopyMatchDelegate |
|
177 |
| old new | |
|
178 |
old := $a asParser token trim. |
|
179 |
new := old copyInContext: Dictionary new. |
|
180 |
self assert: (old match: old inContext: Dictionary new). |
|
181 |
self assert: (old match: new inContext: Dictionary new). |
|
182 |
self deny: (old == new). |
|
183 |
! |
|
184 |
||
185 |
testCopyMatchEpsilon |
|
186 |
| old new | |
|
187 |
old := nil asParser. |
|
188 |
new := old copyInContext: Dictionary new. |
|
189 |
self assert: (old match: old inContext: Dictionary new). |
|
190 |
self assert: (old match: new inContext: Dictionary new). |
|
191 |
self deny: (old == new). |
|
192 |
! |
|
193 |
||
194 |
testCopyMatchFailure |
|
195 |
| old new | |
|
196 |
old := PPFailingParser message: 'problem'. |
|
197 |
new := old copyInContext: Dictionary new. |
|
198 |
self assert: (old match: old inContext: Dictionary new). |
|
199 |
self assert: (old match: new inContext: Dictionary new). |
|
200 |
self deny: (old == new). |
|
201 |
! |
|
202 |
||
203 |
testCopyMatchList |
|
204 |
| old new | |
|
205 |
old := $a asParser , $b asParser , $c asParser. |
|
206 |
new := old copyInContext: Dictionary new. |
|
207 |
self assert: (old match: old inContext: Dictionary new). |
|
208 |
self assert: (old match: new inContext: Dictionary new). |
|
209 |
self deny: (old == new). |
|
210 |
! |
|
211 |
||
212 |
testCopyMatchLiteral |
|
213 |
| old new | |
|
214 |
old := $a asParser. |
|
215 |
new := old copyInContext: Dictionary new. |
|
216 |
self assert: (old match: old inContext: Dictionary new). |
|
217 |
self assert: (old match: new inContext: Dictionary new). |
|
218 |
self deny: (old == new). |
|
219 |
! |
|
220 |
||
221 |
testCopyMatchPluggable |
|
222 |
| old new | |
|
223 |
old := [ :stream | ] asParser. |
|
224 |
new := old copyInContext: Dictionary new. |
|
225 |
self assert: (old match: old inContext: Dictionary new). |
|
226 |
self assert: (old match: new inContext: Dictionary new). |
|
227 |
self deny: (old == new). |
|
228 |
! |
|
229 |
||
230 |
testCopyMatchPredicate |
|
231 |
| old new | |
|
232 |
old := #word asParser. |
|
233 |
new := old copyInContext: Dictionary new. |
|
234 |
self assert: (old match: old inContext: Dictionary new). |
|
235 |
self assert: (old match: new inContext: Dictionary new). |
|
236 |
self deny: (old == new). |
|
237 |
! |
|
238 |
||
239 |
testCopyMatchPredicateSequence |
|
240 |
| old new | |
|
241 |
old := 'foo' asParser caseInsensitive. |
|
242 |
new := old copyInContext: Dictionary new. |
|
243 |
self assert: (old match: old inContext: Dictionary new). |
|
244 |
self assert: (old match: new inContext: Dictionary new). |
|
245 |
self deny: (old == new). |
|
246 |
! |
|
247 |
||
248 |
testCopyMatchRecursiveDelegate |
|
249 |
| old new | |
|
250 |
old := PPDelegateParser new. |
|
251 |
old setParser: old. |
|
252 |
new := old copyInContext: Dictionary new. |
|
253 |
self assert: (old match: old inContext: Dictionary new). |
|
254 |
self assert: (old match: new inContext: Dictionary new). |
|
255 |
self deny: (old == new). |
|
256 |
! |
|
257 |
||
258 |
testCopyMatchRecursiveList |
|
259 |
| old new | |
|
260 |
old := PPChoiceParser new. |
|
261 |
old setParsers: (Array with: old). |
|
262 |
new := old copyInContext: Dictionary new. |
|
263 |
self assert: (old match: old inContext: Dictionary new). |
|
264 |
self assert: (old match: new inContext: Dictionary new). |
|
265 |
self deny: (old == new). |
|
266 |
! |
|
267 |
||
268 |
testCopyMatchRepetition |
|
269 |
| old new | |
|
270 |
old := #word asParser star. |
|
271 |
new := old copyInContext: Dictionary new. |
|
272 |
self assert: (old match: old inContext: Dictionary new). |
|
273 |
self assert: (old match: new inContext: Dictionary new). |
|
274 |
self deny: (old == new). |
|
275 |
! |
|
276 |
||
277 |
testCopyMatchRepetitionGreedy |
|
278 |
| old new | |
|
279 |
old := #word asParser starGreedy: #digit asParser. |
|
280 |
new := old copyInContext: Dictionary new. |
|
281 |
self assert: (old match: old inContext: Dictionary new). |
|
282 |
self assert: (old match: new inContext: Dictionary new). |
|
283 |
self deny: (old == new). |
|
284 |
! |
|
285 |
||
286 |
testCopyMatchRepetitionLazy |
|
287 |
| old new | |
|
288 |
old := #word asParser starLazy: #digit asParser. |
|
289 |
new := old copyInContext: Dictionary new. |
|
290 |
self assert: (old match: old inContext: Dictionary new). |
|
291 |
self assert: (old match: new inContext: Dictionary new). |
|
292 |
self deny: (old == new). |
|
293 |
! |
|
294 |
||
295 |
testCopyMatchRepetitionMinMax |
|
296 |
| old new | |
|
297 |
old := #word asParser min: 5 max: 10. |
|
298 |
new := old copyInContext: Dictionary new. |
|
299 |
self assert: (old match: old inContext: Dictionary new). |
|
300 |
self assert: (old match: new inContext: Dictionary new). |
|
301 |
self deny: (old == new). |
|
302 |
! ! |
|
303 |
||
304 |
!PPSearcherTest methodsFor:'testing-lists'! |
|
305 |
||
306 |
testListInfix |
|
307 |
| result | |
|
308 |
searcher |
|
309 |
matches: PPListPattern any , $a asParser , PPListPattern any |
|
310 |
do: [ :parser :answer | true ]. |
|
311 |
||
312 |
result := searcher |
|
313 |
execute: $a asParser , $a asParser |
|
314 |
initialAnswer: false. |
|
315 |
self assert: result. |
|
316 |
||
317 |
result := searcher |
|
318 |
execute: $a asParser , $b asParser |
|
319 |
initialAnswer: false. |
|
320 |
self assert: result. |
|
321 |
||
322 |
result := searcher |
|
323 |
execute: $b asParser , $a asParser |
|
324 |
initialAnswer: false. |
|
325 |
self assert: result. |
|
326 |
||
327 |
result := searcher |
|
328 |
execute: $b asParser , $b asParser |
|
329 |
initialAnswer: false. |
|
330 |
self deny: result. |
|
331 |
||
332 |
result := searcher |
|
333 |
execute: $a asParser , $a asParser , $a asParser |
|
334 |
initialAnswer: false. |
|
335 |
self assert: result. |
|
336 |
||
337 |
result := searcher |
|
338 |
execute: $b asParser , $a asParser , $a asParser |
|
339 |
initialAnswer: false. |
|
340 |
self assert: result. |
|
341 |
||
342 |
result := searcher |
|
343 |
execute: $a asParser , $b asParser , $a asParser |
|
344 |
initialAnswer: false. |
|
345 |
self assert: result. |
|
346 |
||
347 |
result := searcher |
|
348 |
execute: $a asParser , $a asParser , $b asParser |
|
349 |
initialAnswer: false. |
|
350 |
self assert: result. |
|
351 |
||
352 |
result := searcher |
|
353 |
execute: $b asParser , $b asParser , $a asParser |
|
354 |
initialAnswer: false. |
|
355 |
self assert: result. |
|
356 |
||
357 |
result := searcher |
|
358 |
execute: $a asParser , $b asParser , $b asParser |
|
359 |
initialAnswer: false. |
|
360 |
self assert: result. |
|
361 |
||
362 |
result := searcher |
|
363 |
execute: $b asParser , $a asParser , $b asParser |
|
364 |
initialAnswer: false. |
|
365 |
self assert: result. |
|
366 |
||
367 |
result := searcher |
|
368 |
execute: $b asParser , $b asParser , $b asParser |
|
369 |
initialAnswer: false. |
|
370 |
self deny: result |
|
371 |
! |
|
372 |
||
373 |
testListPostfix |
|
374 |
| result | |
|
375 |
searcher |
|
376 |
matches: PPListPattern any , $b asParser |
|
377 |
do: [ :parser :answer | true ]. |
|
378 |
||
379 |
result := searcher |
|
380 |
execute: $a asParser , $a asParser |
|
381 |
initialAnswer: false. |
|
382 |
self deny: result. |
|
383 |
||
384 |
result := searcher |
|
385 |
execute: $a asParser , $b asParser |
|
386 |
initialAnswer: false. |
|
387 |
self assert: result. |
|
388 |
||
389 |
result := searcher |
|
390 |
execute: $b asParser , $a asParser |
|
391 |
initialAnswer: false. |
|
392 |
self deny: result. |
|
393 |
||
394 |
result := searcher |
|
395 |
execute: $b asParser , $b asParser |
|
396 |
initialAnswer: false. |
|
397 |
self assert: result. |
|
398 |
||
399 |
result := searcher |
|
400 |
execute: $a asParser , $a asParser , $a asParser |
|
401 |
initialAnswer: false. |
|
402 |
self deny: result. |
|
403 |
||
404 |
result := searcher |
|
405 |
execute: $b asParser , $a asParser , $a asParser |
|
406 |
initialAnswer: false. |
|
407 |
self deny: result. |
|
408 |
||
409 |
result := searcher |
|
410 |
execute: $a asParser , $b asParser , $a asParser |
|
411 |
initialAnswer: false. |
|
412 |
self deny: result. |
|
413 |
||
414 |
result := searcher |
|
415 |
execute: $a asParser , $a asParser , $b asParser |
|
416 |
initialAnswer: false. |
|
417 |
self assert: result. |
|
418 |
||
419 |
result := searcher |
|
420 |
execute: $b asParser , $b asParser , $a asParser |
|
421 |
initialAnswer: false. |
|
422 |
self deny: result. |
|
423 |
||
424 |
result := searcher |
|
425 |
execute: $a asParser , $b asParser , $b asParser |
|
426 |
initialAnswer: false. |
|
427 |
self assert: result. |
|
428 |
||
429 |
result := searcher |
|
430 |
execute: $b asParser , $a asParser , $b asParser |
|
431 |
initialAnswer: false. |
|
432 |
self assert: result. |
|
433 |
||
434 |
result := searcher |
|
435 |
execute: $b asParser , $b asParser , $b asParser |
|
436 |
initialAnswer: false. |
|
437 |
self assert: result |
|
438 |
! |
|
439 |
||
440 |
testListPrefix |
|
441 |
| result | |
|
442 |
searcher |
|
443 |
matches: $a asParser , PPListPattern any |
|
444 |
do: [ :parser :answer | true ]. |
|
445 |
||
446 |
result := searcher |
|
447 |
execute: $a asParser , $a asParser |
|
448 |
initialAnswer: false. |
|
449 |
self assert: result. |
|
450 |
||
451 |
result := searcher |
|
452 |
execute: $a asParser , $b asParser |
|
453 |
initialAnswer: false. |
|
454 |
self assert: result. |
|
455 |
||
456 |
result := searcher |
|
457 |
execute: $b asParser , $a asParser |
|
458 |
initialAnswer: false. |
|
459 |
self deny: result. |
|
460 |
||
461 |
result := searcher |
|
462 |
execute: $b asParser , $b asParser |
|
463 |
initialAnswer: false. |
|
464 |
self deny: result. |
|
465 |
||
466 |
||
467 |
||
468 |
result := searcher |
|
469 |
execute: $a asParser , $a asParser , $a asParser |
|
470 |
initialAnswer: false. |
|
471 |
self assert: result. |
|
472 |
||
473 |
result := searcher |
|
474 |
execute: $b asParser , $a asParser , $a asParser |
|
475 |
initialAnswer: false. |
|
476 |
self deny: result. |
|
477 |
||
478 |
result := searcher |
|
479 |
execute: $a asParser , $b asParser , $a asParser |
|
480 |
initialAnswer: false. |
|
481 |
self assert: result. |
|
482 |
||
483 |
result := searcher |
|
484 |
execute: $a asParser , $a asParser , $b asParser |
|
485 |
initialAnswer: false. |
|
486 |
self assert: result. |
|
487 |
||
488 |
result := searcher |
|
489 |
execute: $b asParser , $b asParser , $a asParser |
|
490 |
initialAnswer: false. |
|
491 |
self deny: result. |
|
492 |
||
493 |
result := searcher |
|
494 |
execute: $a asParser , $b asParser , $b asParser |
|
495 |
initialAnswer: false. |
|
496 |
self assert: result. |
|
497 |
||
498 |
result := searcher |
|
499 |
execute: $b asParser , $a asParser , $b asParser |
|
500 |
initialAnswer: false. |
|
501 |
self deny: result. |
|
502 |
||
503 |
result := searcher |
|
504 |
execute: $b asParser , $b asParser , $b asParser |
|
505 |
initialAnswer: false. |
|
506 |
self deny: result |
|
507 |
! ! |
|
508 |
||
509 |
!PPSearcherTest class methodsFor:'documentation'! |
|
510 |
||
511 |
version |
|
512 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/tests/PPSearcherTest.st,v 1.1 2014-03-04 15:43:09 cg Exp $' |
|
513 |
! |
|
514 |
||
515 |
version_CVS |
|
516 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/tests/PPSearcherTest.st,v 1.1 2014-03-04 15:43:09 cg Exp $' |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
517 |
! |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
518 |
|
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
519 |
version_HG |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
520 |
|
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
210
diff
changeset
|
521 |
^ '$Changeset: <not expanded> $' |
210 | 522 |
! ! |
523 |