author | Claus Gittinger <cg@exept.de> |
Mon, 02 Jul 2018 07:47:14 +0200 | |
changeset 595 | fd4aec118d71 |
parent 361 | 39a00be69192 |
permissions | -rw-r--r-- |
342 | 1 |
"{ Package: 'stx:goodies/petitparser/gui/tests' }" |
2 |
||
3 |
TestCase subclass:#PPGrammarRefactoringTest |
|
4 |
instanceVariableNames:'refactoring' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'PetitGui-Tests' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!PPGrammarRefactoringTest methodsFor:'accessing'! |
|
12 |
||
13 |
change |
|
14 |
^ self refactoring changes |
|
15 |
! |
|
16 |
||
17 |
changes |
|
18 |
^ self change changes |
|
19 |
! |
|
20 |
||
21 |
refactoring |
|
22 |
^ refactoring |
|
23 |
! ! |
|
24 |
||
25 |
!PPGrammarRefactoringTest methodsFor:'testing-parsers'! |
|
26 |
||
27 |
testAddParser |
|
28 |
self performRefactoring: (PPAddParserRefactoring |
|
29 |
name: #PPMockParser |
|
30 |
category: #'PetitGui-Mock'). |
|
31 |
self assert: self changes size = 2. |
|
32 |
self assert: self changes first class = AddClassChange. |
|
33 |
self assert: self changes first definitionClass = PPCompositeParser. |
|
34 |
self assert: self changes first changeClassName = #PPMockParser. |
|
35 |
self assert: self changes first category = #'PetitGui-Mock'. |
|
36 |
self assert: self changes last class = AddMethodChange. |
|
37 |
self assert: self changes last parseTree = (RBParser parseMethod: 'start ^ self shouldBeImplemented') |
|
38 |
! |
|
39 |
||
40 |
testAddParserWithSuperclass |
|
41 |
self performRefactoring: (PPAddParserRefactoring |
|
42 |
name: #PPMockParser |
|
43 |
category: #'PetitGui-Mock' |
|
44 |
superclass: PPArithmeticParser). |
|
45 |
self assert: self changes size = 2. |
|
46 |
self assert: self changes first class = AddClassChange. |
|
47 |
self assert: self changes first definitionClass = PPArithmeticParser. |
|
48 |
self assert: self changes first changeClassName = #PPMockParser. |
|
49 |
self assert: self changes first category = #'PetitGui-Mock'. |
|
50 |
self assert: self changes last class = AddMethodChange. |
|
51 |
self assert: self changes last parseTree = (RBParser parseMethod: 'start ^ self shouldBeImplemented') |
|
52 |
! |
|
53 |
||
54 |
testRemoveParser |
|
361
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
55 |
self performRefactoring: (PPRemoveParserRefactoring onClass: PPArithmeticParser). |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
56 |
self assert: self changes size = 1. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
57 |
self assert: self changes first class = RemoveClassChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
58 |
self assert: self changes first changeClassName = 'PPArithmeticParser' |
342 | 59 |
! ! |
60 |
||
61 |
!PPGrammarRefactoringTest methodsFor:'testing-productions'! |
|
62 |
||
63 |
testDefineProduction |
|
361
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
64 |
self performRefactoring: (PPDefineProdcutionRefactoring |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
65 |
onClass: PPArithmeticParser |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
66 |
source: 'function ^ #any plus , $( , $) ==> [ :e | 0 ]' |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
67 |
protocols: (Array with: #productions)). |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
68 |
self assert: self changes size = 2. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
69 |
self assert: self changes first class = AddInstanceVariableChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
70 |
self assert: self changes first variable = 'function'. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
71 |
self assert: self changes last class = AddMethodChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
72 |
self assert: self changes last parseTree = (RBParser parseMethod: 'function ^ #any asParser plus , $( asParser , $) asParser ==> [ :e | 0 ]') |
342 | 73 |
! |
74 |
||
75 |
testExtractProduction |
|
361
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
76 |
self performRefactoring: (PPExtractProdcutionRefactoring |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
77 |
onClass: PPArithmeticParser |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
78 |
production: #addition |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
79 |
interval: (36 to: 60) |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
80 |
to: #plusOrMinus). |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
81 |
self assert: self changes size = 3. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
82 |
self assert: self changes first class = AddInstanceVariableChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
83 |
self assert: self changes first variable = 'plusOrMinus'. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
84 |
self assert: self changes second class = AddMethodChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
85 |
self assert: self changes second parseTree = (RBParser parseMethod: 'plusOrMinus ^ $+ asParser / $- asParser'). |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
86 |
self assert: self changes last class = AddMethodChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
87 |
self assert: self changes last parseTree = (RBParser parseMethod: 'addition ^ (factors separatedBy: plusOrMinus trim) foldLeft: [ :a :op :b | a perform: op asSymbol with: b ]') |
342 | 88 |
! |
89 |
||
90 |
testRemoveProduction |
|
361
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
91 |
self performRefactoring: (PPRemoveProdcutionRefactoring |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
92 |
onClass: PPArithmeticParser |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
93 |
production: #addition). |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
94 |
self assert: self changes size = 2. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
95 |
self assert: self changes first class = RemoveMethodChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
96 |
self assert: self changes first selector = #addition. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
97 |
self assert: self changes last class = RemoveInstanceVariableChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
98 |
self assert: self changes last variable = 'addition' |
342 | 99 |
! |
100 |
||
101 |
testRenameProduction |
|
361
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
102 |
self performRefactoring: (PPRenameProdcutionRefactoring |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
103 |
onClass: PPArithmeticParser |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
104 |
rename: #addition |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
105 |
to: #add). |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
106 |
self assert: self changes size = 3. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
107 |
self assert: self changes first class = RenameInstanceVariableChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
108 |
self assert: self changes first oldName = 'addition'. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
109 |
self assert: self changes first newName = 'add'. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
110 |
self assert: self changes second class = AddMethodChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
111 |
self assert: self changes second parseTree = (RBParser parseMethod: 'add ^ (factors separatedBy: ($+ asParser / $- asParser) trim) foldLeft: [ :a :op :b | a perform: op asSymbol with: b ]'). |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
112 |
self assert: self changes last class = RemoveMethodChange. |
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
113 |
self assert: self changes last selector = #addition |
342 | 114 |
! ! |
115 |
||
116 |
!PPGrammarRefactoringTest methodsFor:'utilities'! |
|
117 |
||
118 |
performRefactoring: aRefactoring |
|
119 |
refactoring := aRefactoring. |
|
120 |
aRefactoring primitiveExecute |
|
121 |
! ! |
|
122 |
||
123 |
!PPGrammarRefactoringTest class methodsFor:'documentation'! |
|
124 |
||
125 |
version |
|
361
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
126 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/gui/tests/PPGrammarRefactoringTest.st,v 1.2 2014-03-04 23:33:40 cg Exp $' |
342 | 127 |
! |
128 |
||
129 |
version_CVS |
|
361
39a00be69192
class: PPGrammarRefactoringTest
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
130 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/gui/tests/PPGrammarRefactoringTest.st,v 1.2 2014-03-04 23:33:40 cg Exp $' |
342 | 131 |
! ! |
132 |