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