tests/PPCompositeParserTest.st
author sr
Wed, 04 Jul 2018 15:23:55 +0200
changeset 607 019302eb9dd9
parent 565 e2529c410388
permissions -rw-r--r--
build order was wrong

"{ Package: 'stx:goodies/petitparser/tests' }"

"{ NameSpace: Smalltalk }"

PPAbstractParserTest subclass:#PPCompositeParserTest
	instanceVariableNames:'parser result'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitTests-Tests'
!


!PPCompositeParserTest class methodsFor:'accessing'!

resources
	^ Array with: PPParserResource
! !

!PPCompositeParserTest class methodsFor:'testing'!

isAbstract
	^ self name = #PPCompositeParserTest
! !

!PPCompositeParserTest methodsFor:'accessing'!

parserClass
	self subclassResponsibility
!

parserInstance
	^ PPParserResource current parserAt: self parserClass
!

parserInstanceFor: aSymbol
	^ aSymbol = #start
		ifTrue: [ self parserInstance ]
		ifFalse: [
			self parserInstance
				productionAt: aSymbol 
				ifAbsent: [ self error: 'Production ' , self parserClass name , '>>' , aSymbol printString , ' not found.' ] ]
! !

!PPCompositeParserTest methodsFor:'parsing'!

fail: aString rule: aSymbol 
	| production |
	production := self parserInstanceFor: aSymbol.
	result := production end parse: aString.
	self
		assert: result isPetitFailure
		description: 'Able to parse ' , aString printString.
	^ result
!

parse: aString 
	^ self parse: aString rule: #start
!

parse: aString rule: aSymbol
	| production |
	production := self parserInstanceFor: aSymbol.
	result := production end parse: aString.
	self
		deny: result isPetitFailure
		description: 'Unable to parse ' , aString printString.
	^ result
! !

!PPCompositeParserTest methodsFor:'running'!

setUp
	super setUp.
	parser := self parserInstance
!

tearDown
	super tearDown.
	parser := result := nil
! !

!PPCompositeParserTest methodsFor:'utilities'!

assert: aCollection is: anObject
	self parse: aCollection.
	self
		assert: result = anObject
		description: 'Got: ' , result printString , '; Expected: ' , anObject printString
		resumable: true
! !

!PPCompositeParserTest class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
!

version_SVN
    ^ '$Id$'
! !