PPCompositeParserTest.st
author sr
Thu, 05 Jul 2018 09:23:25 +0200
changeset 626 5159b1039a8f
parent 4 90de244a7fa2
permissions -rw-r--r--
order

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

PPAbstractParseTest subclass:#PPCompositeParserTest
	instanceVariableNames:'parser result'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitTests-Core'
!


!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
! !

!PPCompositeParserTest methodsFor:'parsing'!

fail: aString rule: aSymbol
	| production |
	production := self parserInstance
		productionAt: 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 parserInstance.
	aSymbol = #start
		ifFalse: [ production := production productionAt: aSymbol ].
	result := production parse: aString.
	self
		deny: result isPetitFailure
		description: 'Unable to parse ' , aString printString
		resumable: true.
	^ 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_SVN
    ^ '$Id: PPCompositeParserTest.st,v 1.2 2012-01-13 11:22:50 cg Exp $'
! !