compiler/tests/PPCGuardTest.st
changeset 391 553a5456963b
child 392 9b297f0d949c
equal deleted inserted replaced
390:17ba167b8ee1 391:553a5456963b
       
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }"
       
     2 
       
     3 TestCase subclass:#PPCGuardTest
       
     4 	instanceVariableNames:'guard compiler'
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitCompiler-Tests-Core'
       
     8 !
       
     9 
       
    10 PPCGuardTest comment:''
       
    11 !
       
    12 
       
    13 !PPCGuardTest methodsFor:'as yet unclassified'!
       
    14 
       
    15 setUp
       
    16 	super setUp.
       
    17 	compiler := PPCMockCompiler new.
       
    18 !
       
    19 
       
    20 testCompiling
       
    21 	guard := PPCGuard new initializeFor: ($a asParser / $b asParser) asCompilerTree.
       
    22 	guard id: #foo.
       
    23 	guard compileGuard: compiler.
       
    24 	
       
    25 	self assert: compiler lines size = 1.
       
    26 	self assert: compiler lines first = '(foo at: context peek asInteger)'.
       
    27 !
       
    28 
       
    29 testCompiling2
       
    30 	guard := PPCGuard new initializeFor: (#letter asParser / #digit asParser) asCompilerTree.
       
    31 	guard id: #foo.
       
    32 	guard compileGuard: compiler.
       
    33 	
       
    34 	self assert: compiler lines size = 1.
       
    35 	self assert: compiler lines first = '(context peek isAlphaNumeric)'.
       
    36 !
       
    37 
       
    38 testCompiling3
       
    39 	guard := PPCGuard new initializeFor: ($a asParser, (#letter asParser / #digit asParser)) asCompilerTree.
       
    40 	guard id: #foo.
       
    41 	guard compileGuard: compiler.
       
    42 	
       
    43 	self assert: compiler lines size = 1.
       
    44 	self assert: compiler lines first = ('(context peek = ', $a printString ,')').
       
    45 !
       
    46 
       
    47 testCompiling4
       
    48 	guard := PPCGuard new initializeFor: ('foo' asParser / 'foobar' asParser) asCompilerTree.
       
    49 	guard id: #foo.
       
    50 	guard compileGuard: compiler.
       
    51 	
       
    52 	self assert: compiler lines size = 1.
       
    53 	self assert: compiler lines first = ('(context peek = ', $f printString ,')').
       
    54 !
       
    55 
       
    56 testMakesSense
       
    57 	guard := PPCGuard new initializeFor: #letter asParser.
       
    58 	self assert: guard makesSense.
       
    59 	
       
    60 	guard := PPCGuard new initializeFor: nil asParser asCompilerTree.
       
    61 	self assert: guard makesSense not.
       
    62 	
       
    63 	guard := PPCGuard new initializeFor: (#letter asParser / nil asParser) asCompilerTree.
       
    64 	self assert: guard makesSense not.
       
    65 	
       
    66 	guard := PPCGuard new initializeFor: (#letter asParser / #digit asParser) asCompilerTree.
       
    67 	self assert: guard makesSense.
       
    68 
       
    69 	guard := PPCGuard new initializeFor: (#letter asParser / #digit asParser star) asCompilerTree.
       
    70 	self assert: guard makesSense not.
       
    71 !
       
    72 
       
    73 testMessage
       
    74 	guard := PPCGuard new initializeFor: #letter asParser asCompilerTree.
       
    75 	self assert: (guard message = #isLetter).
       
    76 	self assert: (guard message = #isAlphaNumeric) not.
       
    77 	
       
    78 	guard := PPCGuard new initializeFor: #word asParser asCompilerTree.
       
    79 	self assert: (guard message = #isAlphaNumeric).
       
    80 	
       
    81 	guard := PPCGuard new initializeFor: #digit asParser asCompilerTree.
       
    82 	self assert: (guard message = #isDigit).
       
    83 	
       
    84 	guard := PPCGuard new initializeFor: 'a' asParser asCompilerTree.
       
    85 	self assert: (guard message = #isDigit) not.
       
    86 	self assert: (guard message = #isLetter) not.
       
    87 	self assert: (guard message = #isAlphaNumeric) not.
       
    88 	
       
    89 !
       
    90 
       
    91 testMessage2
       
    92 	guard := PPCGuard new initializeFor: #letter asParser / #digit asParser.
       
    93 	self assert: guard message = #isAlphaNumeric
       
    94 	
       
    95 !
       
    96 
       
    97 testTestMessage
       
    98 	guard := PPCGuard new initializeFor: #letter asParser.
       
    99 	self assert: (guard testMessage: #isLetter).
       
   100 	self assert: (guard testMessage: #isAlphaNumeric) not.
       
   101 	
       
   102 	guard := PPCGuard new initializeFor: #word asParser.
       
   103 	self assert: (guard testMessage: #isAlphaNumeric).
       
   104 	
       
   105 	guard := PPCGuard new initializeFor: #digit asParser.
       
   106 	self assert: (guard testMessage: #isDigit).
       
   107 	
       
   108 	guard := PPCGuard new initializeFor: 'a' asParser.
       
   109 	self assert: (guard testMessage: #isDigit) not.
       
   110 	self assert: (guard testMessage: #isLetter) not.
       
   111 	self assert: (guard testMessage: #isAlphaNumeric) not.
       
   112 	
       
   113 !
       
   114 
       
   115 testTestSingleCharacter
       
   116 	guard := PPCGuard new initializeFor: $a asParser.
       
   117 	self assert: guard testSingleCharacter.
       
   118 	
       
   119 	guard := PPCGuard new initializeFor: 'foo' asParser.
       
   120 	self assert: guard testSingleCharacter.
       
   121 	
       
   122 	guard := PPCGuard new initializeFor: ('foo' asParser / 'bar' asParser).
       
   123 	self assert: guard testSingleCharacter not.
       
   124 
       
   125 	guard := PPCGuard new initializeFor: ($a asParser, (#letter asParser / #digit asParser)).
       
   126 	self assert: guard testSingleCharacter.
       
   127 ! !
       
   128