compiler/tests/PEGFsaTransitionTest.st
changeset 502 1e45d3c96ec5
child 515 b5316ef15274
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/tests/PEGFsaTransitionTest.st	Fri Jul 24 15:06:54 2015 +0100
@@ -0,0 +1,130 @@
+"{ Package: 'stx:goodies/petitparser/compiler/tests' }"
+
+"{ NameSpace: Smalltalk }"
+
+TestCase subclass:#PEGFsaTransitionTest
+	instanceVariableNames:'t1 t2 result'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Tests-FSA'
+!
+
+!PEGFsaTransitionTest methodsFor:'as yet unclassified'!
+
+setUp
+    t1 := PEGFsaTransition new.
+    t2 := PEGFsaTransition new.
+!
+
+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.
+!
+
+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.
+! !
+