Ported PetitCompiler-(Tests).
Name: PetitCompiler-JanKurs.41
Author: JanKurs
Time: 25-10-2014, 03:30:28 AM
UUID: 105186d1-1187-4ca6-8d66-3d2d47def4d3
Repository: http://smalltalkhub.com/mc/JanKurs/PetitParser/main
Name: PetitCompiler-Tests-JanKurs.4
Author: JanKurs
Time: 25-10-2014, 03:30:58 AM
UUID: 3e798fad-d5f6-4881-a583-f0bbffe27869
Repository: http://smalltalkhub.com/mc/JanKurs/PetitParser/main
In addition, fixed some problems to make it compilable under Smalltalk/X:
* Fixed PPCTokenNode>>initialize - there's no children instvar, it's initialization removed.
* Fixed PPCContextMemento>>propertyAt:ifAbsent: - removed return-in-return, not compilable under Smalltalk/X (C issues)
* Fixed PPCContextMemento>>hash - there's no stream instvar, access to it removed.
* Fixed PPCAbstractCharacterNode>>compileWith:effect:id: - removed dot after method selector (stc does not like it)
"{ Package: 'stx:goodies/petitparser/compiler/tests' }"
TestCase subclass:#PPCGuardTest
instanceVariableNames:'guard compiler'
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Tests-Core'
!
PPCGuardTest comment:''
!
!PPCGuardTest methodsFor:'as yet unclassified'!
setUp
super setUp.
compiler := PPCMockCompiler new.
!
testCompiling
guard := PPCGuard new initializeFor: ($a asParser / $b asParser) asCompilerTree.
guard id: #foo.
guard compileGuard: compiler.
self assert: compiler lines size = 1.
self assert: compiler lines first = '(foo at: context peek asInteger)'.
!
testCompiling2
guard := PPCGuard new initializeFor: (#letter asParser / #digit asParser) asCompilerTree.
guard id: #foo.
guard compileGuard: compiler.
self assert: compiler lines size = 1.
self assert: compiler lines first = '(context peek isAlphaNumeric)'.
!
testCompiling3
guard := PPCGuard new initializeFor: ($a asParser, (#letter asParser / #digit asParser)) asCompilerTree.
guard id: #foo.
guard compileGuard: compiler.
self assert: compiler lines size = 1.
self assert: compiler lines first = ('(context peek = ', $a printString ,')').
!
testCompiling4
guard := PPCGuard new initializeFor: ('foo' asParser / 'foobar' asParser) asCompilerTree.
guard id: #foo.
guard compileGuard: compiler.
self assert: compiler lines size = 1.
self assert: compiler lines first = ('(context peek = ', $f printString ,')').
!
testMakesSense
guard := PPCGuard new initializeFor: #letter asParser.
self assert: guard makesSense.
guard := PPCGuard new initializeFor: nil asParser asCompilerTree.
self assert: guard makesSense not.
guard := PPCGuard new initializeFor: (#letter asParser / nil asParser) asCompilerTree.
self assert: guard makesSense not.
guard := PPCGuard new initializeFor: (#letter asParser / #digit asParser) asCompilerTree.
self assert: guard makesSense.
guard := PPCGuard new initializeFor: (#letter asParser / #digit asParser star) asCompilerTree.
self assert: guard makesSense not.
!
testMessage
guard := PPCGuard new initializeFor: #letter asParser asCompilerTree.
self assert: (guard message = #isLetter).
self assert: (guard message = #isAlphaNumeric) not.
guard := PPCGuard new initializeFor: #word asParser asCompilerTree.
self assert: (guard message = #isAlphaNumeric).
guard := PPCGuard new initializeFor: #digit asParser asCompilerTree.
self assert: (guard message = #isDigit).
guard := PPCGuard new initializeFor: 'a' asParser asCompilerTree.
self assert: (guard message = #isDigit) not.
self assert: (guard message = #isLetter) not.
self assert: (guard message = #isAlphaNumeric) not.
!
testMessage2
guard := PPCGuard new initializeFor: #letter asParser / #digit asParser.
self assert: guard message = #isAlphaNumeric
!
testTestMessage
guard := PPCGuard new initializeFor: #letter asParser.
self assert: (guard testMessage: #isLetter).
self assert: (guard testMessage: #isAlphaNumeric) not.
guard := PPCGuard new initializeFor: #word asParser.
self assert: (guard testMessage: #isAlphaNumeric).
guard := PPCGuard new initializeFor: #digit asParser.
self assert: (guard testMessage: #isDigit).
guard := PPCGuard new initializeFor: 'a' asParser.
self assert: (guard testMessage: #isDigit) not.
self assert: (guard testMessage: #isLetter) not.
self assert: (guard testMessage: #isAlphaNumeric) not.
!
testTestSingleCharacter
guard := PPCGuard new initializeFor: $a asParser.
self assert: guard testSingleCharacter.
guard := PPCGuard new initializeFor: 'foo' asParser.
self assert: guard testSingleCharacter.
guard := PPCGuard new initializeFor: ('foo' asParser / 'bar' asParser).
self assert: guard testSingleCharacter not.
guard := PPCGuard new initializeFor: ($a asParser, (#letter asParser / #digit asParser)).
self assert: guard testSingleCharacter.
! !