compiler/tests/PEGFsaStateTest.st
changeset 515 b5316ef15274
parent 502 1e45d3c96ec5
child 542 bb97dcbe2359
equal deleted inserted replaced
502:1e45d3c96ec5 515:b5316ef15274
    13 
    13 
    14 setUp
    14 setUp
    15     state := PEGFsaState new name: #state; retval: #state; yourself.
    15     state := PEGFsaState new name: #state; retval: #state; yourself.
    16     anotherState := PEGFsaState new name: #anotherState; retval: #anotherState; yourself.
    16     anotherState := PEGFsaState new name: #anotherState; retval: #anotherState; yourself.
    17 
    17 
    18     t1 := PEGFsaTransition new.
    18     t1 := PEGFsaCharacterTransition new.
    19     t2 := PEGFsaTransition new.
    19     t2 := PEGFsaCharacterTransition new.
    20     t3 := PEGFsaTransition new.
    20     t3 := PEGFsaCharacterTransition new.
    21     t4 := PEGFsaTransition new.
    21     t4 := PEGFsaCharacterTransition new.
    22     
    22     
    23 !
    23 !
    24 
    24 
    25 testCopy
    25 testCopy
    26     state addTransition: t1.
    26     state addTransition: t1.
    71     anotherState transitions anyOne addCharacter: $x.	
    71     anotherState transitions anyOne addCharacter: $x.	
    72     self assert: (state = anotherState).
    72     self assert: (state = anotherState).
    73     
    73     
    74 !
    74 !
    75 
    75 
    76 testEquals
    76 testCopy4
    77     state addTransition: t1.
    77     anotherState := state copy.
    78     anotherState addTransition: t2.
    78     
       
    79     self assert: (state = anotherState).
       
    80     self assert: (state == anotherState) not.
       
    81     
       
    82     state priority: -1.
       
    83     self assert: (state = anotherState) not.
    79 
    84 
    80     state retval: #baz.
    85     anotherState priority: -1.
    81     anotherState retval: #baz.
    86     self assert: (state = anotherState).
    82     
    87     
    83     t1 destination: #foo.
    88     anotherState final: true.
    84     t2 destination: #bar.
    89     self assert: (state = anotherState) not.
    85         
    90 
    86     self assert: (state equals: anotherState) not
    91     state final: true.	
       
    92     self assert: (state = anotherState).
       
    93     
    87 !
    94 !
    88 
    95 
    89 testEquals2
    96 testCopy5
    90     state addTransition: t1.
    97     
    91     anotherState addTransition: t2.
    98     
       
    99     state retval: #foo.
       
   100     state failure: true.
       
   101     state final: true.
       
   102     anotherState := state copy.
    92 
   103 
    93     state retval: #baz.
   104     self assert: (state = anotherState).
    94     anotherState retval: #baz.
   105     self assert: (state == anotherState) not.
       
   106 
       
   107     anotherState retval: #bar.
       
   108     self assert: state retval == #foo.
       
   109     self assert: state isFsaFailure.
       
   110     self assert: anotherState retval == #bar.
       
   111     self assert: anotherState isFsaFailure.
    95     
   112     
    96     t1 destination: #foo.
       
    97     t2 destination: #foo.
       
    98         
       
    99     self assert: (state equals: anotherState).
       
   100 !
       
   101 
       
   102 testEquals3
       
   103     state addTransition: t1.
       
   104     anotherState addTransition: t2.
       
   105 
       
   106     state retval: #bar.
       
   107     anotherState retval: #baz.
       
   108     
       
   109     t1 destination: #foo.
       
   110     t2 destination: #foo.
       
   111         
       
   112     self assert: (state equals: anotherState) not
       
   113 !
       
   114 
       
   115 testEquals4
       
   116     state addTransition: t1.
       
   117     anotherState addTransition: t2.
       
   118 
       
   119     state retval: #bar.
       
   120     anotherState retval: #bar.
       
   121     
       
   122     state priority: 0.
       
   123     anotherState priority: -1.
       
   124     
       
   125     t1 destination: #foo.
       
   126     t2 destination: #foo.
       
   127         
       
   128     self assert: (state equals: anotherState) not
       
   129 !
       
   130 
       
   131 testEquals5
       
   132     state addTransition: t1.
       
   133     state addTransition: t2.
       
   134     anotherState addTransition: t2.
       
   135     anotherState addTransition: t3.
       
   136 
       
   137     state retval: #bar.
       
   138     anotherState retval: #bar.
       
   139     
       
   140     state priority: -1.
       
   141     anotherState priority: -1.
       
   142     
       
   143     t1 destination: #foobar.
       
   144     t2 destination: #foo.
       
   145     t3 destination: #foobar.
       
   146         
       
   147     self assert: (state equals: anotherState)
       
   148 !
       
   149 
       
   150 testEquals6
       
   151     state addTransition: t1.
       
   152     state addTransition: t2.
       
   153     anotherState addTransition: t1.
       
   154 
       
   155     state retval: #bar.
       
   156     anotherState retval: #bar.
       
   157     
       
   158     state priority: -1.
       
   159     anotherState priority: -1.
       
   160     
       
   161     t1 destination: #foo.
       
   162     t2 destination: #bar.
       
   163         
       
   164     self assert: (state equals: anotherState) not
       
   165 !
       
   166 
       
   167 testJoin
       
   168     | newState |
       
   169     state addTransition: t1.
       
   170     anotherState addTransition: t2.
       
   171     state final: true.
       
   172     
       
   173     t1 destination: #t1.
       
   174     t2 destination: #t2.
       
   175     
       
   176     newState := state join: anotherState.
       
   177     
       
   178     self assert: (newState transitions contains: [ :t | t = t1 ]).
       
   179     self assert: (newState transitions contains: [ :t | t = t2 ]).
       
   180     self assert: (newState isFinal).	
       
   181 !
       
   182 
       
   183 testJoin2
       
   184     | newState |
       
   185     state addTransition: t1.
       
   186     anotherState addTransition: t2.
       
   187     state final: true.
       
   188     
       
   189     t1 destination: #t1.
       
   190     t2 destination: #t2.
       
   191     
       
   192     newState := anotherState join: state.
       
   193     
       
   194     self assert: (newState transitions contains: [ :t | t = t1 ]).
       
   195     self assert: (newState transitions contains: [ :t | t = t2 ]).
       
   196     self assert: (newState isFinal).	
       
   197 !
   113 !
   198 
   114 
   199 testTransitionPairs
   115 testTransitionPairs
   200     state addTransition: t1.
   116     state addTransition: t1.
   201     state addTransition: t2.
   117     state addTransition: t2.