50 self assert: self changes last class = AddMethodChange. |
50 self assert: self changes last class = AddMethodChange. |
51 self assert: self changes last parseTree = (RBParser parseMethod: 'start ^ self shouldBeImplemented') |
51 self assert: self changes last parseTree = (RBParser parseMethod: 'start ^ self shouldBeImplemented') |
52 ! |
52 ! |
53 |
53 |
54 testRemoveParser |
54 testRemoveParser |
55 self performRefactoring: (PPRemoveParserRefactoring onClass: PPArithmeticParser). |
55 self performRefactoring: (PPRemoveParserRefactoring onClass: PPArithmeticParser). |
56 self assert: self changes size = 1. |
56 self assert: self changes size = 1. |
57 self assert: self changes first class = RBRemoveClassChange. |
57 self assert: self changes first class = RemoveClassChange. |
58 self assert: self changes first changeClassName = 'PPArithmeticParser' |
58 self assert: self changes first changeClassName = 'PPArithmeticParser' |
59 ! ! |
59 ! ! |
60 |
60 |
61 !PPGrammarRefactoringTest methodsFor:'testing-productions'! |
61 !PPGrammarRefactoringTest methodsFor:'testing-productions'! |
62 |
62 |
63 testDefineProduction |
63 testDefineProduction |
64 self performRefactoring: (PPDefineProdcutionRefactoring |
64 self performRefactoring: (PPDefineProdcutionRefactoring |
65 onClass: PPArithmeticParser |
65 onClass: PPArithmeticParser |
66 source: 'function ^ #any plus , $( , $) ==> [ :e | 0 ]' |
66 source: 'function ^ #any plus , $( , $) ==> [ :e | 0 ]' |
67 protocols: (Array with: #productions)). |
67 protocols: (Array with: #productions)). |
68 self assert: self changes size = 2. |
68 self assert: self changes size = 2. |
69 self assert: self changes first class = RBAddInstanceVariableChange. |
69 self assert: self changes first class = AddInstanceVariableChange. |
70 self assert: self changes first variable = 'function'. |
70 self assert: self changes first variable = 'function'. |
71 self assert: self changes last class = RBAddMethodChange. |
71 self assert: self changes last class = AddMethodChange. |
72 self assert: self changes last parseTree = (RBParser parseMethod: 'function ^ #any asParser plus , $( asParser , $) asParser ==> [ :e | 0 ]') |
72 self assert: self changes last parseTree = (RBParser parseMethod: 'function ^ #any asParser plus , $( asParser , $) asParser ==> [ :e | 0 ]') |
73 ! |
73 ! |
74 |
74 |
75 testExtractProduction |
75 testExtractProduction |
76 self performRefactoring: (PPExtractProdcutionRefactoring |
76 self performRefactoring: (PPExtractProdcutionRefactoring |
77 onClass: PPArithmeticParser |
77 onClass: PPArithmeticParser |
78 production: #addition |
78 production: #addition |
79 interval: (36 to: 60) |
79 interval: (36 to: 60) |
80 to: #plusOrMinus). |
80 to: #plusOrMinus). |
81 self assert: self changes size = 3. |
81 self assert: self changes size = 3. |
82 self assert: self changes first class = RBAddInstanceVariableChange. |
82 self assert: self changes first class = AddInstanceVariableChange. |
83 self assert: self changes first variable = 'plusOrMinus'. |
83 self assert: self changes first variable = 'plusOrMinus'. |
84 self assert: self changes second class = RBAddMethodChange. |
84 self assert: self changes second class = AddMethodChange. |
85 self assert: self changes second parseTree = (RBParser parseMethod: 'plusOrMinus ^ $+ asParser / $- asParser'). |
85 self assert: self changes second parseTree = (RBParser parseMethod: 'plusOrMinus ^ $+ asParser / $- asParser'). |
86 self assert: self changes last class = RBAddMethodChange. |
86 self assert: self changes last class = AddMethodChange. |
87 self assert: self changes last parseTree = (RBParser parseMethod: 'addition ^ (factors separatedBy: plusOrMinus trim) foldLeft: [ :a :op :b | a perform: op asSymbol with: b ]') |
87 self assert: self changes last parseTree = (RBParser parseMethod: 'addition ^ (factors separatedBy: plusOrMinus trim) foldLeft: [ :a :op :b | a perform: op asSymbol with: b ]') |
88 ! |
88 ! |
89 |
89 |
90 testRemoveProduction |
90 testRemoveProduction |
91 self performRefactoring: (PPRemoveProdcutionRefactoring |
91 self performRefactoring: (PPRemoveProdcutionRefactoring |
92 onClass: PPArithmeticParser |
92 onClass: PPArithmeticParser |
93 production: #addition). |
93 production: #addition). |
94 self assert: self changes size = 2. |
94 self assert: self changes size = 2. |
95 self assert: self changes first class = RBRemoveMethodChange. |
95 self assert: self changes first class = RemoveMethodChange. |
96 self assert: self changes first selector = #addition. |
96 self assert: self changes first selector = #addition. |
97 self assert: self changes last class = RBRemoveInstanceVariableChange. |
97 self assert: self changes last class = RemoveInstanceVariableChange. |
98 self assert: self changes last variable = 'addition' |
98 self assert: self changes last variable = 'addition' |
99 ! |
99 ! |
100 |
100 |
101 testRenameProduction |
101 testRenameProduction |
102 self performRefactoring: (PPRenameProdcutionRefactoring |
102 self performRefactoring: (PPRenameProdcutionRefactoring |
103 onClass: PPArithmeticParser |
103 onClass: PPArithmeticParser |
104 rename: #addition |
104 rename: #addition |
105 to: #add). |
105 to: #add). |
106 self assert: self changes size = 3. |
106 self assert: self changes size = 3. |
107 self assert: self changes first class = RBRenameInstanceVariableChange. |
107 self assert: self changes first class = RenameInstanceVariableChange. |
108 self assert: self changes first oldName = 'addition'. |
108 self assert: self changes first oldName = 'addition'. |
109 self assert: self changes first newName = 'add'. |
109 self assert: self changes first newName = 'add'. |
110 self assert: self changes second class = RBAddMethodChange. |
110 self assert: self changes second class = AddMethodChange. |
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 ]'). |
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 ]'). |
112 self assert: self changes last class = RBRemoveMethodChange. |
112 self assert: self changes last class = RemoveMethodChange. |
113 self assert: self changes last selector = #addition |
113 self assert: self changes last selector = #addition |
114 ! ! |
114 ! ! |
115 |
115 |
116 !PPGrammarRefactoringTest methodsFor:'utilities'! |
116 !PPGrammarRefactoringTest methodsFor:'utilities'! |
117 |
117 |
118 performRefactoring: aRefactoring |
118 performRefactoring: aRefactoring |