compiler/tests/PEGFsaTransitionTest.st
changeset 502 1e45d3c96ec5
child 515 b5316ef15274
equal deleted inserted replaced
464:f6d77fee9811 502:1e45d3c96ec5
       
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 TestCase subclass:#PEGFsaTransitionTest
       
     6 	instanceVariableNames:'t1 t2 result'
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-Tests-FSA'
       
    10 !
       
    11 
       
    12 !PEGFsaTransitionTest methodsFor:'as yet unclassified'!
       
    13 
       
    14 setUp
       
    15     t1 := PEGFsaTransition new.
       
    16     t2 := PEGFsaTransition new.
       
    17 !
       
    18 
       
    19 testCompare
       
    20     t1 addCharacter: $a.
       
    21     t1 addCharacter: $b.
       
    22     t2 addCharacter: $a.
       
    23     t2 addCharacter: $b.
       
    24     
       
    25     self assert: t1 = t2.
       
    26 !
       
    27 
       
    28 testComplement
       
    29     t1 addCharacter: $a.
       
    30     t1 addCharacter: $b.
       
    31     t2 addCharacter: $b.
       
    32     t2 addCharacter: $c.
       
    33     
       
    34     result := t1 complement: t2.
       
    35     
       
    36     self assert: (result at: $a codePoint).
       
    37     self assert: (result at: $b codePoint) not.
       
    38     self assert: (result at: $c codePoint) not.
       
    39 !
       
    40 
       
    41 testComplement2
       
    42     t1 addCharacter: $a.
       
    43     t1 addCharacter: $b.
       
    44     t2 addCharacter: $b.
       
    45     t2 addCharacter: $c.
       
    46     
       
    47     result := t2 complement: t1.
       
    48     
       
    49     self assert: (result at: $a codePoint) not.
       
    50     self assert: (result at: $b codePoint) not.
       
    51     self assert: (result at: $c codePoint).
       
    52 !
       
    53 
       
    54 testCopy
       
    55     t1 addCharacter: $a.
       
    56     t1 addCharacter: $b.
       
    57     
       
    58     t2 := t1 copy.
       
    59     
       
    60     
       
    61     self assert: t1 = t2.
       
    62     self assert: (t1 == t2) not.
       
    63     
       
    64     t2 destination: #foo.
       
    65     self assert: (t1 = t2) not.
       
    66         
       
    67     t1 destination: #foo.
       
    68     self assert: (t1 = t2).
       
    69 
       
    70     t1 addCharacter: $c.
       
    71     self assert: (t1 = t2) not.
       
    72     
       
    73     t2 addCharacter: $c.
       
    74     t1 priority: -1.
       
    75     self assert: (t1 = t2) not.	
       
    76     
       
    77     t2 priority: -1.
       
    78     self assert: (t1 = t2).
       
    79 !
       
    80 
       
    81 testDisjunction
       
    82     t1 addCharacter: $a.
       
    83     t1 addCharacter: $c.
       
    84     t2 addCharacter: $b.
       
    85     t2 addCharacter: $c.
       
    86     
       
    87     result := t1 disjunction: t2.
       
    88     
       
    89     self assert: (result at: $a codePoint).
       
    90     self assert: (result at: $b codePoint).
       
    91     self assert: (result at: $c codePoint) not.
       
    92 !
       
    93 
       
    94 testIntersection
       
    95     t1 addCharacter: $a.
       
    96     t1 addCharacter: $b.
       
    97     t2 addCharacter: $b.
       
    98     t2 addCharacter: $c.
       
    99     
       
   100     result := t1 intersection: t2.
       
   101     
       
   102     self assert: (result at: $b codePoint).
       
   103     self assert: (result at: $a codePoint) not.
       
   104     self assert: (result at: $c codePoint) not.
       
   105 !
       
   106 
       
   107 testIntersection2
       
   108     t1 addCharacter: $a.
       
   109     t2 addCharacter: $b.
       
   110     
       
   111     result := t1 intersection: t2.
       
   112     
       
   113     self assert: (result allSatisfy: [:e | e not ]).
       
   114     
       
   115 !
       
   116 
       
   117 testUnion
       
   118     t1 addCharacter: $a.
       
   119     t1 addCharacter: $b.
       
   120     t2 addCharacter: $b.
       
   121     t2 addCharacter: $c.
       
   122     
       
   123     result := t1 union: t2.
       
   124     
       
   125     self assert: (result at: $b codePoint).
       
   126     self assert: (result at: $a codePoint).
       
   127     self assert: (result at: $c codePoint).
       
   128     self assert: (result at: $d codePoint) not.
       
   129 ! !
       
   130