compiler/tests/PPCUnivarsalGuardTest.st
changeset 537 fb212e14d1f4
parent 535 a8feb0f47574
child 538 16e8536f5cfb
equal deleted inserted replaced
536:548996aca274 537:fb212e14d1f4
     2 
     2 
     3 "{ NameSpace: Smalltalk }"
     3 "{ NameSpace: Smalltalk }"
     4 
     4 
     5 PPAbstractParserTest subclass:#PPCUnivarsalGuardTest
     5 PPAbstractParserTest subclass:#PPCUnivarsalGuardTest
     6 	instanceVariableNames:'parser result context node compiler id node2 id2 id1 node1 node3
     6 	instanceVariableNames:'parser result context node compiler id node2 id2 id1 node1 node3
     7 		options configuration'
     7 		options'
     8 	classVariableNames:''
     8 	classVariableNames:''
     9 	poolDictionaries:''
     9 	poolDictionaries:''
    10 	category:'PetitCompiler-Tests-Core-Universal'
    10 	category:'PetitCompiler-Tests-Core-Universal'
    11 !
    11 !
    12 
    12 
    20 context	
    20 context	
    21     ^ context := PPCProfilingContext new
    21     ^ context := PPCProfilingContext new
    22 !
    22 !
    23 
    23 
    24 setUp
    24 setUp
    25     options := PPCCompilationOptions default
    25     options := (PPCCompilationOptions default)
    26         profile: true;
    26             profile:true;
    27         tokenize: false;
    27             tokenize:false;
    28         yourself.
    28             yourself.
    29         
    29     compiler := PPCCompiler new.
    30     configuration := PPCConfiguration new.
    30     compiler context options:options
    31     configuration context options: options
       
    32 
    31 
    33     "Modified: / 04-09-2015 / 16:21:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    32     "Modified: / 04-09-2015 / 16:21:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    34 !
    33 !
    35 
    34 
    36 tearDown
    35 tearDown
    43 ! !
    42 ! !
    44 
    43 
    45 !PPCUnivarsalGuardTest methodsFor:'tests - guard'!
    44 !PPCUnivarsalGuardTest methodsFor:'tests - guard'!
    46 
    45 
    47 testChoiceGuard
    46 testChoiceGuard
    48     parser := ('foo' asParser trimmingToken / 'bar' asParser trimmingToken / $d asParser trimmingToken plus) 
    47     parser := ('foo' asParser trimmingToken / 'bar' asParser trimmingToken 
    49         compileWithConfiguration: configuration.
    48                     / $d asParser trimmingToken plus) compileUsingCompiler:compiler.
    50     
    49     
    51     self assert: parser parse: 'foo'.
    50     self assert: parser parse: 'foo'.
    52     self assert: result inputValue = 'foo'.	
    51     self assert: result inputValue = 'foo'.	
    53     self assert: (context invocations anySatisfy: [ :e | e beginsWith: 'token' ]).
    52     self assert: (context invocations anySatisfy: [ :e | e beginsWith: 'token' ]).
    54 
    53 
    68     self assert: parser fail: 'zorg'.		
    67     self assert: parser fail: 'zorg'.		
    69     self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'token' ]).
    68     self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'token' ]).
    70 !
    69 !
    71 
    70 
    72 testEmptyChoiceGuard
    71 testEmptyChoiceGuard
    73     parser := ('foo' asParser trimmingToken / 'bar' asParser trimmingToken / $d asParser trimmingToken star) 
    72     parser := ('foo' asParser trimmingToken / 'bar' asParser trimmingToken 
    74         compileWithConfiguration: configuration.
    73                     / $d asParser trimmingToken star) compileUsingCompiler:compiler.
    75     
    74     
    76     self assert: parser parse: 'foo'.
    75     self assert: parser parse: 'foo'.
    77     self assert: result inputValue = 'foo'.	
    76     self assert: result inputValue = 'foo'.	
    78 
    77 
    79     self assert: parser parse: 'bar'.
    78     self assert: parser parse: 'bar'.
    89 
    88 
    90     self assert: parser parse: 'zorg' end: 0.	
    89     self assert: parser parse: 'zorg' end: 0.	
    91 !
    90 !
    92 
    91 
    93 testGuardSmalltlakToken
    92 testGuardSmalltlakToken
    94     parser := (#letter asParser, #word asParser star) smalltalkToken compileWithConfiguration: configuration.
    93     parser := (#letter asParser , #word asParser star) smalltalkToken 
       
    94                     compileUsingCompiler:compiler.
    95     
    95     
    96     self assert: parser parse: 'bar'.
    96     self assert: parser parse: 'bar'.
    97     self assert: (context invocations anySatisfy: [ :e | e beginsWith: 'seq' ]).
    97     self assert: (context invocations anySatisfy: [ :e | e beginsWith: 'seq' ]).
    98     
    98     
    99     self assert: parser fail: '123'.
    99     self assert: parser fail: '123'.
   100     self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'seq' ]).
   100     self assert: (context invocations noneSatisfy: [ :e | e beginsWith: 'seq' ]).
   101 !
   101 !
   102 
   102 
   103 testSequenceGuard
   103 testSequenceGuard
   104     parser := ((#any asParser, #any asParser) wrapped, (#any asParser, #any asParser)) compileWithConfiguration: configuration.
   104     parser := ((#any asParser , #any asParser) wrapped , (#any asParser , #any asParser)) 
       
   105                     compileUsingCompiler:compiler.
   105     
   106     
   106     self assert: parser parse: 'fooo' to: #(#($f $o) #($o $o)).	
   107     self assert: parser parse: 'fooo' to: #(#($f $o) #($o $o)).	
   107     self assert: parser parse: 'fo oo' to: #(#($f $o) #($  $o)) end: 4.	
   108     self assert: parser parse: 'fo oo' to: #(#($f $o) #($  $o)) end: 4.	
   108     self assert: parser fail: 'fo'.
   109     self assert: parser fail: 'fo'.
   109     
   110     
   110 !
   111 !
   111 
   112 
   112 testTrimmerGuard
   113 testTrimmerGuard
   113     parser := $a asParser trim, $b asParser compileWithConfiguration: configuration.
   114     parser := $a asParser trim , $b asParser compileUsingCompiler:compiler.
   114     
   115     
   115     self assert: parser parse: 'ab'.
   116     self assert: parser parse: 'ab'.
   116     self assert: parser parse: ' ab'.
   117     self assert: parser parse: ' ab'.
   117 ! !
   118 ! !
   118 
   119