compiler/tests/extras/PPCExpressionGrammarVerificationTest.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 19 Mar 2016 00:12:47 +0100
changeset 556 51c6afba5c91
parent 516 3b81c9e53352
permissions -rw-r--r--
CI: Use VM provided by Pharo team on both Linux and Windows. Hand-crafter Pharo VM is no longer needed as the Linux slave in SWING build farm has been upgraded so it has compatible GLIBC. This makes CI scripts simpler and more usable for other people.

"{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"

"{ NameSpace: Smalltalk }"

PPCAbstractParserTest subclass:#PPCExpressionGrammarVerificationTest
	instanceVariableNames:'parser result context resource fileResources'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Extras-Tests-Expressions'
!

!PPCExpressionGrammarVerificationTest class methodsFor:'accessing'!

resources
    ^ (OrderedCollection with: PPCResources)
        addAll: super resources;
        yourself
! !

!PPCExpressionGrammarVerificationTest class methodsFor:'testing'!

isAbstract
    ^ self == PPCExpressionGrammarVerificationTest

    "Modified: / 29-07-2015 / 18:50:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!PPCExpressionGrammarVerificationTest methodsFor:'accessing'!

petitParserClass
    "Return the name of the petit parser to compile"

    ^ PPExpressionGrammar

    "Modified: / 29-07-2015 / 17:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!PPCExpressionGrammarVerificationTest methodsFor:'setup'!

setUp
    super setUp.
    fileResources := (self resources detect: [:e | e = PPCResources ]) current.
!

tearDown
    super tearDown.
    "
    self compiledSmalltalkGrammarClass isNil ifFalse:[ 
        self compiledSmalltalkGrammarClass removeFromSystem
    ].
    "
! !

!PPCExpressionGrammarVerificationTest methodsFor:'tests'!

testExpressions
    | compiledParser petitParser expected actual |
    petitParser := self petitParser.
    compiledParser := self compiledParser.
    
    fileResources expressionSourcesMedium do: [ :source |
        expected := petitParser parse: source.
        expected isPetitFailure ifFalse: [ 
                actual := (compiledParser parse: source withContext: self context). 
            self assert: expected equals: actual.
        ]
    ].

    "Modified: / 29-07-2015 / 17:03:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testSanity
    | compiledParser petitParser source |
    petitParser := self petitParser.
    compiledParser := self compiledParser.
    
    source := fileResources expressionOfSize: 100. 
    result := petitParser parse: source.
    
    self assert: (((self deepFlattened: result) select: [ :e | e isNumber ]) size) = 100.
    self assert: (((self deepFlattened: result)select: [ :e | e isNumber ]) size) = 100.

    "Modified: / 29-07-2015 / 17:03:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!PPCExpressionGrammarVerificationTest 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.
! !