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