initial checkin
authorClaus Gittinger <cg@exept.de>
Tue, 04 Mar 2014 22:16:20 +0100
changeset 342 27e30ee190b9
parent 341 feebcbacf8b1
child 343 0faf1af65792
initial checkin
gui/tests/PPGrammarRefactoringTest.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/tests/PPGrammarRefactoringTest.st	Tue Mar 04 22:16:20 2014 +0100
@@ -0,0 +1,132 @@
+"{ Package: 'stx:goodies/petitparser/gui/tests' }"
+
+TestCase subclass:#PPGrammarRefactoringTest
+	instanceVariableNames:'refactoring'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitGui-Tests'
+!
+
+
+!PPGrammarRefactoringTest methodsFor:'accessing'!
+
+change
+	^ self refactoring changes
+!
+
+changes
+	^ self change changes
+!
+
+refactoring
+	^ refactoring
+! !
+
+!PPGrammarRefactoringTest methodsFor:'testing-parsers'!
+
+testAddParser
+        self performRefactoring: (PPAddParserRefactoring
+                name: #PPMockParser
+                category: #'PetitGui-Mock').
+        self assert: self changes size = 2.
+        self assert: self changes first class = AddClassChange.
+        self assert: self changes first definitionClass = PPCompositeParser.
+        self assert: self changes first changeClassName = #PPMockParser.
+        self assert: self changes first category = #'PetitGui-Mock'.
+        self assert: self changes last class = AddMethodChange.
+        self assert: self changes last parseTree = (RBParser parseMethod: 'start ^ self shouldBeImplemented')
+!
+
+testAddParserWithSuperclass
+        self performRefactoring: (PPAddParserRefactoring
+                name: #PPMockParser
+                category: #'PetitGui-Mock'
+                superclass: PPArithmeticParser).
+        self assert: self changes size = 2.
+        self assert: self changes first class = AddClassChange.
+        self assert: self changes first definitionClass = PPArithmeticParser.
+        self assert: self changes first changeClassName = #PPMockParser.
+        self assert: self changes first category = #'PetitGui-Mock'.
+        self assert: self changes last class = AddMethodChange.
+        self assert: self changes last parseTree = (RBParser parseMethod: 'start ^ self shouldBeImplemented')
+!
+
+testRemoveParser
+	self performRefactoring: (PPRemoveParserRefactoring onClass: PPArithmeticParser).
+	self assert: self changes size = 1.
+	self assert: self changes first class =  RBRemoveClassChange.
+	self assert: self changes first changeClassName = 'PPArithmeticParser'
+! !
+
+!PPGrammarRefactoringTest methodsFor:'testing-productions'!
+
+testDefineProduction
+	self performRefactoring: (PPDefineProdcutionRefactoring
+		onClass: PPArithmeticParser
+		source: 'function ^ #any plus , $( , $) ==> [ :e | 0 ]'
+		protocols: (Array with: #productions)).
+	self assert: self changes size = 2.
+	self assert: self changes first class = RBAddInstanceVariableChange.
+	self assert: self changes first variable = 'function'.
+	self assert: self changes last class = RBAddMethodChange.
+	self assert: self changes last parseTree = (RBParser parseMethod: 'function ^ #any asParser plus , $( asParser , $) asParser ==> [ :e | 0 ]')
+!
+
+testExtractProduction
+	self performRefactoring: (PPExtractProdcutionRefactoring
+		onClass: PPArithmeticParser
+		production: #addition
+		interval: (36 to: 60)
+		to: #plusOrMinus).
+	self assert: self changes size = 3.
+	self assert: self changes first class = RBAddInstanceVariableChange.
+	self assert: self changes first variable = 'plusOrMinus'.
+	self assert: self changes second class = RBAddMethodChange.
+	self assert: self changes second parseTree = (RBParser parseMethod: 'plusOrMinus ^ $+ asParser / $- asParser').
+	self assert: self changes last class = RBAddMethodChange.
+	self assert: self changes last parseTree = (RBParser parseMethod: 'addition ^ (factors separatedBy: plusOrMinus trim) foldLeft: [ :a :op :b | a perform: op asSymbol with: b ]')
+!
+
+testRemoveProduction
+	self performRefactoring: (PPRemoveProdcutionRefactoring
+		onClass: PPArithmeticParser
+		production: #addition).
+	self assert: self changes size = 2.
+	self assert: self changes first class = RBRemoveMethodChange.
+	self assert: self changes first selector = #addition.
+	self assert: self changes last class = RBRemoveInstanceVariableChange.
+	self assert: self changes last variable = 'addition'
+!
+
+testRenameProduction
+	self performRefactoring: (PPRenameProdcutionRefactoring
+		onClass: PPArithmeticParser
+		rename: #addition
+		to: #add).
+	self assert: self changes size = 3.
+	self assert: self changes first class = RBRenameInstanceVariableChange.
+	self assert: self changes first oldName = 'addition'.
+	self assert: self changes first newName = 'add'.
+	self assert: self changes second class = RBAddMethodChange.
+	self assert: self changes second parseTree = (RBParser parseMethod: 'add ^ (factors separatedBy: ($+ asParser / $- asParser) trim) foldLeft: [ :a :op :b | a perform: op asSymbol with: b ]').
+	self assert: self changes last class = RBRemoveMethodChange.
+	self assert: self changes last selector = #addition
+! !
+
+!PPGrammarRefactoringTest methodsFor:'utilities'!
+
+performRefactoring: aRefactoring
+	refactoring := aRefactoring.
+	aRefactoring primitiveExecute
+! !
+
+!PPGrammarRefactoringTest class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/goodies/petitparser/gui/tests/PPGrammarRefactoringTest.st,v 1.1 2014-03-04 21:16:20 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/goodies/petitparser/gui/tests/PPGrammarRefactoringTest.st,v 1.1 2014-03-04 21:16:20 cg Exp $'
+! !
+