compiler/tests/PEGFsaStateTest.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 24 Jul 2015 15:06:54 +0100
changeset 502 1e45d3c96ec5
child 515 b5316ef15274
permissions -rw-r--r--
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12 Name: PetitCompiler-JanVrany.135 Author: JanVrany Time: 22-07-2015, 06:53:29.127 PM UUID: 890178b5-275d-46af-a2ad-1738998f07cb Ancestors: PetitCompiler-JanVrany.134 Name: PetitCompiler-Tests-JanKurs.93 Author: JanKurs Time: 20-07-2015, 11:30:10.283 PM UUID: 6473e671-ad70-42ca-b6c3-654b78edc531 Ancestors: PetitCompiler-Tests-JanKurs.92 Name: PetitCompiler-Extras-Tests-JanVrany.16 Author: JanVrany Time: 22-07-2015, 05:18:22.387 PM UUID: 8f6f9129-dbba-49b1-9402-038470742f98 Ancestors: PetitCompiler-Extras-Tests-JanKurs.15 Name: PetitCompiler-Benchmarks-JanKurs.12 Author: JanKurs Time: 06-07-2015, 02:10:06.901 PM UUID: cb24f1ac-46a4-494d-9780-64576f0f0dba Ancestors: PetitCompiler-Benchmarks-JanKurs.11, PetitCompiler-Benchmarks-JanVrany.e29bd90f388e.20150619081300

"{ 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 := PEGFsaTransition new.
    t2 := PEGFsaTransition new.
    t3 := PEGFsaTransition new.
    t4 := PEGFsaTransition 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).
    
!

testEquals
    state addTransition: t1.
    anotherState addTransition: t2.

    state retval: #baz.
    anotherState retval: #baz.
    
    t1 destination: #foo.
    t2 destination: #bar.
        
    self assert: (state equals: anotherState) not
!

testEquals2
    state addTransition: t1.
    anotherState addTransition: t2.

    state retval: #baz.
    anotherState retval: #baz.
    
    t1 destination: #foo.
    t2 destination: #foo.
        
    self assert: (state equals: anotherState).
!

testEquals3
    state addTransition: t1.
    anotherState addTransition: t2.

    state retval: #bar.
    anotherState retval: #baz.
    
    t1 destination: #foo.
    t2 destination: #foo.
        
    self assert: (state equals: anotherState) not
!

testEquals4
    state addTransition: t1.
    anotherState addTransition: t2.

    state retval: #bar.
    anotherState retval: #bar.
    
    state priority: 0.
    anotherState priority: -1.
    
    t1 destination: #foo.
    t2 destination: #foo.
        
    self assert: (state equals: anotherState) not
!

testEquals5
    state addTransition: t1.
    state addTransition: t2.
    anotherState addTransition: t2.
    anotherState addTransition: t3.

    state retval: #bar.
    anotherState retval: #bar.
    
    state priority: -1.
    anotherState priority: -1.
    
    t1 destination: #foobar.
    t2 destination: #foo.
    t3 destination: #foobar.
        
    self assert: (state equals: anotherState)
!

testEquals6
    state addTransition: t1.
    state addTransition: t2.
    anotherState addTransition: t1.

    state retval: #bar.
    anotherState retval: #bar.
    
    state priority: -1.
    anotherState priority: -1.
    
    t1 destination: #foo.
    t2 destination: #bar.
        
    self assert: (state equals: anotherState) not
!

testJoin
    | newState |
    state addTransition: t1.
    anotherState addTransition: t2.
    state final: true.
    
    t1 destination: #t1.
    t2 destination: #t2.
    
    newState := state join: anotherState.
    
    self assert: (newState transitions contains: [ :t | t = t1 ]).
    self assert: (newState transitions contains: [ :t | t = t2 ]).
    self assert: (newState isFinal).	
!

testJoin2
    | newState |
    state addTransition: t1.
    anotherState addTransition: t2.
    state final: true.
    
    t1 destination: #t1.
    t2 destination: #t2.
    
    newState := anotherState join: state.
    
    self assert: (newState transitions contains: [ :t | t = t1 ]).
    self assert: (newState transitions contains: [ :t | t = t2 ]).
    self assert: (newState isFinal).	
!

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