author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 01 Nov 2014 00:12:10 +0000 | |
changeset 402 | 1d7503124bc8 |
parent 382 | 1825151d6455 |
child 425 | 0a5c4929af56 |
permissions | -rw-r--r-- |
209 | 1 |
"{ Package: 'stx:goodies/petitparser/analyzer/tests' }" |
2 |
||
3 |
PPAbstractParserTest subclass:#PPRewriterTest |
|
4 |
instanceVariableNames:'rewriter' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'PetitAnalyzer-Tests' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!PPRewriterTest methodsFor:'running'! |
|
12 |
||
13 |
setUp |
|
14 |
rewriter := PPRewriter new |
|
15 |
! ! |
|
16 |
||
17 |
!PPRewriterTest methodsFor:'testing'! |
|
18 |
||
19 |
testDuplicationRemoval |
|
20 |
| duplicate before between after result | |
|
21 |
duplicate := PPPattern any. |
|
22 |
before := PPListPattern any. |
|
23 |
between := PPListPattern any. |
|
24 |
after := PPListPattern any. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
25 |
rewriter replace: before / duplicate / between / duplicate / after with: before / duplicate / between / after. |
209 | 26 |
result := rewriter execute: $a asParser / $a asParser. |
27 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
28 |
self assert: result children size equals: 1. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
29 |
self assert: result children first literal equals: $a. |
209 | 30 |
result := rewriter execute: $b asParser / $a asParser / $a asParser. |
31 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
32 |
self assert: result children size equals: 2. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
33 |
self assert: result children first literal equals: $b. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
34 |
self assert: result children last literal equals: $a. |
209 | 35 |
result := rewriter execute: $a asParser / $b asParser / $a asParser. |
36 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
37 |
self assert: result children size equals: 2. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
38 |
self assert: result children 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:
382
diff
changeset
|
39 |
self assert: result children last literal equals: $b. |
209 | 40 |
result := rewriter execute: $a asParser / $a asParser / $b asParser. |
41 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
42 |
self assert: result children size equals: 2. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
43 |
self assert: result children 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:
382
diff
changeset
|
44 |
self assert: result children last literal equals: $b |
209 | 45 |
! |
46 |
||
47 |
testPatternRemoval |
|
48 |
| pattern result | |
|
49 |
pattern := 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:
382
diff
changeset
|
50 |
rewriter replace: pattern / pattern with: pattern. |
209 | 51 |
result := rewriter execute: $a asParser / $a asParser. |
52 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
53 |
self assert: result class equals: PPLiteralObjectParser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
54 |
self assert: result literal equals: $a. |
209 | 55 |
result := rewriter execute: $a asParser / $a asParser / $a asParser. |
56 |
self deny: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
57 |
self assert: result class equals: PPChoiceParser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
58 |
self assert: result children size equals: 3 |
209 | 59 |
! |
60 |
||
61 |
testPatternReplacement |
|
62 |
| pattern result | |
|
63 |
pattern := 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:
382
diff
changeset
|
64 |
rewriter replace: pattern with: pattern , pattern. |
209 | 65 |
result := rewriter execute: $a asParser. |
66 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
67 |
self assert: result class equals: PPSequenceParser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
68 |
self assert: result children 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:
382
diff
changeset
|
69 |
self assert: result children last literal equals: $a. |
209 | 70 |
result := rewriter execute: #any asParser. |
71 |
self deny: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
72 |
self assert: result class equals: PPPredicateObjectParser |
209 | 73 |
! |
74 |
||
75 |
testReplaceLiteral |
|
76 |
| result | |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
77 |
rewriter replace: $a asParser with: $b asParser. |
209 | 78 |
result := rewriter execute: $a asParser. |
79 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
80 |
self assert: result literal equals: $b. |
209 | 81 |
result := rewriter execute: $c asParser. |
82 |
self deny: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
83 |
self assert: result literal equals: $c. |
209 | 84 |
result := rewriter execute: $a asParser , $b asParser , $c asParser. |
85 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
86 |
self assert: result children size equals: 3. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
87 |
self assert: result children first literal equals: $b. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
88 |
self assert: result children last literal equals: $c |
209 | 89 |
! |
90 |
||
91 |
testSwapTwoPattern |
|
92 |
| first second result | |
|
93 |
first := PPPattern any. |
|
94 |
second := PPPattern any. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
95 |
rewriter replace: first , second with: second , first. |
209 | 96 |
result := rewriter execute: $a asParser , $b asParser. |
97 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
98 |
self assert: result children first literal equals: $b. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
99 |
self assert: result children last literal equals: $a. |
209 | 100 |
result := rewriter execute: $a asParser / $b asParser. |
101 |
self deny: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
102 |
self assert: result children 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:
382
diff
changeset
|
103 |
self assert: result children last literal equals: $b |
209 | 104 |
! |
105 |
||
106 |
testWrapLiteral |
|
107 |
| result | |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
108 |
rewriter replace: $a asParser withValueFrom: [ :parser | parser token ]. |
209 | 109 |
result := rewriter execute: $a asParser. |
110 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
111 |
self assert: result class equals: PPTokenParser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
112 |
self assert: result children first literal equals: $a. |
209 | 113 |
result := rewriter execute: $c asParser. |
114 |
self deny: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
115 |
self assert: result literal equals: $c. |
209 | 116 |
result := rewriter execute: $a asParser , $b asParser. |
117 |
self assert: rewriter hasChanged. |
|
402
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
118 |
self assert: result children first class equals: PPTokenParser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
119 |
self assert: result children first children 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:
382
diff
changeset
|
120 |
self assert: result children last class equals: PPLiteralObjectParser. |
1d7503124bc8
Reverted back change from `assert: x equals: y` to assert: (x = u).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
382
diff
changeset
|
121 |
self assert: result children last literal equals: $b |
209 | 122 |
! ! |
123 |
||
124 |
!PPRewriterTest class methodsFor:'documentation'! |
|
125 |
||
126 |
version |
|
127 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/tests/PPRewriterTest.st,v 1.1 2014-03-04 15:43:01 cg Exp $' |
|
128 |
! |
|
129 |
||
130 |
version_CVS |
|
131 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/tests/PPRewriterTest.st,v 1.1 2014-03-04 15:43:01 cg Exp $' |
|
382
1825151d6455
Added target `mcz` to export .mcz package out of Smalltalk/X package.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
209
diff
changeset
|
132 |
! |
1825151d6455
Added target `mcz` to export .mcz package out of Smalltalk/X package.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
209
diff
changeset
|
133 |
|
1825151d6455
Added target `mcz` to export .mcz package out of Smalltalk/X package.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
209
diff
changeset
|
134 |
version_HG |
1825151d6455
Added target `mcz` to export .mcz package out of Smalltalk/X package.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
209
diff
changeset
|
135 |
|
1825151d6455
Added target `mcz` to export .mcz package out of Smalltalk/X package.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
209
diff
changeset
|
136 |
^ '$Changeset: <not expanded> $' |
209 | 137 |
! ! |
138 |