compiler/tests/PPCGuardTest.st
changeset 421 7e08b31e0dae
parent 415 f30eb7ea54cd
child 422 116d2b2af905
equal deleted inserted replaced
420:b2f2f15cef26 421:7e08b31e0dae
    32 	self assert: compiler lines size = 1.
    32 	self assert: compiler lines size = 1.
    33 	self assert: compiler lines first = '(context peek isAlphaNumeric)'.
    33 	self assert: compiler lines first = '(context peek isAlphaNumeric)'.
    34 !
    34 !
    35 
    35 
    36 testCompiling3
    36 testCompiling3
    37         guard := PPCGuard new initializeFor: ($a asParser, (#letter asParser / #digit asParser)) asCompilerTree.
    37 	guard := PPCGuard new initializeFor: ($a asParser, (#letter asParser / #digit asParser)) asCompilerTree.
    38         guard id: #foo.
    38 	guard id: #foo.
    39         guard compileGuard: compiler.
    39 	guard compileGuard: compiler.
    40         
    40 	
    41         self assert: compiler lines size = 1.
    41 	self assert: compiler lines size = 1.
    42         self assert: compiler lines first = ('(context peek = ', $a storeString ,')').
    42 	self assert: compiler lines first = ('(context peek = ', $a storeString ,')').
    43 
       
    44     "Modified: / 06-11-2014 / 00:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    45 !
    43 !
    46 
    44 
    47 testCompiling4
    45 testCompiling4
    48         guard := PPCGuard new initializeFor: ('foo' asParser / 'foobar' asParser) asCompilerTree.
    46 	guard := PPCGuard new initializeFor: ('foo' asParser / 'foobar' asParser) asCompilerTree.
    49         guard id: #foo.
    47 	guard id: #foo.
    50         guard compileGuard: compiler.
    48 	guard compileGuard: compiler.
    51         
    49 	
    52         self assert: compiler lines size = 1.
    50 	self assert: compiler lines size = 1.
    53         self assert: compiler lines first = ('(context peek = ', $f storeString ,')').
    51 	self assert: compiler lines first = ('(context peek = ', $f storeString ,')').
       
    52 !
    54 
    53 
    55     "Modified: / 06-11-2014 / 00:47:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    54 testIdentifierToken
       
    55 	| id parser |
       
    56 	id := (#letter asParser plus)
       
    57 		name: 'identifier';
       
    58 		yourself.
       
    59 		
       
    60 	parser := id smalltalkToken.
       
    61 	parser name: 'kw'.
       
    62 
       
    63 	guard := PPCGuard new initializeFor: parser asCompilerTree optimizeTree.
       
    64 	self assert: (guard classification at: $a asInteger).
       
    65 	self assert: (guard classification at: $z asInteger).
    56 !
    66 !
    57 
    67 
    58 testMakesSense
    68 testMakesSense
    59 	guard := PPCGuard new initializeFor: #letter asParser.
    69 	guard := PPCGuard new initializeFor: #letter asParser.
    60 	self assert: guard makesSense.
    70 	self assert: guard makesSense.
   104 testNot2
   114 testNot2
   105 	guard := PPCGuard new initializeFor: ('foo' asParser not, 'fee' asParser) asCompilerTree optimizeTree.
   115 	guard := PPCGuard new initializeFor: ('foo' asParser not, 'fee' asParser) asCompilerTree optimizeTree.
   106 	self assert: (guard classification at: $f asInteger).
   116 	self assert: (guard classification at: $f asInteger).
   107 !
   117 !
   108 
   118 
       
   119 testNot3
       
   120 	guard := PPCGuard new initializeFor: (#letter asParser negate star, #letter asParser) asCompilerTree optimizeTree.
       
   121 	self assert: (guard classification allSatisfy: [ :e | e]).
       
   122 !
       
   123 
   109 testTestMessage
   124 testTestMessage
   110 	guard := PPCGuard new initializeFor: #letter asParser asCompilerTree.
   125 	guard := PPCGuard new initializeFor: #letter asParser asCompilerTree.
   111 	self assert: (guard testMessage: #isLetter).
   126 	self assert: (guard testMessage: #isLetter).
   112 	self assert: (guard testMessage: #isAlphaNumeric) not.
   127 	self assert: (guard testMessage: #isAlphaNumeric) not.
   113 	
   128