PPCompositeParserTest.st
author sr
Wed, 04 Jul 2018 15:23:44 +0200
changeset 604 afe646509162
parent 4 90de244a7fa2
permissions -rw-r--r--
build order was wrong

"{ 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 $'
! !