Portability fix: override #new for class that implements #initialize
#initialize is not sent by default.
"{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"
"{ NameSpace: Smalltalk }"
PPAbstractParserTest subclass:#PPCExpressionsVerificationTest
instanceVariableNames:'parser result context resource fileResources'
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Extras-Tests-Expressions'
!
!PPCExpressionsVerificationTest class methodsFor:'as yet unclassified'!
isAbstract
^ self name = #PPCExpressionsVerificationTest
!
resources
^ (OrderedCollection with: PPCResources)
addAll: super resources;
yourself
! !
!PPCExpressionsVerificationTest methodsFor:'accessing'!
compiledGrammar
^ self compiledGrammarClass new
!
compiledGrammarClass
self subclassResponsibility
!
grammar
^ PPExpressionGrammar new
! !
!PPCExpressionsVerificationTest methodsFor:'setup'!
setUp
super setUp.
fileResources := (self resources detect: [:e | e = PPCResources ]) current.
!
tearDown
super tearDown.
"
self compiledSmalltalkGrammarClass isNil ifFalse:[
self compiledSmalltalkGrammarClass removeFromSystem
].
"
! !
!PPCExpressionsVerificationTest methodsFor:'tests'!
testExpressions
| compiledParser normalParser expected actual |
normalParser := self grammar.
compiledParser := self compiledGrammar.
fileResources expressionSourcesMedium do: [ :source |
expected := normalParser parse: source.
expected isPetitFailure ifFalse: [
actual := (compiledParser parse: source withContext: self context).
self assert: expected equals: actual.
]
].
!
testSanity
| compiledParser normalParser source |
normalParser := self grammar.
compiledParser := self compiledGrammar.
source := fileResources expressionOfSize: 100.
result := normalParser parse: source.
self assert: (((self deepFlattened: result) select: [ :e | e isNumber ]) size) = 100.
self assert: (((self deepFlattened: result)select: [ :e | e isNumber ]) size) = 100.
! !
!PPCExpressionsVerificationTest methodsFor:'utilities'!
deepFlatten: anObject into: aCollection
(anObject isCollection and:[anObject isString not]) ifTrue:[
anObject do:[:each|self deepFlatten: each into: aCollection]
] ifFalse:[
aCollection add: anObject
].
^aCollection
!
deepFlattened: aCollection
^self deepFlatten: aCollection into: OrderedCollection new.
! !