compiler/tests/PEGFsaTransitionTest.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 17 Aug 2015 12:13:16 +0100
changeset 515 b5316ef15274
parent 502 1e45d3c96ec5
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:#PEGFsaTransitionTest
	instanceVariableNames:'t1 t2 result e1 e2'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Tests-FSA'
!

!PEGFsaTransitionTest methodsFor:'as yet unclassified'!

setUp
    t1 := PEGFsaCharacterTransition new.
    t2 := PEGFsaCharacterTransition new.
    
    e1 := PEGFsaEpsilonTransition new.
    e2 := PEGFsaEpsilonTransition new.
! !

!PEGFsaTransitionTest methodsFor:'character'!

testCompare
    t1 addCharacter: $a.
    t1 addCharacter: $b.
    t2 addCharacter: $a.
    t2 addCharacter: $b.
    
    self assert: t1 = t2.
!

testComplement
    t1 addCharacter: $a.
    t1 addCharacter: $b.
    t2 addCharacter: $b.
    t2 addCharacter: $c.
    
    result := t1 complement: t2.
    
    self assert: (result at: $a codePoint).
    self assert: (result at: $b codePoint) not.
    self assert: (result at: $c codePoint) not.
!

testComplement2
    t1 addCharacter: $a.
    t1 addCharacter: $b.
    t2 addCharacter: $b.
    t2 addCharacter: $c.
    
    result := t2 complement: t1.
    
    self assert: (result at: $a codePoint) not.
    self assert: (result at: $b codePoint) not.
    self assert: (result at: $c codePoint).
!

testCopy
    t1 addCharacter: $a.
    t1 addCharacter: $b.
    
    t2 := t1 copy.
    
    
    self assert: t1 = t2.
    self assert: (t1 == t2) not.
    
    t2 destination: #foo.
    self assert: (t1 = t2) not.
        
    t1 destination: #foo.
    self assert: (t1 = t2).

    t1 addCharacter: $c.
    self assert: (t1 = t2) not.
    
    t2 addCharacter: $c.
    t1 priority: -1.
    self assert: (t1 = t2) not.	
    
    t2 priority: -1.
    self assert: (t1 = t2).
!

testDisjunction
    t1 addCharacter: $a.
    t1 addCharacter: $c.
    t2 addCharacter: $b.
    t2 addCharacter: $c.
    
    result := t1 disjunction: t2.
    
    self assert: (result at: $a codePoint).
    self assert: (result at: $b codePoint).
    self assert: (result at: $c codePoint) not.
!

testEpsilonIntersection
    result := e1 intersection: e2.
    
    self assert: (result isEpsilon)
!

testIntersection
    t1 addCharacter: $a.
    t1 addCharacter: $b.
    t2 addCharacter: $b.
    t2 addCharacter: $c.
    
    result := t1 intersection: t2.
    
    self assert: (result at: $b codePoint).
    self assert: (result at: $a codePoint) not.
    self assert: (result at: $c codePoint) not.
!

testIntersection2
    t1 addCharacter: $a.
    t2 addCharacter: $b.
    
    result := t1 intersection: t2.
    
    self assert: (result allSatisfy: [:e | e not ]).
    
!

testUnion
    t1 addCharacter: $a.
    t1 addCharacter: $b.
    t2 addCharacter: $b.
    t2 addCharacter: $c.
    
    result := t1 union: t2.
    
    self assert: (result at: $b codePoint).
    self assert: (result at: $a codePoint).
    self assert: (result at: $c codePoint).
    self assert: (result at: $d codePoint) not.
! !

!PEGFsaTransitionTest methodsFor:'tests - epsilon'!

testCompareEpsilon

    self assert: e1 = e2.
    
    e1 destination: #a.
    e2 destination: #b.
    
    self assert: (e1 = e2) not.
    
!

testCopyEpsilon
    
    e2 := e1 copy.
    
    
    self assert: e1 = e2.
    self assert: (e1 == e2) not.
    
    e2 destination: #foo.
    self assert: (e1 = e2) not.
        
    e1 destination: #foo.
    self assert: (e1 = e2).

    e1 priority: -1.
    self assert: (e1 = e2) not.	
    
    e2 priority: -1.
    self assert: (e1 = e2).
! !