tests/PPCompositeParserTest.st
changeset 158 6e8ec5d71ae7
child 317 243472b78423
equal deleted inserted replaced
157:46f441ef84a7 158:6e8ec5d71ae7
       
     1 "{ Package: 'stx:goodies/petitparser/tests' }"
       
     2 
       
     3 PPAbstractParserTest subclass:#PPCompositeParserTest
       
     4 	instanceVariableNames:'parser result'
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitTests-Core'
       
     8 !
       
     9 
       
    10 
       
    11 !PPCompositeParserTest class methodsFor:'accessing'!
       
    12 
       
    13 resources
       
    14 	^ Array with: PPParserResource
       
    15 ! !
       
    16 
       
    17 !PPCompositeParserTest class methodsFor:'testing'!
       
    18 
       
    19 isAbstract
       
    20 	^ self name = #PPCompositeParserTest
       
    21 ! !
       
    22 
       
    23 !PPCompositeParserTest methodsFor:'accessing'!
       
    24 
       
    25 parserClass
       
    26 	self subclassResponsibility
       
    27 !
       
    28 
       
    29 parserInstance
       
    30 	^ PPParserResource current parserAt: self parserClass
       
    31 !
       
    32 
       
    33 parserInstanceFor: aSymbol
       
    34 	^ aSymbol = #start
       
    35 		ifTrue: [ self parserInstance ]
       
    36 		ifFalse: [
       
    37 			self parserInstance
       
    38 				productionAt: aSymbol 
       
    39 				ifAbsent: [ self error: 'Production ' , self parserClass name , '>>' , aSymbol printString , ' not found.' ] ]
       
    40 ! !
       
    41 
       
    42 !PPCompositeParserTest methodsFor:'parsing'!
       
    43 
       
    44 fail: aString rule: aSymbol 
       
    45 	| production |
       
    46 	production := self parserInstanceFor: aSymbol.
       
    47 	result := production end parse: aString.
       
    48 	self
       
    49 		assert: result isPetitFailure
       
    50 		description: 'Able to parse ' , aString printString.
       
    51 	^ result
       
    52 !
       
    53 
       
    54 parse: aString 
       
    55 	^ self parse: aString rule: #start
       
    56 !
       
    57 
       
    58 parse: aString rule: aSymbol
       
    59 	| production |
       
    60 	production := self parserInstanceFor: aSymbol.
       
    61 	result := production end parse: aString.
       
    62 	self
       
    63 		deny: result isPetitFailure
       
    64 		description: 'Unable to parse ' , aString printString.
       
    65 	^ result
       
    66 ! !
       
    67 
       
    68 !PPCompositeParserTest methodsFor:'running'!
       
    69 
       
    70 setUp
       
    71 	super setUp.
       
    72 	parser := self parserInstance
       
    73 !
       
    74 
       
    75 tearDown
       
    76 	super tearDown.
       
    77 	parser := result := nil
       
    78 ! !
       
    79 
       
    80 !PPCompositeParserTest methodsFor:'utilities'!
       
    81 
       
    82 assert: aCollection is: anObject
       
    83 	self parse: aCollection.
       
    84 	self
       
    85 		assert: result = anObject
       
    86 		description: 'Got: ' , result printString , '; Expected: ' , anObject printString
       
    87 		resumable: true
       
    88 ! !
       
    89 
       
    90 !PPCompositeParserTest class methodsFor:'documentation'!
       
    91 
       
    92 version
       
    93     ^ '$Header: /cvs/stx/stx/goodies/petitparser/tests/PPCompositeParserTest.st,v 1.1 2014-03-04 14:03:22 cg Exp $'
       
    94 !
       
    95 
       
    96 version_CVS
       
    97     ^ '$Header: /cvs/stx/stx/goodies/petitparser/tests/PPCompositeParserTest.st,v 1.1 2014-03-04 14:03:22 cg Exp $'
       
    98 !
       
    99 
       
   100 version_SVN
       
   101     ^ '$Id: PPCompositeParserTest.st,v 1.1 2014-03-04 14:03:22 cg Exp $'
       
   102 ! !
       
   103