compiler/tests/PEGFsaStateTest.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 17 Aug 2015 12:13:16 +0100
changeset 515 b5316ef15274
parent 502 1e45d3c96ec5
child 542 bb97dcbe2359
permissions -rw-r--r--
Updated to PetitCompiler-JanKurs.160, PetitCompiler-Tests-JanKurs.112, PetitCompiler-Extras-Tests-JanKurs.25, PetitCompiler-Benchmarks-JanKurs.17 Name: PetitCompiler-JanKurs.160 Author: JanKurs Time: 17-08-2015, 09:52:26.291 AM UUID: 3b4bfc98-8098-4951-af83-a59e2585b121 Name: PetitCompiler-Tests-JanKurs.112 Author: JanKurs Time: 16-08-2015, 05:00:32.936 PM UUID: 85613d47-08f3-406f-9823-9cdab451e805 Name: PetitCompiler-Extras-Tests-JanKurs.25 Author: JanKurs Time: 16-08-2015, 05:00:10.328 PM UUID: 09731810-51a1-4151-8d3a-56b636fbd1f7 Name: PetitCompiler-Benchmarks-JanKurs.17 Author: JanKurs Time: 05-08-2015, 05:29:32.407 PM UUID: e544b5f1-bcf8-470b-93a6-d2363e4dfc8a

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

"{ NameSpace: Smalltalk }"

TestCase subclass:#PEGFsaStateTest
	instanceVariableNames:'state t1 t2 t3 t4 anotherState'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Tests-FSA'
!

!PEGFsaStateTest methodsFor:'as yet unclassified'!

setUp
    state := PEGFsaState new name: #state; retval: #state; yourself.
    anotherState := PEGFsaState new name: #anotherState; retval: #anotherState; yourself.

    t1 := PEGFsaCharacterTransition new.
    t2 := PEGFsaCharacterTransition new.
    t3 := PEGFsaCharacterTransition new.
    t4 := PEGFsaCharacterTransition new.
    
!

testCopy
    state addTransition: t1.
    anotherState := state copy.
    
    self assert: (state = anotherState).
    self assert: (state == anotherState) not.
    
    state retval: #foo.
    self assert: (state = anotherState) not.

    anotherState retval: #foo.
    self assert: (state = anotherState).
    
    state addTransition: t2.
    self assert: (state = anotherState) not.
    
    anotherState addTransition: t2.
    self assert: (state = anotherState).
    
!

testCopy2
    state addTransition: t1.
    anotherState := state copy.
    
    self assert: (state = anotherState).
    self assert: (state == anotherState) not.
    
    state addTransition: t2.
    self assert: (state = anotherState) not.
    
    anotherState addTransition: t2 copy.
    self assert: (state = anotherState).
    
!

testCopy3
    state addTransition: t1.
    anotherState := state copy.
    
    self assert: (state = anotherState).
    self assert: (state == anotherState) not.
    
    t1 addCharacter: $x.
    self assert: (state = anotherState) not.
    
    anotherState transitions anyOne addCharacter: $x.	
    self assert: (state = anotherState).
    
!

testCopy4
    anotherState := state copy.
    
    self assert: (state = anotherState).
    self assert: (state == anotherState) not.
    
    state priority: -1.
    self assert: (state = anotherState) not.

    anotherState priority: -1.
    self assert: (state = anotherState).
    
    anotherState final: true.
    self assert: (state = anotherState) not.

    state final: true.	
    self assert: (state = anotherState).
    
!

testCopy5
    
    
    state retval: #foo.
    state failure: true.
    state final: true.
    anotherState := state copy.

    self assert: (state = anotherState).
    self assert: (state == anotherState) not.

    anotherState retval: #bar.
    self assert: state retval == #foo.
    self assert: state isFsaFailure.
    self assert: anotherState retval == #bar.
    self assert: anotherState isFsaFailure.
    
!

testTransitionPairs
    state addTransition: t1.
    state addTransition: t2.
    state addTransition: t3.
    
    self assert: state transitions size = 3.
    self assert: state transitionPairs size = 3.
    self assert: (state transitionPairs includes: (PEGFsaPair with: t1 with: t2)).
    self assert: (state transitionPairs includes: (PEGFsaPair with: t1 with: t3)).
    self assert: (state transitionPairs includes: (PEGFsaPair with: t2 with: t3)).		
! !